From 6585b9ef46e9cf6402a2d2ec5107443218488dc1 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sun, 29 Jan 2023 17:05:59 +0100 Subject: Add traverse methods for declare and pattern types Relates to #215. Signed-off-by: Alexander Kriegisch --- .../org/aspectj/weaver/patterns/DeclareAnnotation.java | 9 +++++++++ .../aspectj/weaver/patterns/DeclareErrorOrWarning.java | 7 +++++++ .../org/aspectj/weaver/patterns/DeclareParents.java | 9 +++++++++ .../org/aspectj/weaver/patterns/DeclarePrecedence.java | 7 +++++++ .../java/org/aspectj/weaver/patterns/DeclareSoft.java | 9 +++++++++ .../weaver/patterns/DeclareTypeErrorOrWarning.java | 7 +++++++ .../aspectj/weaver/patterns/HasMemberTypePattern.java | 6 ++++++ .../org/aspectj/weaver/patterns/SignaturePattern.java | 17 +++++++++++++++++ .../org/aspectj/weaver/patterns/TypePatternList.java | 6 ++++-- .../weaver/patterns/TypeVariablePatternList.java | 6 ++++-- .../weaver/patterns/WildAnnotationTypePattern.java | 7 +++++++ 11 files changed, 86 insertions(+), 4 deletions(-) diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareAnnotation.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareAnnotation.java index 6adc25a3e..7bd8da03d 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareAnnotation.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareAnnotation.java @@ -116,6 +116,15 @@ public class DeclareAnnotation extends Declare { return visitor.visit(this, data); } + public Object traverse(PatternNodeVisitor visitor, Object data) { + Object ret = accept(visitor, data); + if (this.signaturePattern != null && this.signaturePattern instanceof SignaturePattern) + ((SignaturePattern) this.signaturePattern).traverse(visitor, ret); + if (this.typePattern != null) + this.typePattern.traverse(visitor, ret); + return ret; + } + @Override public void resolve(IScope scope) { if (!scope.getWorld().isInJava5Mode()) { diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareErrorOrWarning.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareErrorOrWarning.java index de04e61f4..61e4bfb1e 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareErrorOrWarning.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareErrorOrWarning.java @@ -70,6 +70,13 @@ public class DeclareErrorOrWarning extends Declare { return visitor.visit(this, data); } + public Object traverse(PatternNodeVisitor visitor, Object data) { + Object ret = accept(visitor, data); + if (this.pointcut != null) + this.pointcut.traverse(visitor, ret); + return ret; + } + public void write(CompressingDataOutputStream s) throws IOException { s.writeByte(Declare.ERROR_OR_WARNING); s.writeBoolean(isError); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareParents.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareParents.java index 32e4654e3..87182eba9 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareParents.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareParents.java @@ -66,6 +66,15 @@ public class DeclareParents extends Declare { return visitor.visit(this, data); } + public Object traverse(PatternNodeVisitor visitor, Object data) { + Object ret = accept(visitor, data); + if (this.child != null) + this.child.traverse(visitor, ret); + if (this.parents != null) + this.parents.traverse(visitor, ret); + return ret; + } + @Override public Declare parameterizeWith(Map typeVariableBindingMap, World w) { DeclareParents ret = new DeclareParents(child.parameterizeWith(typeVariableBindingMap, w), parents.parameterizeWith( diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclarePrecedence.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclarePrecedence.java index 880fd8e44..42a9de6f3 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclarePrecedence.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclarePrecedence.java @@ -40,6 +40,13 @@ public class DeclarePrecedence extends Declare { return visitor.visit(this, data); } + public Object traverse(PatternNodeVisitor visitor, Object data) { + Object ret = accept(visitor, data); + if (this.patterns != null) + this.patterns.traverse(visitor, ret); + return ret; + } + public Declare parameterizeWith(Map typeVariableBindingMap, World w) { DeclarePrecedence ret = new DeclarePrecedence(this.patterns.parameterizeWith(typeVariableBindingMap, w)); ret.copyLocationFrom(this); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareSoft.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareSoft.java index 3384f3346..f57a5bc79 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareSoft.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareSoft.java @@ -39,6 +39,15 @@ public class DeclareSoft extends Declare { return visitor.visit(this, data); } + public Object traverse(PatternNodeVisitor visitor, Object data) { + Object ret = accept(visitor, data); + if (this.exception != null) + this.exception.traverse(visitor, ret); + if (this.pointcut != null) + this.pointcut.traverse(visitor, ret); + return ret; + } + @Override public Declare parameterizeWith(Map typeVariableBindingMap, World w) { DeclareSoft ret = new DeclareSoft(exception.parameterizeWith(typeVariableBindingMap, w), pointcut.parameterizeWith( diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareTypeErrorOrWarning.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareTypeErrorOrWarning.java index 8f7954a1b..b76c99f87 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareTypeErrorOrWarning.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/DeclareTypeErrorOrWarning.java @@ -75,6 +75,13 @@ public class DeclareTypeErrorOrWarning extends Declare { return visitor.visit(this, data); } + public Object traverse(PatternNodeVisitor visitor, Object data) { + Object ret = accept(visitor, data); + if (this.typePattern != null) + this.typePattern.traverse(visitor, ret); + return ret; + } + public void write(CompressingDataOutputStream s) throws IOException { s.writeByte(Declare.TYPE_ERROR_OR_WARNING); s.writeBoolean(isError); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/HasMemberTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/HasMemberTypePattern.java index be09f77ba..ea1e15d15 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/HasMemberTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/HasMemberTypePattern.java @@ -198,4 +198,10 @@ public class HasMemberTypePattern extends TypePattern { return visitor.visit(this, data); } + public Object traverse(PatternNodeVisitor visitor, Object data) { + Object ret = accept(visitor, data); + if (this.signaturePattern != null) + this.signaturePattern.traverse(visitor, ret); + return ret; + } } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java index 4285da575..895108ade 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java @@ -980,6 +980,23 @@ public class SignaturePattern extends PatternNode implements ISignaturePattern { return visitor.visit(this, data); } + public Object traverse(PatternNodeVisitor visitor, Object data) { + Object ret = accept(visitor, data); + if (this.annotationPattern != null) + this.annotationPattern.traverse(visitor, ret); + if (this.returnType != null) + this.returnType.traverse(visitor, ret); + if (this.declaringType != null) + this.declaringType.traverse(visitor, ret); + if (this.name != null) + this.name.traverse(visitor, ret); + if (this.parameterTypes != null) + this.parameterTypes.traverse(visitor, ret); + if (this.throwsPattern != null) + this.throwsPattern.traverse(visitor, ret); + return ret; + } + public boolean isExactDeclaringTypePattern() { return isExactDeclaringTypePattern; } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePatternList.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePatternList.java index 2ac2583c6..0f8e60424 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePatternList.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePatternList.java @@ -549,8 +549,10 @@ public class TypePatternList extends PatternNode { @Override public Object traverse(PatternNodeVisitor visitor, Object data) { Object ret = accept(visitor, data); - for (TypePattern typePattern : typePatterns) { - typePattern.traverse(visitor, ret); + if (typePatterns != null) { + for (TypePattern typePattern : typePatterns) { + typePattern.traverse(visitor, ret); + } } return ret; } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypeVariablePatternList.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypeVariablePatternList.java index d3402c4ed..babf57ee4 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypeVariablePatternList.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypeVariablePatternList.java @@ -75,8 +75,10 @@ public class TypeVariablePatternList extends PatternNode { public Object traverse(PatternNodeVisitor visitor, Object data) { Object ret = accept(visitor, data); - for (TypeVariablePattern pattern : patterns) { - pattern.traverse(visitor, ret); + if (patterns != null) { + for (TypeVariablePattern pattern : patterns) { + pattern.traverse(visitor, ret); + } } return ret; } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java index b7e56f613..eaec45aa0 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java @@ -428,4 +428,11 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { public Object accept(PatternNodeVisitor visitor, Object data) { return visitor.visit(this, data); } + + public Object traverse(PatternNodeVisitor visitor, Object data) { + Object ret = accept(visitor, data); + if (this.typePattern != null) + this.typePattern.traverse(visitor, ret); + return ret; + } } -- cgit v1.2.3