From e0cfacd3b307b1ec9f0b62b2f953f0a0e85d9d1e Mon Sep 17 00:00:00 2001 From: grootjans Date: Mon, 21 Feb 2011 22:03:05 +0100 Subject: [PATCH 01/17] Issue 192: Add documentation for onMethod=, onParam, onConstructor still have to make a minor edit in the pre/post files --- buildScripts/website.ant.xml | 3 ++ usage_examples/onXExample_post.jpage | 41 ++++++++++++++++++++ usage_examples/onXExample_pre.jpage | 23 +++++++++++ website/features/Delegate.html | 2 +- website/features/index.html | 2 + website/features/onX.html | 58 ++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 usage_examples/onXExample_post.jpage create mode 100644 usage_examples/onXExample_pre.jpage create mode 100644 website/features/onX.html diff --git a/buildScripts/website.ant.xml b/buildScripts/website.ant.xml index aabc337c..68e20eae 100644 --- a/buildScripts/website.ant.xml +++ b/buildScripts/website.ant.xml @@ -144,6 +144,9 @@ such as converting the changelog into HTML, and creating javadoc. + + + diff --git a/usage_examples/onXExample_post.jpage b/usage_examples/onXExample_post.jpage new file mode 100644 index 00000000..f71f16a3 --- /dev/null +++ b/usage_examples/onXExample_post.jpage @@ -0,0 +1,41 @@ +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +public class OnMethodOnParamExample { + private int fires = 200; + private int firemen = 20; + private String fireStationName = "base"; + + @Deprecated + public int getFires() { + return fires; + } + + @Deprecated + public void setFiremen(int firemen) { + this.firemen = firemen; + } + + public void setFireStationName(@SuppressWarnings("all") int fireStationName) { + this.fireStationName = fireStationName; + } + + @Override public String toString() { + return String.format("firestation:%s, %d firemen are fighting %d fires", fireStationName, firemen, fires); + } +} + +class OnConstructorExample { + private final int radishes; + private int bananas; + + @Deprecated + public OnConstructorExample(int radishes) { + this.radishes = radishes; + } + + @Override public String toString() { + return String.format("I have %d bananas and %d radishes", bananas, radishes); + } +} \ No newline at end of file diff --git a/usage_examples/onXExample_pre.jpage b/usage_examples/onXExample_pre.jpage new file mode 100644 index 00000000..3e91fb3a --- /dev/null +++ b/usage_examples/onXExample_pre.jpage @@ -0,0 +1,23 @@ +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +public class OnMethodOnParamExample { + @Getter(onMethod=@Deprecated) private int fires = 200; + @Setter(onMethod=@Deprecated) private int firemen = 20; + @Setter(onParam=@SuppressWarnings("all")) private String fireStationName = "base"; + + @Override public String toString() { + return String.format("firestation:%s, %d firemen are fighting %d fires", fireStationName, firemen, fires); + } +} + +@RequiredArgsConstructor(onConstructor=@Deprecated) +class OnConstructorExample { + private final int radishes; + private int bananas; + + @Override public String toString() { + return String.format("I have %d bananas and %d radishes", bananas, radishes); + } +} \ No newline at end of file diff --git a/website/features/Delegate.html b/website/features/Delegate.html index bdb22c26..52b1035d 100644 --- a/website/features/Delegate.html +++ b/website/features/Delegate.html @@ -51,7 +51,7 @@
diff --git a/website/features/index.html b/website/features/index.html index 06b6763e..e9a2255b 100644 --- a/website/features/index.html +++ b/website/features/index.html @@ -38,6 +38,8 @@
Finally! hassle-free final local variables.
@Delegate
Don't lose your composition
+
onMethod=,onParam=,onConstructor=
+
Annotate this! Add you favorite annotation to methods generated by lombok.
diff --git a/website/features/onX.html b/website/features/onX.html new file mode 100644 index 00000000..b94dea4b --- /dev/null +++ b/website/features/onX.html @@ -0,0 +1,58 @@ + + + + + + + + onMethod=,onParam=,onConstructor= +
+
+
+ +

onMethod=,onParam=,onConstructor=

+ +
+

Overview

+

+ Lombok lets you add your favorite annotation to methods generated by @Getter and @Setter by using the attribute onMethod + on the lombok annotation. You can specify annotations to the parameters of the method on @Setter with the attribute onParameter. + You can add annotation to constructors generated by @NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructor by using the attribute + onConstructor +

+
+
+
+

With Lombok

+
@HTML_PRE@
+
+
+
+

Vanilla Java

+
@HTML_POST@
+
+
+
+
+

Small print

