aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers/HandleSetter.java
diff options
context:
space:
mode:
authorCaleb Brinkman <cbrinkman@sonatype.com>2019-07-16 10:39:54 -0500
committerCaleb Brinkman <cbrinkman@sonatype.com>2019-07-16 10:39:54 -0500
commit4dc5c32d6b47264b5c8abb6fdf24077eec5aa7e7 (patch)
tree9779fbf1d16dab92b0f5076f773870653de49820 /src/core/lombok/eclipse/handlers/HandleSetter.java
parent88bf742e3e107cc0bbfc3a72c2f456d34ef3079c (diff)
parent218f28cc95ee30d5d362c3ac9d5440c2f86fd712 (diff)
downloadlombok-4dc5c32d6b47264b5c8abb6fdf24077eec5aa7e7.tar.gz
lombok-4dc5c32d6b47264b5c8abb6fdf24077eec5aa7e7.tar.bz2
lombok-4dc5c32d6b47264b5c8abb6fdf24077eec5aa7e7.zip
Merge branch 'master' of github.com:rzwitserloot/lombok into feature/builder-setter-prefixes
Diffstat (limited to 'src/core/lombok/eclipse/handlers/HandleSetter.java')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java
index 4ea83cf6..bb704ead 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -184,11 +184,11 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
}
}
- MethodDeclaration method = createSetter((TypeDeclaration) fieldNode.up().get(), false, fieldNode, setterName, null, shouldReturnThis, modifier, sourceNode, onMethod, onParam);
+ MethodDeclaration method = createSetter((TypeDeclaration) fieldNode.up().get(), false, fieldNode, setterName, null, null, shouldReturnThis, modifier, sourceNode, onMethod, onParam);
injectMethod(fieldNode.up(), method);
}
- static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate, EclipseNode fieldNode, String name, char[] booleanFieldToSet, boolean shouldReturnThis, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
+ static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate, EclipseNode fieldNode, String name, char[] paramName, char[] booleanFieldToSet, boolean shouldReturnThis, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
ASTNode source = sourceNode.get();
int pS = source.sourceStart, pE = source.sourceEnd;
@@ -200,14 +200,15 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
returnThis = new ReturnStatement(thisRef, pS, pE);
}
- return createSetter(parent, deprecate, fieldNode, name, booleanFieldToSet, returnType, returnThis, modifier, sourceNode, onMethod, onParam);
+ return createSetter(parent, deprecate, fieldNode, name, paramName, booleanFieldToSet, returnType, returnThis, modifier, sourceNode, onMethod, onParam);
}
- static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate, EclipseNode fieldNode, String name, char[] booleanFieldToSet, TypeReference returnType, Statement returnStatement, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
+ static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate, EclipseNode fieldNode, String name, char[] paramName, char[] booleanFieldToSet, TypeReference returnType, Statement returnStatement, int modifier, EclipseNode sourceNode, List<Annotation> onMethod, List<Annotation> onParam) {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
+ if (paramName == null) paramName = field.name;
ASTNode source = sourceNode.get();
int pS = source.sourceStart, pE = source.sourceEnd;
- long p = (long)pS << 32 | pE;
+ long p = (long) pS << 32 | pE;
MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
method.modifiers = modifier;
if (returnType != null) {
@@ -221,7 +222,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
}
method.annotations = mergeAnnotations(copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated), findCopyableToSetterAnnotations(fieldNode));
- Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL);
+ Argument param = new Argument(paramName, p, copyType(field.type, source), Modifier.FINAL);
param.sourceStart = pS; param.sourceEnd = pE;
method.arguments = new Argument[] { param };
method.selector = name.toCharArray();
@@ -230,8 +231,8 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
method.typeParameters = null;
method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
Expression fieldRef = createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source);
- NameReference fieldNameRef = new SingleNameReference(field.name, p);
- Assignment assignment = new Assignment(fieldRef, fieldNameRef, (int)p);
+ NameReference fieldNameRef = new SingleNameReference(paramName, p);
+ Assignment assignment = new Assignment(fieldRef, fieldNameRef, (int) p);
assignment.sourceStart = pS; assignment.sourceEnd = assignment.statementEnd = pE;
method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
@@ -241,7 +242,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
if (!hasNonNullAnnotations(fieldNode) && !hasNonNullAnnotations(fieldNode, onParam)) {
statements.add(assignment);
} else {
- Statement nullCheck = generateNullCheck(field, sourceNode);
+ Statement nullCheck = generateNullCheck(field.type, paramName, sourceNode);
if (nullCheck != null) statements.add(nullCheck);
statements.add(assignment);
}