From ec16696e47b91bf3f522611a4c3e9bf1d2d7bd1d Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Mon, 12 Feb 2024 10:29:53 +0000 Subject: [PATCH 1/2] Fix type detection of nested annotations This commit fixes type detection of java annotations that are nested within the annotated class. A simple example of this can be seen in the test class `SimpleNestedAnnotation.java`. --- src/core/lombok/core/TypeResolver.java | 105 ++++++++++++++++-- test/stubs/test/lombok/other/Other.java | 11 ++ ...sAndAnnotationNestedInImportedSibling.java | 35 ++++++ ...dAnnotationNestedInNonImportedSibling.java | 32 ++++++ .../NestedClassAndNestedAnnotation.java | 27 +++++ ...estedClassAndNestedAnnotationImported.java | 33 ++++++ ...AnnotationWithConflictingNestedImport.java | 31 ++++++ ...nWithOverridingNestedAnnotationImport.java | 31 ++++++ .../SimpleNestedAnnotation.java | 25 +++++ .../TwiceNestedClassAndSiblingAnnotation.java | 34 ++++++ .../TwiceNestedClassAndUpperAnnotation.java | 30 +++++ ...sAndAnnotationNestedInImportedSibling.java | 34 ++++++ ...dAnnotationNestedInNonImportedSibling.java | 32 ++++++ .../NestedClassAndNestedAnnotation.java | 22 ++++ ...estedClassAndNestedAnnotationImported.java | 33 ++++++ ...AnnotationWithConflictingNestedImport.java | 28 +++++ ...nWithOverridingNestedAnnotationImport.java | 28 +++++ .../after-ecj/SimpleNestedAnnotation.java | 17 +++ .../TwiceNestedClassAndSiblingAnnotation.java | 29 +++++ .../TwiceNestedClassAndUpperAnnotation.java | 27 +++++ ...sAndAnnotationNestedInImportedSibling.java | 26 +++++ ...dAnnotationNestedInNonImportedSibling.java | 25 +++++ .../NestedClassAndNestedAnnotation.java | 20 ++++ ...estedClassAndNestedAnnotationImported.java | 26 +++++ ...AnnotationWithConflictingNestedImport.java | 23 ++++ ...nWithOverridingNestedAnnotationImport.java | 23 ++++ .../before/SimpleNestedAnnotation.java | 17 +++ .../TwiceNestedClassAndSiblingAnnotation.java | 26 +++++ .../TwiceNestedClassAndUpperAnnotation.java | 23 ++++ 29 files changed, 846 insertions(+), 7 deletions(-) create mode 100644 test/stubs/test/lombok/other/Other.java create mode 100644 test/transform/resource/after-delombok/NestedClassAndAnnotationNestedInImportedSibling.java create mode 100644 test/transform/resource/after-delombok/NestedClassAndAnnotationNestedInNonImportedSibling.java create mode 100644 test/transform/resource/after-delombok/NestedClassAndNestedAnnotation.java create mode 100644 test/transform/resource/after-delombok/NestedClassAndNestedAnnotationImported.java create mode 100644 test/transform/resource/after-delombok/NestedClassAndNestedAnnotationWithConflictingNestedImport.java create mode 100644 test/transform/resource/after-delombok/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java create mode 100644 test/transform/resource/after-delombok/SimpleNestedAnnotation.java create mode 100644 test/transform/resource/after-delombok/TwiceNestedClassAndSiblingAnnotation.java create mode 100644 test/transform/resource/after-delombok/TwiceNestedClassAndUpperAnnotation.java create mode 100644 test/transform/resource/after-ecj/NestedClassAndAnnotationNestedInImportedSibling.java create mode 100644 test/transform/resource/after-ecj/NestedClassAndAnnotationNestedInNonImportedSibling.java create mode 100644 test/transform/resource/after-ecj/NestedClassAndNestedAnnotation.java create mode 100644 test/transform/resource/after-ecj/NestedClassAndNestedAnnotationImported.java create mode 100644 test/transform/resource/after-ecj/NestedClassAndNestedAnnotationWithConflictingNestedImport.java create mode 100644 test/transform/resource/after-ecj/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java create mode 100644 test/transform/resource/after-ecj/SimpleNestedAnnotation.java create mode 100644 test/transform/resource/after-ecj/TwiceNestedClassAndSiblingAnnotation.java create mode 100644 test/transform/resource/after-ecj/TwiceNestedClassAndUpperAnnotation.java create mode 100644 test/transform/resource/before/NestedClassAndAnnotationNestedInImportedSibling.java create mode 100644 test/transform/resource/before/NestedClassAndAnnotationNestedInNonImportedSibling.java create mode 100644 test/transform/resource/before/NestedClassAndNestedAnnotation.java create mode 100644 test/transform/resource/before/NestedClassAndNestedAnnotationImported.java create mode 100644 test/transform/resource/before/NestedClassAndNestedAnnotationWithConflictingNestedImport.java create mode 100644 test/transform/resource/before/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java create mode 100644 test/transform/resource/before/SimpleNestedAnnotation.java create mode 100644 test/transform/resource/before/TwiceNestedClassAndSiblingAnnotation.java create mode 100644 test/transform/resource/before/TwiceNestedClassAndUpperAnnotation.java diff --git a/src/core/lombok/core/TypeResolver.java b/src/core/lombok/core/TypeResolver.java index 4f2df72e0f..f906960ebd 100644 --- a/src/core/lombok/core/TypeResolver.java +++ b/src/core/lombok/core/TypeResolver.java @@ -21,6 +21,8 @@ */ package lombok.core; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import lombok.core.AST.Kind; @@ -32,7 +34,7 @@ * and this importer also can't find inner types from superclasses/interfaces. */ public class TypeResolver { - private ImportList imports; + private final ImportList imports; /** * Creates a new TypeResolver that can be used to resolve types in a source file with the given package and import statements. @@ -53,6 +55,14 @@ public String typeRefToFullyQualifiedName(LombokNode context, TypeLibra // When asking if 'lombok.Getter' could possibly be referring to 'lombok.Getter', the answer is obviously yes. if (qualifieds.contains(typeRef)) return LombokInternalAliasing.processAliases(typeRef); + // Types defined on the containing type, or on any of its parents in the source file, take precedence over any imports + String nestedTypeFqn = new NestedTypeFinder(typeRef).findNestedType(context); + if (nestedTypeFqn != null) { + // we found a nestedType - check edge case where nestedType is in type library + qualifieds = library.toQualifieds(nestedTypeFqn); + return qualifieds == null || !qualifieds.contains(nestedTypeFqn) ? null : nestedTypeFqn; + } + // When asking if 'Getter' could possibly be referring to 'lombok.Getter' if 'import lombok.Getter;' is in the source file, the answer is yes. int firstDot = typeRef.indexOf('.'); if (firstDot == -1) firstDot = typeRef.length(); @@ -96,12 +106,7 @@ public String typeRefToFullyQualifiedName(LombokNode context, TypeLibra continue mainLoop; } - if (n.getKind() == Kind.TYPE || n.getKind() == Kind.COMPILATION_UNIT) { - for (LombokNode child : n.down()) { - // Inner class that's visible to us has 'typeRef' as name, so that's the one being referred to, not one of our type library classes. - if (child.getKind() == Kind.TYPE && firstTypeRef.equals(child.getName())) return null; - } - } + // don't need to check for inner class shadowing, we already do that in NestedTypeFinder n = n.directUp(); } @@ -113,4 +118,90 @@ public String typeRefToFullyQualifiedName(LombokNode context, TypeLibra // No star import matches either. return null; } + + /** + * Traverse up the containing types until we find a match, or hit the package. At each level, + * we check for a type with matching name (including traversing into child types if typeRef is + * not a simple name). + */ + private static class NestedTypeFinder { + + private final String typeRef; + private final List typeRefElements; + + public NestedTypeFinder(String typeRef) { + this.typeRef = typeRef; + this.typeRefElements = Arrays.asList(typeRef.split("\\.", -1)); + } + + /** Finds a matching nestedType and returns its FQN, or {@code null} if no match found. */ + public String findNestedType(LombokNode context) { + LombokNode nearestType = traverseUpToNearestType(context); + if (nearestType == null) { + return null; + } + + boolean found = findTypeRef(nearestType, 0); + if (found) { + // return FQN + return getFoundFqn(nearestType); + } + + return findNestedType(nearestType.up()); + } + + /** Traverse up to the nearest type or package (including {@code node} if it is a type). */ + private LombokNode traverseUpToNearestType(LombokNode node) { + if (node == null) { + return null; // parent is null once we hit the package + } + if (node.getKind() == Kind.COMPILATION_UNIT || node.getKind() == Kind.TYPE) { + return node; + } + return traverseUpToNearestType(node.up()); + } + + /** Check whether {@code typeRef[nameIndex]} exists as a child of {@code typeNode}. */ + private boolean findTypeRef(LombokNode typeNode, int nameIndex) { + for (LombokNode child : typeNode.down()) { + if (child.getKind() == Kind.TYPE) { + // check if this node matches the first element + if (child.getName().equals(typeRefElements.get(nameIndex))) { + if (nameIndex == typeRefElements.size() - 1) { + // we've found a match as we've matched all elements of typeRef + return true; + } + // otherwise, check match of remaining typeRef elements + boolean found = findTypeRef(child, nameIndex + 1); + if (found) { + return true; + } + } + } + } + return false; + } + + private String getFoundFqn(LombokNode typeNode) { + List elements = new ArrayList(); + while (typeNode.getKind() != Kind.COMPILATION_UNIT) { + elements.add(typeNode.getName()); + typeNode = traverseUpToNearestType(typeNode.up()); + } + + String pkg = typeNode.getPackageDeclaration(); + StringBuilder fqn; + if (pkg == null) { // pkg can be null e.g. if top-level type is in default package + fqn = new StringBuilder(elements.size() * 10); + } else { + fqn = new StringBuilder(pkg.length() + elements.size() * 10); + fqn.append(pkg).append('.'); + } + for (int i = elements.size() - 1; i >= 0; i--) { + fqn.append(elements.get(i)).append('.'); + } + fqn.append(typeRef); + return fqn.toString(); + } + } } diff --git a/test/stubs/test/lombok/other/Other.java b/test/stubs/test/lombok/other/Other.java new file mode 100644 index 0000000000..2a29a0df6b --- /dev/null +++ b/test/stubs/test/lombok/other/Other.java @@ -0,0 +1,11 @@ +package test.lombok.other; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class Other { + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } +} diff --git a/test/transform/resource/after-delombok/NestedClassAndAnnotationNestedInImportedSibling.java b/test/transform/resource/after-delombok/NestedClassAndAnnotationNestedInImportedSibling.java new file mode 100644 index 0000000000..1424231c07 --- /dev/null +++ b/test/transform/resource/after-delombok/NestedClassAndAnnotationNestedInImportedSibling.java @@ -0,0 +1,35 @@ +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import test.lombok.NestedClassAndAnnotationNestedInImportedSibling.Other.OtherNested.TA; + +public class NestedClassAndAnnotationNestedInImportedSibling { + + public static class Inner { + + @TA + private final int someVal; + + @java.lang.SuppressWarnings("all") + public Inner(@TA final int someVal) { + this.someVal = someVal; + } + + @TA + @java.lang.SuppressWarnings("all") + public int getSomeVal() { + return this.someVal; + } + } + + public static class Other { + + public static class OtherNested { + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } + } + } +} diff --git a/test/transform/resource/after-delombok/NestedClassAndAnnotationNestedInNonImportedSibling.java b/test/transform/resource/after-delombok/NestedClassAndAnnotationNestedInNonImportedSibling.java new file mode 100644 index 0000000000..68ec9b5c72 --- /dev/null +++ b/test/transform/resource/after-delombok/NestedClassAndAnnotationNestedInNonImportedSibling.java @@ -0,0 +1,32 @@ +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class NestedClassAndAnnotationNestedInNonImportedSibling { + + public static class Inner { + @Other.OtherNested.TA + private final int someVal; + + @java.lang.SuppressWarnings("all") + public Inner(@Other.OtherNested.TA final int someVal) { + this.someVal = someVal; + } + + @Other.OtherNested.TA + @java.lang.SuppressWarnings("all") + public int getSomeVal() { + return this.someVal; + } + } + + public static class Other { + + public static class OtherNested { + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } + } + } +} diff --git a/test/transform/resource/after-delombok/NestedClassAndNestedAnnotation.java b/test/transform/resource/after-delombok/NestedClassAndNestedAnnotation.java new file mode 100644 index 0000000000..ccaff1cd0e --- /dev/null +++ b/test/transform/resource/after-delombok/NestedClassAndNestedAnnotation.java @@ -0,0 +1,27 @@ +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class NestedClassAndNestedAnnotation { + + public static class Inner { + @TA + private final int someVal; + + @java.lang.SuppressWarnings("all") + public Inner(@TA final int someVal) { + this.someVal = someVal; + } + + @TA + @java.lang.SuppressWarnings("all") + public int getSomeVal() { + return this.someVal; + } + } + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } +} diff --git a/test/transform/resource/after-delombok/NestedClassAndNestedAnnotationImported.java b/test/transform/resource/after-delombok/NestedClassAndNestedAnnotationImported.java new file mode 100644 index 0000000000..1398359a29 --- /dev/null +++ b/test/transform/resource/after-delombok/NestedClassAndNestedAnnotationImported.java @@ -0,0 +1,33 @@ +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import test.lombok.NestedClassAndNestedAnnotationImported.Other.OtherNested.TA; + +public class NestedClassAndNestedAnnotationImported { + + public static class Inner { + @TA + private final int someVal; + + @java.lang.SuppressWarnings("all") + public Inner(@TA final int someVal) { + this.someVal = someVal; + } + + @TA + @java.lang.SuppressWarnings("all") + public int getSomeVal() { + return this.someVal; + } + } + + public static class Other { + + public static class OtherNested { + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } + } + } +} diff --git a/test/transform/resource/after-delombok/NestedClassAndNestedAnnotationWithConflictingNestedImport.java b/test/transform/resource/after-delombok/NestedClassAndNestedAnnotationWithConflictingNestedImport.java new file mode 100644 index 0000000000..05dd724dc9 --- /dev/null +++ b/test/transform/resource/after-delombok/NestedClassAndNestedAnnotationWithConflictingNestedImport.java @@ -0,0 +1,31 @@ +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import test.lombok.other.Other; + +public class NestedClassAndNestedAnnotationWithConflictingNestedImport { + + public static class Inner { + @Other.TA + private final int someVal; + + @java.lang.SuppressWarnings("all") + public Inner(@Other.TA final int someVal) { + this.someVal = someVal; + } + + @Other.TA + @java.lang.SuppressWarnings("all") + public int getSomeVal() { + return this.someVal; + } + } + + public static class Other { + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } + } +} diff --git a/test/transform/resource/after-delombok/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java b/test/transform/resource/after-delombok/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java new file mode 100644 index 0000000000..437440eeb8 --- /dev/null +++ b/test/transform/resource/after-delombok/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java @@ -0,0 +1,31 @@ +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import test.lombok.other.Other.TA; + +public class NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport { + + public static class Inner { + @TA + private final int someVal; + + @java.lang.SuppressWarnings("all") + public Inner(@TA final int someVal) { + this.someVal = someVal; + } + + @TA + @java.lang.SuppressWarnings("all") + public int getSomeVal() { + return this.someVal; + } + } + + public static class Other { + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } + } +} diff --git a/test/transform/resource/after-delombok/SimpleNestedAnnotation.java b/test/transform/resource/after-delombok/SimpleNestedAnnotation.java new file mode 100644 index 0000000000..fede9a0239 --- /dev/null +++ b/test/transform/resource/after-delombok/SimpleNestedAnnotation.java @@ -0,0 +1,25 @@ +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class SimpleNestedAnnotation { + + @TA + private final int someVal; + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } + + @java.lang.SuppressWarnings("all") + public SimpleNestedAnnotation(@TA final int someVal) { + this.someVal = someVal; + } + + @TA + @java.lang.SuppressWarnings("all") + public int getSomeVal() { + return this.someVal; + } +} diff --git a/test/transform/resource/after-delombok/TwiceNestedClassAndSiblingAnnotation.java b/test/transform/resource/after-delombok/TwiceNestedClassAndSiblingAnnotation.java new file mode 100644 index 0000000000..c8416748f2 --- /dev/null +++ b/test/transform/resource/after-delombok/TwiceNestedClassAndSiblingAnnotation.java @@ -0,0 +1,34 @@ +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class TwiceNestedClassAndSiblingAnnotation { + + public static class Other { + + public static class OtherInner { + @TA + private final int someVal; + + @java.lang.SuppressWarnings("all") + public OtherInner(@TA final int someVal) { + this.someVal = someVal; + } + + @TA + @java.lang.SuppressWarnings("all") + public int getSomeVal() { + return this.someVal; + } + } + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } + } + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } +} diff --git a/test/transform/resource/after-delombok/TwiceNestedClassAndUpperAnnotation.java b/test/transform/resource/after-delombok/TwiceNestedClassAndUpperAnnotation.java new file mode 100644 index 0000000000..273f564ddd --- /dev/null +++ b/test/transform/resource/after-delombok/TwiceNestedClassAndUpperAnnotation.java @@ -0,0 +1,30 @@ +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class TwiceNestedClassAndUpperAnnotation { + + public static class Other { + + public static class OtherInner { + @TA + private final int someVal; + + @java.lang.SuppressWarnings("all") + public OtherInner(@TA final int someVal) { + this.someVal = someVal; + } + + @TA + @java.lang.SuppressWarnings("all") + public int getSomeVal() { + return this.someVal; + } + } + } + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA { + } +} diff --git a/test/transform/resource/after-ecj/NestedClassAndAnnotationNestedInImportedSibling.java b/test/transform/resource/after-ecj/NestedClassAndAnnotationNestedInImportedSibling.java new file mode 100644 index 0000000000..ed79313221 --- /dev/null +++ b/test/transform/resource/after-ecj/NestedClassAndAnnotationNestedInImportedSibling.java @@ -0,0 +1,34 @@ +package test.lombok; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import test.lombok.NestedClassAndAnnotationNestedInImportedSibling.Other.OtherNested.TA; +public class NestedClassAndAnnotationNestedInImportedSibling { + public static @RequiredArgsConstructor @Getter class Inner { + private final @TA int someVal; + + public @java.lang.SuppressWarnings("all") Inner(final @TA int someVal) { + super(); + this.someVal = someVal; + } + public @TA @java.lang.SuppressWarnings("all") int getSomeVal() { + return this.someVal; + } + } + public static class Other { + public static class OtherNested { + public @Retention(RetentionPolicy.RUNTIME) @interface TA { + } + public OtherNested() { + super(); + } + } + public Other() { + super(); + } + } + public NestedClassAndAnnotationNestedInImportedSibling() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/NestedClassAndAnnotationNestedInNonImportedSibling.java b/test/transform/resource/after-ecj/NestedClassAndAnnotationNestedInNonImportedSibling.java new file mode 100644 index 0000000000..d293010cb7 --- /dev/null +++ b/test/transform/resource/after-ecj/NestedClassAndAnnotationNestedInNonImportedSibling.java @@ -0,0 +1,32 @@ +package test.lombok; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +public class NestedClassAndAnnotationNestedInNonImportedSibling { + public static @RequiredArgsConstructor @Getter class Inner { + private final @Other.OtherNested.TA int someVal; + public @java.lang.SuppressWarnings("all") Inner(final @Other.OtherNested.TA int someVal) { + super(); + this.someVal = someVal; + } + public @Other.OtherNested.TA @java.lang.SuppressWarnings("all") int getSomeVal() { + return this.someVal; + } + } + public static class Other { + public static class OtherNested { + public @Retention(RetentionPolicy.RUNTIME) @interface TA { + } + public OtherNested() { + super(); + } + } + public Other() { + super(); + } + } + public NestedClassAndAnnotationNestedInNonImportedSibling() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/NestedClassAndNestedAnnotation.java b/test/transform/resource/after-ecj/NestedClassAndNestedAnnotation.java new file mode 100644 index 0000000000..ac0d2215f7 --- /dev/null +++ b/test/transform/resource/after-ecj/NestedClassAndNestedAnnotation.java @@ -0,0 +1,22 @@ +package test.lombok; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +public class NestedClassAndNestedAnnotation { + public static @RequiredArgsConstructor @Getter class Inner { + private final @TA int someVal; + public @java.lang.SuppressWarnings("all") Inner(final @TA int someVal) { + super(); + this.someVal = someVal; + } + public @TA @java.lang.SuppressWarnings("all") int getSomeVal() { + return this.someVal; + } + } + public @Retention(RetentionPolicy.RUNTIME) @interface TA { + } + public NestedClassAndNestedAnnotation() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/NestedClassAndNestedAnnotationImported.java b/test/transform/resource/after-ecj/NestedClassAndNestedAnnotationImported.java new file mode 100644 index 0000000000..52e9c3b6b5 --- /dev/null +++ b/test/transform/resource/after-ecj/NestedClassAndNestedAnnotationImported.java @@ -0,0 +1,33 @@ +package test.lombok; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import test.lombok.NestedClassAndNestedAnnotationImported.Other.OtherNested.TA; +public class NestedClassAndNestedAnnotationImported { + public static @RequiredArgsConstructor @Getter class Inner { + private final @TA int someVal; + public @java.lang.SuppressWarnings("all") Inner(final @TA int someVal) { + super(); + this.someVal = someVal; + } + public @TA @java.lang.SuppressWarnings("all") int getSomeVal() { + return this.someVal; + } + } + public static class Other { + public static class OtherNested { + public @Retention(RetentionPolicy.RUNTIME) @interface TA { + } + public OtherNested() { + super(); + } + } + public Other() { + super(); + } + } + public NestedClassAndNestedAnnotationImported() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/NestedClassAndNestedAnnotationWithConflictingNestedImport.java b/test/transform/resource/after-ecj/NestedClassAndNestedAnnotationWithConflictingNestedImport.java new file mode 100644 index 0000000000..1c5f253fb6 --- /dev/null +++ b/test/transform/resource/after-ecj/NestedClassAndNestedAnnotationWithConflictingNestedImport.java @@ -0,0 +1,28 @@ +package test.lombok; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import test.lombok.other.Other; +public class NestedClassAndNestedAnnotationWithConflictingNestedImport { + public static @RequiredArgsConstructor @Getter class Inner { + private final @Other.TA int someVal; + public @java.lang.SuppressWarnings("all") Inner(final @Other.TA int someVal) { + super(); + this.someVal = someVal; + } + public @Other.TA @java.lang.SuppressWarnings("all") int getSomeVal() { + return this.someVal; + } + } + public static class Other { + public @Retention(RetentionPolicy.RUNTIME) @interface TA { + } + public Other() { + super(); + } + } + public NestedClassAndNestedAnnotationWithConflictingNestedImport() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java b/test/transform/resource/after-ecj/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java new file mode 100644 index 0000000000..0c84e6e8c9 --- /dev/null +++ b/test/transform/resource/after-ecj/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java @@ -0,0 +1,28 @@ +package test.lombok; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import test.lombok.other.Other.TA; +public class NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport { + public static @RequiredArgsConstructor @Getter class Inner { + private final @TA int someVal; + public @java.lang.SuppressWarnings("all") Inner(final @TA int someVal) { + super(); + this.someVal = someVal; + } + public @TA @java.lang.SuppressWarnings("all") int getSomeVal() { + return this.someVal; + } + } + public static class Other { + public @Retention(RetentionPolicy.RUNTIME) @interface TA { + } + public Other() { + super(); + } + } + public NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/SimpleNestedAnnotation.java b/test/transform/resource/after-ecj/SimpleNestedAnnotation.java new file mode 100644 index 0000000000..9263336d45 --- /dev/null +++ b/test/transform/resource/after-ecj/SimpleNestedAnnotation.java @@ -0,0 +1,17 @@ +package test.lombok; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +public @RequiredArgsConstructor @Getter class SimpleNestedAnnotation { + public @Retention(RetentionPolicy.RUNTIME) @interface TA { + } + private final @TA int someVal; + public @java.lang.SuppressWarnings("all") SimpleNestedAnnotation(final @TA int someVal) { + super(); + this.someVal = someVal; + } + public @TA @java.lang.SuppressWarnings("all") int getSomeVal() { + return this.someVal; + } +} diff --git a/test/transform/resource/after-ecj/TwiceNestedClassAndSiblingAnnotation.java b/test/transform/resource/after-ecj/TwiceNestedClassAndSiblingAnnotation.java new file mode 100644 index 0000000000..81d92cff6a --- /dev/null +++ b/test/transform/resource/after-ecj/TwiceNestedClassAndSiblingAnnotation.java @@ -0,0 +1,29 @@ +package test.lombok; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +public class TwiceNestedClassAndSiblingAnnotation { + public static class Other { + public static @RequiredArgsConstructor @Getter class OtherInner { + private final @TA int someVal; + public @java.lang.SuppressWarnings("all") OtherInner(final @TA int someVal) { + super(); + this.someVal = someVal; + } + public @TA @java.lang.SuppressWarnings("all") int getSomeVal() { + return this.someVal; + } + } + public @Retention(RetentionPolicy.RUNTIME) @interface TA { + } + public Other() { + super(); + } + } + public @Retention(RetentionPolicy.RUNTIME) @interface TA { + } + public TwiceNestedClassAndSiblingAnnotation() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/TwiceNestedClassAndUpperAnnotation.java b/test/transform/resource/after-ecj/TwiceNestedClassAndUpperAnnotation.java new file mode 100644 index 0000000000..4d446e2566 --- /dev/null +++ b/test/transform/resource/after-ecj/TwiceNestedClassAndUpperAnnotation.java @@ -0,0 +1,27 @@ +package test.lombok; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +public class TwiceNestedClassAndUpperAnnotation { + public static class Other { + public static @RequiredArgsConstructor @Getter class OtherInner { + private final @TA int someVal; + public @java.lang.SuppressWarnings("all") OtherInner(final @TA int someVal) { + super(); + this.someVal = someVal; + } + public @TA @java.lang.SuppressWarnings("all") int getSomeVal() { + return this.someVal; + } + } + public Other() { + super(); + } + } + public @Retention(RetentionPolicy.RUNTIME) @interface TA { + } + public TwiceNestedClassAndUpperAnnotation() { + super(); + } +} diff --git a/test/transform/resource/before/NestedClassAndAnnotationNestedInImportedSibling.java b/test/transform/resource/before/NestedClassAndAnnotationNestedInImportedSibling.java new file mode 100644 index 0000000000..feeb1247f9 --- /dev/null +++ b/test/transform/resource/before/NestedClassAndAnnotationNestedInImportedSibling.java @@ -0,0 +1,26 @@ +//CONF: lombok.copyableAnnotations += test.lombok.NestedClassAndAnnotationNestedInImportedSibling$Other$OtherNested$TA +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import test.lombok.NestedClassAndAnnotationNestedInImportedSibling.Other.OtherNested.TA; + +public class NestedClassAndAnnotationNestedInImportedSibling { + + @RequiredArgsConstructor + @Getter + public static class Inner { + @TA + private final int someVal; + } + + public static class Other { + + public static class OtherNested { + @Retention(RetentionPolicy.RUNTIME) + public @interface TA {} + } + } +} diff --git a/test/transform/resource/before/NestedClassAndAnnotationNestedInNonImportedSibling.java b/test/transform/resource/before/NestedClassAndAnnotationNestedInNonImportedSibling.java new file mode 100644 index 0000000000..6b5f77d33c --- /dev/null +++ b/test/transform/resource/before/NestedClassAndAnnotationNestedInNonImportedSibling.java @@ -0,0 +1,25 @@ +//CONF: lombok.copyableAnnotations += test.lombok.NestedClassAndAnnotationNestedInNonImportedSibling$Other$OtherNested$TA +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +public class NestedClassAndAnnotationNestedInNonImportedSibling { + + @RequiredArgsConstructor + @Getter + public static class Inner { + @Other.OtherNested.TA + private final int someVal; + } + + public static class Other { + + public static class OtherNested { + @Retention(RetentionPolicy.RUNTIME) + public @interface TA {} + } + } +} diff --git a/test/transform/resource/before/NestedClassAndNestedAnnotation.java b/test/transform/resource/before/NestedClassAndNestedAnnotation.java new file mode 100644 index 0000000000..8953f699a7 --- /dev/null +++ b/test/transform/resource/before/NestedClassAndNestedAnnotation.java @@ -0,0 +1,20 @@ +//CONF: lombok.copyableAnnotations += test.lombok.NestedClassAndNestedAnnotation$TA +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +public class NestedClassAndNestedAnnotation { + + @RequiredArgsConstructor + @Getter + public static class Inner { + @TA + private final int someVal; + } + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA {} +} diff --git a/test/transform/resource/before/NestedClassAndNestedAnnotationImported.java b/test/transform/resource/before/NestedClassAndNestedAnnotationImported.java new file mode 100644 index 0000000000..183cd00ae4 --- /dev/null +++ b/test/transform/resource/before/NestedClassAndNestedAnnotationImported.java @@ -0,0 +1,26 @@ +//CONF: lombok.copyableAnnotations += test.lombok.NestedClassAndNestedAnnotationImported$Other$OtherNested$TA +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import test.lombok.NestedClassAndNestedAnnotationImported.Other.OtherNested.TA; + +public class NestedClassAndNestedAnnotationImported { + + @RequiredArgsConstructor + @Getter + public static class Inner { + @TA + private final int someVal; + } + + public static class Other { + + public static class OtherNested { + @Retention(RetentionPolicy.RUNTIME) + public @interface TA {} + } + } +} diff --git a/test/transform/resource/before/NestedClassAndNestedAnnotationWithConflictingNestedImport.java b/test/transform/resource/before/NestedClassAndNestedAnnotationWithConflictingNestedImport.java new file mode 100644 index 0000000000..9f045d54de --- /dev/null +++ b/test/transform/resource/before/NestedClassAndNestedAnnotationWithConflictingNestedImport.java @@ -0,0 +1,23 @@ +//CONF: lombok.copyableAnnotations += test.lombok.NestedClassAndNestedAnnotationWithConflictingNestedImport$Other$TA +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import test.lombok.other.Other; + +public class NestedClassAndNestedAnnotationWithConflictingNestedImport { + + @RequiredArgsConstructor + @Getter + public static class Inner { + @Other.TA private final int someVal; + } + + public static class Other { + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA {} + } +} diff --git a/test/transform/resource/before/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java b/test/transform/resource/before/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java new file mode 100644 index 0000000000..43fca08c30 --- /dev/null +++ b/test/transform/resource/before/NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport.java @@ -0,0 +1,23 @@ +//CONF: lombok.copyableAnnotations += test.lombok.other.Other$TA +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import test.lombok.other.Other.TA; + +public class NestedClassAndNestedAnnotationWithOverridingNestedAnnotationImport { + + @RequiredArgsConstructor + @Getter + public static class Inner { + @TA private final int someVal; + } + + public static class Other { + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA {} + } +} diff --git a/test/transform/resource/before/SimpleNestedAnnotation.java b/test/transform/resource/before/SimpleNestedAnnotation.java new file mode 100644 index 0000000000..d3824804de --- /dev/null +++ b/test/transform/resource/before/SimpleNestedAnnotation.java @@ -0,0 +1,17 @@ +//CONF: lombok.copyableAnnotations += test.lombok.SimpleNestedAnnotation$TA +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public class SimpleNestedAnnotation { + + @TA private final int someVal; + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA {} +} diff --git a/test/transform/resource/before/TwiceNestedClassAndSiblingAnnotation.java b/test/transform/resource/before/TwiceNestedClassAndSiblingAnnotation.java new file mode 100644 index 0000000000..83af82bfee --- /dev/null +++ b/test/transform/resource/before/TwiceNestedClassAndSiblingAnnotation.java @@ -0,0 +1,26 @@ +//CONF: lombok.copyableAnnotations += test.lombok.TwiceNestedClassAndSiblingAnnotation.Other$TA +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +public class TwiceNestedClassAndSiblingAnnotation { + + public static class Other { + + @RequiredArgsConstructor + @Getter + public static class OtherInner { + @TA + private final int someVal; + } + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA {} + } + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA {} +} diff --git a/test/transform/resource/before/TwiceNestedClassAndUpperAnnotation.java b/test/transform/resource/before/TwiceNestedClassAndUpperAnnotation.java new file mode 100644 index 0000000000..7428e61f90 --- /dev/null +++ b/test/transform/resource/before/TwiceNestedClassAndUpperAnnotation.java @@ -0,0 +1,23 @@ +//CONF: lombok.copyableAnnotations += test.lombok.TwiceNestedClassAndUpperAnnotation$TA +package test.lombok; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +public class TwiceNestedClassAndUpperAnnotation { + + public static class Other { + + @RequiredArgsConstructor + @Getter + public static class OtherInner { + @TA + private final int someVal; + } + } + + @Retention(RetentionPolicy.RUNTIME) + public @interface TA {} +} From 4bd5a24caf9e3714fe474592fab0d47823ad2bfc Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Mon, 21 Oct 2024 12:25:30 +0100 Subject: [PATCH 2/2] Fix bug in `vm-finder.ant.xml` when asking for vm location The `` task had an invalid declaration - it can't have an `if` and a nested `` --- buildScripts/vm-finder.ant.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildScripts/vm-finder.ant.xml b/buildScripts/vm-finder.ant.xml index 2a33b2b88a..050ee531e1 100644 --- a/buildScripts/vm-finder.ant.xml +++ b/buildScripts/vm-finder.ant.xml @@ -143,7 +143,7 @@ and rerun the build; this build is capable of finding VMs automatically on many aborted - . + . ERROR: That does not appear to be a valid location; ${jvm.loc}/bin/${exe.java} should exist.