aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2010-07-25 01:49:58 +0200
committerRoel Spilker <r.spilker@gmail.com>2010-07-25 01:49:58 +0200
commitacb0e52bc09a66e9a5b5446c374cbc90a732762a (patch)
treeb57a208be83f1624d69e500f3e15c61d3cb8f631
parent9bc463231524e634091b314376ff5a38cc5cbb51 (diff)
downloadlombok-acb0e52bc09a66e9a5b5446c374cbc90a732762a.tar.gz
lombok-acb0e52bc09a66e9a5b5446c374cbc90a732762a.tar.bz2
lombok-acb0e52bc09a66e9a5b5446c374cbc90a732762a.zip
Do not generate @ConstructorProperties for method-local classes
-rw-r--r--src/core/lombok/eclipse/handlers/HandleConstructor.java9
-rw-r--r--src/core/lombok/javac/handlers/HandleConstructor.java14
-rw-r--r--test/transform/resource/after-delombok/DataOnLocalClass.java129
-rw-r--r--test/transform/resource/after-ecj/DataOnLocalClass.java125
-rw-r--r--test/transform/resource/before/DataOnLocalClass.java19
5 files changed, 292 insertions, 4 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java
index 6c857c34..91733839 100644
--- a/src/core/lombok/eclipse/handlers/HandleConstructor.java
+++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java
@@ -256,13 +256,20 @@ public class HandleConstructor {
constructor.statements = nullChecks.isEmpty() ? null : nullChecks.toArray(new Statement[nullChecks.size()]);
constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[params.size()]);
- if (!suppressConstructorProperties && level != AccessLevel.PRIVATE) {
+ if (!suppressConstructorProperties && level != AccessLevel.PRIVATE && !isLocalType(type)) {
constructor.annotations = createConstructorProperties(source, constructor.annotations, fields);
}
return constructor;
}
+ private boolean isLocalType(EclipseNode type) {
+ Kind kind = type.up().getKind();
+ if (kind == Kind.COMPILATION_UNIT) return false;
+ if (kind == Kind.TYPE) return isLocalType(type.up());
+ return true;
+ }
+
private MethodDeclaration createStaticConstructor(AccessLevel level, String name, EclipseNode type, Collection<EclipseNode> fields, ASTNode source) {
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java
index e24c19d1..36deb013 100644
--- a/src/core/lombok/javac/handlers/HandleConstructor.java
+++ b/src/core/lombok/javac/handlers/HandleConstructor.java
@@ -26,16 +26,18 @@ import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
-import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
+import lombok.core.AST.Kind;
import lombok.core.handlers.TransformationsUtil;
import lombok.javac.Javac;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
+import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult;
import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCAssign;
import com.sun.tools.javac.tree.JCTree.JCBlock;
@@ -50,7 +52,6 @@ import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.tree.JCTree.JCTypeApply;
import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
-import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.List;
public class HandleConstructor {
@@ -197,7 +198,7 @@ public class HandleConstructor {
}
JCModifiers mods = maker.Modifiers(toJavacModifier(level));
- if (!suppressConstructorProperties && level != AccessLevel.PRIVATE) {
+ if (!suppressConstructorProperties && level != AccessLevel.PRIVATE && !isLocalType(typeNode)) {
addConstructorProperties(mods, typeNode, fields);
}
@@ -205,6 +206,13 @@ public class HandleConstructor {
null, type.typarams, params, List.<JCExpression>nil(), maker.Block(0L, nullChecks.appendList(assigns)), null);
}
+ private boolean isLocalType(JavacNode type) {
+ Kind kind = type.up().getKind();
+ if (kind == Kind.COMPILATION_UNIT) return false;
+ if (kind == Kind.TYPE) return isLocalType(type.up());
+ return true;
+ }
+
private JCMethodDecl createStaticConstructor(String name, AccessLevel level, JavacNode typeNode, List<JavacNode> fields) {
TreeMaker maker = typeNode.getTreeMaker();
JCClassDecl type = (JCClassDecl) typeNode.get();
diff --git a/test/transform/resource/after-delombok/DataOnLocalClass.java b/test/transform/resource/after-delombok/DataOnLocalClass.java
new file mode 100644
index 00000000..f5f5ef31
--- /dev/null
+++ b/test/transform/resource/after-delombok/DataOnLocalClass.java
@@ -0,0 +1,129 @@
+class DataOnLocalClass1 {
+ public static void main(String[] args) {
+ class Local {
+ final int x;
+ String name;
+ @java.lang.SuppressWarnings("all")
+ public Local(final int x) {
+ this.x = x;
+ }
+ @java.lang.SuppressWarnings("all")
+ public int getX() {
+ return this.x;
+ }
+ @java.lang.SuppressWarnings("all")
+ public String getName() {
+ return this.name;
+ }
+ @java.lang.SuppressWarnings("all")
+ public void setName(final String name) {
+ this.name = name;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (o == null) return false;
+ if (o.getClass() != this.getClass()) return false;
+ final Local other = (Local)o;
+ if (this.getX() != other.getX()) return false;
+ if (this.getName() == null ? other.getName() != null : !this.getName().equals(other.getName())) return false;
+ return true;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = result * PRIME + this.getX();
+ result = result * PRIME + (this.getName() == null ? 0 : this.getName().hashCode());
+ return result;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public java.lang.String toString() {
+ return "Local(x=" + this.getX() + ", name=" + this.getName() + ")";
+ }
+ }
+ }
+}
+class DataOnLocalClass2 {
+ {
+ class Local {
+ final int x;
+ class InnerLocal {
+ @lombok.NonNull
+ String name;
+ @java.lang.SuppressWarnings("all")
+ public InnerLocal(@lombok.NonNull final String name) {
+ if (name == null) throw new java.lang.NullPointerException("name");
+ this.name = name;
+ }
+ @lombok.NonNull
+ @java.lang.SuppressWarnings("all")
+ public String getName() {
+ return this.name;
+ }
+ @java.lang.SuppressWarnings("all")
+ public void setName(@lombok.NonNull final String name) {
+ if (name == null) throw new java.lang.NullPointerException("name");
+ this.name = name;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (o == null) return false;
+ if (o.getClass() != this.getClass()) return false;
+ final InnerLocal other = (InnerLocal)o;
+ if (this.getName() == null ? other.getName() != null : !this.getName().equals(other.getName())) return false;
+ return true;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = result * PRIME + (this.getName() == null ? 0 : this.getName().hashCode());
+ return result;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public java.lang.String toString() {
+ return "InnerLocal(name=" + this.getName() + ")";
+ }
+ }
+ @java.lang.SuppressWarnings("all")
+ public Local(final int x) {
+ this.x = x;
+ }
+ @java.lang.SuppressWarnings("all")
+ public int getX() {
+ return this.x;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (o == null) return false;
+ if (o.getClass() != this.getClass()) return false;
+ final Local other = (Local)o;
+ if (this.getX() != other.getX()) return false;
+ return true;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = result * PRIME + this.getX();
+ return result;
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public java.lang.String toString() {
+ return "Local(x=" + this.getX() + ")";
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/after-ecj/DataOnLocalClass.java b/test/transform/resource/after-ecj/DataOnLocalClass.java
new file mode 100644
index 00000000..fca83e06
--- /dev/null
+++ b/test/transform/resource/after-ecj/DataOnLocalClass.java
@@ -0,0 +1,125 @@
+import lombok.Data;
+class DataOnLocalClass1 {
+ DataOnLocalClass1() {
+ super();
+ }
+ public static void main(String[] args) {
+ @Data class Local {
+ final int x;
+ String name;
+ public @java.lang.SuppressWarnings("all") Local(final int x) {
+ super();
+ this.x = x;
+ }
+ public @java.lang.SuppressWarnings("all") int getX() {
+ return this.x;
+ }
+ public @java.lang.SuppressWarnings("all") String getName() {
+ return this.name;
+ }
+ public @java.lang.SuppressWarnings("all") void setName(final String name) {
+ this.name = name;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
+ if ((o == this))
+ return true;
+ if ((o == null))
+ return false;
+ if ((o.getClass() != this.getClass()))
+ return false;
+ final Local other = (Local) o;
+ if ((this.getX() != other.getX()))
+ return false;
+ if (((this.getName() == null) ? (other.getName() != null) : (! this.getName().equals(other.getName()))))
+ return false;
+ return true;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = ((result * PRIME) + this.getX());
+ result = ((result * PRIME) + ((this.getName() == null) ? 0 : this.getName().hashCode()));
+ return result;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
+ return (((("Local(x=" + this.getX()) + ", name=") + this.getName()) + ")");
+ }
+ }
+ }
+}
+class DataOnLocalClass2 {
+ {
+ @Data class Local {
+ @Data class InnerLocal {
+ @lombok.NonNull String name;
+ public @java.lang.SuppressWarnings("all") InnerLocal(final @lombok.NonNull String name) {
+ super();
+ if ((name == null))
+ throw new java.lang.NullPointerException("name");
+ this.name = name;
+ }
+ public @lombok.NonNull @java.lang.SuppressWarnings("all") String getName() {
+ return this.name;
+ }
+ public @java.lang.SuppressWarnings("all") void setName(final @lombok.NonNull String name) {
+ if ((name == null))
+ throw new java.lang.NullPointerException("name");
+ this.name = name;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
+ if ((o == this))
+ return true;
+ if ((o == null))
+ return false;
+ if ((o.getClass() != this.getClass()))
+ return false;
+ final InnerLocal other = (InnerLocal) o;
+ if (((this.getName() == null) ? (other.getName() != null) : (! this.getName().equals(other.getName()))))
+ return false;
+ return true;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = ((result * PRIME) + ((this.getName() == null) ? 0 : this.getName().hashCode()));
+ return result;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
+ return (("InnerLocal(name=" + this.getName()) + ")");
+ }
+ }
+ final int x;
+ public @java.lang.SuppressWarnings("all") Local(final int x) {
+ super();
+ this.x = x;
+ }
+ public @java.lang.SuppressWarnings("all") int getX() {
+ return this.x;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
+ if ((o == this))
+ return true;
+ if ((o == null))
+ return false;
+ if ((o.getClass() != this.getClass()))
+ return false;
+ final Local other = (Local) o;
+ if ((this.getX() != other.getX()))
+ return false;
+ return true;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = ((result * PRIME) + this.getX());
+ return result;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
+ return (("Local(x=" + this.getX()) + ")");
+ }
+ }
+ }
+ DataOnLocalClass2() {
+ super();
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/before/DataOnLocalClass.java b/test/transform/resource/before/DataOnLocalClass.java
new file mode 100644
index 00000000..b1272b7e
--- /dev/null
+++ b/test/transform/resource/before/DataOnLocalClass.java
@@ -0,0 +1,19 @@
+import lombok.Data;
+class DataOnLocalClass1 {
+ public static void main(String[] args) {
+ @Data class Local {
+ final int x;
+ String name;
+ }
+ }
+}
+class DataOnLocalClass2 {
+ {
+ @Data class Local {
+ final int x;
+ @Data class InnerLocal {
+ @lombok.NonNull String name;
+ }
+ }
+ }
+} \ No newline at end of file