From: acolyer Date: Wed, 5 Jan 2005 15:15:28 +0000 (+0000) Subject: test cases and fix for Bugzilla Bug 81863 X-Git-Tag: Root_AspectJ5_Development~118 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8a8930fd9808b03e3c117086d7ba0eaa654a2438;p=aspectj.git test cases and fix for Bugzilla Bug 81863 Annotation matching using within() PCD doesn't appear to be working. --- diff --git a/tests/java5/annotations/within/PlainWithin.jar b/tests/java5/annotations/within/PlainWithin.jar new file mode 100644 index 000000000..d5411677a Binary files /dev/null and b/tests/java5/annotations/within/PlainWithin.jar differ diff --git a/tests/java5/annotations/within/PlainWithin.java b/tests/java5/annotations/within/PlainWithin.java index e19368cb2..ac541dbaa 100644 --- a/tests/java5/annotations/within/PlainWithin.java +++ b/tests/java5/annotations/within/PlainWithin.java @@ -15,7 +15,7 @@ * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */ -@MyClassRetententionAnnotation +@MyAnnotation public class PlainWithin { public void foo() {} diff --git a/tests/src/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java b/tests/src/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java index 54bc08ffc..cc75ea350 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java @@ -46,10 +46,30 @@ public class AnnotationPointcutsTests extends TestUtils { assertMessages(cR, new MessageSpec(expectedWarnings, new ArrayList())); } + public void test003_Within_Code() { + baseDir = new File("../tests/java5/annotations/within_code"); + CompilationResult cR = binaryWeave("TestingAnnotations.jar","WithinAndWithinCodeTests.java",0,5); + List warnings = new ArrayList(); + warnings.add(new Message(32,"@within match on non-inherited annotation")); + warnings.add(new Message(39,"@within match on non-inherited annotation")); + warnings.add(new Message(39,"@within match on inheritable annotation")); + warnings.add(new Message(43,"@within match on inheritable annotation")); + warnings.add(new Message(32,"@withincode match")); + MessageSpec mSpec = new MessageSpec(warnings,new ArrayList()); + assertMessages(cR,mSpec); + } + + public void test004_Within() { + baseDir = new File("../tests/java5/annotations/within"); + CompilationResult cR = binaryWeave("PlainWithin.jar","PlainWithinTests.java",0,2); + List warnings = new ArrayList(); + warnings.add(new Message(21,"positive within match on annotation")); + warnings.add(new Message(25,"negative within match on annotation")); + MessageSpec mSpec = new MessageSpec(warnings,new ArrayList()); + assertMessages(cR,mSpec); + } // TODO extra tests - // 1) @within (matches, does not match, matches inherited annotation) - // 2) @withincode (matches, does not match) // 3) @annotation on the different join point kinds, matches with inherited annotation } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java b/tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java index 53b43299c..b59f21423 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java @@ -75,16 +75,4 @@ public class AnnotationRuntimeTests extends TestUtils { assertMessages(cR, messageSpec); } - public void test007_Within_Code() { - baseDir = new File("../tests/java5/annotations/within_code"); - CompilationResult cR = binaryWeave("TestingAnnotations.jar","WithinAndWithinCodeTests.java",0,5); - List warnings = new ArrayList(); - warnings.add(new Message(32,"@within match on non-inherited annotation")); - warnings.add(new Message(39,"@within match on non-inherited annotation")); - warnings.add(new Message(39,"@within match on inheritable annotation")); - warnings.add(new Message(43,"@within match on inheritable annotation")); - warnings.add(new Message(32,"@withincode match")); - MessageSpec mSpec = new MessageSpec(warnings,new ArrayList()); - assertMessages(cR,mSpec); - } } diff --git a/weaver/src/org/aspectj/weaver/patterns/AnnotationTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/AnnotationTypePattern.java index 1a4a34d18..df5952b72 100644 --- a/weaver/src/org/aspectj/weaver/patterns/AnnotationTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/AnnotationTypePattern.java @@ -83,6 +83,10 @@ public abstract class AnnotationTypePattern extends PatternNode { class AnyAnnotationTypePattern extends AnnotationTypePattern { + public FuzzyBoolean fastMatches(AnnotatedElement annotated) { + return FuzzyBoolean.YES; + } + public FuzzyBoolean matches(AnnotatedElement annotated) { return FuzzyBoolean.YES; } diff --git a/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java index 51ac632c6..61b1eaa13 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java @@ -81,7 +81,8 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { public void resolve(World world) { - annotationType = annotationType.resolve(world); + if (!resolved) annotationType = annotationType.resolve(world); + resolved = true; } /* (non-Javadoc) diff --git a/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java index 864a896da..2f150d3f4 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java @@ -89,17 +89,20 @@ public class ExactTypePattern extends TypePattern { } protected boolean matchesExactly(ResolvedTypeX matchType) { - return this.type.equals(matchType); + boolean typeMatch = this.type.equals(matchType); + boolean annMatch = this.annotationPattern.matches(matchType).alwaysTrue(); + return (typeMatch && annMatch); } public TypeX getType() { return type; } public FuzzyBoolean matchesInstanceof(ResolvedTypeX matchType) { // in our world, Object is assignable from anything - if (type.equals(ResolvedTypeX.OBJECT)) return FuzzyBoolean.YES; + if (type.equals(ResolvedTypeX.OBJECT)) + return FuzzyBoolean.YES.and(annotationPattern.matches(matchType)); if (type.isAssignableFrom(matchType, matchType.getWorld())) { - return FuzzyBoolean.YES; + return FuzzyBoolean.YES.and(annotationPattern.matches(matchType)); } // fix for PR 64262 - shouldn't try to coerce primitives diff --git a/weaver/src/org/aspectj/weaver/patterns/HandlerPointcut.java b/weaver/src/org/aspectj/weaver/patterns/HandlerPointcut.java index f27f1f81d..398763788 100644 --- a/weaver/src/org/aspectj/weaver/patterns/HandlerPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/HandlerPointcut.java @@ -61,6 +61,8 @@ public class HandlerPointcut extends Pointcut { protected FuzzyBoolean matchInternal(Shadow shadow) { if (shadow.getKind() != Shadow.ExceptionHandler) return FuzzyBoolean.NO; + exceptionType.resolve(shadow.getIWorld()); + // we know we have exactly one parameter since we're checking an exception handler return exceptionType.matches( shadow.getSignature().getParameterTypes()[0].resolve(shadow.getIWorld()), diff --git a/weaver/src/org/aspectj/weaver/patterns/TypePattern.java b/weaver/src/org/aspectj/weaver/patterns/TypePattern.java index a0c42e19e..256373198 100644 --- a/weaver/src/org/aspectj/weaver/patterns/TypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/TypePattern.java @@ -26,6 +26,7 @@ import org.aspectj.weaver.IntMap; import org.aspectj.weaver.ResolvedTypeX; import org.aspectj.weaver.TypeX; import org.aspectj.weaver.WeaverMessages; +import org.aspectj.weaver.World; /** * On creation, type pattern only contains WildTypePattern nodes, not BindingType or ExactType. * @@ -91,13 +92,15 @@ public abstract class TypePattern extends PatternNode { if (type == ResolvedTypeX.MISSING) return FuzzyBoolean.NO; if (kind == STATIC) { - typeMatch = FuzzyBoolean.fromBoolean(matchesStatically(type)); - return typeMatch.and(annotationPattern.matches(type)); +// typeMatch = FuzzyBoolean.fromBoolean(matchesStatically(type)); +// return typeMatch.and(annotationPattern.matches(type)); + return FuzzyBoolean.fromBoolean(matchesStatically(type)); } else if (kind == DYNAMIC) { //System.err.println("matching: " + this + " with " + type); - typeMatch = matchesInstanceof(type); +// typeMatch = matchesInstanceof(type); //System.err.println(" got: " + ret); - return typeMatch.and(annotationPattern.matches(type)); +// return typeMatch.and(annotationPattern.matches(type)); + return matchesInstanceof(type); } else { throw new IllegalArgumentException("kind must be DYNAMIC or STATIC"); } @@ -218,6 +221,10 @@ public abstract class TypePattern extends PatternNode { return this; } + public void resolve(World world) { + annotationPattern.resolve(world); + } + public void postRead(ResolvedTypeX enclosingType) { } diff --git a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java index 105d8aaca..d0cc882a6 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/WildTypePattern.java @@ -114,7 +114,8 @@ public class WildTypePattern extends TypePattern { //System.err.println("match: " + targetTypeName + ", " + knownMatches); //Arrays.asList(importedPrefixes)); - return matchesExactlyByName(targetTypeName); + return matchesExactlyByName(targetTypeName) && + annotationPattern.matches(type).alwaysTrue(); } /** diff --git a/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java b/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java index f622b8088..96201d203 100644 --- a/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/WithinPointcut.java @@ -42,7 +42,7 @@ public class WithinPointcut extends Pointcut { private FuzzyBoolean isWithinType(ResolvedTypeX type) { while (type != null) { - if (typePattern.matchesStatically(type)) { + if (typePattern.matchesStatically(type)) { return FuzzyBoolean.YES; } type = type.getDeclaringType(); @@ -55,7 +55,10 @@ public class WithinPointcut extends Pointcut { } public FuzzyBoolean fastMatch(FastMatchInfo info) { - return isWithinType(info.getType()); + if (typePattern.annotationPattern instanceof AnyAnnotationTypePattern) { + return isWithinType(info.getType()); + } + return FuzzyBoolean.MAYBE; } protected FuzzyBoolean matchInternal(Shadow shadow) { @@ -67,6 +70,7 @@ public class WithinPointcut extends Pointcut { shadow.getSourceLocation(),true,new ISourceLocation[]{getSourceLocation()}); shadow.getIWorld().getMessageHandler().handleMessage(msg); } + typePattern.resolve(shadow.getIWorld()); return isWithinType(enclosingType); }