aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/javac/handlers/HandleSetter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/lombok/javac/handlers/HandleSetter.java')
-rw-r--r--src/lombok/javac/handlers/HandleSetter.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lombok/javac/handlers/HandleSetter.java b/src/lombok/javac/handlers/HandleSetter.java
index 2e25ee57..412b1c43 100644
--- a/src/lombok/javac/handlers/HandleSetter.java
+++ b/src/lombok/javac/handlers/HandleSetter.java
@@ -119,9 +119,19 @@ 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));
- JCBlock methodBody = treeMaker.Block(0, List.<JCStatement>of(treeMaker.Exec(assign)));
+ List<JCStatement> statements;
+ List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
+ List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
+ if (nonNulls.isEmpty()) {
+ statements = List.<JCStatement>of(treeMaker.Exec(assign));
+ }
+ else {
+ statements = List.<JCStatement>of(generateNullCheck(treeMaker, field), treeMaker.Exec(assign));
+ }
+
+ JCBlock methodBody = treeMaker.Block(0, statements);
Name methodName = field.toName(toSetterName(fieldDecl));
- JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL), fieldDecl.name, fieldDecl.vartype, null);
+ JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL, nonNulls.appendList(nullables)), fieldDecl.name, fieldDecl.vartype, null);
JCExpression methodType = treeMaker.Type(field.getSymbolTable().voidType);
List<JCTypeParameter> methodGenericParams = List.nil();