diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-15 23:58:52 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-15 23:58:52 +0200 |
commit | 12162391160713e67b5bee7d6b98cfbee54225b8 (patch) | |
tree | a2545495ea1d460e68c554cd94a1b06702c8869d /src | |
parent | 92ab0e7971df9d1efc9345f17ad48355df95161a (diff) | |
download | lombok-12162391160713e67b5bee7d6b98cfbee54225b8.tar.gz lombok-12162391160713e67b5bee7d6b98cfbee54225b8.tar.bz2 lombok-12162391160713e67b5bee7d6b98cfbee54225b8.zip |
Propagated the fact that you get the Node object belonging to the annotation, and not the field/type/local/method it goes with, all the way, so that you can easily generate a warning on an annotation in a handler.
Diffstat (limited to 'src')
-rw-r--r-- | src/lombok/eclipse/EclipseAnnotationHandler.java | 2 | ||||
-rw-r--r-- | src/lombok/eclipse/HandlerLibrary.java | 16 | ||||
-rw-r--r-- | src/lombok/eclipse/TransformEclipseAST.java | 12 | ||||
-rw-r--r-- | src/lombok/eclipse/handlers/HandleGetter_ecj.java | 16 |
4 files changed, 29 insertions, 17 deletions
diff --git a/src/lombok/eclipse/EclipseAnnotationHandler.java b/src/lombok/eclipse/EclipseAnnotationHandler.java index e760917b..c6cc23be 100644 --- a/src/lombok/eclipse/EclipseAnnotationHandler.java +++ b/src/lombok/eclipse/EclipseAnnotationHandler.java @@ -1,5 +1,5 @@ package lombok.eclipse; public interface EclipseAnnotationHandler<T extends java.lang.annotation.Annotation> { - void handle(T annotation, org.eclipse.jdt.internal.compiler.ast.Annotation ast, EclipseAST.Node node); + void handle(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 70c7b267..3590d64a 100644 --- a/src/lombok/eclipse/HandlerLibrary.java +++ b/src/lombok/eclipse/HandlerLibrary.java @@ -45,8 +45,8 @@ public class HandlerLibrary { @SuppressWarnings("unchecked") public void handle(Object annInstance, org.eclipse.jdt.internal.compiler.ast.Annotation annotation, - Node node) { - handler.handle((T) annInstance, annotation, node); + Node annotationNode) { + handler.handle((T) annInstance, annotation, annotationNode); } } @@ -287,19 +287,19 @@ public class HandlerLibrary { return null; } - public void handle(CompilationUnitDeclaration ast, EclipseAST.Node node, + public void handle(CompilationUnitDeclaration ast, EclipseAST.Node annotationNode, org.eclipse.jdt.internal.compiler.ast.Annotation annotation) { - TypeResolver resolver = new TypeResolver(typeLibrary, node.top()); + TypeResolver resolver = new TypeResolver(typeLibrary, annotationNode.top()); TypeReference rawType = annotation.type; if ( rawType == null ) return; - for ( String fqn : resolver.findTypeMatches(node, annotation.type) ) { + for ( String fqn : resolver.findTypeMatches(annotationNode, annotation.type) ) { HandlerContainer<?> container = handlers.get(fqn); if ( container == null ) continue; try { Object annInstance = createAnnotation(container.annotationClass, ast, annotation); - container.handle(annInstance, annotation, node); - } catch (EnumDecodeFail e) { - node.addError(e.getMessage(), e.pair.sourceStart, e.pair.sourceEnd); + container.handle(annInstance, annotation, annotationNode); + } catch ( EnumDecodeFail e ) { + annotationNode.addError(e.getMessage(), e.pair.sourceStart, e.pair.sourceEnd); } } } diff --git a/src/lombok/eclipse/TransformEclipseAST.java b/src/lombok/eclipse/TransformEclipseAST.java index afc4cdb3..6847fd94 100644 --- a/src/lombok/eclipse/TransformEclipseAST.java +++ b/src/lombok/eclipse/TransformEclipseAST.java @@ -113,22 +113,26 @@ public class TransformEclipseAST { private static class AnnotationVisitor extends EclipseASTAdapter { @Override public void visitAnnotationOnField(FieldDeclaration field, Node annotationNode, Annotation annotation) { - handlers.handle((CompilationUnitDeclaration) annotationNode.top().node, annotationNode.up(), annotation); + if ( annotationNode.isHandled() ) return; + handlers.handle((CompilationUnitDeclaration) annotationNode.top().node, annotationNode, annotation); annotationNode.setHandled(); } @Override public void visitAnnotationOnLocal(LocalDeclaration local, Node annotationNode, Annotation annotation) { - handlers.handle((CompilationUnitDeclaration) annotationNode.top().node, annotationNode.up(), annotation); + if ( annotationNode.isHandled() ) return; + handlers.handle((CompilationUnitDeclaration) annotationNode.top().node, annotationNode, annotation); annotationNode.setHandled(); } @Override public void visitAnnotationOnMethod(AbstractMethodDeclaration method, Node annotationNode, Annotation annotation) { - handlers.handle((CompilationUnitDeclaration) annotationNode.top().node, annotationNode.up(), annotation); + if ( annotationNode.isHandled() ) return; + handlers.handle((CompilationUnitDeclaration) annotationNode.top().node, annotationNode, annotation); annotationNode.setHandled(); } @Override public void visitAnnotationOnType(TypeDeclaration type, Node annotationNode, Annotation annotation) { - handlers.handle((CompilationUnitDeclaration) annotationNode.top().node, annotationNode.up(), annotation); + if ( annotationNode.isHandled() ) return; + handlers.handle((CompilationUnitDeclaration) annotationNode.top().node, annotationNode, annotation); annotationNode.setHandled(); } } diff --git a/src/lombok/eclipse/handlers/HandleGetter_ecj.java b/src/lombok/eclipse/handlers/HandleGetter_ecj.java index 8d00df9f..f9bbb884 100644 --- a/src/lombok/eclipse/handlers/HandleGetter_ecj.java +++ b/src/lombok/eclipse/handlers/HandleGetter_ecj.java @@ -24,15 +24,23 @@ import org.mangosdk.spi.ProviderFor; @ProviderFor(EclipseAnnotationHandler.class) public class HandleGetter_ecj implements EclipseAnnotationHandler<Getter> { - @Override public void handle(Getter annotation, Annotation ast, Node node) { - FieldDeclaration field = (FieldDeclaration) node.getEclipseNode(); + private void generateDuplicateGetterWarning(Node annotationNode, String methodName) { + annotationNode.addWarning(String.format("Not generating %s(): A method with that name already exists", methodName)); + } + + @Override public void handle(Getter annotation, Annotation ast, Node annotationNode) { + if ( !(annotationNode.up().getEclipseNode() instanceof FieldDeclaration) ) return; + FieldDeclaration field = (FieldDeclaration) annotationNode.up().getEclipseNode(); TypeReference fieldType = field.type; String getterName = TransformationsUtil.toGetterName( new String(field.name), nameEquals(fieldType.getTypeName(), "boolean")); - TypeDeclaration parent = (TypeDeclaration) node.up().getEclipseNode(); + TypeDeclaration parent = (TypeDeclaration) annotationNode.up().up().getEclipseNode(); if ( parent.methods != null ) for ( AbstractMethodDeclaration method : parent.methods ) { - if ( method.selector != null && new String(method.selector).equals(getterName) ) return; + if ( method.selector != null && new String(method.selector).equals(getterName) ) { + generateDuplicateGetterWarning(annotationNode, getterName); + return; + } } MethodDeclaration method = new MethodDeclaration(parent.compilationResult); |