From: acolyer Date: Tue, 12 Jul 2005 14:24:13 +0000 (+0000) Subject: a pointcut now has a simple list of type variable names in scope rather than a TypeVa... X-Git-Tag: PRE_ANDY~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=21de41aba25e317167a22e491ab9c9381388498d;p=aspectj.git a pointcut now has a simple list of type variable names in scope rather than a TypeVariableListPattern --- diff --git a/weaver/src/org/aspectj/weaver/patterns/DeclareParents.java b/weaver/src/org/aspectj/weaver/patterns/DeclareParents.java index 21a493b13..f144900ad 100644 --- a/weaver/src/org/aspectj/weaver/patterns/DeclareParents.java +++ b/weaver/src/org/aspectj/weaver/patterns/DeclareParents.java @@ -37,7 +37,7 @@ public class DeclareParents extends Declare { 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) { @@ -50,11 +50,11 @@ public class DeclareParents extends Declare { 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; } @@ -102,14 +102,21 @@ public class DeclareParents extends Declare { 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; diff --git a/weaver/src/org/aspectj/weaver/patterns/PatternParser.java b/weaver/src/org/aspectj/weaver/patterns/PatternParser.java index a80e9bdea..56ae7a782 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PatternParser.java +++ b/weaver/src/org/aspectj/weaver/patterns/PatternParser.java @@ -182,7 +182,7 @@ public class PatternParser { } private Declare parseParents() { - TypeVariablePatternList typeParameters = maybeParseTypeVariableList(); + String[] typeParameters = maybeParseSimpleTypeVariableList(); eat(":"); TypePattern p = parseTypePattern(false,false); IToken t = tokenSource.next(); @@ -199,7 +199,7 @@ public class PatternParser { DeclareParents decp = new DeclareParents(p, l); if (typeParameters != null) { - decp.setTypeParameters(typeParameters); + decp.setTypeParametersInScope(typeParameters); } return decp; } @@ -279,7 +279,7 @@ public class PatternParser { 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); @@ -372,11 +372,11 @@ public class PatternParser { 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); } @@ -385,7 +385,7 @@ public class PatternParser { 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"; @@ -1196,18 +1196,16 @@ public class PatternParser { } // of the form execution - 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) { diff --git a/weaver/src/org/aspectj/weaver/patterns/Pointcut.java b/weaver/src/org/aspectj/weaver/patterns/Pointcut.java index 402c4ad47..62ec32b6f 100644 --- a/weaver/src/org/aspectj/weaver/patterns/Pointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/Pointcut.java @@ -104,7 +104,7 @@ public abstract class Pointcut extends PatternNode implements PointcutExpression protected int lastMatchedShadowId; private FuzzyBoolean lastMatchedShadowResult; private Test lastMatchedShadowResidue; - private TypeVariablePatternList typeVariables = TypeVariablePatternList.EMPTY; + private String[] typeVariablesInScope = new String[0]; /** * Constructor for Pattern. @@ -130,12 +130,12 @@ public abstract class Pointcut extends PatternNode implements PointcutExpression */ public abstract /*Enum*/Set/**/ 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; } /** @@ -228,8 +228,12 @@ public abstract class Pointcut extends PatternNode implements PointcutExpression 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; } diff --git a/weaver/src/org/aspectj/weaver/patterns/ScopeWithTypeVariables.java b/weaver/src/org/aspectj/weaver/patterns/ScopeWithTypeVariables.java index b6d450ad6..14aeb4807 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ScopeWithTypeVariables.java +++ b/weaver/src/org/aspectj/weaver/patterns/ScopeWithTypeVariables.java @@ -15,7 +15,9 @@ import org.aspectj.bridge.IMessageHandler; 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; /** @@ -25,23 +27,28 @@ 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) diff --git a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java index c981aa798..cc7f1b430 100644 --- a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java @@ -230,8 +230,10 @@ public class SignaturePattern extends PatternNode { 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()); diff --git a/weaver/src/org/aspectj/weaver/patterns/TypeVariablePattern.java b/weaver/src/org/aspectj/weaver/patterns/TypeVariablePattern.java index 6b0262456..c0235d9c0 100644 --- a/weaver/src/org/aspectj/weaver/patterns/TypeVariablePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/TypeVariablePattern.java @@ -111,11 +111,6 @@ public class TypeVariablePattern extends PatternNode { } } - 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; diff --git a/weaver/src/org/aspectj/weaver/patterns/TypeVariablePatternList.java b/weaver/src/org/aspectj/weaver/patterns/TypeVariablePatternList.java index a01633130..8ede2a073 100644 --- a/weaver/src/org/aspectj/weaver/patterns/TypeVariablePatternList.java +++ b/weaver/src/org/aspectj/weaver/patterns/TypeVariablePatternList.java @@ -43,7 +43,11 @@ public class TypeVariablePatternList extends PatternNode { } 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++) { diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java index 9fb105ca8..85d08e211 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java @@ -322,9 +322,9 @@ public class ParserTestCase extends TestCase { public void testParseDeclareParentsWithTypeParameterList() { PatternParser parser = new PatternParser("declare parents : Foo 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() { @@ -361,18 +361,17 @@ public class ParserTestCase extends TestCase { public void testSimpleTypeVariableList() { PatternParser parser = new PatternParser(""); - 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(""); try { - TypeVariablePatternList tl = parser.maybeParseSimpleTypeVariableList(); + String[] tl = parser.maybeParseSimpleTypeVariableList(); } catch (ParserException ex) { assertEquals("Expecting ',' or '>'","',' or '>'",ex.getMessage()); } @@ -382,9 +381,9 @@ public class ParserTestCase extends TestCase { public void testParseCallPCDWithTypeVariables() { PatternParser parser = new PatternParser("call(* Foo.*(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() { @@ -530,41 +529,41 @@ public class ParserTestCase extends TestCase { public void testExecutionWithTypeVariables() { PatternParser parser = new PatternParser("execution(T Bar.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(Bar.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(Bar.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(Bar)"); 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(Bar)"); 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() { @@ -580,35 +579,35 @@ public class ParserTestCase extends TestCase { public void testWithinCodeWithTypeVariables() { PatternParser parser = new PatternParser("withincode(Bar.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(* Bar.*(..))"); 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(* Bar.*)"); 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(* Bar.*)"); 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]); }