aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers/HandleSetter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lombok/eclipse/handlers/HandleSetter.java')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java
index 6a9a5123..434939a6 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -119,7 +119,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
createSetterForField(level, fieldNode, sourceNode, false, empty, empty);
}
- public void handle(AnnotationValues<Setter> annotation, Annotation ast, EclipseNode annotationNode) {
+ @Override public void handle(AnnotationValues<Setter> annotation, Annotation ast, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.SETTER_FLAG_USAGE, "@Setter");
EclipseNode node = annotationNode.up();
@@ -196,22 +196,34 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
MethodDeclaration method = createSetter((TypeDeclaration) fieldNode.up().get(), false, fieldNode, setterName, 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) {
+ ASTNode source = sourceNode.get();
+ int pS = source.sourceStart, pE = source.sourceEnd;
+
+ TypeReference returnType = null;
+ ReturnStatement returnThis = null;
+ if (shouldReturnThis) {
+ returnType = cloneSelfType(fieldNode, source);
+ ThisReference thisRef = new ThisReference(pS, pE);
+ returnThis = new ReturnStatement(thisRef, pS, pE);
+ }
+
+ return createSetter(parent, deprecate, fieldNode, name, booleanFieldToSet, returnType, returnThis, modifier, sourceNode, onMethod, onParam);
+ }
+
+ static MethodDeclaration createSetter(TypeDeclaration parent, boolean deprecate, EclipseNode fieldNode, String name, char[] booleanFieldToSet, TypeReference returnType, ReturnStatement returnStatement, 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);
method.modifiers = modifier;
- if (shouldReturnThis) {
- method.returnType = cloneSelfType(fieldNode, source);
- }
-
- if (method.returnType == null) {
+ if (returnType != null) {
+ method.returnType = returnType;
+ } else {
method.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0);
method.returnType.sourceStart = pS; method.returnType.sourceEnd = pE;
- shouldReturnThis = false;
}
Annotation[] deprecated = null;
if (isFieldDeprecated(fieldNode) || deprecate) {
@@ -248,10 +260,8 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> {
statements.add(new Assignment(new SingleNameReference(booleanFieldToSet, p), new TrueLiteral(pS, pE), pE));
}
- if (shouldReturnThis) {
- ThisReference thisRef = new ThisReference(pS, pE);
- ReturnStatement returnThis = new ReturnStatement(thisRef, pS, pE);
- statements.add(returnThis);
+ if (returnType != null && returnStatement != null) {
+ statements.add(returnStatement);
}
method.statements = statements.toArray(new Statement[0]);
param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0]));