diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/core/src/lombok/RunTestsViaDelombok.java | 67 | ||||
-rw-r--r-- | test/transform/resource/after-delombok/SuperBuilderCustomName.java (renamed from test/transform/resource/after-delombok/BuilderCustomName.java) | 20 | ||||
-rw-r--r-- | test/transform/resource/after-ecj/SuperBuilderCustomName.java (renamed from test/transform/resource/after-ecj/BuilderCustomName.java) | 20 | ||||
-rw-r--r-- | test/transform/resource/before/SuperBuilderCustomName.java (renamed from test/transform/resource/before/BuilderCustomName.java) | 2 | ||||
-rw-r--r-- | test/transform/resource/messages-delombok/NonNullPlain.java.messages | 4 |
5 files changed, 91 insertions, 22 deletions
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index e4eb1a30..adfb1fce 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -29,9 +29,12 @@ import java.io.PrintStream; import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayDeque; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Deque; +import java.util.IdentityHashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -56,6 +59,7 @@ import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.tree.JCTree.JCIdent; import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCModifiers; +import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.tree.JCTree.TypeBoundKind; import com.sun.tools.javac.tree.TreeScanner; @@ -81,6 +85,7 @@ public class RunTestsViaDelombok extends AbstractRunTests { if (checkPositions) delombok.addAdditionalAnnotationProcessor(new ValidatePositionProcessor(version)); delombok.addAdditionalAnnotationProcessor(new ValidateTypesProcessor()); + delombok.addAdditionalAnnotationProcessor(new ValidateNoDuplicateTreeNodeProcessor()); delombok.addFile(file.getAbsoluteFile().getParentFile(), file.getName()); delombok.setSourcepath(file.getAbsoluteFile().getParent()); @@ -232,6 +237,68 @@ public class RunTestsViaDelombok extends AbstractRunTests { } } + public static class ValidateNoDuplicateTreeNodeProcessor extends TreeProcessor { + + private String craftFailMsg(Collection<JCTree> astContext) { + StringBuilder msg = new StringBuilder(); + for (JCTree t : astContext) { + msg.append("\n ").append(t.getClass().getSimpleName()); + String asStr = t.toString(); + if (asStr.length() < 80) msg.append(": ").append(asStr); + else if (t instanceof JCClassDecl) msg.append(": ").append(((JCClassDecl) t).name); + else if (t instanceof JCMethodDecl) msg.append(": ").append(((JCMethodDecl) t).name); + else if (t instanceof JCVariableDecl) msg.append(": ").append(((JCVariableDecl) t).name); + } + return msg.append("\n-------").toString(); + } + + @Override + void processCompilationUnit(JCCompilationUnit unit) { + final Deque<JCTree> parents = new ArrayDeque<JCTree>(); + parents.add(unit); + + final Map<JCTree, List<JCTree>> knownTreeNode = new IdentityHashMap<JCTree, List<JCTree>>(); + + unit.accept(new TreeScanner() { + private JCTree parent; + + @Override + public void scan(JCTree tree) { + parent = parents.peek(); + + if (tree == null) return; + if (tree instanceof JCPrimitiveTypeTree) return; + // javac generates duplicates for record members + if (tree instanceof JCVariableDecl && (((JCVariableDecl) tree).mods.flags & Javac.GENERATED_MEMBER) != 0) return; + + List<JCTree> knownNodeContext = knownTreeNode.put(tree, new ArrayList<JCTree>(parents)); + if (knownNodeContext != null) { + // javac generates two JCVariableDecl elements for 'int a, b;' + if (parent instanceof JCVariableDecl) { + if (tree instanceof JCModifiers) return; + if (tree instanceof JCIdent) return; + } + + fail("Node " + tree + " found twice:" + craftFailMsg(knownNodeContext) + craftFailMsg(parents)); + } + + parents.push(tree); + super.scan(tree); + parents.pop(); + } + + /** + * We always generate shallow copies for annotations + */ + @Override + public void visitAnnotation(JCAnnotation tree) { + return; + } + }); + } + + } + public static abstract class TreeProcessor extends AbstractProcessor { private Trees trees; @Override public synchronized void init(ProcessingEnvironment processingEnv) { diff --git a/test/transform/resource/after-delombok/BuilderCustomName.java b/test/transform/resource/after-delombok/SuperBuilderCustomName.java index 900fbb03..cad2716c 100644 --- a/test/transform/resource/after-delombok/BuilderCustomName.java +++ b/test/transform/resource/after-delombok/SuperBuilderCustomName.java @@ -1,8 +1,8 @@ import java.util.List; -class BuilderCustomName<T> { +class SuperBuilderCustomName<T> { private final int field; @java.lang.SuppressWarnings("all") - public static abstract class SimpleTestBuilder<T, C extends BuilderCustomName<T>, B extends BuilderCustomName.SimpleTestBuilder<T, C, B>> { + public static abstract class SimpleTestBuilder<T, C extends SuperBuilderCustomName<T>, B extends SuperBuilderCustomName.SimpleTestBuilder<T, C, B>> { @java.lang.SuppressWarnings("all") private int field; /** @@ -20,31 +20,31 @@ class BuilderCustomName<T> { @java.lang.Override @java.lang.SuppressWarnings("all") public java.lang.String toString() { - return "BuilderCustomName.SimpleTestBuilder(field=" + this.field + ")"; + return "SuperBuilderCustomName.SimpleTestBuilder(field=" + this.field + ")"; } } @java.lang.SuppressWarnings("all") - private static final class SimpleTestBuilderImpl<T> extends BuilderCustomName.SimpleTestBuilder<T, BuilderCustomName<T>, BuilderCustomName.SimpleTestBuilderImpl<T>> { + private static final class SimpleTestBuilderImpl<T> extends SuperBuilderCustomName.SimpleTestBuilder<T, SuperBuilderCustomName<T>, SuperBuilderCustomName.SimpleTestBuilderImpl<T>> { @java.lang.SuppressWarnings("all") private SimpleTestBuilderImpl() { } @java.lang.Override @java.lang.SuppressWarnings("all") - protected BuilderCustomName.SimpleTestBuilderImpl<T> self() { + protected SuperBuilderCustomName.SimpleTestBuilderImpl<T> self() { return this; } @java.lang.Override @java.lang.SuppressWarnings("all") - public BuilderCustomName<T> build() { - return new BuilderCustomName<T>(this); + public SuperBuilderCustomName<T> build() { + return new SuperBuilderCustomName<T>(this); } } @java.lang.SuppressWarnings("all") - protected BuilderCustomName(final BuilderCustomName.SimpleTestBuilder<T, ?, ?> b) { + protected SuperBuilderCustomName(final SuperBuilderCustomName.SimpleTestBuilder<T, ?, ?> b) { this.field = b.field; } @java.lang.SuppressWarnings("all") - public static <T> BuilderCustomName.SimpleTestBuilder<T, ?, ?> builder() { - return new BuilderCustomName.SimpleTestBuilderImpl<T>(); + public static <T> SuperBuilderCustomName.SimpleTestBuilder<T, ?, ?> builder() { + return new SuperBuilderCustomName.SimpleTestBuilderImpl<T>(); } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderCustomName.java b/test/transform/resource/after-ecj/SuperBuilderCustomName.java index cb578ccd..fc834090 100644 --- a/test/transform/resource/after-ecj/BuilderCustomName.java +++ b/test/transform/resource/after-ecj/SuperBuilderCustomName.java @@ -1,6 +1,6 @@ import java.util.List; -@lombok.experimental.SuperBuilder class BuilderCustomName<T> { - public static abstract @java.lang.SuppressWarnings("all") class SimpleTestBuilder<T, C extends BuilderCustomName<T>, B extends BuilderCustomName.SimpleTestBuilder<T, C, B>> { +@lombok.experimental.SuperBuilder class SuperBuilderCustomName<T> { + public static abstract @java.lang.SuppressWarnings("all") class SimpleTestBuilder<T, C extends SuperBuilderCustomName<T>, B extends SuperBuilderCustomName.SimpleTestBuilder<T, C, B>> { private @java.lang.SuppressWarnings("all") int field; public SimpleTestBuilder() { super(); @@ -15,26 +15,26 @@ import java.util.List; protected abstract @java.lang.SuppressWarnings("all") B self(); public abstract @java.lang.SuppressWarnings("all") C build(); public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { - return (("BuilderCustomName.SimpleTestBuilder(field=" + this.field) + ")"); + return (("SuperBuilderCustomName.SimpleTestBuilder(field=" + this.field) + ")"); } } - private static final @java.lang.SuppressWarnings("all") class SimpleTestBuilderImpl<T> extends BuilderCustomName.SimpleTestBuilder<T, BuilderCustomName<T>, BuilderCustomName.SimpleTestBuilderImpl<T>> { + private static final @java.lang.SuppressWarnings("all") class SimpleTestBuilderImpl<T> extends SuperBuilderCustomName.SimpleTestBuilder<T, SuperBuilderCustomName<T>, SuperBuilderCustomName.SimpleTestBuilderImpl<T>> { private SimpleTestBuilderImpl() { super(); } - protected @java.lang.Override @java.lang.SuppressWarnings("all") BuilderCustomName.SimpleTestBuilderImpl<T> self() { + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomName.SimpleTestBuilderImpl<T> self() { return this; } - public @java.lang.Override @java.lang.SuppressWarnings("all") BuilderCustomName<T> build() { - return new BuilderCustomName<T>(this); + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomName<T> build() { + return new SuperBuilderCustomName<T>(this); } } private final int field; - protected @java.lang.SuppressWarnings("all") BuilderCustomName(final BuilderCustomName.SimpleTestBuilder<T, ?, ?> b) { + protected @java.lang.SuppressWarnings("all") SuperBuilderCustomName(final SuperBuilderCustomName.SimpleTestBuilder<T, ?, ?> b) { super(); this.field = b.field; } - public static @java.lang.SuppressWarnings("all") <T>BuilderCustomName.SimpleTestBuilder<T, ?, ?> builder() { - return new BuilderCustomName.SimpleTestBuilderImpl<T>(); + public static @java.lang.SuppressWarnings("all") <T>SuperBuilderCustomName.SimpleTestBuilder<T, ?, ?> builder() { + return new SuperBuilderCustomName.SimpleTestBuilderImpl<T>(); } } diff --git a/test/transform/resource/before/BuilderCustomName.java b/test/transform/resource/before/SuperBuilderCustomName.java index d5709e63..7308e282 100644 --- a/test/transform/resource/before/BuilderCustomName.java +++ b/test/transform/resource/before/SuperBuilderCustomName.java @@ -2,6 +2,6 @@ import java.util.List; @lombok.experimental.SuperBuilder -class BuilderCustomName<T> { +class SuperBuilderCustomName<T> { private final int field; } diff --git a/test/transform/resource/messages-delombok/NonNullPlain.java.messages b/test/transform/resource/messages-delombok/NonNullPlain.java.messages index 7b0c540b..385efa23 100644 --- a/test/transform/resource/messages-delombok/NonNullPlain.java.messages +++ b/test/transform/resource/messages-delombok/NonNullPlain.java.messages @@ -1 +1,3 @@ -5 @NonNull is meaningless on a primitive.
\ No newline at end of file +8 @NonNull is meaningless on a primitive. +4 @NonNull is meaningless on a primitive. +6 @NonNull is meaningless on a primitive.
\ No newline at end of file |