diff options
author | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2021-10-26 04:14:46 +0200 |
---|---|---|
committer | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2021-10-26 04:14:46 +0200 |
commit | 3a0176fd907ec594194cabf843a5681fd7b811fd (patch) | |
tree | d40257a3a2583974f936234e01c601a8c2fc4b0c | |
parent | c359a4b41f2800c63ad28037fe02ccf8910dcc2e (diff) | |
download | lombok-3a0176fd907ec594194cabf843a5681fd7b811fd.tar.gz lombok-3a0176fd907ec594194cabf843a5681fd7b811fd.tar.bz2 lombok-3a0176fd907ec594194cabf843a5681fd7b811fd.zip |
[fixes #3014] Detecting whether inner classes are static wouldn't work if placed inside an enum or interface.
-rw-r--r-- | src/core/lombok/eclipse/EclipseNode.java | 9 | ||||
-rw-r--r-- | src/core/lombok/javac/JavacNode.java | 8 | ||||
-rw-r--r-- | test/core/src/lombok/DirectoryRunner.java | 1 | ||||
-rw-r--r-- | test/transform/resource/after-delombok/BuilderNestedInEnum.java | 70 | ||||
-rw-r--r-- | test/transform/resource/after-ecj/BuilderNestedInEnum.java | 68 |
5 files changed, 149 insertions, 7 deletions
diff --git a/src/core/lombok/eclipse/EclipseNode.java b/src/core/lombok/eclipse/EclipseNode.java index 4f86f0a5..4950aeef 100644 --- a/src/core/lombok/eclipse/EclipseNode.java +++ b/src/core/lombok/eclipse/EclipseNode.java @@ -215,13 +215,16 @@ public class EclipseNode extends lombok.core.LombokNode<EclipseAST, EclipseNode, @Override public boolean isStatic() { if (node instanceof TypeDeclaration) { + TypeDeclaration t = (TypeDeclaration) node; + int f = t.modifiers; + if (((ClassFileConstants.AccInterface | ClassFileConstants.AccEnum) & f) != 0) return true; + EclipseNode directUp = directUp(); if (directUp == null || directUp.getKind() == Kind.COMPILATION_UNIT) return true; if (!(directUp.get() instanceof TypeDeclaration)) return false; TypeDeclaration p = (TypeDeclaration) directUp.get(); - int f = p.modifiers; - if ((ClassFileConstants.AccInterface & f) != 0) return true; - if ((ClassFileConstants.AccEnum & f) != 0) return true; + f = p.modifiers; + if (((ClassFileConstants.AccInterface | ClassFileConstants.AccEnum) & f) != 0) return true; } if (node instanceof FieldDeclaration) { diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java index 035f7c53..fca0d0d1 100644 --- a/src/core/lombok/javac/JavacNode.java +++ b/src/core/lombok/javac/JavacNode.java @@ -286,13 +286,15 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre @Override public boolean isStatic() { if (node instanceof JCClassDecl) { + JCClassDecl t = (JCClassDecl) node; + long f = t.mods.flags; + if (((Flags.INTERFACE | Flags.ENUM) & f) != 0) return true; JavacNode directUp = directUp(); if (directUp == null || directUp.getKind() == Kind.COMPILATION_UNIT) return true; if (!(directUp.get() instanceof JCClassDecl)) return false; JCClassDecl p = (JCClassDecl) directUp.get(); - long f = p.mods.flags; - if ((Flags.INTERFACE & f) != 0) return true; - if ((Flags.ENUM & f) != 0) return true; + f = p.mods.flags; + if (((Flags.INTERFACE | Flags.ENUM) & f) != 0) return true; } if (node instanceof JCVariableDecl) { diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java index 65e5e002..53347e24 100644 --- a/test/core/src/lombok/DirectoryRunner.java +++ b/test/core/src/lombok/DirectoryRunner.java @@ -40,7 +40,6 @@ import lombok.javac.Javac; public class DirectoryRunner extends Runner { /** Add 1 or more file names to reduce the testset to just the named file(s). No files = test it all. */ private static final List<String> DEBUG_FOCUS_ON_FILE = Arrays.asList( - "BuilderNestedInEnum.java" ); public enum Compiler { diff --git a/test/transform/resource/after-delombok/BuilderNestedInEnum.java b/test/transform/resource/after-delombok/BuilderNestedInEnum.java new file mode 100644 index 00000000..26dc2a06 --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderNestedInEnum.java @@ -0,0 +1,70 @@ +class BuilderNestedInEnum { + public enum TestEnum { + FOO, BAR; + public static final class TestBuilder { + private final String field; + @java.lang.SuppressWarnings("all") + TestBuilder(final String field) { + this.field = field; + } + @java.lang.SuppressWarnings("all") + public static class TestBuilderBuilder { + @java.lang.SuppressWarnings("all") + private String field; + @java.lang.SuppressWarnings("all") + TestBuilderBuilder() { + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder field(final String field) { + this.field = field; + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderNestedInEnum.TestEnum.TestBuilder build() { + return new BuilderNestedInEnum.TestEnum.TestBuilder(this.field); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder(field=" + this.field + ")"; + } + } + @java.lang.SuppressWarnings("all") + public static BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder builder() { + return new BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder(); + } + @java.lang.SuppressWarnings("all") + public String getField() { + return this.field; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof BuilderNestedInEnum.TestEnum.TestBuilder)) return false; + final BuilderNestedInEnum.TestEnum.TestBuilder other = (BuilderNestedInEnum.TestEnum.TestBuilder) o; + final java.lang.Object this$field = this.getField(); + final java.lang.Object other$field = other.getField(); + if (this$field == null ? other$field != null : !this$field.equals(other$field)) return false; + return true; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $field = this.getField(); + result = result * PRIME + ($field == null ? 43 : $field.hashCode()); + return result; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderNestedInEnum.TestEnum.TestBuilder(field=" + this.getField() + ")"; + } + } + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/BuilderNestedInEnum.java b/test/transform/resource/after-ecj/BuilderNestedInEnum.java new file mode 100644 index 00000000..b3fb54f3 --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderNestedInEnum.java @@ -0,0 +1,68 @@ +class BuilderNestedInEnum { + public enum TestEnum { + public static final @lombok.Builder @lombok.Value class TestBuilder { + public static @java.lang.SuppressWarnings("all") class TestBuilderBuilder { + private @java.lang.SuppressWarnings("all") String field; + @java.lang.SuppressWarnings("all") TestBuilderBuilder() { + super(); + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder field(final String field) { + this.field = field; + return this; + } + public @java.lang.SuppressWarnings("all") BuilderNestedInEnum.TestEnum.TestBuilder build() { + return new BuilderNestedInEnum.TestEnum.TestBuilder(this.field); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder(field=" + this.field) + ")"); + } + } + private final String field; + @java.lang.SuppressWarnings("all") TestBuilder(final String field) { + super(); + this.field = field; + } + public static @java.lang.SuppressWarnings("all") BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder builder() { + return new BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder(); + } + public @java.lang.SuppressWarnings("all") String getField() { + return this.field; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof BuilderNestedInEnum.TestEnum.TestBuilder))) + return false; + final BuilderNestedInEnum.TestEnum.TestBuilder other = (BuilderNestedInEnum.TestEnum.TestBuilder) o; + final java.lang.Object this$field = this.getField(); + final java.lang.Object other$field = other.getField(); + if (((this$field == null) ? (other$field != null) : (! this$field.equals(other$field)))) + return false; + return true; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int PRIME = 59; + int result = 1; + final java.lang.Object $field = this.getField(); + result = ((result * PRIME) + (($field == null) ? 43 : $field.hashCode())); + return result; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("BuilderNestedInEnum.TestEnum.TestBuilder(field=" + this.getField()) + ")"); + } + } + FOO(), + BAR(), + <clinit>() { + } + public TestEnum() { + super(); + } + } + BuilderNestedInEnum() { + super(); + } +}
\ No newline at end of file |