diff options
author | acolyer <acolyer> | 2005-08-11 15:29:56 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-08-11 15:29:56 +0000 |
commit | f509577970fe3ee7f7b33ba60d0c80f129503fac (patch) | |
tree | f5693940b22bfdfa2824e4da892221b0a8d9a371 /weaver | |
parent | c53371b40761561cc0a70abe3f97926955d302fd (diff) | |
download | aspectj-f509577970fe3ee7f7b33ba60d0c80f129503fac.tar.gz aspectj-f509577970fe3ee7f7b33ba60d0c80f129503fac.zip |
early "parameterizeWith" support for type patterns
Diffstat (limited to 'weaver')
5 files changed, 68 insertions, 15 deletions
diff --git a/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java index 121e4a4ed..0b0b6aed3 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java @@ -24,6 +24,8 @@ import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.BCException; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.TypeVariableDeclaringElement; +import org.aspectj.weaver.TypeVariableReference; import org.aspectj.weaver.TypeVariableReferenceType; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.VersionedDataInputStream; @@ -283,6 +285,29 @@ public class ExactTypePattern extends TypePattern { throw new IllegalStateException("trying to re-resolve"); } + /** + * return a version of this type pattern with all type variables references replaced + * by the corresponding entry in the map. + */ + public TypePattern parameterizeWith(Map typeVariableMap) { + UnresolvedType newType = type; + if (type.isTypeVariableReference()) { + TypeVariableReference t = (TypeVariableReference) type; + String key = t.getTypeVariable().getName(); + if (typeVariableMap.containsKey(key)) { + newType = (UnresolvedType) typeVariableMap.get(key); + } + } else if (type.isParameterizedType()) { + newType = type.parameterize(typeVariableMap); + } + ExactTypePattern ret = new ExactTypePattern(newType,includeSubtypes,isVarArgs); + ret.annotationPattern = annotationPattern; + ret.start = start; + ret.end = end; + ret.sourceContext = sourceContext; + return ret; + } + public Object accept(PatternNodeVisitor visitor, Object data) { return visitor.visit(this, data); } diff --git a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java index 122287329..18c765a4b 100644 --- a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.Signature; @@ -121,6 +122,22 @@ public class SignaturePattern extends PatternNode { } } + /** + * return a copy of this signature pattern in which every type variable reference + * is replaced by the corresponding entry in the map. + */ + public SignaturePattern parameterizeWith(Map typeVariableMap) { + return new SignaturePattern( + kind, + modifiers, + returnType, + declaringType, + name, + parameterTypes.parameterizeWith(typeVariableMap), + throwsPattern, + annotationPattern); + } + public boolean matches(Member joinPointSignature, World world, boolean allowBridgeMethods) { // fail (or succeed!) fast tests... if (joinPointSignature == null) return false; diff --git a/weaver/src/org/aspectj/weaver/patterns/TypePattern.java b/weaver/src/org/aspectj/weaver/patterns/TypePattern.java index 216dafb53..0805e6895 100644 --- a/weaver/src/org/aspectj/weaver/patterns/TypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/TypePattern.java @@ -16,6 +16,7 @@ package org.aspectj.weaver.patterns; import java.io.DataOutputStream; import java.io.IOException; import java.util.Iterator; +import java.util.Map; import org.aspectj.bridge.MessageUtil; import org.aspectj.util.FuzzyBoolean; @@ -278,6 +279,15 @@ public abstract class TypePattern extends PatternNode { annotationPattern.resolve(world); } + /** + * return a version of this type pattern in which all type variable references have been + * replaced by their corresponding entry in the map. + * Should ultimately be made abstract and all subtypes forced to implement. + */ + public TypePattern parameterizeWith(Map typeVariableMap) { + throw new UnsupportedOperationException("add test cases for the sub-type in question and then override this method in it"); + } + public void postRead(ResolvedType enclosingType) { } @@ -580,7 +590,7 @@ class AnyWithAnnotationTypePattern extends TypePattern { public boolean equals(Object obj) { if (!(obj instanceof AnyWithAnnotationTypePattern)) return false; AnyWithAnnotationTypePattern awatp = (AnyWithAnnotationTypePattern) obj; - return (annotationPattern.equals(awatp)); + return (annotationPattern.equals(awatp.annotationPattern)); } public int hashCode() { diff --git a/weaver/src/org/aspectj/weaver/patterns/TypePatternList.java b/weaver/src/org/aspectj/weaver/patterns/TypePatternList.java index 761bb478b..5f8ceab02 100644 --- a/weaver/src/org/aspectj/weaver/patterns/TypePatternList.java +++ b/weaver/src/org/aspectj/weaver/patterns/TypePatternList.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.ISourceContext; @@ -413,7 +414,19 @@ public class TypePatternList extends PatternNode { } } - + /** + * Return a version of this type pattern list in which all type variable references + * are replaced by their corresponding entry in the map + * @param typeVariableMap + * @return + */ + public TypePatternList parameterizeWith(Map typeVariableMap) { + TypePattern[] parameterizedPatterns = new TypePattern[typePatterns.length]; + for (int i = 0; i < parameterizedPatterns.length; i++) { + parameterizedPatterns[i] = typePatterns[i].parameterizeWith(typeVariableMap); + } + return new TypePatternList(parameterizedPatterns); + } public TypePatternList resolveBindings(IScope scope, Bindings bindings, boolean allowBinding, boolean requireExactType) { for (int i=0; i<typePatterns.length; i++) { diff --git a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java index 493d82fcc..97d418f90 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java @@ -543,19 +543,7 @@ public class WildTypePattern extends TypePattern { // resolve any type parameters if (typeParameters!=null && typeParameters.size()>0) { typeParameters.resolveBindings(scope,bindings,allowBinding,requireExactType); - // now we have to decide whether to create a "generic" type pattern or a "parameterized" type - // pattern - // start with the simple rule that if all parameters have resolved to a type variable based pattern - // then it is generic, otherwise it is parameterized - // if we have e.g. staticinitialization<T>(Foo<T,String>) then that's a parameterized type - isGeneric = true; - TypePattern[] tps = typeParameters.getTypePatterns(); - for (int i = 0; i < tps.length; i++) { - if (!tps[i].getExactType().isTypeVariableReference()) { - isGeneric = false; - break; - } - } + isGeneric = false; } // resolve any bounds |