Annotation matching using within() PCD doesn't appear to be working.
* 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() {}
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
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);
- }
}
class AnyAnnotationTypePattern extends AnnotationTypePattern {
+ public FuzzyBoolean fastMatches(AnnotatedElement annotated) {
+ return FuzzyBoolean.YES;
+ }
+
public FuzzyBoolean matches(AnnotatedElement annotated) {
return FuzzyBoolean.YES;
}
public void resolve(World world) {
- annotationType = annotationType.resolve(world);
+ if (!resolved) annotationType = annotationType.resolve(world);
+ resolved = true;
}
/* (non-Javadoc)
}
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
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()),
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.
*
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");
}
return this;
}
+ public void resolve(World world) {
+ annotationPattern.resolve(world);
+ }
+
public void postRead(ResolvedTypeX enclosingType) {
}
//System.err.println("match: " + targetTypeName + ", " + knownMatches); //Arrays.asList(importedPrefixes));
- return matchesExactlyByName(targetTypeName);
+ return matchesExactlyByName(targetTypeName) &&
+ annotationPattern.matches(type).alwaysTrue();
}
/**
private FuzzyBoolean isWithinType(ResolvedTypeX type) {
while (type != null) {
- if (typePattern.matchesStatically(type)) {
+ if (typePattern.matchesStatically(type)) {
return FuzzyBoolean.YES;
}
type = type.getDeclaringType();
}
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) {
shadow.getSourceLocation(),true,new ISourceLocation[]{getSourceLocation()});
shadow.getIWorld().getMessageHandler().handleMessage(msg);
}
+ typePattern.resolve(shadow.getIWorld());
return isWithinType(enclosingType);
}