diff options
author | Roel Spilker <r.spilker@gmail.com> | 2009-08-01 01:42:52 +0200 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2009-08-01 01:42:52 +0200 |
commit | f2c837bb47771a7eba5ad5a885af162d8d133559 (patch) | |
tree | 23be7f4b58a82b3c573edcd0e927d55cb4c7a290 /src/lombok/javac | |
parent | 0cfa9e99d99fc353d0c486e96cc53f5214ab031c (diff) | |
download | lombok-f2c837bb47771a7eba5ad5a885af162d8d133559.tar.gz lombok-f2c837bb47771a7eba5ad5a885af162d8d133559.tar.bz2 lombok-f2c837bb47771a7eba5ad5a885af162d8d133559.zip |
@Setter will copy all NotNull and NonNull (case-insensitive) annotations to the parameter
@Getter will copy them to the getter method
Added @NonNull to lombok to support null-checks in the setter
Diffstat (limited to 'src/lombok/javac')
-rw-r--r-- | src/lombok/javac/handlers/HandleGetter.java | 3 | ||||
-rw-r--r-- | src/lombok/javac/handlers/HandleSetter.java | 8 | ||||
-rw-r--r-- | src/lombok/javac/handlers/PKG.java | 11 |
3 files changed, 13 insertions, 9 deletions
diff --git a/src/lombok/javac/handlers/HandleGetter.java b/src/lombok/javac/handlers/HandleGetter.java index 3d3227e4..370a405b 100644 --- a/src/lombok/javac/handlers/HandleGetter.java +++ b/src/lombok/javac/handlers/HandleGetter.java @@ -128,7 +128,8 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> { List<JCExpression> throwsClauses = List.nil(); JCExpression annotationMethodDefaultValue = null; - return treeMaker.MethodDef(treeMaker.Modifiers(access, List.<JCAnnotation>nil()), methodName, methodType, + List<JCAnnotation> annotations = findNonNullAnnotations(field); + return treeMaker.MethodDef(treeMaker.Modifiers(access, annotations), methodName, methodType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue); } } diff --git a/src/lombok/javac/handlers/HandleSetter.java b/src/lombok/javac/handlers/HandleSetter.java index b4720387..2f41e716 100644 --- a/src/lombok/javac/handlers/HandleSetter.java +++ b/src/lombok/javac/handlers/HandleSetter.java @@ -121,10 +121,9 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> { JCFieldAccess thisX = treeMaker.Select(treeMaker.Ident(field.toName("this")), fieldDecl.name); JCAssign assign = treeMaker.Assign(thisX, treeMaker.Ident(fieldDecl.name)); - List<JCStatement> statements; - JCAnnotation nonNull = findNonNullAnnotation(field); - if (nonNull == null) { + List<JCAnnotation> nonNulls = findNonNullAnnotations(field); + if (nonNulls.isEmpty()) { statements = List.<JCStatement>of(treeMaker.Exec(assign)); } else { @@ -137,7 +136,8 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> { JCBlock methodBody = treeMaker.Block(0, statements); Name methodName = field.toName(toSetterName(fieldDecl)); - JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(0), fieldDecl.name, fieldDecl.vartype, null); + + JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(0, nonNulls), fieldDecl.name, fieldDecl.vartype, null); JCExpression methodType = treeMaker.Type(field.getSymbolTable().voidType); List<JCTypeParameter> methodGenericParams = List.nil(); diff --git a/src/lombok/javac/handlers/PKG.java b/src/lombok/javac/handlers/PKG.java index bc5b691c..ea794296 100644 --- a/src/lombok/javac/handlers/PKG.java +++ b/src/lombok/javac/handlers/PKG.java @@ -254,16 +254,19 @@ class PKG { return e; } - static JCAnnotation findNonNullAnnotation(Node fieldNode) { + static List<JCAnnotation> findNonNullAnnotations(Node fieldNode) { + List<JCAnnotation> result = List.nil(); for ( Node child : fieldNode.down() ) { if ( child.getKind() == Kind.ANNOTATION ) { JCAnnotation annotation = (JCAnnotation) child.get(); String name = annotation.annotationType.toString(); - if (name.equals("NonNull") || name.endsWith(".NonNull")) { - return annotation; + int idx = name.lastIndexOf("."); + String suspect = idx == -1 ? name : name.substring(idx + 1); + if (suspect.equalsIgnoreCase("NonNull") || suspect.equalsIgnoreCase("NotNull")) { + result = result.append(annotation); } } } - return null; + return result; } } |