aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/javac
diff options
context:
space:
mode:
Diffstat (limited to 'src/lombok/javac')
-rw-r--r--src/lombok/javac/HandlerLibrary.java11
-rw-r--r--src/lombok/javac/JavacAnnotationHandler.java2
-rw-r--r--src/lombok/javac/apt/Processor.java25
-rw-r--r--src/lombok/javac/handlers/HandleGetter.java7
-rw-r--r--src/lombok/javac/handlers/HandlePrintAST.java3
-rw-r--r--src/lombok/javac/handlers/HandleSetter.java7
6 files changed, 33 insertions, 22 deletions
diff --git a/src/lombok/javac/HandlerLibrary.java b/src/lombok/javac/HandlerLibrary.java
index d816438e..05aebf20 100644
--- a/src/lombok/javac/HandlerLibrary.java
+++ b/src/lombok/javac/HandlerLibrary.java
@@ -67,7 +67,7 @@ public class HandlerLibrary {
} else return null;
}
- public void handle(final JavacAST.Node node) {
+ public boolean handle(final JavacAST.Node node) {
Map<String, AnnotationValue> values = new HashMap<String, AnnotationValue>();
JCAnnotation anno = (JCAnnotation) node.get();
List<JCExpression> arguments = anno.getArguments();
@@ -104,7 +104,7 @@ public class HandlerLibrary {
});
}
- handler.handle(new AnnotationValues<T>(annotationClass, values, node), (JCAnnotation)node.get(), node);
+ return handler.handle(new AnnotationValues<T>(annotationClass, values, node), (JCAnnotation)node.get(), node);
}
}
@@ -168,21 +168,24 @@ public class HandlerLibrary {
}
}
- public void handleAnnotation(JCCompilationUnit unit, JavacAST.Node node, JCAnnotation annotation) {
+ public boolean handleAnnotation(JCCompilationUnit unit, JavacAST.Node node, JCAnnotation annotation) {
TypeResolver resolver = new TypeResolver(typeLibrary, node.getPackageDeclaration(), node.getImportStatements());
String rawType = annotation.annotationType.toString();
+ boolean handled = false;
for ( String fqn : resolver.findTypeMatches(node, rawType) ) {
AnnotationHandlerContainer<?> container = annotationHandlers.get(fqn);
if ( container == null ) continue;
try {
- container.handle(node);
+ handled |= container.handle(node);
} catch ( AnnotationValueDecodeFail fail ) {
fail.owner.setError(fail.getMessage(), fail.idx);
} catch ( Throwable t ) {
javacError(String.format("Lombok annotation handler %s failed", container.handler.getClass()), t);
}
}
+
+ return handled;
}
public void callASTVisitors(JavacAST ast) {
diff --git a/src/lombok/javac/JavacAnnotationHandler.java b/src/lombok/javac/JavacAnnotationHandler.java
index 0df83346..58308de1 100644
--- a/src/lombok/javac/JavacAnnotationHandler.java
+++ b/src/lombok/javac/JavacAnnotationHandler.java
@@ -7,5 +7,5 @@ import lombok.core.AnnotationValues;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
public interface JavacAnnotationHandler<T extends Annotation> {
- void handle(AnnotationValues<T> annotation, JCAnnotation ast, JavacAST.Node annotationNode);
+ boolean handle(AnnotationValues<T> annotation, JCAnnotation ast, JavacAST.Node annotationNode);
}
diff --git a/src/lombok/javac/apt/Processor.java b/src/lombok/javac/apt/Processor.java
index 6027daa6..8558a0ba 100644
--- a/src/lombok/javac/apt/Processor.java
+++ b/src/lombok/javac/apt/Processor.java
@@ -66,32 +66,37 @@ public class Processor extends AbstractProcessor {
private class AnnotationVisitor extends JavacASTAdapter {
@Override public void visitAnnotationOnType(JCClassDecl type, Node annotationNode, JCAnnotation annotation) {
if ( annotationNode.isHandled() ) return;
- handlers.handleAnnotation((JCCompilationUnit) annotationNode.top().get(), annotationNode, annotation);
- annotationNode.setHandled();
+ JCCompilationUnit top = (JCCompilationUnit) annotationNode.top().get();
+ boolean handled = handlers.handleAnnotation(top, annotationNode, annotation);
+ if ( handled ) annotationNode.setHandled();
}
@Override public void visitAnnotationOnField(JCVariableDecl field, Node annotationNode, JCAnnotation annotation) {
if ( annotationNode.isHandled() ) return;
- handlers.handleAnnotation((JCCompilationUnit) annotationNode.top().get(), annotationNode, annotation);
- annotationNode.setHandled();
+ JCCompilationUnit top = (JCCompilationUnit) annotationNode.top().get();
+ boolean handled = handlers.handleAnnotation(top, annotationNode, annotation);
+ if ( handled ) annotationNode.setHandled();
}
@Override public void visitAnnotationOnMethod(JCMethodDecl method, Node annotationNode, JCAnnotation annotation) {
if ( annotationNode.isHandled() ) return;
- handlers.handleAnnotation((JCCompilationUnit) annotationNode.top().get(), annotationNode, annotation);
- annotationNode.setHandled();
+ JCCompilationUnit top = (JCCompilationUnit) annotationNode.top().get();
+ boolean handled = handlers.handleAnnotation(top, annotationNode, annotation);
+ if ( handled ) annotationNode.setHandled();
}
@Override public void visitAnnotationOnMethodArgument(JCVariableDecl argument, JCMethodDecl method, Node annotationNode, JCAnnotation annotation) {
if ( annotationNode.isHandled() ) return;
- handlers.handleAnnotation((JCCompilationUnit) annotationNode.top().get(), annotationNode, annotation);
- annotationNode.setHandled();
+ JCCompilationUnit top = (JCCompilationUnit) annotationNode.top().get();
+ boolean handled = handlers.handleAnnotation(top, annotationNode, annotation);
+ if ( handled ) annotationNode.setHandled();
}
@Override public void visitAnnotationOnLocal(JCVariableDecl local, Node annotationNode, JCAnnotation annotation) {
if ( annotationNode.isHandled() ) return;
- handlers.handleAnnotation((JCCompilationUnit) annotationNode.top().get(), annotationNode, annotation);
- annotationNode.setHandled();
+ JCCompilationUnit top = (JCCompilationUnit) annotationNode.top().get();
+ boolean handled = handlers.handleAnnotation(top, annotationNode, annotation);
+ if ( handled ) annotationNode.setHandled();
}
}
diff --git a/src/lombok/javac/handlers/HandleGetter.java b/src/lombok/javac/handlers/HandleGetter.java
index da1b7107..5cc2c108 100644
--- a/src/lombok/javac/handlers/HandleGetter.java
+++ b/src/lombok/javac/handlers/HandleGetter.java
@@ -24,10 +24,10 @@ import com.sun.tools.javac.util.Name;
@ProviderFor(JavacAnnotationHandler.class)
public class HandleGetter implements JavacAnnotationHandler<Getter> {
- @Override public void handle(AnnotationValues<Getter> annotation, JCAnnotation ast, JavacAST.Node annotationNode) {
+ @Override public boolean handle(AnnotationValues<Getter> annotation, JCAnnotation ast, JavacAST.Node annotationNode) {
if ( annotationNode.up().getKind() != Kind.FIELD ) {
annotationNode.addError("@Getter is only supported on a field.");
- return;
+ return false;
}
String methodName = toGetterName((JCVariableDecl) annotationNode.up().get());
@@ -35,7 +35,7 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
if ( methodExists(methodName, annotationNode.up()) ) {
annotationNode.addWarning(
String.format("Not generating %s(): A method with that name already exists", methodName));
- return;
+ return false;
}
Getter getter = annotation.getInstance();
@@ -46,6 +46,7 @@ public class HandleGetter implements JavacAnnotationHandler<Getter> {
JCMethodDecl getterMethod = createGetter(access, annotationNode.up(), annotationNode.getTreeMaker());
javacClassTree.defs = javacClassTree.defs.append(getterMethod);
+ return true;
}
private JCMethodDecl createGetter(int access, JavacAST.Node field, TreeMaker treeMaker) {
diff --git a/src/lombok/javac/handlers/HandlePrintAST.java b/src/lombok/javac/handlers/HandlePrintAST.java
index 23f4c6d6..3a738b4f 100644
--- a/src/lombok/javac/handlers/HandlePrintAST.java
+++ b/src/lombok/javac/handlers/HandlePrintAST.java
@@ -12,7 +12,8 @@ import lombok.javac.JavacAST.Node;
@ProviderFor(JavacAnnotationHandler.class)
public class HandlePrintAST implements JavacAnnotationHandler<PrintAST> {
- @Override public void handle(AnnotationValues<PrintAST> annotation, JCAnnotation ast, Node annotationNode) {
+ @Override public boolean handle(AnnotationValues<PrintAST> annotation, JCAnnotation ast, Node annotationNode) {
annotationNode.up().traverse(new JavacASTVisitor.JavacASTPrinter());
+ return true;
}
}
diff --git a/src/lombok/javac/handlers/HandleSetter.java b/src/lombok/javac/handlers/HandleSetter.java
index 0fbfe8ae..da4e9ff0 100644
--- a/src/lombok/javac/handlers/HandleSetter.java
+++ b/src/lombok/javac/handlers/HandleSetter.java
@@ -26,10 +26,10 @@ import com.sun.tools.javac.util.Name;
@ProviderFor(JavacAnnotationHandler.class)
public class HandleSetter implements JavacAnnotationHandler<Setter> {
- @Override public void handle(AnnotationValues<Setter> annotation, JCAnnotation ast, Node annotationNode) {
+ @Override public boolean handle(AnnotationValues<Setter> annotation, JCAnnotation ast, Node annotationNode) {
if ( annotationNode.up().getKind() != Kind.FIELD ) {
annotationNode.addError("@Setter is only supported on a field.");
- return;
+ return false;
}
JCVariableDecl fieldNode = (JCVariableDecl) annotationNode.up().get();
@@ -39,7 +39,7 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
annotationNode.addWarning(
String.format("Not generating %s(%s %s): A method with that name already exists",
methodName, fieldNode.vartype, fieldNode.name));
- return;
+ return false;
}
Setter setter = annotation.getInstance();
@@ -50,6 +50,7 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
JCMethodDecl setterMethod = createSetter(access, annotationNode.up(), annotationNode.getTreeMaker());
javacClassTree.defs = javacClassTree.defs.append(setterMethod);
+ return true;
}
private JCMethodDecl createSetter(int access, JavacAST.Node field, TreeMaker treeMaker) {