]> source.dussan.org Git - aspectj.git/commitdiff
a pointcut now has a simple list of type variable names in scope rather than a TypeVa...
authoracolyer <acolyer>
Tue, 12 Jul 2005 14:24:13 +0000 (14:24 +0000)
committeracolyer <acolyer>
Tue, 12 Jul 2005 14:24:13 +0000 (14:24 +0000)
weaver/src/org/aspectj/weaver/patterns/DeclareParents.java
weaver/src/org/aspectj/weaver/patterns/PatternParser.java
weaver/src/org/aspectj/weaver/patterns/Pointcut.java
weaver/src/org/aspectj/weaver/patterns/ScopeWithTypeVariables.java
weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java
weaver/src/org/aspectj/weaver/patterns/TypeVariablePattern.java
weaver/src/org/aspectj/weaver/patterns/TypeVariablePatternList.java
weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java

index 21a493b13e3f0d0ab42850d7a68cc8baebfac80e..f144900adb70cf8906d86fb2f082c3b2c373160f 100644 (file)
@@ -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;
index a80e9bdea091c5be77c800708ffb95d14cab7a0c..56ae7a782ffdd2e709f0de48631897ebd18b1cdf 100644 (file)
@@ -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<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) {
index 402c4ad471501f70958d72f7b10bb108503d56e3..62ec32b6f394a6fdd9dfc695b965c99d9d0029fb 100644 (file)
@@ -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/*<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;
        }
        
        /**
@@ -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;   
     }
index b6d450ad69f2b78a3a3b2cf57945938c88f8791b..14aeb480708bc8d5ecdb5427ba827c676de277f1 100644 (file)
@@ -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)
index c981aa79850d1181037b370da0c5ffd8660543e4..cc7f1b4309019e6fbb0541f090e5ecb15d182b6d 100644 (file)
@@ -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());
index 6b026245622b517d2cf4d7db0d97a19efd8873f7..c0235d9c0faa867869671b3bb2e53f4d2237f1ef 100644 (file)
@@ -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;
index a01633130eda3a113e01855cc2f97acb58b0d177..8ede2a0732e51f97c573a13ac19e5214717235a0 100644 (file)
@@ -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++) {
index 9fb105ca86d78fef2605bb9f7718d5a26dcbae53..85d08e211b7e5262661fa39ceba86b4b42d889ec 100644 (file)
@@ -322,9 +322,9 @@ public class ParserTestCase extends TestCase {
        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() {
@@ -361,18 +361,17 @@ public class ParserTestCase extends TestCase {
 
        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());
                }       
@@ -382,9 +381,9 @@ public class ParserTestCase extends TestCase {
        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() {
@@ -530,41 +529,41 @@ public class ParserTestCase extends TestCase {
        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() {
@@ -580,35 +579,35 @@ public class ParserTestCase extends TestCase {
        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]);               
        }