Browse Source

fixes for annotation type pattern bugs uncovered in 150 tests

tags/V1_5_0M2
acolyer 19 years ago
parent
commit
922aeaa57d

+ 4
- 5
tests/java5/annotations/ajdkExamples/RuntimeTypeMatching.aj View File

before() : insideCriticalMethod(Critical) { before() : insideCriticalMethod(Critical) {
Signature sig = thisEnclosingJoinPointStaticPart.getSignature(); Signature sig = thisEnclosingJoinPointStaticPart.getSignature();
AnnotatedElement declaringTypeAnnotationInfo = sig.getDeclaringType(); AnnotatedElement declaringTypeAnnotationInfo = sig.getDeclaringType();
if (sig instanceof MemberSignature) {
// this must be an initialization, pre-initialization, call, execution, get, or
// set join point.
AnnotatedElement memberAnnotationInfo = ((MemberSignature)sig).getAccessibleObject();
Critical c = memberAnnotationInfo.getAnnotation(Critical.class);
if (sig instanceof MethodSignature) {
// this must be a call or execution join point.
Method method = ((MethodSignature)sig).getMethod();
Critical c = method.getAnnotation(Critical.class);
System.out.println("Entering critical join point with reflectively obtained priority " + c.priority()); System.out.println("Entering critical join point with reflectively obtained priority " + c.priority());
} }
} }

+ 2
- 1
tests/java5/pertypewithin/ajdk/AJDKExamples.aj View File

package org.xyz.foo;
import java.util.*; import java.util.*;
public aspect AJDKExamples pertypewithin(org.xyz..*) {
public aspect AJDKExamples pertypewithin(org.xyz..* && !AJDKExamples) {
// use WeakHashMap for auto-garbage collection of keys // use WeakHashMap for auto-garbage collection of keys
private Map<Object,Boolean> instances = new WeakHashMap<Object,Boolean>(); private Map<Object,Boolean> instances = new WeakHashMap<Object,Boolean>();

+ 6
- 4
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml View File



<ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: runtime annotations"> <ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: runtime annotations">
<compile files="RuntimeTypeMatching.aj" options="-1.5"> <compile files="RuntimeTypeMatching.aj" options="-1.5">
<message kind="warning" line="121" text="@within(Foo)"/>
<message kind="warning" line="122" text="@within(Foo)"/> <message kind="warning" line="122" text="@within(Foo)"/>
<message kind="warning" line="123" text="@within(Foo)"/>
</compile> </compile>
<run class="RuntimeTypeMatching"> <run class="RuntimeTypeMatching">
<stdout> <stdout>
<line text="This information is TOP-SECRET"/> <line text="This information is TOP-SECRET"/>
<line text="@target(Classified) at call(void A.a())"/> <line text="@target(Classified) at call(void A.a())"/>
<line text="@this(Foo) at execution(void B.b())"/> <line text="@this(Foo) at execution(void B.b())"/>
<line text="Classified data being passed at call(void B.callA(A))"/>
<line text="Classified data being passed at execution(void B.callA(A))"/>
<line text="This information is TOP-SECRET"/> <line text="This information is TOP-SECRET"/>
<line text="@target(Classified) at call(Class java.lang.Object.getClass())"/> <line text="@target(Classified) at call(Class java.lang.Object.getClass())"/>
<line text="1 @Foo()"/> <line text="1 @Foo()"/>


<ajc-test dir="java5/pertypewithin/ajdk" title="ajdk: ptw"> <ajc-test dir="java5/pertypewithin/ajdk" title="ajdk: ptw">
<compile files="AJDKExamples.aj" options="-1.5"/> <compile files="AJDKExamples.aj" options="-1.5"/>
<run class="AJDKExamples">
<run class="org.xyz.foo.AJDKExamples">
<stdout> <stdout>
<line text="true"/> <line text="true"/>
<line text="true"/> <line text="true"/>
<line text="There are 3 As"/>
<line text="There are 2 Bs"/>
<line text="There are 2 As"/>
<line text="There are 3 Bs"/>
</stdout> </stdout>
</run> </run>
</ajc-test> </ajc-test>

+ 8
- 5
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java View File

if (element instanceof BcelAdvice) { // This will stop us incorrectly reporting deow Checkers if (element instanceof BcelAdvice) { // This will stop us incorrectly reporting deow Checkers
BcelAdvice ba = (BcelAdvice)element; BcelAdvice ba = (BcelAdvice)element;
if (!ba.hasMatchedSomething()) { if (!ba.hasMatchedSomething()) {
Annotation[] anns = ((BcelMethod)ba.getSignature()).getAnnotations();
// Check if they want to suppress the warning on this piece of advice
if (!Utility.isSuppressing(anns,"adviceDidNotMatch")) {
world.getLint().adviceDidNotMatch.signal(ba.getDeclaringAspect().getNameAsIdentifier(),element.getSourceLocation());
}
BcelMethod meth = ((BcelMethod)ba.getSignature());
if (meth != null) {
Annotation[] anns = meth.getAnnotations();
// Check if they want to suppress the warning on this piece of advice
if (!Utility.isSuppressing(anns,"adviceDidNotMatch")) {
world.getLint().adviceDidNotMatch.signal(ba.getDeclaringAspect().getNameAsIdentifier(),element.getSourceLocation());
}
}
} }
} }
} }

+ 1
- 0
weaver/src/org/aspectj/weaver/patterns/AnnotationPatternList.java View File

} else { } else {
// match the argument type at argsIndex with the ExactAnnotationTypePattern // match the argument type at argsIndex with the ExactAnnotationTypePattern
// we know it is exact because nothing else is allowed in args // we know it is exact because nothing else is allowed in args
if (someArgs[argsIndex].isPrimitive()) return FuzzyBoolean.NO; // can never match
ExactAnnotationTypePattern ap = (ExactAnnotationTypePattern)typePatterns[i]; ExactAnnotationTypePattern ap = (ExactAnnotationTypePattern)typePatterns[i];
FuzzyBoolean matches = ap.matchesRuntimeType(someArgs[argsIndex]); FuzzyBoolean matches = ap.matchesRuntimeType(someArgs[argsIndex]);
if (matches == FuzzyBoolean.NO) { if (matches == FuzzyBoolean.NO) {

+ 1
- 1
weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java View File

if (ap instanceof BindingAnnotationTypePattern) { if (ap instanceof BindingAnnotationTypePattern) {
BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern)ap; BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern)ap;
Var annvar = shadow.getArgAnnotationVar(argsIndex,rAnnType); Var annvar = shadow.getArgAnnotationVar(argsIndex,rAnnType);
state.set(argsIndex,annvar);
state.set(btp.getFormalIndex(),annvar);
ret = Test.makeAnd(ret,Test.makeHasAnnotation(shadow.getArgVar(argsIndex),rAnnType)); ret = Test.makeAnd(ret,Test.makeHasAnnotation(shadow.getArgVar(argsIndex),rAnnType));
argsIndex++; argsIndex++;
} else { } else {

Loading…
Cancel
Save