private TypePattern child;
private TypePatternList parents;
private boolean isWildChild = false;
- private TypeVariablePatternList typeVariablesInScope = TypeVariablePatternList.EMPTY; // AspectJ 5 extension for generic types
+ private String[] typeVariablesInScope = new String[0]; // AspectJ 5 extension for generic types
public DeclareParents(TypePattern child, List parents) {
if (child instanceof WildTypePattern) isWildChild = true;
}
- public TypeVariablePatternList getTypeParameters() {
+ public String[] getTypeParameterNames() {
return this.typeVariablesInScope;
}
- public void setTypeParameters(TypeVariablePatternList typeParameters) {
+ public void setTypeParametersInScope(String[] typeParameters) {
this.typeVariablesInScope = typeParameters;
}
s.writeByte(Declare.PARENTS);
child.write(s);
parents.write(s);
- typeVariablesInScope.write(s); // change to binary form in AJ 5
+ s.writeInt(typeVariablesInScope.length);
+ for (int i = 0; i < typeVariablesInScope.length; i++) {
+ s.writeUTF(typeVariablesInScope[i]);
+ }
writeLocation(s);
}
public static Declare read(VersionedDataInputStream s, ISourceContext context) throws IOException {
DeclareParents ret = new DeclareParents(TypePattern.read(s, context), TypePatternList.read(s, context));
if (s.getMajorVersion()>=AjAttribute.WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ150) {
- ret.setTypeParameters(TypeVariablePatternList.read(s,context));
+ int numTypeVariablesInScope = s.readInt();
+ ret.typeVariablesInScope = new String[numTypeVariablesInScope];
+ for (int i = 0; i < numTypeVariablesInScope; i++) {
+ ret.typeVariablesInScope[i] = s.readUTF();
+ }
}
ret.readLocation(context, s);
return ret;
}
private Declare parseParents() {
- TypeVariablePatternList typeParameters = maybeParseTypeVariableList();
+ String[] typeParameters = maybeParseSimpleTypeVariableList();
eat(":");
TypePattern p = parseTypePattern(false,false);
IToken t = tokenSource.next();
DeclareParents decp = new DeclareParents(p, l);
if (typeParameters != null) {
- decp.setTypeParameters(typeParameters);
+ decp.setTypeParametersInScope(typeParameters);
}
return decp;
}
String kind = parseIdentifier();
IToken possibleTypeVariableToken = tokenSource.peek();
- TypeVariablePatternList typeVariables = maybeParseSimpleTypeVariableList();
+ String[] typeVariables = maybeParseSimpleTypeVariableList();
if (kind.equals("execution") || kind.equals("call") ||
kind.equals("get") || kind.equals("set")) {
p = parseKindedPointcut(kind);
if (typeVariables != null)
throw new ParserException("type variable specification not allowed for reference pointcuts",possibleTypeVariableToken);
}
- if (typeVariables != null) p.setTypeVariables(typeVariables);
+ if (typeVariables != null) p.setTypeVariablesInScope(typeVariables);
return p;
}
- private void assertNoTypeVariables(TypeVariablePatternList tvs, String errorMessage,IToken token) {
+ private void assertNoTypeVariables(String[] tvs, String errorMessage,IToken token) {
if ( tvs != null ) throw new ParserException(errorMessage,token);
}
IToken t = tokenSource.peek();
String kind = parseIdentifier();
IToken possibleTypeVariableToken = tokenSource.peek();
- TypeVariablePatternList typeVariables = maybeParseSimpleTypeVariableList();
+ String[] typeVariables = maybeParseSimpleTypeVariableList();
if (typeVariables != null) {
String message = "( - type variables not allowed with @" +
kind + " pointcut designator";
}
// of the form execution<T,S,V> - allows identifiers only
- public TypeVariablePatternList maybeParseSimpleTypeVariableList() {
+ public String[] maybeParseSimpleTypeVariableList() {
if (!maybeEat("<")) return null;
- List typeVars = new ArrayList();
+ List typeVarNames = new ArrayList();
do {
- String typeVarName = parseIdentifier();
- TypeVariablePattern tv = new TypeVariablePattern(typeVarName);
- typeVars.add(tv);
+ typeVarNames.add(parseIdentifier());
} while (maybeEat(","));
eat(">","',' or '>'");
- TypeVariablePattern[] tvs = new TypeVariablePattern[typeVars.size()];
- typeVars.toArray(tvs);
- return new TypeVariablePatternList(tvs);
+ String[] tvs = new String[typeVarNames.size()];
+ typeVarNames.toArray(tvs);
+ return tvs;
}
public TypePatternList maybeParseTypeParameterList(boolean allowTypeVariables) {
protected int lastMatchedShadowId;
private FuzzyBoolean lastMatchedShadowResult;
private Test lastMatchedShadowResidue;
- private TypeVariablePatternList typeVariables = TypeVariablePatternList.EMPTY;
+ private String[] typeVariablesInScope = new String[0];
/**
* Constructor for Pattern.
*/
public abstract /*Enum*/Set/*<Shadow.Kind>*/ couldMatchKinds();
- public TypeVariablePatternList getTypeVariables() {
- return typeVariables;
+ public String[] getTypeVariablesInScope() {
+ return typeVariablesInScope;
}
- public void setTypeVariables(TypeVariablePatternList typeVars) {
- this.typeVariables = typeVars;
+ public void setTypeVariablesInScope(String[] typeVars) {
+ this.typeVariablesInScope = typeVars;
}
/**
public final Pointcut resolve(IScope scope) {
assertState(SYMBOLIC);
Bindings bindingTable = new Bindings(scope.getFormalCount());
- this.resolveBindings(scope, bindingTable);
- bindingTable.checkAllBound(scope);
+ IScope bindingResolutionScope = scope;
+ if (typeVariablesInScope.length > 0) {
+ bindingResolutionScope = new ScopeWithTypeVariables(typeVariablesInScope,scope);
+ }
+ this.resolveBindings(bindingResolutionScope, bindingTable);
+ bindingTable.checkAllBound(bindingResolutionScope);
this.state = RESOLVED;
return this;
}
import org.aspectj.bridge.IMessage.Kind;
import org.aspectj.weaver.IHasPosition;
import org.aspectj.weaver.ResolvedTypeX;
+import org.aspectj.weaver.TypeVariable;
import org.aspectj.weaver.TypeX;
+import org.aspectj.weaver.UnresolvedTypeVariableReferenceType;
import org.aspectj.weaver.World;
/**
public class ScopeWithTypeVariables implements IScope {
private IScope delegateScope;
- private TypeVariablePatternList typeVariables;
+ private String[] typeVariableNames;
+ private UnresolvedTypeVariableReferenceType[] typeVarTypeXs;
- public ScopeWithTypeVariables(TypeVariablePatternList typeVars, IScope delegate) {
+ public ScopeWithTypeVariables(String[] typeVarNames, IScope delegate) {
this.delegateScope = delegate;
- this.typeVariables = typeVars;
+ this.typeVariableNames = typeVarNames;
+ this.typeVarTypeXs = new UnresolvedTypeVariableReferenceType[typeVarNames.length];
}
/* (non-Javadoc)
* @see org.aspectj.weaver.patterns.IScope#lookupType(java.lang.String, org.aspectj.weaver.IHasPosition)
*/
public TypeX lookupType(String name, IHasPosition location) {
- TypeVariablePattern typeVariableMatch = typeVariables.lookupTypeVariable(name);
- if (typeVariableMatch != null) {
- return typeVariableMatch.resolvedType();
- } else {
- return delegateScope.lookupType(name, location);
- }
+ for (int i = 0; i < typeVariableNames.length; i++) {
+ if (typeVariableNames[i].equals(name)) {
+ if (typeVarTypeXs[i] == null) {
+ typeVarTypeXs[i] = new UnresolvedTypeVariableReferenceType(new TypeVariable(name));
+ return typeVarTypeXs[i];
+ }
+ }
+ }
+ return delegateScope.lookupType(name, location);
}
/* (non-Javadoc)
ResolvedTypeX[] resolvedParameters = world.resolve(sig.getParameterTypes());
if (!parameterTypes.matches(resolvedParameters, TypePattern.STATIC).alwaysTrue()) {
// It could still be a match based on the erasure of a parameterized type
- // method in our hierarchy.
+ // method in our hierarchy - this is only allowed if the declaring type pattern
+ // is raw.
// We need to find out as cheaply as possible.
+ if (declaringType.getTypeParameters().size() > 0) return false;
ResolvedMember sigErasure = sig.getErasure();
if (sigErasure != null) {
ResolvedTypeX[] erasureParameters = world.resolve(sigErasure.getParameterTypes());
}
}
- public ResolvedTypeX resolvedType() {
- throw new UnsupportedOperationException("Haven't implement ResolvedTypeX for TypeVariables yet...");
- //return this.resolvedType;
- }
-
public boolean equals(Object obj) {
if (!(obj instanceof TypeVariablePattern)) return false;
TypeVariablePattern other = (TypeVariablePattern) obj;
}
return null;
}
-
+
+ public boolean isEmpty() {
+ return ((patterns == null) || (patterns.length == 0));
+ }
+
public void write(DataOutputStream s) throws IOException {
s.writeInt(patterns.length);
for (int i = 0; i < patterns.length; i++) {
public void testParseDeclareParentsWithTypeParameterList() {
PatternParser parser = new PatternParser("declare parents<T> : Foo<T> implements IveGoneMad");
DeclareParents decp = (DeclareParents) parser.parseDeclare();
- TypeVariablePatternList tvp = decp.getTypeParameters();
- assertEquals("one type parameter",1,tvp.getTypeVariablePatterns().length);
- assertEquals("expecting T","T",tvp.getTypeVariablePatterns()[0].getName());
+ String[] tvp = decp.getTypeParameterNames();
+ assertEquals("one type parameter",1,tvp.length);
+ assertEquals("expecting T","T",tvp[0]);
}
public void testParameterizedTypePatternsAny() {
public void testSimpleTypeVariableList() {
PatternParser parser = new PatternParser("<T,S,V>");
- TypeVariablePatternList tl = parser.maybeParseSimpleTypeVariableList();
- TypeVariablePattern[] patterns = tl.getTypeVariablePatterns();
- assertEquals("3 patterns",3,patterns.length);
- assertEquals("T",new TypeVariablePattern("T"),patterns[0]);
- assertEquals("S",new TypeVariablePattern("S"),patterns[1]);
- assertEquals("V",new TypeVariablePattern("V"),patterns[2]);
+ String[] tl = parser.maybeParseSimpleTypeVariableList();
+ assertEquals("3 patterns",3,tl.length);
+ assertEquals("T",tl[0]);
+ assertEquals("S",tl[1]);
+ assertEquals("V",tl[2]);
}
public void testSimpleTypeVariableListError() {
PatternParser parser = new PatternParser("<T extends Number>");
try {
- TypeVariablePatternList tl = parser.maybeParseSimpleTypeVariableList();
+ String[] tl = parser.maybeParseSimpleTypeVariableList();
} catch (ParserException ex) {
assertEquals("Expecting ',' or '>'","',' or '>'",ex.getMessage());
}
public void testParseCallPCDWithTypeVariables() {
PatternParser parser = new PatternParser("call<T>(* Foo<T>.*(T))");
Pointcut pc = parser.parsePointcut();
- TypeVariablePattern[] tvps = pc.getTypeVariables().getTypeVariablePatterns();
+ String[] tvps = pc.getTypeVariablesInScope();
assertEquals("1 type variable",1,tvps.length);
- assertEquals("T",tvps[0].getName());
+ assertEquals("T",tvps[0]);
}
public void testParseCallPCDWithIllegalBounds() {
public void testExecutionWithTypeVariables() {
PatternParser parser = new PatternParser("execution<T>(T Bar<T>.doSomething())");
Pointcut pc = parser.parsePointcut();
- TypeVariablePattern[] tvs = pc.getTypeVariables().getTypeVariablePatterns();
+ String[] tvs = pc.getTypeVariablesInScope();
assertEquals("1 type pattern",1,tvs.length);
- assertEquals("T",tvs[0].getName());
+ assertEquals("T",tvs[0]);
}
public void testInitializationWithTypeVariables() {
PatternParser parser = new PatternParser("initialization<T>(Bar<T>.new())");
Pointcut pc = parser.parsePointcut();
- TypeVariablePattern[] tvs = pc.getTypeVariables().getTypeVariablePatterns();
+ String[] tvs = pc.getTypeVariablesInScope();
assertEquals("1 type pattern",1,tvs.length);
- assertEquals("T",tvs[0].getName());
+ assertEquals("T",tvs[0]);
}
public void testPreInitializationWithTypeVariables() {
PatternParser parser = new PatternParser("preinitialization<T>(Bar<T>.new())");
Pointcut pc = parser.parsePointcut();
- TypeVariablePattern[] tvs = pc.getTypeVariables().getTypeVariablePatterns();
+ String[] tvs = pc.getTypeVariablesInScope();
assertEquals("1 type pattern",1,tvs.length);
- assertEquals("T",tvs[0].getName());
+ assertEquals("T",tvs[0]);
}
public void testStaticInitializationWithTypeVariables() {
PatternParser parser = new PatternParser("staticinitialization<T>(Bar<T>)");
Pointcut pc = parser.parsePointcut();
- TypeVariablePattern[] tvs = pc.getTypeVariables().getTypeVariablePatterns();
+ String[] tvs = pc.getTypeVariablesInScope();
assertEquals("1 type pattern",1,tvs.length);
- assertEquals("T",tvs[0].getName());
+ assertEquals("T",tvs[0]);
}
public void testWithinWithTypeVariables() {
PatternParser parser = new PatternParser("within<T>(Bar<T>)");
Pointcut pc = parser.parsePointcut();
- TypeVariablePattern[] tvs = pc.getTypeVariables().getTypeVariablePatterns();
+ String[] tvs = pc.getTypeVariablesInScope();
assertEquals("1 type pattern",1,tvs.length);
- assertEquals("T",tvs[0].getName());
+ assertEquals("T",tvs[0]);
}
public void testTypeParamList() {
public void testWithinCodeWithTypeVariables() {
PatternParser parser = new PatternParser("withincode<T,S,R>(Bar<T,S extends T, R extends S>.new())");
Pointcut pc = parser.parsePointcut();
- TypeVariablePattern[] tvs = pc.getTypeVariables().getTypeVariablePatterns();
+ String[] tvs = pc.getTypeVariablesInScope();
assertEquals("3 type patterns",3,tvs.length);
- assertEquals("T",tvs[0].getName());
- assertEquals("S",tvs[1].getName());
- assertEquals("R",tvs[2].getName());
+ assertEquals("T",tvs[0]);
+ assertEquals("S",tvs[1]);
+ assertEquals("R",tvs[2]);
}
public void testCallWithTypeVariables() {
PatternParser parser = new PatternParser("call<T>(* Bar<T>.*(..))");
Pointcut pc = parser.parsePointcut();
- TypeVariablePattern[] tvs = pc.getTypeVariables().getTypeVariablePatterns();
+ String[] tvs = pc.getTypeVariablesInScope();
assertEquals("1 type pattern",1,tvs.length);
- assertEquals("T",tvs[0].getName());
+ assertEquals("T",tvs[0]);
}
public void testGetWithTypeVariables() {
PatternParser parser = new PatternParser("get<T>(* Bar<T>.*)");
Pointcut pc = parser.parsePointcut();
- TypeVariablePattern[] tvs = pc.getTypeVariables().getTypeVariablePatterns();
+ String[] tvs = pc.getTypeVariablesInScope();
assertEquals("1 type pattern",1,tvs.length);
- assertEquals("T",tvs[0].getName());
+ assertEquals("T",tvs[0]);
}
public void testSetWithTypeVariables() {
PatternParser parser = new PatternParser("set<T>(* Bar<T>.*)");
Pointcut pc = parser.parsePointcut();
- TypeVariablePattern[] tvs = pc.getTypeVariables().getTypeVariablePatterns();
+ String[] tvs = pc.getTypeVariablesInScope();
assertEquals("1 type pattern",1,tvs.length);
- assertEquals("T",tvs[0].getName());
+ assertEquals("T",tvs[0]);
}