aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/javac/handlers/PKG.java
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2009-08-01 02:10:29 +0200
committerRoel Spilker <r.spilker@gmail.com>2009-08-01 02:10:29 +0200
commitc4d97b008afc85e495784929c312c6828aefde1d (patch)
tree920c80009a00c0a27e03c8f2aeaae459c28d7ad4 /src/lombok/javac/handlers/PKG.java
parentf2c837bb47771a7eba5ad5a885af162d8d133559 (diff)
downloadlombok-c4d97b008afc85e495784929c312c6828aefde1d.tar.gz
lombok-c4d97b008afc85e495784929c312c6828aefde1d.tar.bz2
lombok-c4d97b008afc85e495784929c312c6828aefde1d.zip
Moved the check to see if a variable is null to the PKG utility classes
Diffstat (limited to 'src/lombok/javac/handlers/PKG.java')
-rw-r--r--src/lombok/javac/handlers/PKG.java11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/lombok/javac/handlers/PKG.java b/src/lombok/javac/handlers/PKG.java
index ea794296..006e92a3 100644
--- a/src/lombok/javac/handlers/PKG.java
+++ b/src/lombok/javac/handlers/PKG.java
@@ -30,14 +30,17 @@ import lombok.javac.JavacAST;
import lombok.javac.JavacAST.Node;
import com.sun.tools.javac.code.Flags;
+import com.sun.tools.javac.code.TypeTags;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
+import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.Name;
/**
* Container for static utility methods relevant to this package.
@@ -269,4 +272,12 @@ class PKG {
}
return result;
}
+
+ static JCStatement generateNullCheck(TreeMaker treeMaker, JavacAST.Node variable) {
+ Name fieldName = ((JCVariableDecl) variable.get()).name;
+ JCExpression npe = chainDots(treeMaker, variable, "java", "lang", "NullPointerException");
+ JCTree exception = treeMaker.NewClass(null, List.<JCExpression>nil(), npe, List.<JCExpression>of(treeMaker.Literal(fieldName.toString())), null);
+ JCStatement throwStatement = treeMaker.Throw(exception);
+ return treeMaker.If(treeMaker.Binary(JCTree.EQ, treeMaker.Ident(fieldName), treeMaker.Literal(TypeTags.BOT, null)), throwStatement, null);
+ }
}