diff options
Diffstat (limited to 'test')
6 files changed, 144 insertions, 8 deletions
diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index 46eb54a0..c10ef4d3 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -35,19 +35,21 @@ import java.util.Deque; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.Stack; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import com.sun.source.util.TreePath; import com.sun.source.util.Trees; import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCAssign; import com.sun.tools.javac.tree.JCTree.JCClassDecl; @@ -57,11 +59,12 @@ import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.tree.JCTree.TypeBoundKind; +import com.sun.tools.javac.tree.TreeScanner; import lombok.delombok.Delombok; import lombok.javac.CapturingDiagnosticListener; -import lombok.javac.Javac; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; +import lombok.javac.Javac; public class RunTestsViaDelombok extends AbstractRunTests { private Delombok delombok = new Delombok(); @@ -78,6 +81,7 @@ public class RunTestsViaDelombok extends AbstractRunTests { delombok.setDiagnosticsListener(new CapturingDiagnosticListener(file, messages)); if (checkPositions) delombok.addAdditionalAnnotationProcessor(new ValidatePositionProcessor(version)); + delombok.addAdditionalAnnotationProcessor(new ValidateTypesProcessor()); delombok.addFile(file.getAbsoluteFile().getParentFile(), file.getName()); delombok.setSourcepath(file.getAbsoluteFile().getParent()); @@ -178,6 +182,57 @@ public class RunTestsViaDelombok extends AbstractRunTests { } } + public static class ValidateTypesProcessor extends TreeProcessor { + @Override void processCompilationUnit(final JCCompilationUnit unit) { + final Stack<JCTree> parents = new Stack<JCTree>(); + parents.add(unit); + + unit.accept(new TreeScanner() { + private JCTree parent; + @Override public void scan(JCTree tree) { + parent = parents.peek(); + + parents.push(tree); + super.scan(tree); + parents.pop(); + } + + @Override public void visitClassDef(JCClassDecl tree) { + // Skip anonymous or local classes, they have no symbol + if (!(parent instanceof JCClassDecl || parent instanceof JCCompilationUnit)) return; + + validateSymbol(tree, tree.sym); + super.visitClassDef(tree); + }; + + @Override public void visitMethodDef(JCMethodDecl tree) { + validateSymbol(tree, tree.sym); + super.visitMethodDef(tree); + } + + @Override public void visitVarDef(JCVariableDecl tree) { + // Skip non-field variables + if (!(parent instanceof JCClassDecl)) return; + + validateSymbol(tree, tree.sym); + super.visitVarDef(tree); + } + + private void validateSymbol(JCTree tree, Symbol sym) { + if (sym == null) { + fail("Missing symbol for " + tree); + } + // Skip top level classes + if (sym.owner.getKind() == ElementKind.PACKAGE) return; + + if (!sym.owner.getEnclosedElements().contains(sym)) { + fail(tree + " not added to parent"); + } + } + }); + } + } + public static abstract class TreeProcessor extends AbstractProcessor { private Trees trees; @Override public synchronized void init(ProcessingEnvironment processingEnv) { diff --git a/test/transform/resource/after-delombok/NonNullExistingConstructorOnRecord.java b/test/transform/resource/after-delombok/NonNullExistingConstructorOnRecord.java index 45364815..dec91261 100644 --- a/test/transform/resource/after-delombok/NonNullExistingConstructorOnRecord.java +++ b/test/transform/resource/after-delombok/NonNullExistingConstructorOnRecord.java @@ -1,12 +1,6 @@ // version 16: import lombok.NonNull; public record NonNullExistingConstructorOnRecord(@NonNull String a, @NonNull String b) { - public NonNullExistingConstructorOnRecord(@NonNull String b) { - this("default", b); - if (b == null) { - throw new java.lang.NullPointerException("b is marked non-null but is null"); - } - } @java.lang.SuppressWarnings("all") public NonNullExistingConstructorOnRecord { if (a == null) { @@ -16,4 +10,10 @@ public record NonNullExistingConstructorOnRecord(@NonNull String a, @NonNull Str throw new java.lang.NullPointerException("b is marked non-null but is null"); } } + public NonNullExistingConstructorOnRecord(@NonNull String b) { + this("default", b); + if (b == null) { + throw new java.lang.NullPointerException("b is marked non-null but is null"); + } + } } diff --git a/test/transform/resource/after-delombok/StandardExceptions.java b/test/transform/resource/after-delombok/StandardExceptions.java new file mode 100644 index 00000000..d60fcaf2 --- /dev/null +++ b/test/transform/resource/after-delombok/StandardExceptions.java @@ -0,0 +1,36 @@ +class EmptyException extends Exception { + @java.lang.SuppressWarnings("all") + public EmptyException() { + this(null, null); + } + @java.lang.SuppressWarnings("all") + public EmptyException(final java.lang.String message) { + this(message, null); + } + @java.lang.SuppressWarnings("all") + public EmptyException(final java.lang.Throwable cause) { + this(cause != null ? cause.getMessage() : null, cause); + } + @java.lang.SuppressWarnings("all") + public EmptyException(final java.lang.String message, final java.lang.Throwable cause) { + super(message); + if (cause != null) super.initCause(cause); + } +} +class NoArgsException extends Exception { + public NoArgsException() { + } + @java.lang.SuppressWarnings("all") + protected NoArgsException(final java.lang.String message) { + this(message, null); + } + @java.lang.SuppressWarnings("all") + protected NoArgsException(final java.lang.Throwable cause) { + this(cause != null ? cause.getMessage() : null, cause); + } + @java.lang.SuppressWarnings("all") + protected NoArgsException(final java.lang.String message, final java.lang.Throwable cause) { + super(message); + if (cause != null) super.initCause(cause); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/StandardExceptions.java b/test/transform/resource/after-ecj/StandardExceptions.java new file mode 100644 index 00000000..a26a16f7 --- /dev/null +++ b/test/transform/resource/after-ecj/StandardExceptions.java @@ -0,0 +1,34 @@ +import lombok.AccessLevel; +import lombok.experimental.StandardException; +@StandardException class EmptyException extends Exception { + public @java.lang.SuppressWarnings("all") EmptyException() { + this(null, null); + } + public @java.lang.SuppressWarnings("all") EmptyException(final java.lang.String message) { + this(message, null); + } + public @java.lang.SuppressWarnings("all") EmptyException(final java.lang.Throwable cause) { + this(((cause != null) ? cause.getMessage() : null), cause); + } + public @java.lang.SuppressWarnings("all") EmptyException(final java.lang.String message, final java.lang.Throwable cause) { + super(message); + if ((cause != null)) + super.initCause(cause); + } +} +@StandardException(access = AccessLevel.PROTECTED) class NoArgsException extends Exception { + public NoArgsException() { + super(); + } + protected @java.lang.SuppressWarnings("all") NoArgsException(final java.lang.String message) { + this(message, null); + } + protected @java.lang.SuppressWarnings("all") NoArgsException(final java.lang.Throwable cause) { + this(((cause != null) ? cause.getMessage() : null), cause); + } + protected @java.lang.SuppressWarnings("all") NoArgsException(final java.lang.String message, final java.lang.Throwable cause) { + super(message); + if ((cause != null)) + super.initCause(cause); + } +}
\ No newline at end of file diff --git a/test/transform/resource/before/StandardExceptions.java b/test/transform/resource/before/StandardExceptions.java new file mode 100644 index 00000000..1316011d --- /dev/null +++ b/test/transform/resource/before/StandardExceptions.java @@ -0,0 +1,9 @@ +import lombok.AccessLevel; +import lombok.experimental.StandardException; + +@StandardException class EmptyException extends Exception { +} +@StandardException(access = AccessLevel.PROTECTED) class NoArgsException extends Exception { + public NoArgsException() { + } +} diff --git a/test/transform/resource/messages-ecj/StandardExceptions.java.messages b/test/transform/resource/messages-ecj/StandardExceptions.java.messages new file mode 100644 index 00000000..6fdc61c5 --- /dev/null +++ b/test/transform/resource/messages-ecj/StandardExceptions.java.messages @@ -0,0 +1,2 @@ +4 The serializable class EmptyException does not declare a static final serialVersionUID field of type long +6 The serializable class NoArgsException does not declare a static final serialVersionUID field of type long |