aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers/HandleCleanup.java
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2010-11-02 20:39:58 +0100
committerRoel Spilker <r.spilker@gmail.com>2010-11-02 20:39:58 +0100
commit17bcfda43b9e939ac22d5247ef98905741650432 (patch)
tree435ab418b82486b17931a2f9feb94b9eecc53940 /src/core/lombok/eclipse/handlers/HandleCleanup.java
parent5897d9685e4f606319a9707ae22efe4740b3f630 (diff)
downloadlombok-17bcfda43b9e939ac22d5247ef98905741650432.tar.gz
lombok-17bcfda43b9e939ac22d5247ef98905741650432.tar.bz2
lombok-17bcfda43b9e939ac22d5247ef98905741650432.zip
Issue 154: Add null-check to @Cleanup
Diffstat (limited to 'src/core/lombok/eclipse/handlers/HandleCleanup.java')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleCleanup.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleCleanup.java b/src/core/lombok/eclipse/handlers/HandleCleanup.java
index d296e96b..33ab7fb9 100644
--- a/src/core/lombok/eclipse/handlers/HandleCleanup.java
+++ b/src/core/lombok/eclipse/handlers/HandleCleanup.java
@@ -37,9 +37,13 @@ import org.eclipse.jdt.internal.compiler.ast.Assignment;
import org.eclipse.jdt.internal.compiler.ast.Block;
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
import org.eclipse.jdt.internal.compiler.ast.CastExpression;
+import org.eclipse.jdt.internal.compiler.ast.EqualExpression;
+import org.eclipse.jdt.internal.compiler.ast.IfStatement;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
+import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
+import org.eclipse.jdt.internal.compiler.ast.OperatorIds;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.Statement;
import org.eclipse.jdt.internal.compiler.ast.SwitchStatement;
@@ -157,7 +161,29 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
}
unsafeClose.nameSourcePosition = nameSourcePosition;
unsafeClose.selector = cleanupName.toCharArray();
- finallyBlock[0] = unsafeClose;
+
+
+ int pS = ast.sourceStart, pE = ast.sourceEnd;
+ long p = (long)pS << 32 | pE;
+
+ SingleNameReference varName = new SingleNameReference(decl.name, p);
+ Eclipse.setGeneratedBy(varName, ast);
+ NullLiteral nullLiteral = new NullLiteral(pS, pE);
+ Eclipse.setGeneratedBy(nullLiteral, ast);
+ EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, OperatorIds.NOT_EQUAL);
+ equalExpression.sourceStart = pS; equalExpression.sourceEnd = pE;
+ Eclipse.setGeneratedBy(equalExpression, ast);
+
+ Block closeBlock = new Block(0);
+ closeBlock.statements = new Statement[1];
+ closeBlock.statements[0] = unsafeClose;
+ Eclipse.setGeneratedBy(closeBlock, ast);
+ IfStatement ifStatement = new IfStatement(equalExpression, closeBlock, 0, 0);
+ Eclipse.setGeneratedBy(ifStatement, ast);
+
+
+
+ finallyBlock[0] = ifStatement;
tryStatement.finallyBlock = new Block(0);
Eclipse.setGeneratedBy(tryStatement.finallyBlock, ast);
tryStatement.finallyBlock.statements = finallyBlock;