aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2011-05-13 20:18:29 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2011-05-13 20:18:29 +0200
commit8830e883fc522ab2bf7c3e16e03a23b9fd1b3f49 (patch)
tree535b9baf2e7340dd9d26ac7619480e9b34953583 /src
parent045bc9a60d7d97985791ec80b8b423a49e5c1a7a (diff)
downloadlombok-8830e883fc522ab2bf7c3e16e03a23b9fd1b3f49.tar.gz
lombok-8830e883fc522ab2bf7c3e16e03a23b9fd1b3f49.tar.bz2
lombok-8830e883fc522ab2bf7c3e16e03a23b9fd1b3f49.zip
@Delegate in javac on the new types/excludes model without autoexclusion now works.
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/javac/handlers/HandleDelegate.java58
1 files changed, 42 insertions, 16 deletions
diff --git a/src/core/lombok/javac/handlers/HandleDelegate.java b/src/core/lombok/javac/handlers/HandleDelegate.java
index 0c3dfd6b..697d7aab 100644
--- a/src/core/lombok/javac/handlers/HandleDelegate.java
+++ b/src/core/lombok/javac/handlers/HandleDelegate.java
@@ -50,7 +50,6 @@ import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol;
-import com.sun.tools.javac.code.Symbol.MethodSymbol;
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.ClassType;
@@ -96,41 +95,68 @@ public class HandleDelegate implements JavacAnnotationHandler<Delegate> {
return false;
}
- List<Object> delegateTypes = annotation.getActualExpressions("value");
+ List<Object> delegateTypes = annotation.getActualExpressions("types");
+ List<Object> excludeTypes = annotation.getActualExpressions("excludes");
JavacResolution reso = new JavacResolution(annotationNode.getContext());
- List<Type> resolved = new ArrayList<Type>();
+ List<Type> toDelegate = new ArrayList<Type>();
+ List<Type> toExclude = new ArrayList<Type>();
if (delegateTypes.isEmpty()) {
Type type = ((JCVariableDecl)annotationNode.up().get()).type;
if (type == null) reso.resolveClassMember(annotationNode.up());
//TODO I'm fairly sure the above line (and that entire method) does effectively bupkis!
type = ((JCVariableDecl)annotationNode.up().get()).type;
- if (type != null) resolved.add(type);
+ if (type != null) toDelegate.add(type);
} else {
for (Object dt : delegateTypes) {
if (dt instanceof JCFieldAccess && ((JCFieldAccess)dt).name.toString().equals("class")) {
Type type = ((JCFieldAccess)dt).selected.type;
if (type == null) reso.resolveClassMember(annotationNode);
type = ((JCFieldAccess)dt).selected.type;
- if (type != null) resolved.add(type);
+ if (type != null) toDelegate.add(type);
}
}
}
- List<MethodSig> signatures = new ArrayList<MethodSig>();
+ for (Object et : excludeTypes) {
+ if (et instanceof JCFieldAccess && ((JCFieldAccess)et).name.toString().equals("class")) {
+ Type type = ((JCFieldAccess)et).selected.type;
+ if (type == null) reso.resolveClassMember(annotationNode);
+ type = ((JCFieldAccess)et).selected.type;
+ if (type != null) toExclude.add(type);
+ }
+ }
+
+ List<MethodSig> signaturesToDelegate = new ArrayList<MethodSig>();
+ List<MethodSig> signaturesToExclude = new ArrayList<MethodSig>();
Set<String> banList = new HashSet<String>();
- for (Type t : resolved) {
- banList.addAll(METHODS_IN_OBJECT);
- JavacNode typeNode = annotationNode.up().up();
- for (Symbol member : ((JCClassDecl)typeNode.get()).sym.getEnclosedElements()) {
- if (member instanceof MethodSymbol) {
- MethodSymbol method = (MethodSymbol) member;
- banList.add(printSig((ExecutableType) method.asType(), method.name, annotationNode.getTypesUtil()));
- }
+ banList.addAll(METHODS_IN_OBJECT);
+ /* To exclude all methods in the class itself, try this:
+ for (Symbol member : ((JCClassDecl)typeNode.get()).sym.getEnclosedElements()) {
+ if (member instanceof MethodSymbol) {
+ MethodSymbol method = (MethodSymbol) member;
+ banList.add(printSig((ExecutableType) method.asType(), method.name, annotationNode.getTypesUtil()));
+ }
+ }
+ */
+ for (Type t : toExclude) {
+ if (t instanceof ClassType) {
+ ClassType ct = (ClassType) t;
+ addMethodBindings(signaturesToExclude, ct, annotationNode, banList);
+ } else {
+ annotationNode.addError("@Delegate can only use concrete class types, not wildcards, arrays, type variables, or primitives.");
+ return false;
}
+ }
+
+ for (MethodSig sig : signaturesToExclude) {
+ banList.add(printSig(sig.type, sig.name, annotationNode.getTypesUtil()));
+ }
+
+ for (Type t : toDelegate) {
if (t instanceof ClassType) {
ClassType ct = (ClassType) t;
- addMethodBindings(signatures, ct, annotationNode, banList);
+ addMethodBindings(signaturesToDelegate, ct, annotationNode, banList);
} else {
annotationNode.addError("@Delegate can only use concrete class types, not wildcards, arrays, type variables, or primitives.");
return false;
@@ -139,7 +165,7 @@ public class HandleDelegate implements JavacAnnotationHandler<Delegate> {
Name delegateFieldName = annotationNode.toName(annotationNode.up().getName());
- for (MethodSig sig : signatures) generateAndAdd(sig, annotationNode, delegateFieldName);
+ for (MethodSig sig : signaturesToDelegate) generateAndAdd(sig, annotationNode, delegateFieldName);
return false;
}