aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-06-17 21:57:54 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-06-17 21:57:54 +0200
commiteca3cd7ccc6e8c5736f5a70c3b1c095bd949689d (patch)
tree872695cfa92999e0ad1bd8843d08f9760aaebad6 /src/lombok/eclipse
parent8fa50054449d88380ce45ba91881df6655737f20 (diff)
downloadlombok-eca3cd7ccc6e8c5736f5a70c3b1c095bd949689d.tar.gz
lombok-eca3cd7ccc6e8c5736f5a70c3b1c095bd949689d.tar.bz2
lombok-eca3cd7ccc6e8c5736f5a70c3b1c095bd949689d.zip
AnnotationHandlers can now return a boolean to set if they actually handled the annotation or not (previously, the presumption was they always handled the annotation).
This is very useful for PrintAST on eclipse, because before this change, you'd never see method contents (as the initial dietParse would come first). Now Eclipse PrintASTHandler will skip any non-full runs, and only print non-diet. It then returns true only if it printed.
Diffstat (limited to 'src/lombok/eclipse')
-rw-r--r--src/lombok/eclipse/EclipseAnnotationHandler.java2
-rw-r--r--src/lombok/eclipse/HandlerLibrary.java13
-rw-r--r--src/lombok/eclipse/TransformEclipseAST.java25
-rw-r--r--src/lombok/eclipse/handlers/HandleGetter.java8
-rw-r--r--src/lombok/eclipse/handlers/HandlePrintAST.java4
5 files changed, 32 insertions, 20 deletions
diff --git a/src/lombok/eclipse/EclipseAnnotationHandler.java b/src/lombok/eclipse/EclipseAnnotationHandler.java
index 816ba61c..e94607f6 100644
--- a/src/lombok/eclipse/EclipseAnnotationHandler.java
+++ b/src/lombok/eclipse/EclipseAnnotationHandler.java
@@ -3,5 +3,5 @@ package lombok.eclipse;
import lombok.core.AnnotationValues;
public interface EclipseAnnotationHandler<T extends java.lang.annotation.Annotation> {
- void handle(AnnotationValues<T> annotation, org.eclipse.jdt.internal.compiler.ast.Annotation ast, EclipseAST.Node annotationNode);
+ boolean handle(AnnotationValues<T> annotation, org.eclipse.jdt.internal.compiler.ast.Annotation ast, EclipseAST.Node annotationNode);
}
diff --git a/src/lombok/eclipse/HandlerLibrary.java b/src/lombok/eclipse/HandlerLibrary.java
index 2e3e4541..86efd53e 100644
--- a/src/lombok/eclipse/HandlerLibrary.java
+++ b/src/lombok/eclipse/HandlerLibrary.java
@@ -45,7 +45,7 @@ public class HandlerLibrary {
this.annotationClass = annotationClass;
}
- public void handle(org.eclipse.jdt.internal.compiler.ast.Annotation annotation,
+ public boolean handle(org.eclipse.jdt.internal.compiler.ast.Annotation annotation,
final Node annotationNode) {
Map<String, AnnotationValue> values = new HashMap<String, AnnotationValue>();
@@ -94,7 +94,7 @@ public class HandlerLibrary {
});
}
- handler.handle(new AnnotationValues<T>(annotationClass, values, annotationNode), annotation, annotationNode);
+ return handler.handle(new AnnotationValues<T>(annotationClass, values, annotationNode), annotation, annotationNode);
}
}
@@ -169,26 +169,29 @@ public class HandlerLibrary {
}
}
- public void handle(CompilationUnitDeclaration ast, EclipseAST.Node annotationNode,
+ public boolean handle(CompilationUnitDeclaration ast, EclipseAST.Node annotationNode,
org.eclipse.jdt.internal.compiler.ast.Annotation annotation) {
String pkgName = annotationNode.getPackageDeclaration();
Collection<String> imports = annotationNode.getImportStatements();
TypeResolver resolver = new TypeResolver(typeLibrary, pkgName, imports);
TypeReference rawType = annotation.type;
- if ( rawType == null ) return;
+ if ( rawType == null ) return false;
+ boolean handled = false;
for ( String fqn : resolver.findTypeMatches(annotationNode, toQualifiedName(annotation.type.getTypeName())) ) {
AnnotationHandlerContainer<?> container = annotationHandlers.get(fqn);
if ( container == null ) continue;
try {
- container.handle(annotation, annotationNode);
+ handled |= container.handle(annotation, annotationNode);
} catch ( AnnotationValueDecodeFail fail ) {
fail.owner.setError(fail.getMessage(), fail.idx);
} catch ( Throwable t ) {
Eclipse.error(String.format("Lombok annotation handler %s failed", container.handler.getClass()), t);
}
}
+
+ return handled;
}
public void callASTVisitors(EclipseAST ast) {
diff --git a/src/lombok/eclipse/TransformEclipseAST.java b/src/lombok/eclipse/TransformEclipseAST.java
index f77639e1..b56c594a 100644
--- a/src/lombok/eclipse/TransformEclipseAST.java
+++ b/src/lombok/eclipse/TransformEclipseAST.java
@@ -115,32 +115,37 @@ public class TransformEclipseAST {
private static class AnnotationVisitor extends EclipseASTAdapter {
@Override public void visitAnnotationOnField(FieldDeclaration field, Node annotationNode, Annotation annotation) {
if ( annotationNode.isHandled() ) return;
- handlers.handle((CompilationUnitDeclaration) annotationNode.top().get(), annotationNode, annotation);
- annotationNode.setHandled();
+ CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get();
+ boolean handled = handlers.handle(top, annotationNode, annotation);
+ if ( handled ) annotationNode.setHandled();
}
@Override public void visitAnnotationOnMethodArgument(Argument arg, AbstractMethodDeclaration method, Node annotationNode, Annotation annotation) {
if ( annotationNode.isHandled() ) return;
- handlers.handle((CompilationUnitDeclaration) annotationNode.top().get(), annotationNode, annotation);
- annotationNode.setHandled();
+ CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get();
+ boolean handled = handlers.handle(top, annotationNode, annotation);
+ if ( handled ) annotationNode.setHandled();
}
@Override public void visitAnnotationOnLocal(LocalDeclaration local, Node annotationNode, Annotation annotation) {
if ( annotationNode.isHandled() ) return;
- handlers.handle((CompilationUnitDeclaration) annotationNode.top().get(), annotationNode, annotation);
- annotationNode.setHandled();
+ CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get();
+ boolean handled = handlers.handle(top, annotationNode, annotation);
+ if ( handled ) annotationNode.setHandled();
}
@Override public void visitAnnotationOnMethod(AbstractMethodDeclaration method, Node annotationNode, Annotation annotation) {
if ( annotationNode.isHandled() ) return;
- handlers.handle((CompilationUnitDeclaration) annotationNode.top().get(), annotationNode, annotation);
- annotationNode.setHandled();
+ CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get();
+ boolean handled = handlers.handle(top, annotationNode, annotation);
+ if ( handled ) annotationNode.setHandled();
}
@Override public void visitAnnotationOnType(TypeDeclaration type, Node annotationNode, Annotation annotation) {
if ( annotationNode.isHandled() ) return;
- handlers.handle((CompilationUnitDeclaration) annotationNode.top().get(), annotationNode, annotation);
- annotationNode.setHandled();
+ CompilationUnitDeclaration top = (CompilationUnitDeclaration) annotationNode.top().get();
+ boolean handled = handlers.handle(top, annotationNode, annotation);
+ if ( handled ) annotationNode.setHandled();
}
}
}
diff --git a/src/lombok/eclipse/handlers/HandleGetter.java b/src/lombok/eclipse/handlers/HandleGetter.java
index bf1aa9b0..6be978c6 100644
--- a/src/lombok/eclipse/handlers/HandleGetter.java
+++ b/src/lombok/eclipse/handlers/HandleGetter.java
@@ -29,8 +29,8 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> {
annotationNode.addWarning(String.format("Not generating %s(): A method with that name already exists", methodName));
}
- @Override public void handle(AnnotationValues<Getter> annotation, Annotation ast, Node annotationNode) {
- if ( !(annotationNode.up().get() instanceof FieldDeclaration) ) return;
+ @Override public boolean handle(AnnotationValues<Getter> annotation, Annotation ast, Node annotationNode) {
+ if ( !(annotationNode.up().get() instanceof FieldDeclaration) ) return false;
FieldDeclaration field = (FieldDeclaration) annotationNode.up().get();
TypeReference fieldType = field.type;
String getterName = TransformationsUtil.toGetterName(
@@ -40,7 +40,7 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> {
if ( parent.methods != null ) for ( AbstractMethodDeclaration method : parent.methods ) {
if ( method.selector != null && new String(method.selector).equals(getterName) ) {
generateDuplicateGetterWarning(annotationNode, getterName);
- return;
+ return false;
}
}
@@ -69,6 +69,8 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> {
newArray[parent.methods.length] = method;
parent.methods = newArray;
}
+
+ return true;
}
private int toModifier(AccessLevel value) {
diff --git a/src/lombok/eclipse/handlers/HandlePrintAST.java b/src/lombok/eclipse/handlers/HandlePrintAST.java
index 2e379ce3..4438f4e4 100644
--- a/src/lombok/eclipse/handlers/HandlePrintAST.java
+++ b/src/lombok/eclipse/handlers/HandlePrintAST.java
@@ -11,7 +11,9 @@ import lombok.eclipse.EclipseAST.Node;
@ProviderFor(EclipseAnnotationHandler.class)
public class HandlePrintAST implements EclipseAnnotationHandler<PrintAST> {
- @Override public void handle(AnnotationValues<PrintAST> annotation, Annotation ast, Node annotationNode) {
+ @Override public boolean handle(AnnotationValues<PrintAST> annotation, Annotation ast, Node annotationNode) {
+ if ( !annotationNode.isCompleteParse() ) return false;
annotationNode.up().traverse(new EclipseASTVisitor.EclipseASTPrinter());
+ return true;
}
}