aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers/HandleSetter.java
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2010-11-10 01:44:04 +0100
committerRoel Spilker <r.spilker@gmail.com>2010-11-10 01:44:04 +0100
commitfe7f0db2fce7b4c80853b9aed100908ff1f55f40 (patch)
tree41f7c7a289237153307402b7ebe25e372254ae40 /src/core/lombok/javac/handlers/HandleSetter.java
parent46d471e9c3dc32b03c34804df1819739a4dffc50 (diff)
downloadlombok-fe7f0db2fce7b4c80853b9aed100908ff1f55f40.tar.gz
lombok-fe7f0db2fce7b4c80853b9aed100908ff1f55f40.tar.bz2
lombok-fe7f0db2fce7b4c80853b9aed100908ff1f55f40.zip
From now on it is possible to specify annotations to be placed on the method
or the parameter of the generated getter/setter methods.
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleSetter.java')
-rw-r--r--src/core/lombok/javac/handlers/HandleSetter.java63
1 files changed, 11 insertions, 52 deletions
diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java
index b8c05a9c..af6f546d 100644
--- a/src/core/lombok/javac/handlers/HandleSetter.java
+++ b/src/core/lombok/javac/handlers/HandleSetter.java
@@ -32,8 +32,8 @@ import javax.lang.model.type.TypeVisitor;
import lombok.AccessLevel;
import lombok.Setter;
-import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
+import lombok.core.AST.Kind;
import lombok.core.handlers.TransformationsUtil;
import lombok.javac.Javac;
import lombok.javac.JavacAnnotationHandler;
@@ -44,28 +44,26 @@ import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.TypeTags;
+import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCAssign;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCExpression;
-import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
-import com.sun.tools.javac.tree.JCTree.JCNewArray;
import com.sun.tools.javac.tree.JCTree.JCStatement;
import com.sun.tools.javac.tree.JCTree.JCTypeParameter;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
-import com.sun.tools.javac.tree.TreeMaker;
-import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Name;
+import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
/**
* Handles the {@code lombok.Setter} annotation for javac.
*/
@ProviderFor(JavacAnnotationHandler.class)
public class HandleSetter implements JavacAnnotationHandler<Setter> {
- public boolean generateSetterForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelSetter, List<JCExpression> onMethod, List<JCExpression> onParam) {
+ public boolean generateSetterForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelSetter) {
if (checkForTypeLevelSetter) {
if (typeNode != null) for (JavacNode child : typeNode.down()) {
if (child.getKind() == Kind.ANNOTATION) {
@@ -97,7 +95,7 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
//Skip final fields.
if ((fieldDecl.mods.flags & Flags.FINAL) != 0) continue;
- generateSetterForField(field, errorNode.get(), level, onMethod, onParam);
+ generateSetterForField(field, errorNode.get(), level, List.<JCExpression>nil(), List.<JCExpression>nil());
}
return true;
}
@@ -140,47 +138,17 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
if (level == AccessLevel.NONE) return true;
if (node == null) return false;
- List<JCExpression> params = List.nil();
- List<JCExpression> onMethodList = List.nil();
- List<JCExpression> onParamList = List.nil();
-
- for (JCExpression param : ast.args) {
- System.out.println("T: " + param.getClass());
- if (param instanceof JCAssign) {
- JCAssign assign = (JCAssign) param;
- System.out.println("TL: " + assign.lhs.getClass());
- if (assign.lhs instanceof JCIdent) {
- JCIdent name = (JCIdent) assign.lhs;
- if ("onMethod".equals(name.name.toString())) {
- if (assign.rhs instanceof JCNewArray) {
- onMethodList = ((JCNewArray) assign.rhs).elems;
- } else {
- onMethodList = onMethodList.append(assign.rhs);
- }
- continue;
- } else if ("onParam".equals(name.name.toString())) {
- if (assign.rhs instanceof JCNewArray) {
- onParamList = ((JCNewArray) assign.rhs).elems;
- } else {
- onParamList = onParamList.append(assign.rhs);
- }
- continue;
- }
- }
- }
-
- params = params.append(param);
- }
-
- System.out.println("IN HANDLE SETTER5");
- ast.args = params;
- System.out.println("Args now: " + ast.args);
+ List<JCExpression> onParamList = getAndRemoveAnnotationParameter(ast, "onParam");
+ List<JCExpression> onMethodList = getAndRemoveAnnotationParameter(ast, "onMethod");
if (node.getKind() == Kind.FIELD) {
return createSetterForFields(level, fields, annotationNode, true, onMethodList, onParamList);
}
if (node.getKind() == Kind.TYPE) {
- return generateSetterForType(node, annotationNode, level, false, onMethodList, onParamList);
+ if (!onMethodList.isEmpty()) annotationNode.addError("'onMethod' is not supported for @Setter on a type.");
+ if (!onParamList.isEmpty()) annotationNode.addError("'onParam' is not supported for @Setter on a type.");
+
+ return generateSetterForType(node, annotationNode, level, false);
}
return false;
}
@@ -261,15 +229,6 @@ public class HandleSetter implements JavacAnnotationHandler<Setter> {
methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue);
}
- private static List<JCAnnotation> copyAnnotations(List<JCExpression> in) {
- List<JCAnnotation> out = List.nil();
- for (JCExpression expr : in) {
- if (!(expr instanceof JCAnnotation)) continue;
- out = out.append((JCAnnotation) expr.clone());
- }
- return out;
- }
-
private static class JCNoType extends Type implements NoType {
public JCNoType(int tag) {
super(tag, null);