diff --git a/buildScripts/vm-finder.ant.xml b/buildScripts/vm-finder.ant.xml index 2a33b2b88a..57b5904d42 100644 --- a/buildScripts/vm-finder.ant.xml +++ b/buildScripts/vm-finder.ant.xml @@ -143,12 +143,12 @@ 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. - - - diff --git a/src/core/lombok/core/TypeResolver.java b/src/core/lombok/core/TypeResolver.java index 4f2df72e0f..b38b2dba29 100644 --- a/src/core/lombok/core/TypeResolver.java +++ b/src/core/lombok/core/TypeResolver.java @@ -1,16 +1,16 @@ /* * Copyright (C) 2009-2020 The Project Lombok Authors. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -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,27 +34,35 @@ * 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. */ public TypeResolver(ImportList importList) { this.imports = importList; } - + public boolean typeMatches(LombokNode context, String fqn, String typeRef) { return typeRefToFullyQualifiedName(context, TypeLibrary.createLibraryForSingleType(fqn), typeRef) != null; } - + public String typeRefToFullyQualifiedName(LombokNode context, TypeLibrary library, String typeRef) { // When asking if 'Foo' could possibly be referring to 'bar.Baz', the answer is obviously no. List qualifieds = library.toQualifieds(typeRef); if (qualifieds == null || qualifieds.isEmpty()) return null; - + // 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(); @@ -64,26 +74,26 @@ public String typeRefToFullyQualifiedName(LombokNode context, TypeLibra // ... and if 'import foobar.Getter;' is in the source file, the answer is no. return null; } - + // When asking if 'Getter' could possibly be referring to 'lombok.Getter' and 'import lombok.*; / package lombok;' isn't in the source file. the answer is no. for (String qualified : qualifieds) { String pkgName = qualified.substring(0, qualified.length() - typeRef.length() - 1); if (!imports.hasStarImport(pkgName)) continue; - + // Now the hard part: Given that there is a star import, 'Getter' most likely refers to 'lombok.Getter', but type shadowing may occur in which case it doesn't. LombokNode n = context; - + mainLoop: while (n != null) { if (n.getKind() == Kind.TYPE && firstTypeRef.equals(n.getName())) { // Our own class or one of our outer classes is named 'typeRef' so that's what 'typeRef' is referring to, not one of our type library classes. return null; } - + if (n.getKind() == Kind.STATEMENT || n.getKind() == Kind.LOCAL) { LombokNode newN = n.directUp(); if (newN == null) break mainLoop; - + if (newN.getKind() == Kind.STATEMENT || newN.getKind() == Kind.INITIALIZER || newN.getKind() == Kind.METHOD) { for (LombokNode child : newN.down()) { // We found a method local with the same name above our code. That's the one 'typeRef' is referring to, not @@ -95,22 +105,103 @@ public String typeRefToFullyQualifiedName(LombokNode context, TypeLibra n = newN; 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(); } - + // If no shadowing thing has been found, the star import 'wins', so, return that. return LombokInternalAliasing.processAliases(qualified); } - + // 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 {} +}