From eca3cd7ccc6e8c5736f5a70c3b1c095bd949689d Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 17 Jun 2009 21:57:54 +0200 Subject: 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. --- src/lombok/eclipse/HandlerLibrary.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/lombok/eclipse/HandlerLibrary.java') 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 values = new HashMap(); @@ -94,7 +94,7 @@ public class HandlerLibrary { }); } - handler.handle(new AnnotationValues(annotationClass, values, annotationNode), annotation, annotationNode); + return handler.handle(new AnnotationValues(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 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) { -- cgit