diff --git a/src/core/lombok/core/TypeResolver.java b/src/core/lombok/core/TypeResolver.java index 4f2df72e0..f906960eb 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 000000000..2a29a0df6 --- /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 000000000..1424231c0 --- /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 000000000..68ec9b5c7 --- /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 000000000..ccaff1cd0 --- /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 000000000..1398359a2 --- /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 000000000..05dd724dc --- /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 000000000..437440eeb --- /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 000000000..fede9a023 --- /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 000000000..c8416748f --- /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 000000000..273f564dd --- /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 000000000..ed7931322 --- /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 000000000..d293010cb --- /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 000000000..ac0d2215f --- /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 000000000..52e9c3b6b --- /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 000000000..1c5f253fb --- /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 000000000..0c84e6e8c --- /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 000000000..9263336d4 --- /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 000000000..81d92cff6 --- /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 000000000..4d446e256 --- /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 000000000..feeb1247f --- /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 000000000..6b5f77d33 --- /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 000000000..8953f699a --- /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 000000000..183cd00ae --- /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 000000000..9f045d54d --- /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 000000000..43fca08c3 --- /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 000000000..d3824804d --- /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 000000000..83af82bfe --- /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 000000000..7428e61f9 --- /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 {} +}