+ When the @Getter or @Setter annotation is placed on the type in stead of a field, using the attribute is not supported and it will result in a warning. +
+
+ +
+
+
+ + + From 0fa03d313263991f6f7f55e68097e5e9794e4a7b Mon Sep 17 00:00:00 2001 From: grootjans Date: Mon, 28 Feb 2011 12:32:27 +0100 Subject: [PATCH 02/17] Updates examples to use Guice and hibernate validators. --- usage_examples/onXExample_post.jpage | 55 ++++++++++++++-------------- usage_examples/onXExample_pre.jpage | 17 +++++---- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/usage_examples/onXExample_post.jpage b/usage_examples/onXExample_post.jpage index f71f16a3..85e3c58f 100644 --- a/usage_examples/onXExample_post.jpage +++ b/usage_examples/onXExample_post.jpage @@ -1,41 +1,42 @@ +import com.google.inject.Inject; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.hibernate.validator.Min; public class OnMethodOnParamExample { - private int fires = 200; - private int firemen = 20; - private String fireStationName = "base"; - - @Deprecated - public int getFires() { - return fires; - } - - @Deprecated - public void setFiremen(int firemen) { - this.firemen = firemen; - } - - public void setFireStationName(@SuppressWarnings("all") int fireStationName) { - this.fireStationName = fireStationName; - } - - @Override public String toString() { - return String.format("firestation:%s, %d firemen are fighting %d fires", fireStationName, firemen, fires); - } -} - -class OnConstructorExample { - private final int radishes; private int bananas; + private int radishes; @Deprecated - public OnConstructorExample(int radishes) { + public int getBananas() { + return bananas; + } + + @Min(10) + public int setRadishes(int radishes) { this.radishes = radishes; } @Override public String toString() { - return String.format("I have %d bananas and %d radishes", bananas, radishes); + return String.format("I have %d bananas and %d beautiful radishes", bananas, radishes); + } +} + +class OnConstructorExample { + private final Fireman fireman; + private int fires = 10; + + @Inject + public OnConstructorExample(Fireman fireman) { + this.fireman = fireman; + } + + public void setFires(@SuppressWarnings("all") int fires) { + this.fires = fires; + } + + @Override public String toString() { + return String.format("Fireman: %s has %d fires", fireman, fires); } } \ No newline at end of file diff --git a/usage_examples/onXExample_pre.jpage b/usage_examples/onXExample_pre.jpage index 3e91fb3a..1bab3835 100644 --- a/usage_examples/onXExample_pre.jpage +++ b/usage_examples/onXExample_pre.jpage @@ -1,23 +1,24 @@ +import com.google.inject.Inject; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.hibernate.validator.Min; public class OnMethodOnParamExample { - @Getter(onMethod=@Deprecated) private int fires = 200; - @Setter(onMethod=@Deprecated) private int firemen = 20; - @Setter(onParam=@SuppressWarnings("all")) private String fireStationName = "base"; + @Getter(onMethod=@Deprecated) private int bananas; + @Setter(onMethod=@Min(10)) private int radishes; @Override public String toString() { - return String.format("firestation:%s, %d firemen are fighting %d fires", fireStationName, firemen, fires); + return String.format("I have %d bananas and %d beautiful radishes", bananas, radishes); } } -@RequiredArgsConstructor(onConstructor=@Deprecated) +@RequiredArgsConstructor(onConstructor=@Inject) class OnConstructorExample { - private final int radishes; - private int bananas; + private final Fireman fireman; + @Setter(onParam=@SuppressWarnings("all")) private int fires = 10; @Override public String toString() { - return String.format("I have %d bananas and %d radishes", bananas, radishes); + return String.format("Fireman: %s has %d fires", fireman, fires); } } \ No newline at end of file From 1c3ed9ac5d321a2c6c33659e9c97a557f99227a8 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Sun, 6 Mar 2011 01:21:54 +0100 Subject: [PATCH 03/17] added developers and contributors to maven pom. --- doc/maven-pom.xml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/maven-pom.xml b/doc/maven-pom.xml index bf22ea5d..e5be451e 100644 --- a/doc/maven-pom.xml +++ b/doc/maven-pom.xml @@ -20,6 +20,28 @@ scm:git:git://github.com/rzwitserloot/lombok.git scm:git:git://github.com/rzwitserloot/lombok.git + + + rzwitserloot + Reinier Zwitserloot + reinier@projectlombok.org + http://zwitserloot.com + +1 + + + rspilker + Roel Spilker + roel@projectlombok.org + +1 + + + + + rgrootjans + Robbert Jan Grootjans + +1 + + + + diff --git a/website/mavenrepo/index.html b/website/mavenrepo/index.html index 6b8ea48d..aa7f4935 100644 --- a/website/mavenrepo/index.html +++ b/website/mavenrepo/index.html @@ -43,7 +43,7 @@
-

Use Lombok via Maven

+

Use Lombok via Maven or ivy

You can use lombok with maven by adding the following to your pom.xml:
<dependencies> @@ -53,25 +53,14 @@ <version>@VERSION@</version> <scope>provided</scope> </dependency> -</dependencies> -<repositories> - <repository> - <id>projectlombok.org</id> - <url>http://projectlombok.org/mavenrepo</url> - </repository> -</repositories>
+</dependencies>
+
- CAREFUL: lombok requires using the javac v1.6 compiler. If this is not your default compiler, you'll need to add the following to your - pom file to explicitly set the java compiler version to use: -
<plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <compilerVersion>1.6</compilerVersion> - <source>1.6</source> - <target>1.6</target> - </configuration> -</plugin>
+ You can use lombok with ivy by adding the following to your ivy.xml: +
<dependency org="projectlombok.org" name="lombok" rev="@VERSION@" conf="build" />
+
+
+ CAREFUL: lombok requires using the javac v1.6 compiler or higher.
That's all there is to it!
note: You'll still need to download lombok, or doubleclick on the lombok.jar file downloaded by maven, to install lombok into your eclipse installation.
From 4afc7e5c2344fc5edbd55e815ce62fa1ac8fb357 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 16 Mar 2011 07:43:55 +0100 Subject: [PATCH 08/17] Added printing oss.sonatype.org usernamepass to build script when publishing maven --- build.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.xml b/build.xml index f3de4339..d747e617 100644 --- a/build.xml +++ b/build.xml @@ -322,6 +322,12 @@ the common tasks and can be called on to run the main aspects of all the sub-scr username="lombokup" keyfile="escudo-upload.key" passphrase="" trust="true" command="./publishToMavenCentral" /> + The artifact has been published to staging. Now go to http://oss.sonatype.org/ and log in as Reinier, then doublecheck if all is well and 'release' it. + From d0131d9c9bf8fb2dcc87c8dbec430c58bf926880 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 16 Mar 2011 07:56:29 +0100 Subject: [PATCH 09/17] Updated instructions for publishing a new version --- doc/publishing.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/publishing.txt b/doc/publishing.txt index 01a2c294..85a13a9c 100644 --- a/doc/publishing.txt +++ b/doc/publishing.txt @@ -10,4 +10,6 @@ Step #4: git push && git push --tags Step #5: ant publish-all +Step #6: Follow the instructions that flew by when the maven-publish task ran, which involves going to http://oss.sonatype.org/ and logging in with the username/pass that are in your scroll log, to test and then 'release' the staged repo to maven central. Note that once you do this there's no turning back, and that version number is forever associated with this release. + Step #6: Change src/core/lombok/core/Version.java to "0.8.2-EDGE", and commit this. From 38b4128f899e81d8a5d19dca8b6cd1357ca3bd1a Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 18 Mar 2011 18:25:59 +0100 Subject: [PATCH 10/17] previous attempt to use more maven central repos failed, so reverted most of it. see commit 1a28ccb3471c1309357547e72a3997e1ec4c91de. --- .../org.eclipse.custom-core.runtime-3.6.0.xml | 14 ++++++++++++++ ...-3.6.0.xml => org.eclipse.custom-ecj-3.6.0.xml} | 6 +++--- .../org.eclipse.custom-equinox.common-3.6.0.xml | 14 ++++++++++++++ ...0.xml => org.eclipse.custom-jdt.core-3.6.0.xml} | 6 +++--- ...6.0.xml => org.eclipse.custom-jdt.ui-3.6.0.xml} | 6 +++--- .../ivy-repo/org.eclipse.custom-osgi-3.6.0.xml | 14 ++++++++++++++ buildScripts/ivy.xml | 12 ++++++------ 7 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 buildScripts/ivy-repo/org.eclipse.custom-core.runtime-3.6.0.xml rename buildScripts/ivy-repo/{eclipse.org-ecj-3.6.0.xml => org.eclipse.custom-ecj-3.6.0.xml} (72%) create mode 100644 buildScripts/ivy-repo/org.eclipse.custom-equinox.common-3.6.0.xml rename buildScripts/ivy-repo/{eclipse.org-jdt.core-3.6.0.xml => org.eclipse.custom-jdt.core-3.6.0.xml} (71%) rename buildScripts/ivy-repo/{eclipse.org-jdt.ui-3.6.0.xml => org.eclipse.custom-jdt.ui-3.6.0.xml} (72%) create mode 100644 buildScripts/ivy-repo/org.eclipse.custom-osgi-3.6.0.xml diff --git a/buildScripts/ivy-repo/org.eclipse.custom-core.runtime-3.6.0.xml b/buildScripts/ivy-repo/org.eclipse.custom-core.runtime-3.6.0.xml new file mode 100644 index 00000000..fe812bbc --- /dev/null +++ b/buildScripts/ivy-repo/org.eclipse.custom-core.runtime-3.6.0.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/buildScripts/ivy-repo/eclipse.org-ecj-3.6.0.xml b/buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.0.xml similarity index 72% rename from buildScripts/ivy-repo/eclipse.org-ecj-3.6.0.xml rename to buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.0.xml index e3b8aceb..6ea9088e 100644 --- a/buildScripts/ivy-repo/eclipse.org-ecj-3.6.0.xml +++ b/buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.0.xml @@ -1,14 +1,14 @@ - + - + - + diff --git a/buildScripts/ivy-repo/org.eclipse.custom-equinox.common-3.6.0.xml b/buildScripts/ivy-repo/org.eclipse.custom-equinox.common-3.6.0.xml new file mode 100644 index 00000000..889a2ceb --- /dev/null +++ b/buildScripts/ivy-repo/org.eclipse.custom-equinox.common-3.6.0.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildScripts/ivy-repo/eclipse.org-jdt.core-3.6.0.xml b/buildScripts/ivy-repo/org.eclipse.custom-jdt.core-3.6.0.xml similarity index 71% rename from buildScripts/ivy-repo/eclipse.org-jdt.core-3.6.0.xml rename to buildScripts/ivy-repo/org.eclipse.custom-jdt.core-3.6.0.xml index 7a3225d8..f9a8f52d 100644 --- a/buildScripts/ivy-repo/eclipse.org-jdt.core-3.6.0.xml +++ b/buildScripts/ivy-repo/org.eclipse.custom-jdt.core-3.6.0.xml @@ -1,14 +1,14 @@ - + - + - + diff --git a/buildScripts/ivy-repo/eclipse.org-jdt.ui-3.6.0.xml b/buildScripts/ivy-repo/org.eclipse.custom-jdt.ui-3.6.0.xml similarity index 72% rename from buildScripts/ivy-repo/eclipse.org-jdt.ui-3.6.0.xml rename to buildScripts/ivy-repo/org.eclipse.custom-jdt.ui-3.6.0.xml index 6244df5b..dbee2865 100644 --- a/buildScripts/ivy-repo/eclipse.org-jdt.ui-3.6.0.xml +++ b/buildScripts/ivy-repo/org.eclipse.custom-jdt.ui-3.6.0.xml @@ -1,14 +1,14 @@ - + - + - + diff --git a/buildScripts/ivy-repo/org.eclipse.custom-osgi-3.6.0.xml b/buildScripts/ivy-repo/org.eclipse.custom-osgi-3.6.0.xml new file mode 100644 index 00000000..93a7f381 --- /dev/null +++ b/buildScripts/ivy-repo/org.eclipse.custom-osgi-3.6.0.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index 83bd3a19..4d3bb679 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -26,17 +26,17 @@ - + - - - - - + + + + + From 04e9397971d3689e0710df026f673f8b0a6cb685 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 18 Mar 2011 19:30:02 +0100 Subject: [PATCH 11/17] Rewritten @Cleanup's new null analysis prevention to not use Lombok.preventNullAnalysis but go with Collections.singletonList(expr).get(0) instead; while this does create a pointless object, it doesn't cause a clash when eclipse has lombok 0.10 installed but the project uses 0.9, which doesn't have preventNullAnalysis. Eventually, once 0.9 is long forgotten, this can be reverted. --- .../eclipse/handlers/HandleCleanup.java | 43 +++++++++++++------ .../lombok/javac/handlers/HandleCleanup.java | 8 +++- .../resource/after-delombok/CleanupName.java | 4 +- .../resource/after-delombok/CleanupPlain.java | 4 +- .../resource/after-ecj/CleanupName.java | 4 +- .../resource/after-ecj/CleanupPlain.java | 4 +- 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/core/lombok/eclipse/handlers/HandleCleanup.java b/src/core/lombok/eclipse/handlers/HandleCleanup.java index 964653bc..9a63ce47 100644 --- a/src/core/lombok/eclipse/handlers/HandleCleanup.java +++ b/src/core/lombok/eclipse/handlers/HandleCleanup.java @@ -42,6 +42,7 @@ import org.eclipse.jdt.internal.compiler.ast.CastExpression; import org.eclipse.jdt.internal.compiler.ast.EqualExpression; import org.eclipse.jdt.internal.compiler.ast.Expression; import org.eclipse.jdt.internal.compiler.ast.IfStatement; +import org.eclipse.jdt.internal.compiler.ast.IntLiteral; import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; import org.eclipse.jdt.internal.compiler.ast.MemberValuePair; import org.eclipse.jdt.internal.compiler.ast.MessageSend; @@ -174,16 +175,7 @@ public class HandleCleanup implements EclipseAnnotationHandler { NullLiteral nullLiteral = new NullLiteral(pS, pE); Eclipse.setGeneratedBy(nullLiteral, ast); - MessageSend preventNullAnalysis = new MessageSend(); - Eclipse.setGeneratedBy(preventNullAnalysis, ast); - - preventNullAnalysis.receiver = createNameReference("lombok.Lombok", ast); - preventNullAnalysis.selector = "preventNullAnalysis".toCharArray(); - - preventNullAnalysis.arguments = new Expression[] { varName }; - preventNullAnalysis.nameSourcePosition = p; - preventNullAnalysis.sourceStart = pS; - preventNullAnalysis.sourceEnd = preventNullAnalysis.statementEnd = pE; + MessageSend preventNullAnalysis = preventNullAnalysis(ast, varName); EqualExpression equalExpression = new EqualExpression(preventNullAnalysis, nullLiteral, OperatorIds.NOT_EQUAL); equalExpression.sourceStart = pS; equalExpression.sourceEnd = pE; @@ -195,8 +187,6 @@ public class HandleCleanup implements EclipseAnnotationHandler { Eclipse.setGeneratedBy(closeBlock, ast); IfStatement ifStatement = new IfStatement(equalExpression, closeBlock, 0, 0); Eclipse.setGeneratedBy(ifStatement, ast); - - finallyBlock[0] = ifStatement; tryStatement.finallyBlock = new Block(0); @@ -219,6 +209,35 @@ public class HandleCleanup implements EclipseAnnotationHandler { return true; } + private MessageSend preventNullAnalysis(Annotation ast, Expression expr) { + MessageSend singletonList = new MessageSend(); + Eclipse.setGeneratedBy(singletonList, ast); + + int pS = ast.sourceStart, pE = ast.sourceEnd; + long p = (long)pS << 32 | pE; + + singletonList.receiver = createNameReference("java.util.Collections", ast); + singletonList.selector = "singletonList".toCharArray(); + + singletonList.arguments = new Expression[] { expr }; + singletonList.nameSourcePosition = p; + singletonList.sourceStart = pS; + singletonList.sourceEnd = singletonList.statementEnd = pE; + + MessageSend preventNullAnalysis = new MessageSend(); + Eclipse.setGeneratedBy(preventNullAnalysis, ast); + + preventNullAnalysis.receiver = singletonList; + preventNullAnalysis.selector = "get".toCharArray(); + + preventNullAnalysis.arguments = new Expression[] { new IntLiteral(new char[] { '0' }, pS, pE) }; + preventNullAnalysis.nameSourcePosition = p; + preventNullAnalysis.sourceStart = pS; + preventNullAnalysis.sourceEnd = singletonList.statementEnd = pE; + + return preventNullAnalysis; + } + private void doAssignmentCheck(EclipseNode node, Statement[] tryBlock, char[] varName) { for (Statement statement : tryBlock) doAssignmentCheck0(node, statement, varName); } diff --git a/src/core/lombok/javac/handlers/HandleCleanup.java b/src/core/lombok/javac/handlers/HandleCleanup.java index 9e2fddf6..b681ab28 100644 --- a/src/core/lombok/javac/handlers/HandleCleanup.java +++ b/src/core/lombok/javac/handlers/HandleCleanup.java @@ -117,7 +117,7 @@ public class HandleCleanup implements JavacAnnotationHandler { List cleanupCall = List.of(maker.Exec( maker.Apply(List.nil(), cleanupMethod, List.nil()))); - JCMethodInvocation preventNullAnalysis = maker.Apply(List.nil(), JavacHandlerUtil.chainDotsString(maker, annotationNode, "lombok.Lombok.preventNullAnalysis"), List.of(maker.Ident(decl.name))); + JCMethodInvocation preventNullAnalysis = preventNullAnalysis(maker, annotationNode, maker.Ident(decl.name)); JCBinary isNull = maker.Binary(Javac.getCTCint(JCTree.class, "NE"), preventNullAnalysis, maker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null)); JCIf ifNotNullCleanup = maker.If(isNull, maker.Block(0, cleanupCall), null); @@ -139,6 +139,12 @@ public class HandleCleanup implements JavacAnnotationHandler { return true; } + private JCMethodInvocation preventNullAnalysis(TreeMaker maker, JavacNode node, JCExpression expression) { + JCMethodInvocation singletonList = maker.Apply(List.nil(), JavacHandlerUtil.chainDotsString(maker, node, "java.util.Collections.singletonList"), List.of(expression)); + JCMethodInvocation cleanedExpr = maker.Apply(List.nil(), maker.Select(singletonList, node.toName("get")) , List.of(maker.Literal(TypeTags.INT, 0))); + return cleanedExpr; + } + private void doAssignmentCheck(JavacNode node, List statements, Name name) { for (JCStatement statement : statements) doAssignmentCheck0(node, statement, name); } diff --git a/test/transform/resource/after-delombok/CleanupName.java b/test/transform/resource/after-delombok/CleanupName.java index 37a8d117..a4ab8267 100644 --- a/test/transform/resource/after-delombok/CleanupName.java +++ b/test/transform/resource/after-delombok/CleanupName.java @@ -4,7 +4,7 @@ class CleanupName { try { System.out.println(o); } finally { - if (lombok.Lombok.preventNullAnalysis(o) != null) { + if (java.util.Collections.singletonList(o).get(0) != null) { o.toString(); } } @@ -14,7 +14,7 @@ class CleanupName { try { System.out.println(o); } finally { - if (lombok.Lombok.preventNullAnalysis(o) != null) { + if (java.util.Collections.singletonList(o).get(0) != null) { o.toString(); } } diff --git a/test/transform/resource/after-delombok/CleanupPlain.java b/test/transform/resource/after-delombok/CleanupPlain.java index 67c82f60..f91f35ee 100644 --- a/test/transform/resource/after-delombok/CleanupPlain.java +++ b/test/transform/resource/after-delombok/CleanupPlain.java @@ -9,12 +9,12 @@ class CleanupPlain { out.flush(); } } finally { - if (lombok.Lombok.preventNullAnalysis(out) != null) { + if (java.util.Collections.singletonList(out).get(0) != null) { out.close(); } } } finally { - if (lombok.Lombok.preventNullAnalysis(in) != null) { + if (java.util.Collections.singletonList(in).get(0) != null) { in.close(); } } diff --git a/test/transform/resource/after-ecj/CleanupName.java b/test/transform/resource/after-ecj/CleanupName.java index 8948e91d..f3f725f2 100644 --- a/test/transform/resource/after-ecj/CleanupName.java +++ b/test/transform/resource/after-ecj/CleanupName.java @@ -10,7 +10,7 @@ class CleanupName { } finally { - if ((lombok.Lombok.preventNullAnalysis(o) != null)) + if ((java.util.Collections.singletonList(o).get(0) != null)) { o.toString(); } @@ -24,7 +24,7 @@ class CleanupName { } finally { - if ((lombok.Lombok.preventNullAnalysis(o) != null)) + if ((java.util.Collections.singletonList(o).get(0) != null)) { o.toString(); } diff --git a/test/transform/resource/after-ecj/CleanupPlain.java b/test/transform/resource/after-ecj/CleanupPlain.java index 6eaa4377..a9b9eceb 100644 --- a/test/transform/resource/after-ecj/CleanupPlain.java +++ b/test/transform/resource/after-ecj/CleanupPlain.java @@ -18,7 +18,7 @@ class CleanupPlain { } finally { - if ((lombok.Lombok.preventNullAnalysis(out) != null)) + if ((java.util.Collections.singletonList(out).get(0) != null)) { out.close(); } @@ -26,7 +26,7 @@ class CleanupPlain { } finally { - if ((lombok.Lombok.preventNullAnalysis(in) != null)) + if ((java.util.Collections.singletonList(in).get(0) != null)) { in.close(); } From ead7ff428c14cbfd3a84723f8abae13d5ea79330 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 22 Mar 2011 21:02:04 +0100 Subject: [PATCH 12/17] jarjar now used to make sure asm is no longer on the bootclasspath when using lombok. --- build.xml | 7 +++++-- buildScripts/ivy.xml | 1 + doc/maven-pom.xml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/build.xml b/build.xml index d747e617..676c34d7 100644 --- a/build.xml +++ b/build.xml @@ -164,12 +164,15 @@ the common tasks and can be called on to run the main aspects of all the sub-scr - + + + + @@ -177,7 +180,7 @@ the common tasks and can be called on to run the main aspects of all the sub-scr - + diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index 4d3bb679..33d62da9 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -16,6 +16,7 @@ + diff --git a/doc/maven-pom.xml b/doc/maven-pom.xml index 61738a72..34955ab8 100644 --- a/doc/maven-pom.xml +++ b/doc/maven-pom.xml @@ -18,7 +18,7 @@ scm:git:git://github.com/rzwitserloot/lombok.git - scm:git:git://github.com/rzwitserloot/lombok.git + http://github.com/rzwitserloot/lombok Google Code From 816c0b99e7f0395b26f8a8c26e52110107f0b1e1 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 23 Mar 2011 07:39:13 +0100 Subject: [PATCH 13/17] Updated documentation of XArgsConstructor to highlight that we won't/can't remove suppressConstructorProperties until GWT and Android get the CP annotation. See issue #202 --- website/features/Constructor.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/features/Constructor.html b/website/features/Constructor.html index 072e46ed..c0ab9ef8 100644 --- a/website/features/Constructor.html +++ b/website/features/Constructor.html @@ -71,6 +71,10 @@

@XArgsConstructor can also be used on an enum definition. The generated constructor will always be private, because non-private constructors aren't legal in enums. You don't have to specify AccessLevel.PRIVATE. +

+ While suppressConstructorProperties has been marked deprecated in anticipation of a world where all java environments have the + @ConstructorProperties annotation available, first GWT 2.2 and Android 2.3.3, which do not (yet) have this annotation, will have + to be ancient history before this annotation parameter will be removed.

From ab1d938ca85870639dc912fdfc46955cb3b4764f Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 28 Mar 2011 21:36:08 +0200 Subject: [PATCH 14/17] Now delegating classes defined in the same project works. At this revision, you can easily and reliably reproduce issue #164 by creating a loop (A delegates B and B delegates A). --- src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java index 0aa47dba..846232f6 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java @@ -74,7 +74,6 @@ import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding; import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; -import org.eclipse.jdt.internal.compiler.lookup.MemberTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; @@ -475,7 +474,7 @@ public class PatchDelegate { inner = binding; } - if (inner instanceof MemberTypeBinding) { + if (inner instanceof SourceTypeBinding) { ClassScope cs = ((SourceTypeBinding)inner).scope; if (cs != null) { try { @@ -527,6 +526,7 @@ public class PatchDelegate { private static final List METHODS_IN_OBJECT = Collections.unmodifiableList(Arrays.asList( "hashCode()", + "canEqual(java.lang.Object)", //Not in j.l.Object, but it goes with hashCode and equals so if we ignore those two, we should ignore this one. "equals(java.lang.Object)", "wait()", "wait(long)", From 7ebf05aaec0c4ed0e70a3a2a8a0f56afd029bd46 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 1 Apr 2011 18:07:17 +0200 Subject: [PATCH 15/17] Added ability to log warnings in eclipse error log. --- src/core/lombok/eclipse/Eclipse.java | 77 ++++++++++++++++----- src/core/lombok/eclipse/HandlerLibrary.java | 2 +- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/core/lombok/eclipse/Eclipse.java b/src/core/lombok/eclipse/Eclipse.java index ddba726a..8910bb3e 100644 --- a/src/core/lombok/eclipse/Eclipse.java +++ b/src/core/lombok/eclipse/Eclipse.java @@ -1,5 +1,5 @@ /* - * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. + * Copyright © 2009-2011 Reinier Zwitserloot and Roel Spilker. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -89,46 +89,85 @@ public class Eclipse { /** * Generates an error in the Eclipse error log. Note that most people never look at it! - */ - public static void error(CompilationUnitDeclaration cud, String message) { - error(cud, message, DEFAULT_BUNDLE, null); - } - - /** - * Generates an error in the Eclipse error log. Note that most people never look at it! + * + * @param cud The {@code CompilationUnitDeclaration} where the error occurred. + * An error will be generated on line 0 linking to the error log entry. Can be {@code null}. + * @param message Human readable description of the problem. + * @param error The associated exception. Can be {@code null}. */ public static void error(CompilationUnitDeclaration cud, String message, Throwable error) { - error(cud, message, DEFAULT_BUNDLE, error); - } - - /** - * Generates an error in the Eclipse error log. Note that most people never look at it! - */ - public static void error(CompilationUnitDeclaration cud, String message, String bundleName) { - error(cud, message, bundleName, null); + error(cud, message, null, error); } /** * Generates an error in the Eclipse error log. Note that most people never look at it! + * + * @param cud The {@code CompilationUnitDeclaration} where the error occurred. + * An error will be generated on line 0 linking to the error log entry. Can be {@code null}. + * @param message Human readable description of the problem. + * @param bundleName Can be {@code null} to default to {@code org.eclipse.jdt.core} which is usually right. + * @param error The associated exception. Can be {@code null}. */ public static void error(CompilationUnitDeclaration cud, String message, String bundleName, Throwable error) { + if (bundleName == null) bundleName = DEFAULT_BUNDLE; try { new EclipseWorkspaceLogger().error(message, bundleName, error); - } catch (NoClassDefFoundError e) { //standalone ecj does not jave Platform, ILog, IStatus, and friends. + } catch (NoClassDefFoundError e) { //standalone ecj does not jave Platform, ILog, IStatus, and friends. new TerminalLogger().error(message, bundleName, error); } if (cud != null) EclipseAST.addProblemToCompilationResult(cud, false, message + " - See error log.", 0, 0); } + /** + * Generates a warning in the Eclipse error log. Note that most people never look at it! + * + * @param cud The {@code CompilationUnitDeclaration} where the error occurred. + * An error will be generated on line 0 linking to the error log entry. Can be {@code null}. + * @param message Human readable description of the problem. + * @param error The associated exception. Can be {@code null}. + */ + public static void warning(String message, Throwable error) { + warning(message, null, error); + } + + /** + * Generates a warning in the Eclipse error log. Note that most people never look at it! + * + * @param message Human readable description of the problem. + * @param bundleName Can be {@code null} to default to {@code org.eclipse.jdt.core} which is usually right. + * @param error The associated exception. Can be {@code null}. + */ + public static void warning(String message, String bundleName, Throwable error) { + if (bundleName == null) bundleName = DEFAULT_BUNDLE; + try { + new EclipseWorkspaceLogger().warning(message, bundleName, error); + } catch (NoClassDefFoundError e) { //standalone ecj does not jave Platform, ILog, IStatus, and friends. + new TerminalLogger().warning(message, bundleName, error); + } + } + private static class TerminalLogger { void error(String message, String bundleName, Throwable error) { System.err.println(message); - error.printStackTrace(); + if (error != null) error.printStackTrace(); + } + + void warning(String message, String bundleName, Throwable error) { + System.err.println(message); + if (error != null) error.printStackTrace(); } } private static class EclipseWorkspaceLogger { void error(String message, String bundleName, Throwable error) { + msg(IStatus.ERROR, message, bundleName, error); + } + + void warning(String message, String bundleName, Throwable error) { + msg(IStatus.WARNING, message, bundleName, error); + } + + private void msg(int msgType, String message, String bundleName, Throwable error) { Bundle bundle = Platform.getBundle(bundleName); if (bundle == null) { System.err.printf("Can't find bundle %s while trying to report error:\n%s\n", bundleName, message); @@ -137,7 +176,7 @@ public class Eclipse { ILog log = Platform.getLog(bundle); - log.log(new Status(IStatus.ERROR, bundleName, message, error)); + log.log(new Status(msgType, bundleName, message, error)); } } diff --git a/src/core/lombok/eclipse/HandlerLibrary.java b/src/core/lombok/eclipse/HandlerLibrary.java index df4681f0..ba7f891a 100644 --- a/src/core/lombok/eclipse/HandlerLibrary.java +++ b/src/core/lombok/eclipse/HandlerLibrary.java @@ -103,7 +103,7 @@ public class HandlerLibrary { SpiLoadUtil.findAnnotationClass(handler.getClass(), EclipseAnnotationHandler.class); AnnotationHandlerContainer container = new AnnotationHandlerContainer(handler, annotationClass); if (lib.annotationHandlers.put(container.annotationClass.getName(), container) != null) { - Eclipse.error(null, "Duplicate handlers for annotation type: " + container.annotationClass.getName()); + Eclipse.error(null, "Duplicate handlers for annotation type: " + container.annotationClass.getName(), null); } lib.typeLibrary.addType(container.annotationClass.getName()); } catch (Throwable t) { From 1a589ca221a172845a108a6c759018c6e25d5cdd Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 1 Apr 2011 18:07:46 +0200 Subject: [PATCH 16/17] Now logging a warning with diagnostic info so that the next time a user runs into issue #164, we can get a more useful stracktrace from them. --- .../eclipse/handlers/EclipseHandlerUtil.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 860cf44f..a83ba836 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -500,6 +500,27 @@ public class EclipseHandlerUtil { method.annotations = createSuppressWarningsAll(method, method.annotations); TypeDeclaration parent = (TypeDeclaration) type.get(); + if (parent.scope != null && method.scope == null) { + // We think this means heisenbug #164 is about to happen later in some other worker thread. + // To improve our ability to figure out what the heck is going on, let's generate a log so we can ask those who stumble on this about it, + // and thus see a far more useful stack trace. + boolean report = true; + for (StackTraceElement elem : Thread.currentThread().getStackTrace()) { + // We intentionally hook into the middle of ClassScope filling in BlockScopes for PatchDelegate, + // meaning that will trigger a false positive. Detect it and do not report the occurence of #164 if so. + if ("lombok.eclipse.agent.PatchDelegate".equals(elem.getClassName())) { + report = false; + break; + } + } + + if (report) { + Eclipse.warning("We believe you may have just stumbled on lombok issue #164. Please " + + "report the stack trace associated with this message at:\n" + + "http://code.google.com/p/projectlombok/issues/detail?id=164", new Throwable()); + } + } + if (parent.methods == null) { parent.methods = new AbstractMethodDeclaration[1]; parent.methods[0] = method; From 12e4f36a2f5aae5b17266fb15376c82d74b7bf95 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 1 Apr 2011 19:55:50 +0200 Subject: [PATCH 17/17] Yet another eclipse mirror went down or deleted an older version. We're now hosting this dependency ourselves; it was the last one we weren't already hosting. Also upped version from 3.6.0 to 3.6.2. --- ...ustom-ecj-3.6.0.xml => org.eclipse.custom-ecj-3.6.2.xml} | 6 +++--- buildScripts/ivy.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename buildScripts/ivy-repo/{org.eclipse.custom-ecj-3.6.0.xml => org.eclipse.custom-ecj-3.6.2.xml} (57%) diff --git a/buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.0.xml b/buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.2.xml similarity index 57% rename from buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.0.xml rename to buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.2.xml index 6ea9088e..fc9fa661 100644 --- a/buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.0.xml +++ b/buildScripts/ivy-repo/org.eclipse.custom-ecj-3.6.2.xml @@ -1,5 +1,5 @@ - + @@ -8,7 +8,7 @@ - - + + diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index 33d62da9..7ff6bdc9 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -27,7 +27,7 @@ - +