diff options
Diffstat (limited to 'src/core/lombok/eclipse/handlers/HandleWither.java')
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleWither.java | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleWither.java b/src/core/lombok/eclipse/handlers/HandleWither.java index 30306b72..8b038676 100644 --- a/src/core/lombok/eclipse/handlers/HandleWither.java +++ b/src/core/lombok/eclipse/handlers/HandleWither.java @@ -88,7 +88,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { //Skip final fields. if ((fieldDecl.modifiers & ClassFileConstants.AccFinal) != 0 && fieldDecl.initialization != null) continue; - generateWitherForField(field, pos.get(), level); + generateWitherForField(field, pos, level); } return true; } @@ -106,7 +106,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { * If not, the wither is still generated if it isn't already there, though there will not * be a warning if its already there. The default access level is used. */ - public void generateWitherForField(EclipseNode fieldNode, ASTNode pos, AccessLevel level) { + public void generateWitherForField(EclipseNode fieldNode, EclipseNode sourceNode, AccessLevel level) { for (EclipseNode child : fieldNode.down()) { if (child.getKind() == Kind.ANNOTATION) { if (annotationTypeMatches(Wither.class, child)) { @@ -117,7 +117,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { } List<Annotation> empty = Collections.emptyList(); - createWitherForField(level, fieldNode, fieldNode, pos, false, empty, empty); + createWitherForField(level, fieldNode, sourceNode, false, empty, empty); } @Override public void handle(AnnotationValues<Wither> annotation, Annotation ast, EclipseNode annotationNode) { @@ -132,7 +132,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { switch (node.getKind()) { case FIELD: - createWitherForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, annotationNode.get(), true, onMethod, onParam); + createWitherForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, true, onMethod, onParam); break; case TYPE: if (!onMethod.isEmpty()) { @@ -146,18 +146,20 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { } } - public void createWitherForFields(AccessLevel level, Collection<EclipseNode> fieldNodes, EclipseNode errorNode, ASTNode source, boolean whineIfExists, List<Annotation> onMethod, List<Annotation> onParam) { + public void createWitherForFields(AccessLevel level, Collection<EclipseNode> fieldNodes, EclipseNode sourceNode, boolean whineIfExists, List<Annotation> onMethod, List<Annotation> onParam) { for (EclipseNode fieldNode : fieldNodes) { - createWitherForField(level, fieldNode, errorNode, source, whineIfExists, onMethod, onParam); + createWitherForField(level, fieldNode, sourceNode, whineIfExists, onMethod, onParam); } } public void createWitherForField( - AccessLevel level, EclipseNode fieldNode, EclipseNode errorNode, - ASTNode source, boolean whineIfExists, List<Annotation> onMethod, + AccessLevel level, EclipseNode fieldNode, EclipseNode sourceNode, + boolean whineIfExists, List<Annotation> onMethod, List<Annotation> onParam) { + + ASTNode source = sourceNode.get(); if (fieldNode.getKind() != Kind.FIELD) { - errorNode.addError("@Wither is only supported on a class or a field."); + sourceNode.addError("@Wither is only supported on a class or a field."); return; } @@ -167,22 +169,22 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { String witherName = toWitherName(fieldNode, isBoolean); if (witherName == null) { - errorNode.addWarning("Not generating wither for this field: It does not fit your @Accessors prefix list."); + fieldNode.addWarning("Not generating wither for this field: It does not fit your @Accessors prefix list."); return; } if ((field.modifiers & ClassFileConstants.AccStatic) != 0) { - errorNode.addWarning("Not generating wither for this field: Withers cannot be generated for static fields."); + fieldNode.addWarning("Not generating wither for this field: Withers cannot be generated for static fields."); return; } if ((field.modifiers & ClassFileConstants.AccFinal) != 0 && field.initialization != null) { - errorNode.addWarning("Not generating wither for this field: Withers cannot be generated for final, initialized fields."); + fieldNode.addWarning("Not generating wither for this field: Withers cannot be generated for final, initialized fields."); return; } if (field.name != null && field.name.length > 0 && field.name[0] == '$') { - errorNode.addWarning("Not generating wither for this field: Withers cannot be generated for fields starting with $."); + fieldNode.addWarning("Not generating wither for this field: Withers cannot be generated for fields starting with $."); return; } @@ -194,7 +196,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { if (whineIfExists) { String altNameExpl = ""; if (!altName.equals(witherName)) altNameExpl = String.format(" (%s)", altName); - errorNode.addWarning( + fieldNode.addWarning( String.format("Not generating %s(): A method with that name already exists%s", witherName, altNameExpl)); } return; @@ -206,11 +208,12 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { int modifier = toEclipseModifier(level); - MethodDeclaration method = createWither((TypeDeclaration) fieldNode.up().get(), fieldNode, witherName, modifier, source, onMethod, onParam); + MethodDeclaration method = createWither((TypeDeclaration) fieldNode.up().get(), fieldNode, witherName, modifier, sourceNode, onMethod, onParam); injectMethod(fieldNode.up(), method); } - public MethodDeclaration createWither(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, ASTNode source, List<Annotation> onMethod, List<Annotation> onParam) { + public MethodDeclaration createWither(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) { + ASTNode source = sourceNode.get(); if (name == null) return null; FieldDeclaration field = (FieldDeclaration) fieldNode.get(); int pS = source.sourceStart, pE = source.sourceEnd; @@ -273,7 +276,7 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> { Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN); List<Statement> statements = new ArrayList<Statement>(5); if (nonNulls.length > 0) { - Statement nullCheck = generateNullCheck(field, source); + Statement nullCheck = generateNullCheck(field, sourceNode); if (nullCheck != null) statements.add(nullCheck); } statements.add(returnStatement); |