diff options
author | Roel Spilker <r.spilker@gmail.com> | 2014-02-20 23:08:37 +0100 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2014-02-20 23:08:37 +0100 |
commit | 4372aedbd03cc4e43b90a4c0c4f703da01f322ef (patch) | |
tree | bca1eb59e1101790b0f4b554bcc83a6db80ad9f7 /src/core/lombok | |
parent | bef8d3cb41cc895226ebc29ecef8555d15f9beae (diff) | |
download | lombok-4372aedbd03cc4e43b90a4c0c4f703da01f322ef.tar.gz lombok-4372aedbd03cc4e43b90a4c0c4f703da01f322ef.tar.bz2 lombok-4372aedbd03cc4e43b90a4c0c4f703da01f322ef.zip |
Issue 641: @Delegate is incorrectly allowed on static members in javac. Also added tests, Reinier.
Diffstat (limited to 'src/core/lombok')
-rw-r--r-- | src/core/lombok/javac/handlers/HandleDelegate.java | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/core/lombok/javac/handlers/HandleDelegate.java b/src/core/lombok/javac/handlers/HandleDelegate.java index c9da4738..5e603777 100644 --- a/src/core/lombok/javac/handlers/HandleDelegate.java +++ b/src/core/lombok/javac/handlers/HandleDelegate.java @@ -62,6 +62,7 @@ import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.TypeVar; import com.sun.tools.javac.code.Types; import com.sun.tools.javac.model.JavacTypes; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCClassDecl; @@ -93,6 +94,8 @@ public class HandleDelegate extends JavacAnnotationHandler<Delegate> { "clone()", "finalize()")); + private static final String LEGALITY_OF_DELEGATE = "@Delegate is legal only on instance fields or no-argument instance methods."; + @Override public void handle(AnnotationValues<Delegate> annotation, JCAnnotation ast, JavacNode annotationNode) { deleteAnnotationIfNeccessary(annotationNode, Delegate.class); @@ -100,19 +103,24 @@ public class HandleDelegate extends JavacAnnotationHandler<Delegate> { Name delegateName = annotationNode.toName(annotationNode.up().getName()); DelegateReceiver delegateReceiver; JavacResolution reso = new JavacResolution(annotationNode.getContext()); + JCTree member = annotationNode.up().get(); if (annotationNode.up().getKind() == Kind.FIELD) { + if ((((JCVariableDecl) member).mods.flags & Flags.STATIC) != 0) { + annotationNode.addError(LEGALITY_OF_DELEGATE); + return; + } delegateReceiver = DelegateReceiver.FIELD; - delegateType = annotationNode.up().get().type; + delegateType = member.type; if (delegateType == null) reso.resolveClassMember(annotationNode.up()); - delegateType = annotationNode.up().get().type; + delegateType = member.type; } else if (annotationNode.up().getKind() == Kind.METHOD) { - if (!(annotationNode.up().get() instanceof JCMethodDecl)) { - annotationNode.addError("@Delegate is legal only on no-argument methods."); + if (!(member instanceof JCMethodDecl)) { + annotationNode.addError(LEGALITY_OF_DELEGATE); return; } - JCMethodDecl methodDecl = (JCMethodDecl) annotationNode.up().get(); - if (!methodDecl.params.isEmpty()) { - annotationNode.addError("@Delegate is legal only on no-argument methods."); + JCMethodDecl methodDecl = (JCMethodDecl) member; + if (!methodDecl.params.isEmpty() || (methodDecl.mods.flags & Flags.STATIC) != 0) { + annotationNode.addError(LEGALITY_OF_DELEGATE); return; } delegateReceiver = DelegateReceiver.METHOD; |