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/eclipse/handlers/HandleGetter.java | |
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/eclipse/handlers/HandleGetter.java')
-rw-r--r-- | src/lombok/eclipse/handlers/HandleGetter.java | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/lombok/eclipse/handlers/HandleGetter.java b/src/lombok/eclipse/handlers/HandleGetter.java index 982ccc97..6a4c5ceb 100644 --- a/src/lombok/eclipse/handlers/HandleGetter.java +++ b/src/lombok/eclipse/handlers/HandleGetter.java @@ -27,7 +27,7 @@ import lombok.Getter; import lombok.core.AnnotationValues; import lombok.core.TransformationsUtil; import lombok.core.AST.Kind; -import lombok.eclipse.Eclipse; +import static lombok.eclipse.Eclipse.*; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseAST.Node; @@ -64,7 +64,7 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> { public void generateGetterForField(Node fieldNode, ASTNode pos) { for ( Node child : fieldNode.down() ) { if ( child.getKind() == Kind.ANNOTATION ) { - if ( Eclipse.annotationTypeMatches(Getter.class, child) ) { + if ( annotationTypeMatches(Getter.class, child) ) { //The annotation will make it happen, so we can skip it. return; } @@ -87,7 +87,7 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> { } FieldDeclaration field = (FieldDeclaration) fieldNode.get(); - TypeReference fieldType = Eclipse.copyType(field.type); + TypeReference fieldType = copyType(field.type); String fieldName = new String(field.name); boolean isBoolean = nameEquals(fieldType.getTypeName(), "boolean") && fieldType.dimensions() == 0; String getterName = TransformationsUtil.toGetterName(fieldName, isBoolean); @@ -113,6 +113,10 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> { } MethodDeclaration method = generateGetter((TypeDeclaration) fieldNode.up().get(), field, getterName, modifier, pos); + Annotation[] nonNulls = findNonNullAnnotations(field); + if (nonNulls.length != 0) { + method.annotations = copyAnnotations(nonNulls); + } injectMethod(fieldNode.up(), method); @@ -123,14 +127,14 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> { int modifier, ASTNode pos) { MethodDeclaration method = new MethodDeclaration(parent.compilationResult); method.modifiers = modifier; - method.returnType = Eclipse.copyType(field.type); + method.returnType = copyType(field.type); method.annotations = null; method.arguments = null; method.selector = name.toCharArray(); method.binding = null; method.thrownExceptions = null; method.typeParameters = null; - method.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; + method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; Expression fieldExpression = new SingleNameReference(field.name, (field.declarationSourceStart << 32) | field.declarationSourceEnd); Statement returnStatement = new ReturnStatement(fieldExpression, field.sourceStart, field.sourceEnd); method.bodyStart = method.declarationSourceStart = method.sourceStart = pos.sourceStart; |