diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-08-28 00:02:15 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-08-28 00:02:15 +0200 |
commit | e1ee1b7d2db1ea998aa4d6aa3f6b4141315a9496 (patch) | |
tree | 5f014017561f6a9cff56e8ad35f2c6e3cf7b882e /src/lombok/javac/handlers/PKG.java | |
parent | d16775032b638789f998f3f362b7ed7d4f5098ae (diff) | |
download | lombok-e1ee1b7d2db1ea998aa4d6aa3f6b4141315a9496.tar.gz lombok-e1ee1b7d2db1ea998aa4d6aa3f6b4141315a9496.tar.bz2 lombok-e1ee1b7d2db1ea998aa4d6aa3f6b4141315a9496.zip |
null checks are no longer generated if you put @NonNull on primitives.
Diffstat (limited to 'src/lombok/javac/handlers/PKG.java')
-rw-r--r-- | src/lombok/javac/handlers/PKG.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lombok/javac/handlers/PKG.java b/src/lombok/javac/handlers/PKG.java index 42cfed13..4b05b9ae 100644 --- a/src/lombok/javac/handlers/PKG.java +++ b/src/lombok/javac/handlers/PKG.java @@ -51,6 +51,11 @@ class PKG { //Prevent instantiation } + static boolean isPrimitive(JCExpression ref) { + String typeName = ref.toString(); + return TransformationsUtil.PRIMITIVE_TYPE_NAME_PATTERN.matcher(typeName).matches(); + } + static java.util.List<String> toAllGetterNames(JCVariableDecl field) { CharSequence fieldName = field.name; @@ -258,9 +263,6 @@ class PKG { return e; } - static final Pattern NON_NULL_PATTERN = Pattern.compile("^no[tn]null$", Pattern.CASE_INSENSITIVE); - static final Pattern NULLABLE_PATTERN = Pattern.compile("^nullable$", Pattern.CASE_INSENSITIVE); - static List<JCAnnotation> findAnnotations(Node fieldNode, Pattern namePattern) { List<JCAnnotation> result = List.nil(); for ( Node child : fieldNode.down() ) { @@ -278,7 +280,9 @@ class PKG { } static JCStatement generateNullCheck(TreeMaker treeMaker, JavacAST.Node variable) { - Name fieldName = ((JCVariableDecl) variable.get()).name; + JCVariableDecl varDecl = (JCVariableDecl) variable.get(); + if (isPrimitive(varDecl.vartype)) return null; + Name fieldName = varDecl.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); |