aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers/HandleSetter.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2011-05-30 22:04:46 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2011-05-30 22:08:12 +0200
commitaa8a627349bb68f376b98847b6f73c2c89e989fd (patch)
tree70df1fa6ba0f8e3c34a45d868d7f763e5b7ccbf9 /src/core/lombok/eclipse/handlers/HandleSetter.java
parentdaf84dd00ed5059710acf9f40b4663ba7fed06e0 (diff)
downloadlombok-aa8a627349bb68f376b98847b6f73c2c89e989fd.tar.gz
lombok-aa8a627349bb68f376b98847b6f73c2c89e989fd.tar.bz2
lombok-aa8a627349bb68f376b98847b6f73c2c89e989fd.zip
tracking if an annotation has been handled or not is now no longer done
via the LombokAST object. Instead its tracked more directly in an attempt to avoid having to write all handlers as idempotent, and just in case issue #164 is a race condition (the handled-or-not is a synchronized CAS check). This does break API for other plugins, but the fix is trivial: Just make your 'handle' method return void. That 'we won't call you again' business in the decks never quite worked right anyway. Also, you might want to call Javac.(recursive)setHandledBy when you generate nodes, now.
Diffstat (limited to 'src/core/lombok/eclipse/handlers/HandleSetter.java')
-rw-r--r--src/core/lombok/eclipse/handlers/HandleSetter.java35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java
index 945495c6..ac3ff2a2 100644
--- a/src/core/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/core/lombok/eclipse/handlers/HandleSetter.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2009-2010 Reinier Zwitserloot and Roel Spilker.
+ * Copyright © 2009-2011 Reinier Zwitserloot and Roel Spilker.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -120,40 +120,37 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
createSetterForField(level, fieldNode, fieldNode, pos, false, onMethod, onParam);
}
- public boolean handle(AnnotationValues<Setter> annotation, Annotation ast, EclipseNode annotationNode) {
+ public void handle(AnnotationValues<Setter> annotation, Annotation ast, EclipseNode annotationNode) {
EclipseNode node = annotationNode.up();
AccessLevel level = annotation.getInstance().value();
- if (level == AccessLevel.NONE) return true;
-
- if (node == null) return false;
+ if (level == AccessLevel.NONE || node == null) return;
Annotation[] onMethod = getAndRemoveAnnotationParameter(ast, "onMethod");
Annotation[] onParam = getAndRemoveAnnotationParameter(ast, "onParam");
- if (node.getKind() == Kind.FIELD) {
- return createSetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, annotationNode.get(), true, onMethod, onParam);
-
- }
- if (node.getKind() == Kind.TYPE) {
+ switch (node.getKind()) {
+ case FIELD:
+ createSetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, annotationNode.get(), true, onMethod, onParam);
+ break;
+ case TYPE:
if (onMethod != null && onMethod.length != 0) annotationNode.addError("'onMethod' is not supported for @Setter on a type.");
if (onParam != null && onParam.length != 0) annotationNode.addError("'onParam' is not supported for @Setter on a type.");
- return generateSetterForType(node, annotationNode, level, false);
+ generateSetterForType(node, annotationNode, level, false);
+ break;
}
- return false;
}
- private boolean createSetterForFields(AccessLevel level, Collection<EclipseNode> fieldNodes, EclipseNode errorNode, ASTNode source, boolean whineIfExists, Annotation[] onMethod , Annotation[] onParam) {
+ private void createSetterForFields(AccessLevel level, Collection<EclipseNode> fieldNodes, EclipseNode errorNode, ASTNode source, boolean whineIfExists, Annotation[] onMethod , Annotation[] onParam) {
for (EclipseNode fieldNode : fieldNodes) {
createSetterForField(level, fieldNode, errorNode, source, whineIfExists, onMethod, onParam);
}
- return true;
}
- private boolean createSetterForField(AccessLevel level,
+ private void createSetterForField(AccessLevel level,
EclipseNode fieldNode, EclipseNode errorNode, ASTNode source, boolean whineIfExists, Annotation[] onMethod , Annotation[] onParam) {
if (fieldNode.getKind() != Kind.FIELD) {
errorNode.addError("@Setter is only supported on a class or a field.");
- return true;
+ return;
}
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
@@ -166,7 +163,7 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
for (String altName : TransformationsUtil.toAllSetterNames(new String(field.name), isBoolean)) {
switch (methodExists(altName, fieldNode, false)) {
case EXISTS_BY_LOMBOK:
- return true;
+ return;
case EXISTS_BY_USER:
if (whineIfExists) {
String altNameExpl = "";
@@ -174,7 +171,7 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
errorNode.addWarning(
String.format("Not generating %s(): A method with that name already exists%s", setterName, altNameExpl));
}
- return true;
+ return;
default:
case NOT_EXISTS:
//continue scanning the other alt names.
@@ -188,8 +185,6 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
}
injectMethod(fieldNode.up(), method);
-
- return true;
}
private MethodDeclaration generateSetter(TypeDeclaration parent, EclipseNode fieldNode, String name, int modifier, ASTNode source, Annotation[] onParam) {