return (binding.getAccessFlags() & ACC_ANNOTATION)!=0;
}
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
throw new RuntimeException("How to implement this? Needs to ask eclipse!");
}
suite.addTestSuite(CovarianceTests.class);
suite.addTestSuite(Enums.class);
suite.addTestSuite(Annotations.class);
+ suite.addTestSuite(AnnotationPointcuts.class);
suite.addTestSuite(Varargs.class);
//$JUnit-END$
return suite;
}
// before(): call(@SimpleAnnotation * *(..)) { }
-// public void test001_usingAnnotationsInPointcuts() {
-// CompilationResult cR = binaryWeave("testcode.jar","AnnotationAspect02.aj",0,0);
-// System.err.println(cR.getStandardError());
-// System.err.println(cR.getErrorMessages());
-// System.err.println(cR.getInfoMessages());
+ public void test001_usingAnnotationsInPointcuts() {
+ CompilationResult cR = binaryWeave("testcode.jar","AnnotationAspect02.aj",0,0);
+ System.err.println(cR.getStandardError());
+ System.err.println(cR.getErrorMessages());
+ System.err.println(cR.getInfoMessages());
+ verifyWeavingMessagesOutput(cR,new String[]{
+"weaveinfo Type 'AnnotatedType' (AnnotatedType.java:3) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:4)",
+"weaveinfo Type 'AnnotatedType' (AnnotatedType.java:3) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:2)",
+"weaveinfo Type 'AnnotatedType' (AnnotatedType.java:4) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:4)"});
+
+// assertTrue("Expected three message about ITDs not allowed on Annotations but got: #"+
+// cR.getErrorMessages().size()+": \n"+cR.getErrorMessages(),
+// cR.getErrorMessages().size()==3);
+// IMessage msg1_ctor = (IMessage)cR.getErrorMessages().get(0);
+// IMessage msg2_method = (IMessage)cR.getErrorMessages().get(1);
+// IMessage msg3_field = (IMessage)cR.getErrorMessages().get(2);
+// assertTrue("Expected message about ITDCs on annotations not allowed, but got: \n"+msg1_ctor,
+// msg1_ctor.toString().indexOf("can't make inter-type constructor declarations")!=-1);
+// assertTrue("Expected message about ITDMs on annotations not allowed, but got: \n"+msg2_method,
+// msg2_method.toString().indexOf("can't make inter-type method declarations")!=-1);
+// assertTrue("Expected message about ITDFs on annotations not allowed, but got: \n"+msg3_field,
+// msg3_field.toString().indexOf("can't make inter-type field declarations")!=-1);
// verifyWeavingMessagesOutput(cR,new String[]{});
-//// assertTrue("Expected three message about ITDs not allowed on Annotations but got: #"+
-//// cR.getErrorMessages().size()+": \n"+cR.getErrorMessages(),
-//// cR.getErrorMessages().size()==3);
-//// IMessage msg1_ctor = (IMessage)cR.getErrorMessages().get(0);
-//// IMessage msg2_method = (IMessage)cR.getErrorMessages().get(1);
-//// IMessage msg3_field = (IMessage)cR.getErrorMessages().get(2);
-//// assertTrue("Expected message about ITDCs on annotations not allowed, but got: \n"+msg1_ctor,
-//// msg1_ctor.toString().indexOf("can't make inter-type constructor declarations")!=-1);
-//// assertTrue("Expected message about ITDMs on annotations not allowed, but got: \n"+msg2_method,
-//// msg2_method.toString().indexOf("can't make inter-type method declarations")!=-1);
-//// assertTrue("Expected message about ITDFs on annotations not allowed, but got: \n"+msg3_field,
-//// msg3_field.toString().indexOf("can't make inter-type field declarations")!=-1);
-//// verifyWeavingMessagesOutput(cR,new String[]{});
-// }
+ }
}
\ No newline at end of file
* Represents any element that may have annotations
*/
public interface AnnotatedElement {
- boolean hasAnnotation(ResolvedTypeX ofType);
+ boolean hasAnnotation(TypeX ofType);
ResolvedTypeX[] getAnnotationTypes();
// SomeType getAnnotation(TypeX ofType);
* If you want a sensible answer, resolve the member and call
* hasAnnotation() on the ResolvedMember.
*/
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
throw new UnsupportedOperationException("You should resolve this member and call hasAnnotation() on the result...");
}
return delegate.isClass();
}
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
return delegate.hasAnnotation(ofType);
}
public abstract boolean isEnum();
public abstract boolean isAnnotation();
- public abstract boolean hasAnnotation(ResolvedTypeX ofType);
+ public abstract boolean hasAnnotation(TypeX ofType);
public abstract ResolvedTypeX[] getAnnotationTypes();
public abstract ResolvedMember[] getDeclaredFields();
return ResolvedMember.NONE;
}
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
return false;
}
public final boolean isPrimitive() {
return true;
}
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
return false;
}
public final boolean isAssignableFrom(TypeX other) {
public final String getName() {
return MISSING_NAME;
}
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
return false;
}
public final ResolvedMember[] getDeclaredFields() {
return world.resolve(this);
}
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
throw new UnsupportedOperationException("You should resolve this member and call hasAnnotation() on the result...");
}
return isSynthetic;
}
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
Annotation[] anns = field.getAnnotations();
for (int i = 0; i < anns.length; i++) {
Annotation annotation = anns[i];
}
}
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
Annotation[] anns = method.getAnnotations();
for (int i = 0; i < anns.length; i++) {
Annotation annotation = anns[i];
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
Annotation[] annotationsOnThisType = javaClass.getAnnotations();
for (int i = 0; i < annotationsOnThisType.length; i++) {
Annotation a = annotationsOnThisType[i];
}
public FuzzyBoolean matches(AnnotatedElement annotated) {
- if (!resolved) {
- throw new IllegalStateException("Can't match on an unresolved annotation type pattern");
- }
- return (annotated.hasAnnotation((ResolvedTypeX)annotationType) ?
+ return (annotated.hasAnnotation(annotationType) ?
FuzzyBoolean.YES : FuzzyBoolean.NO);
}
this.annotationTypes = annotationTypes;
}
- public boolean hasAnnotation(ResolvedTypeX ofType) {
+ public boolean hasAnnotation(TypeX ofType) {
for (int i = 0; i < annotationTypes.length; i++) {
if (annotationTypes[i].equals(ofType.getName())) return true;
}
}
public void testParseWithAnnotation() {
- PatternParser parser = new PatternParser("execution(@p.SimpleAnnotation void Hello.*(..))");
+ PatternParser parser = new PatternParser("execution(@SimpleAnnotation void Hello.*(..))");
KindedPointcut p = (KindedPointcut) parser.parsePointcut();
// XXX - needs finishing...
- // p.resolveBindings(makeSimpleScope(),new Bindings(3));
-// System.err.println(p);
+ p.resolveBindings(makeSimpleScope(),new Bindings(3));
+ System.err.println(p);
// assertEquals(p.kind, BcelShadow.MethodExecution);
// assertTrue(p.signature.getName().matches("foobar"));
// p.signature.resolveBindings(makeSimpleScope(),new Bindings(3));
}
public TestScope makeSimpleScope() {
- return new TestScope(new String[] {"int", "java.lang.String"}, new String[] {"a", "b"}, world);
+ TestScope s = new TestScope(new String[] {"int", "java.lang.String"}, new String[] {"a", "b"}, world);
+ s.setImportedPrefixes(new String[]{"p."});
+ return s;
}
}