From fde9f247531b5257ebdff886054e9fd6cfd3e03d Mon Sep 17 00:00:00 2001 From: acolyer Date: Fri, 11 Feb 2005 12:56:35 +0000 Subject: [PATCH] fix bug whereby we were statically matching annotations that we shouldn't --- .../weaver/patterns/AnnotationPatternList.java | 2 +- .../weaver/patterns/ArgsAnnotationPointcut.java | 1 + .../weaver/patterns/ExactAnnotationTypePattern.java | 12 ++++++++++++ .../patterns/ThisOrTargetAnnotationPointcut.java | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/patterns/AnnotationPatternList.java b/weaver/src/org/aspectj/weaver/patterns/AnnotationPatternList.java index 8361e65e4..71be36a23 100644 --- a/weaver/src/org/aspectj/weaver/patterns/AnnotationPatternList.java +++ b/weaver/src/org/aspectj/weaver/patterns/AnnotationPatternList.java @@ -83,7 +83,7 @@ public class AnnotationPatternList extends PatternNode { // match the argument type at argsIndex with the ExactAnnotationTypePattern // we know it is exact because nothing else is allowed in args ExactAnnotationTypePattern ap = (ExactAnnotationTypePattern)typePatterns[i]; - FuzzyBoolean matches = ap.matches(someArgs[argsIndex]); + FuzzyBoolean matches = ap.matchesRuntimeType(someArgs[argsIndex]); if (matches == FuzzyBoolean.NO) { return FuzzyBoolean.MAYBE; // could still match at runtime } else { diff --git a/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java index 5ba432e81..fdc09557d 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java @@ -138,6 +138,7 @@ public class ArgsAnnotationPointcut extends NameBindingPointcut { "",IMessage.ERROR,shadow.getSourceLocation(),null,new ISourceLocation[]{getSourceLocation()}); } if (ap.matches(rArgType).alwaysTrue()) { // !!! ASC Can we ever take this branch? + // !!! AMC - Yes, if annotation is @Inherited argsIndex++; continue; } else { diff --git a/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java index 23a36e84d..811874fe4 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java @@ -78,6 +78,18 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { } return FuzzyBoolean.NO; } + + // this version should be called for @this, @target, @args + public FuzzyBoolean matchesRuntimeType(AnnotatedElement annotated) { + if (annotationType.hasAnnotation(TypeX.AT_INHERITED)) { + // a static match is good enough + if (matches(annotated).alwaysTrue()) { + return FuzzyBoolean.YES; + } + } + // a subtype could match at runtime + return FuzzyBoolean.MAYBE; + } public void resolve(World world) { diff --git a/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java index c06ec95e2..6aff2dbd9 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java @@ -88,7 +88,7 @@ public class ThisOrTargetAnnotationPointcut extends NameBindingPointcut { ResolvedTypeX toMatchAgainst = (isThis ? shadow.getThisType() : shadow.getTargetType() ).resolve(shadow.getIWorld()); annotationTypePattern.resolve(shadow.getIWorld()); - if (annotationTypePattern.matches(toMatchAgainst).alwaysTrue()) { + if (annotationTypePattern.matchesRuntimeType(toMatchAgainst).alwaysTrue()) { return FuzzyBoolean.YES; } else { // a subtype may match at runtime -- 2.39.5