aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers/HandleSetter.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2014-05-23 04:07:39 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2014-05-23 04:07:39 +0200
commit4b878f9ba996f852ce555c3024512ae34e34774e (patch)
tree51ac37ecbb2e5f35b62523f9eec896211f758072 /src/core/lombok/eclipse/handlers/HandleSetter.java
parent57c92478a92360a1d1547794d5a5d0b5393f59f6 (diff)
downloadlombok-4b878f9ba996f852ce555c3024512ae34e34774e.tar.gz
lombok-4b878f9ba996f852ce555c3024512ae34e34774e.tar.bz2
lombok-4b878f9ba996f852ce555c3024512ae34e34774e.zip
Added confkey to make @NonNull generate a different exception because of the IllegalArgumentException vs. NullPointerException that we really don’t want to get into.
Diffstat (limited to 'src/core/lombok/eclipse/handlers/HandleSetter.java')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java
index 74ef07b5..c22af676 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -90,7 +90,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
//Skip final fields.
if ((fieldDecl.modifiers & ClassFileConstants.AccFinal) != 0) continue;
- generateSetterForField(field, pos.get(), level);
+ generateSetterForField(field, pos, level);
}
return true;
}
@@ -107,7 +107,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
* If not, the setter 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 generateSetterForField(EclipseNode fieldNode, ASTNode pos, AccessLevel level) {
+ public void generateSetterForField(EclipseNode fieldNode, EclipseNode sourceNode, AccessLevel level) {
if (hasAnnotation(Setter.class, fieldNode)) {
//The annotation will make it happen, so we can skip it.
return;
@@ -115,7 +115,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
List<Annotation> empty = Collections.emptyList();
- createSetterForField(level, fieldNode, fieldNode, pos, false, empty, empty);
+ createSetterForField(level, fieldNode, sourceNode, false, empty, empty);
}
public void handle(AnnotationValues<Setter> annotation, Annotation ast, EclipseNode annotationNode) {
@@ -130,7 +130,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
switch (node.getKind()) {
case FIELD:
- createSetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, annotationNode.get(), true, onMethod, onParam);
+ createSetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, true, onMethod, onParam);
break;
case TYPE:
if (!onMethod.isEmpty()) {
@@ -144,19 +144,20 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
}
}
- public void createSetterForFields(AccessLevel level, Collection<EclipseNode> fieldNodes, EclipseNode errorNode, ASTNode source, boolean whineIfExists, List<Annotation> onMethod, List<Annotation> onParam) {
+ public void createSetterForFields(AccessLevel level, Collection<EclipseNode> fieldNodes, EclipseNode sourceNode, boolean whineIfExists, List<Annotation> onMethod, List<Annotation> onParam) {
for (EclipseNode fieldNode : fieldNodes) {
- createSetterForField(level, fieldNode, errorNode, source, whineIfExists, onMethod, onParam);
+ createSetterForField(level, fieldNode, sourceNode, whineIfExists, onMethod, onParam);
}
}
public void createSetterForField(
- 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("@Setter is only supported on a class or a field.");
+ sourceNode.addError("@Setter is only supported on a class or a field.");
return;
}
@@ -167,7 +168,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
boolean shouldReturnThis = shouldReturnThis(fieldNode);
if (setterName == null) {
- errorNode.addWarning("Not generating setter for this field: It does not fit your @Accessors prefix list.");
+ fieldNode.addWarning("Not generating setter for this field: It does not fit your @Accessors prefix list.");
return;
}
@@ -181,7 +182,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
if (whineIfExists) {
String altNameExpl = "";
if (!altName.equals(setterName)) altNameExpl = String.format(" (%s)", altName);
- errorNode.addWarning(
+ fieldNode.addWarning(
String.format("Not generating %s(): A method with that name already exists%s", setterName, altNameExpl));
}
return;
@@ -191,12 +192,13 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
}
}
- MethodDeclaration method = createSetter((TypeDeclaration) fieldNode.up().get(), fieldNode, setterName, shouldReturnThis, modifier, source, onMethod, onParam);
+ MethodDeclaration method = createSetter((TypeDeclaration) fieldNode.up().get(), fieldNode, setterName, shouldReturnThis, modifier, sourceNode, onMethod, onParam);
injectMethod(fieldNode.up(), method);
}
- static MethodDeclaration createSetter(TypeDeclaration parent, EclipseNode fieldNode, String name, boolean shouldReturnThis, int modifier, ASTNode source, List<Annotation> onMethod, List<Annotation> onParam) {
+ static MethodDeclaration createSetter(TypeDeclaration parent, EclipseNode fieldNode, String name, boolean shouldReturnThis, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
+ ASTNode source = sourceNode.get();
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
@@ -239,7 +241,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
if (nonNulls.length == 0) {
statements.add(assignment);
} else {
- Statement nullCheck = generateNullCheck(field, source);
+ Statement nullCheck = generateNullCheck(field, sourceNode);
if (nullCheck != null) statements.add(nullCheck);
statements.add(assignment);
}