aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse
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
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')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java24
-rw-r--r--src/core/lombok/eclipse/handlers/HandleBuilder.java13
-rw-r--r--src/core/lombok/eclipse/handlers/HandleConstructor.java43
-rw-r--r--src/core/lombok/eclipse/handlers/HandleData.java4
-rw-r--r--src/core/lombok/eclipse/handlers/HandleNonNull.java2
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java30
-rw-r--r--src/core/lombok/eclipse/handlers/HandleValue.java3
-rw-r--r--src/core/lombok/eclipse/handlers/HandleWither.java37
8 files changed, 102 insertions, 54 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index a93f321b..022cad91 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -1396,17 +1396,35 @@ public class EclipseHandlerUtil {
}
/**
- * Generates a new statement that checks if the given variable is null, and if so, throws a {@code NullPointerException} with the
+ * Generates a new statement that checks if the given variable is null, and if so, throws a specified exception with the
* variable name as message.
+ *
+ * @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}.
*/
- public static Statement generateNullCheck(AbstractVariableDeclaration variable, ASTNode source) {
+ public static Statement generateNullCheck(AbstractVariableDeclaration variable, EclipseNode sourceNode) {
+ String exceptionType = sourceNode.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE);
+ if (exceptionType == null) {
+ exceptionType = HandlerUtil.DEFAULT_EXCEPTION_FOR_NON_NULL;
+ } else {
+ if (!HandlerUtil.isLegalBasicClassReference(exceptionType)) {
+ sourceNode.addWarning("Configuration key contains invalid java type reference '" + exceptionType + "'; use something like 'java.lang.NullPointerException' as value for this key.");
+ exceptionType = HandlerUtil.DEFAULT_EXCEPTION_FOR_NON_NULL;
+ }
+ }
+
+ ASTNode source = sourceNode.get();
+
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
if (isPrimitive(variable.type)) return null;
AllocationExpression exception = new AllocationExpression();
setGeneratedBy(exception, source);
- exception.type = new QualifiedTypeReference(fromQualifiedName("java.lang.NullPointerException"), new long[]{p, p, p});
+ int partCount = 0;
+ for (int i = 0; i < exceptionType.length(); i++) if (exceptionType.charAt(i) == '.') partCount++;
+ long[] ps = new long[partCount];
+ Arrays.fill(ps, 0L);
+ exception.type = new QualifiedTypeReference(fromQualifiedName(exceptionType), ps);
setGeneratedBy(exception.type, source);
exception.arguments = new Expression[] { new StringLiteral(variable.name, pS, pE, 0)};
setGeneratedBy(exception.arguments[0], source);
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index 64e01c6e..522501f6 100644
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -120,7 +120,8 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
fields.add(fieldNode);
}
- new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, fields, null, SkipIfConstructorExists.I_AM_BUILDER, null, Collections.<Annotation>emptyList(), ast);
+ new HandleConstructor().generateConstructor(tdParent, AccessLevel.PACKAGE, fields, null, SkipIfConstructorExists.I_AM_BUILDER, null,
+ Collections.<Annotation>emptyList(), annotationNode);
returnType = namePlusTypeParamsToTypeReference(td.name, td.typeParameters, p);
typeParams = td.typeParameters;
@@ -204,12 +205,14 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
List<EclipseNode> fieldNodes = addFieldsToBuilder(builderType, namesOfParameters, typesOfParameters, ast);
List<AbstractMethodDeclaration> newMethods = new ArrayList<AbstractMethodDeclaration>();
for (EclipseNode fieldNode : fieldNodes) {
- MethodDeclaration newMethod = makeSetterMethodForBuilder(builderType, fieldNode, ast, builderInstance.fluent(), builderInstance.chain());
+ MethodDeclaration newMethod = makeSetterMethodForBuilder(builderType, fieldNode, annotationNode, builderInstance.fluent(), builderInstance.chain());
if (newMethod != null) newMethods.add(newMethod);
}
if (constructorExists(builderType) == MemberExistsResult.NOT_EXISTS) {
- ConstructorDeclaration cd = HandleConstructor.createConstructor(AccessLevel.PACKAGE, builderType, Collections.<EclipseNode>emptyList(), null, ast, Collections.<Annotation>emptyList());
+ ConstructorDeclaration cd = HandleConstructor.createConstructor(
+ AccessLevel.PACKAGE, builderType, Collections.<EclipseNode>emptyList(), null,
+ annotationNode, Collections.<Annotation>emptyList());
if (cd != null) injectMethod(builderType, cd);
}
@@ -334,7 +337,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
private static final AbstractMethodDeclaration[] EMPTY = {};
- public MethodDeclaration makeSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, ASTNode source, boolean fluent, boolean chain) {
+ public MethodDeclaration makeSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode, EclipseNode sourceNode, boolean fluent, boolean chain) {
TypeDeclaration td = (TypeDeclaration) builderType.get();
AbstractMethodDeclaration[] existing = td.methods;
if (existing == null) existing = EMPTY;
@@ -352,7 +355,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
String setterName = fluent ? fieldNode.getName() : toSetterName(builderType.getAst(), null, fieldNode.getName(), isBoolean);
return HandleSetter.createSetter(td, fieldNode, setterName, chain, ClassFileConstants.AccPublic,
- source, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
+ sourceNode, Collections.<Annotation>emptyList(), Collections.<Annotation>emptyList());
}
public EclipseNode findInnerClass(EclipseNode parent, String name) {
diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java
index 4e35ebb6..b72d000f 100644
--- a/src/core/lombok/eclipse/handlers/HandleConstructor.java
+++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java
@@ -82,7 +82,7 @@ public class HandleConstructor {
List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@NoArgsConstructor(onConstructor=", annotationNode);
- new HandleConstructor().generateConstructor(typeNode, level, fields, staticName, SkipIfConstructorExists.NO, null, onConstructor, ast);
+ new HandleConstructor().generateConstructor(typeNode, level, fields, staticName, SkipIfConstructorExists.NO, null, onConstructor, annotationNode);
}
}
@@ -106,7 +106,9 @@ public class HandleConstructor {
List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@RequiredArgsConstructor(onConstructor=", annotationNode);
- new HandleConstructor().generateConstructor(typeNode, level, findRequiredFields(typeNode), staticName, SkipIfConstructorExists.NO, suppressConstructorProperties, onConstructor, ast);
+ new HandleConstructor().generateConstructor(
+ typeNode, level, findRequiredFields(typeNode), staticName, SkipIfConstructorExists.NO,
+ suppressConstructorProperties, onConstructor, annotationNode);
}
}
@@ -158,7 +160,9 @@ public class HandleConstructor {
List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@AllArgsConstructor(onConstructor=", annotationNode);
- new HandleConstructor().generateConstructor(typeNode, level, findAllFields(typeNode), staticName, SkipIfConstructorExists.NO, suppressConstructorProperties, onConstructor, ast);
+ new HandleConstructor().generateConstructor(
+ typeNode, level, findAllFields(typeNode), staticName, SkipIfConstructorExists.NO,
+ suppressConstructorProperties, onConstructor, annotationNode);
}
}
@@ -176,19 +180,29 @@ public class HandleConstructor {
return true;
}
- public void generateRequiredArgsConstructor(EclipseNode typeNode, AccessLevel level, String staticName, SkipIfConstructorExists skipIfConstructorExists, List<Annotation> onConstructor, ASTNode source) {
- generateConstructor(typeNode, level, findRequiredFields(typeNode), staticName, skipIfConstructorExists, null, onConstructor, source);
+ public void generateRequiredArgsConstructor(
+ EclipseNode typeNode, AccessLevel level, String staticName, SkipIfConstructorExists skipIfConstructorExists,
+ List<Annotation> onConstructor, EclipseNode sourceNode) {
+
+ generateConstructor(typeNode, level, findRequiredFields(typeNode), staticName, skipIfConstructorExists, null, onConstructor, sourceNode);
}
- public void generateAllArgsConstructor(EclipseNode typeNode, AccessLevel level, String staticName, SkipIfConstructorExists skipIfConstructorExists, List<Annotation> onConstructor, ASTNode source) {
- generateConstructor(typeNode, level, findAllFields(typeNode), staticName, skipIfConstructorExists, null, onConstructor, source);
+ public void generateAllArgsConstructor(
+ EclipseNode typeNode, AccessLevel level, String staticName, SkipIfConstructorExists skipIfConstructorExists,
+ List<Annotation> onConstructor, EclipseNode sourceNode) {
+
+ generateConstructor(typeNode, level, findAllFields(typeNode), staticName, skipIfConstructorExists, null, onConstructor, sourceNode);
}
public enum SkipIfConstructorExists {
YES, NO, I_AM_BUILDER;
}
- public void generateConstructor(EclipseNode typeNode, AccessLevel level, List<EclipseNode> fields, String staticName, SkipIfConstructorExists skipIfConstructorExists, Boolean suppressConstructorProperties, List<Annotation> onConstructor, ASTNode source) {
+ public void generateConstructor(
+ EclipseNode typeNode, AccessLevel level, List<EclipseNode> fields, String staticName, SkipIfConstructorExists skipIfConstructorExists,
+ Boolean suppressConstructorProperties, List<Annotation> onConstructor, EclipseNode sourceNode) {
+
+ ASTNode source = sourceNode.get();
boolean staticConstrRequired = staticName != null && !staticName.equals("");
if (skipIfConstructorExists != SkipIfConstructorExists.NO && constructorExists(typeNode) != MemberExistsResult.NOT_EXISTS) return;
@@ -209,7 +223,9 @@ public class HandleConstructor {
// will take care of it. However, @Data also wants a specific static name; this will be ignored; the appropriate way to do this is to use
// the 'staticName' parameter of the @XArgsConstructor you've stuck on your type.
// We should warn that we're ignoring @Data's 'staticConstructor' param.
- typeNode.addWarning("Ignoring static constructor name: explicit @XxxArgsConstructor annotation present; its `staticName` parameter will be used.", source.sourceStart, source.sourceEnd);
+ typeNode.addWarning(
+ "Ignoring static constructor name: explicit @XxxArgsConstructor annotation present; its `staticName` parameter will be used.",
+ source.sourceStart, source.sourceEnd);
}
return;
}
@@ -217,7 +233,9 @@ public class HandleConstructor {
}
}
- ConstructorDeclaration constr = createConstructor(staticConstrRequired ? AccessLevel.PRIVATE : level, typeNode, fields, suppressConstructorProperties, source, onConstructor);
+ ConstructorDeclaration constr = createConstructor(
+ staticConstrRequired ? AccessLevel.PRIVATE : level, typeNode, fields,
+ suppressConstructorProperties, sourceNode, onConstructor);
injectMethod(typeNode, constr);
if (staticConstrRequired) {
MethodDeclaration staticConstr = createStaticConstructor(level, staticName, typeNode, fields, source);
@@ -259,8 +277,9 @@ public class HandleConstructor {
public static ConstructorDeclaration createConstructor(
AccessLevel level, EclipseNode type, Collection<EclipseNode> fields,
- Boolean suppressConstructorProperties, ASTNode source, List<Annotation> onConstructor) {
+ Boolean suppressConstructorProperties, EclipseNode sourceNode, List<Annotation> onConstructor) {
+ ASTNode source = sourceNode.get();
TypeDeclaration typeDeclaration = ((TypeDeclaration)type.get());
long p = (long)source.sourceStart << 32 | source.sourceEnd;
@@ -311,7 +330,7 @@ public class HandleConstructor {
Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
if (nonNulls.length != 0) {
- Statement nullCheck = generateNullCheck(field, source);
+ Statement nullCheck = generateNullCheck(field, sourceNode);
if (nullCheck != null) nullChecks.add(nullCheck);
}
Annotation[] copiedAnnotations = copyAnnotations(source, nonNulls, nullables);
diff --git a/src/core/lombok/eclipse/handlers/HandleData.java b/src/core/lombok/eclipse/handlers/HandleData.java
index a6a8842d..0ff65a47 100644
--- a/src/core/lombok/eclipse/handlers/HandleData.java
+++ b/src/core/lombok/eclipse/handlers/HandleData.java
@@ -70,6 +70,8 @@ public class HandleData extends EclipseAnnotationHandler<Data> {
new HandleSetter().generateSetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode);
new HandleToString().generateToStringForType(typeNode, annotationNode);
- new HandleConstructor().generateRequiredArgsConstructor(typeNode, AccessLevel.PUBLIC, ann.staticConstructor(), SkipIfConstructorExists.YES, Collections.<Annotation>emptyList(), ast);
+ new HandleConstructor().generateRequiredArgsConstructor(
+ typeNode, AccessLevel.PUBLIC, ann.staticConstructor(), SkipIfConstructorExists.YES,
+ Collections.<Annotation>emptyList(), annotationNode);
}
}
diff --git a/src/core/lombok/eclipse/handlers/HandleNonNull.java b/src/core/lombok/eclipse/handlers/HandleNonNull.java
index 79bb7a08..d904de2f 100644
--- a/src/core/lombok/eclipse/handlers/HandleNonNull.java
+++ b/src/core/lombok/eclipse/handlers/HandleNonNull.java
@@ -99,7 +99,7 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> {
// and if they exist, create a new method in the class: 'private static <T> T lombok$nullCheck(T expr, String msg) {if (expr == null) throw NPE; return expr;}' and
// wrap all references to it in the super/this to a call to this method.
- Statement nullCheck = generateNullCheck(arg, ast);
+ Statement nullCheck = generateNullCheck(arg, annotationNode);
if (nullCheck == null) {
// @NonNull applied to a primitive. Kinda pointless. Let's generate a warning.
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);
}
diff --git a/src/core/lombok/eclipse/handlers/HandleValue.java b/src/core/lombok/eclipse/handlers/HandleValue.java
index 211b337a..79c11771 100644
--- a/src/core/lombok/eclipse/handlers/HandleValue.java
+++ b/src/core/lombok/eclipse/handlers/HandleValue.java
@@ -83,6 +83,7 @@ public class HandleValue extends EclipseAnnotationHandler<Value> {
new HandleGetter().generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode);
new HandleToString().generateToStringForType(typeNode, annotationNode);
- new HandleConstructor().generateAllArgsConstructor(typeNode, AccessLevel.PUBLIC, ann.staticConstructor(), SkipIfConstructorExists.YES, Collections.<Annotation>emptyList(), ast);
+ new HandleConstructor().generateAllArgsConstructor(typeNode, AccessLevel.PUBLIC, ann.staticConstructor(), SkipIfConstructorExists.YES,
+ Collections.<Annotation>emptyList(), annotationNode);
}
}
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);