]> source.dussan.org Git - aspectj.git/commitdiff
Enable type parameter traversal in exact type patterns
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Mon, 30 Jan 2023 11:41:47 +0000 (12:41 +0100)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Fri, 12 Apr 2024 12:19:06 +0000 (14:19 +0200)
Closes #221

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/BindingTypePattern.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/ExactTypePattern.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/HasMemberTypePattern.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePattern.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypeVariablePattern.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypeVariablePatternList.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java
org.aspectj.matcher/src/test/java/org/aspectj/weaver/patterns/ParserTestCase.java

index d7921d5894b051e8451282fac7a41529bc25c990..4175d436e04969fd699865522fceb7cb638cde19 100644 (file)
@@ -29,7 +29,7 @@ public class BindingTypePattern extends ExactTypePattern implements BindingPatte
        private String bindingName;
 
        public BindingTypePattern(UnresolvedType type, int index, boolean isVarArgs) {
-               super(type, false, isVarArgs);
+               super(type, false, isVarArgs, null);
                this.formalIndex = index;
        }
 
@@ -89,7 +89,7 @@ public class BindingTypePattern extends ExactTypePattern implements BindingPatte
 
        public TypePattern remapAdviceFormals(IntMap bindings) {
                if (!bindings.hasKey(formalIndex)) {
-                       return new ExactTypePattern(type, false, isVarArgs);
+                       return new ExactTypePattern(type, false, isVarArgs, null);
                } else {
                        int newFormalIndex = bindings.get(formalIndex);
                        return new BindingTypePattern(type, newFormalIndex, isVarArgs);
index 6a747a3ecad9d5014350b653842d30e1c3e10c2c..7c48a97c545656ed9b99fe36c77d745428f4c06e 100644 (file)
@@ -79,14 +79,14 @@ public class ExactTypePattern extends TypePattern {
                if (type.isArray() && this.type.isArray()) {
                        ResolvedType componentType = type.getComponentType().resolve(type.getWorld());
                        UnresolvedType newPatternType = this.type.getComponentType();
-                       ExactTypePattern etp = new ExactTypePattern(newPatternType, includeSubtypes, false);
+                       ExactTypePattern etp = new ExactTypePattern(newPatternType, includeSubtypes, false, typeParameters);
                        return etp.matchesSubtypes(componentType, type);
                }
                return match;
        }
 
-       public ExactTypePattern(UnresolvedType type, boolean includeSubtypes, boolean isVarArgs) {
-               super(includeSubtypes, isVarArgs);
+       public ExactTypePattern(UnresolvedType type, boolean includeSubtypes, boolean isVarArgs, TypePatternList typeParams) {
+               super(includeSubtypes, isVarArgs, typeParams);
                this.type = type;
        }
 
@@ -283,8 +283,12 @@ public class ExactTypePattern extends TypePattern {
                if (version > EXACT_VERSION) {
                        throw new BCException("ExactTypePattern was written by a more recent version of AspectJ");
                }
-               TypePattern ret = new ExactTypePattern(s.isAtLeast169() ? s.readSignatureAsUnresolvedType() : UnresolvedType.read(s), s
-                               .readBoolean(), s.readBoolean());
+               TypePattern ret = new ExactTypePattern(
+                       s.isAtLeast169() ? s.readSignatureAsUnresolvedType() : UnresolvedType.read(s),
+                       s.readBoolean(),
+                       s.readBoolean(),
+                       null // set null first, use 'setTypeParameters' below
+               );
                ret.setAnnotationTypePattern(AnnotationTypePattern.read(s, context));
                ret.setTypeParameters(TypePatternList.read(s, context));
                ret.readLocation(context, s);
@@ -292,7 +296,7 @@ public class ExactTypePattern extends TypePattern {
        }
 
        public static TypePattern readTypePatternOldStyle(DataInputStream s, ISourceContext context) throws IOException {
-               TypePattern ret = new ExactTypePattern(UnresolvedType.read(s), s.readBoolean(), false);
+               TypePattern ret = new ExactTypePattern(UnresolvedType.read(s), s.readBoolean(), false, null);
                ret.readLocation(context, s);
                return ret;
        }
@@ -342,7 +346,7 @@ public class ExactTypePattern extends TypePattern {
                } else if (type.isParameterizedType()) {
                        newType = w.resolve(type).parameterize(typeVariableMap);
                }
-               ExactTypePattern ret = new ExactTypePattern(newType, includeSubtypes, isVarArgs);
+               ExactTypePattern ret = new ExactTypePattern(newType, includeSubtypes, isVarArgs, typeParameters);
                ret.annotationPattern = annotationPattern.parameterizeWith(typeVariableMap, w);
                ret.copyLocationFrom(this);
                return ret;
index ea1e15d15d8de91f11080b3e45c2819c39dea9c6..0cd87001c832febf2769461a62eab47bab49d57d 100644 (file)
@@ -198,8 +198,10 @@ public class HasMemberTypePattern extends TypePattern {
                return visitor.visit(this, data);
        }
 
+       @Override
        public Object traverse(PatternNodeVisitor visitor, Object data) {
                Object ret = accept(visitor, data);
+               super.traverse(visitor, ret);
                if (this.signaturePattern != null)
                        this.signaturePattern.traverse(visitor, ret);
                return ret;
index b0e058d4528c7c212dcfb8af6a5837dd7a2a0eb1..36e8f26412f6bb9cf13f1374d32888171c4ef90a 100644 (file)
@@ -360,4 +360,13 @@ public abstract class TypePattern extends PatternNode {
                return false;
        }
 
+       @Override
+       public Object traverse(PatternNodeVisitor visitor, Object data) {
+               Object ret = accept(visitor, data);
+               if (annotationPattern != null)
+                       annotationPattern.traverse(visitor, ret);
+               if (typeParameters != null)
+                       typeParameters.traverse(visitor, ret);
+               return ret;
+       }
 }
index f887a4077844f5d2c20c5d3efde2fb53538c167d..26eac039ac964f8ad7a21029693e28626165b4f3 100644 (file)
@@ -45,7 +45,7 @@ public class TypeVariablePattern extends PatternNode {
         */
        public TypeVariablePattern(String variableName) {
                this.name = variableName;
-               this.upperBound = new ExactTypePattern(UnresolvedType.OBJECT, false, false);
+               this.upperBound = new ExactTypePattern(UnresolvedType.OBJECT, false, false, null);
                this.lowerBound = null;
                this.interfaceBounds = null;
        }
@@ -67,7 +67,7 @@ public class TypeVariablePattern extends PatternNode {
                this.name = variableName;
                this.upperBound = upperLimit;
                if (upperBound == null) {
-                       upperBound = new ExactTypePattern(UnresolvedType.OBJECT, false, false);
+                       upperBound = new ExactTypePattern(UnresolvedType.OBJECT, false, false, null);
                }
                this.interfaceBounds = interfaceBounds;
                this.lowerBound = lowerBound;
@@ -77,7 +77,21 @@ public class TypeVariablePattern extends PatternNode {
                return visitor.visit(this, data);
        }
 
-       public String getName() {
+       public Object traverse(PatternNodeVisitor visitor, Object data) {
+               Object ret = accept(visitor, data);
+               if (lowerBound != null)
+                       lowerBound.traverse(visitor, ret);
+               if (upperBound != null)
+                       upperBound.traverse(visitor, ret);
+               if (interfaceBounds != null) {
+                       for (TypePattern pattern : interfaceBounds) {
+                               pattern.traverse(visitor, ret);
+                       }
+               }
+               return ret;
+       }
+
+  public String getName() {
                return name;
        }
 
index babf57ee4cac2def98ab5a0ce9f73ed45c98b40f..153b7f4aadd963e2ffc377a2c4a889ed0cc8bc78 100644 (file)
@@ -73,6 +73,7 @@ public class TypeVariablePatternList extends PatternNode {
                return visitor.visit(this, data);
        }
 
+       @Override
        public Object traverse(PatternNodeVisitor visitor, Object data) {
                Object ret = accept(visitor, data);
                if (patterns != null) {
index eaec45aa07c4461898b0eddc9e827ddeafc4b0ab..4e75a25bc69c5a42b3c6685410a89049dae9dadd 100644 (file)
@@ -299,7 +299,7 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern {
                                if (fullyQualifiedName != null && fullyQualifiedName.contains(".")) {
                                        ResolvedType resolvedType = world.resolve(UnresolvedType.forName(fullyQualifiedName));
                                        if (resolvedType != null && !resolvedType.isMissing()) {
-                                               typePattern = new ExactTypePattern(resolvedType, false, false);
+                                               typePattern = new ExactTypePattern(resolvedType, false, false, null);
                                        }
                                }
                        }
index 212378bf71ffa13e357360fdd347d7614d4a3c3b..407b2f8d171cd4832b136db60945f3dc81bc3fe0 100644 (file)
@@ -804,7 +804,7 @@ public class WildTypePattern extends TypePattern {
                        if (dim != 0) {
                                aType = UnresolvedType.makeArray(aType, dim);
                        }
-                       ret = new ExactTypePattern(aType, includeSubtypes, isVarArgs);
+                       ret = new ExactTypePattern(aType, includeSubtypes, isVarArgs, typeParameters);
                }
                ret.setAnnotationTypePattern(annotationPattern);
                ret.copyLocationFrom(this);
@@ -841,7 +841,7 @@ public class WildTypePattern extends TypePattern {
                        }
                        if (canBeExact) {
                                // might have changed if we find out include subtypes is set on one of the bounds...
-                               return new ExactTypePattern(type, includeSubtypes, isVarArgs);
+                               return new ExactTypePattern(type, includeSubtypes, isVarArgs, typeParameters);
                        }
                }
 
@@ -878,7 +878,7 @@ public class WildTypePattern extends TypePattern {
                        if (dim != 0) {
                                type = ResolvedType.makeArray(type, dim);
                        }
-                       return new ExactTypePattern(type, includeSubtypes, isVarArgs);
+                       return new ExactTypePattern(type, includeSubtypes, isVarArgs, typeParameters);
                } else {
                        // AMC... just leave it as a wild type pattern then?
                        importedPrefixes = scope.getImportedPrefixes();
@@ -940,7 +940,7 @@ public class WildTypePattern extends TypePattern {
                        if (dim != 0) {
                                rType = ResolvedType.makeArray(rType, dim);
                        }
-                       return new ExactTypePattern(rType, includeSubtypes, isVarArgs);
+                       return new ExactTypePattern(rType, includeSubtypes, isVarArgs, typeParameters);
                } else {
                        // we have to set bounds on the TypeVariable held by tvrType before resolving it
                        boolean canCreateExactTypePattern = true;
@@ -973,7 +973,7 @@ public class WildTypePattern extends TypePattern {
                                if (dim != 0) {
                                        rType = ResolvedType.makeArray(rType, dim);
                                }
-                               return new ExactTypePattern(rType, includeSubtypes, isVarArgs);
+                               return new ExactTypePattern(rType, includeSubtypes, isVarArgs, typeParameters);
                        }
                        return this; // leave as wild type pattern then
                }
index 8c7258d59ff6e32d27099ddff683bb614b9fbc87..7378b6661f40ab668c1ec2aea1696c01eecc166f 100644 (file)
@@ -290,7 +290,7 @@ public class ParserTestCase extends PatternsTestCase {
        public void testParseAllowedSuperInTypeVariable() {
                PatternParser parser = new PatternParser("T super Number+");
                TypeVariablePattern tv = parser.parseTypeVariable();
-               TypeVariablePattern expected = new TypeVariablePattern("T", new ExactTypePattern(UnresolvedType.OBJECT, false, false),
+               TypeVariablePattern expected = new TypeVariablePattern("T", new ExactTypePattern(UnresolvedType.OBJECT, false, false, null),
                                null, new PatternParser("Number+").parseTypePattern());
                assertEquals("Expected type variable T super Number+", expected, tv);
        }