aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/lombok/javac/handlers/HandleDelegate.java22
-rw-r--r--test/transform/resource/before/DelegateOnStatic.java12
-rw-r--r--test/transform/resource/messages-delombok/DelegateOnStatic.java.messages2
-rw-r--r--test/transform/resource/messages-ecj/DelegateOnStatic.java.messages2
4 files changed, 31 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;
diff --git a/test/transform/resource/before/DelegateOnStatic.java b/test/transform/resource/before/DelegateOnStatic.java
new file mode 100644
index 00000000..ef56ef54
--- /dev/null
+++ b/test/transform/resource/before/DelegateOnStatic.java
@@ -0,0 +1,12 @@
+import lombok.Delegate;
+import lombok.Getter;
+
+class DelegateOnStatic {
+ @Delegate private static final java.lang.Runnable staticField = null;
+}
+
+class DelegateOnStaticMethod {
+ @Delegate private static final java.lang.Runnable staticMethod() {
+ return null;
+ };
+} \ No newline at end of file
diff --git a/test/transform/resource/messages-delombok/DelegateOnStatic.java.messages b/test/transform/resource/messages-delombok/DelegateOnStatic.java.messages
new file mode 100644
index 00000000..b807b155
--- /dev/null
+++ b/test/transform/resource/messages-delombok/DelegateOnStatic.java.messages
@@ -0,0 +1,2 @@
+5 @Delegate is legal only on instance fields or no-argument instance methods.
+9 @Delegate is legal only on instance fields or no-argument instance methods. \ No newline at end of file
diff --git a/test/transform/resource/messages-ecj/DelegateOnStatic.java.messages b/test/transform/resource/messages-ecj/DelegateOnStatic.java.messages
new file mode 100644
index 00000000..b807b155
--- /dev/null
+++ b/test/transform/resource/messages-ecj/DelegateOnStatic.java.messages
@@ -0,0 +1,2 @@
+5 @Delegate is legal only on instance fields or no-argument instance methods.
+9 @Delegate is legal only on instance fields or no-argument instance methods. \ No newline at end of file