--- /dev/null
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@interface TestAnnotation {
+ public boolean value() default true;
+}
+
+aspect TestAspect {
+ declare parents: Failing implements TestInterface;
+// this also does not work (even when removing annotation in the following ITD)
+// declare @method: public void TestInterface.foo(): @TestAnnotation;
+ @TestAnnotation
+ public void TestInterface.foo() {
+ System.err.println("foo");
+ }
+}
+
+interface TestInterface {
+ public void foo();
+}
+
+public class Failing {
+ public static void main(String[] args) throws Exception {
+ System.err.println("On TestInterface:"+TestInterface.class.getDeclaredMethod("foo").getAnnotation(TestAnnotation.class));
+ System.err.println("On Failing:"+Failing.class.getDeclaredMethod("foo").getAnnotation(TestAnnotation.class));
+ }
+}
\ No newline at end of file
--- /dev/null
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@interface TestAnnotation {
+ public boolean value() default true;
+}
+
+aspect TestAspect {
+ declare parents: Failing2 implements TestInterface;
+
+ declare @method: public void TestInterface.foo(): @TestAnnotation;
+
+ public void TestInterface.foo() {
+ System.err.println("foo");
+ }
+}
+
+interface TestInterface {
+ public void foo();
+}
+
+public class Failing2 {
+ public static void main(String[] args) throws Exception {
+ System.err.println("On TestInterface:"+TestInterface.class.getDeclaredMethod("foo").getAnnotation(TestAnnotation.class));
+ System.err.println("On Failing2:"+Failing2.class.getDeclaredMethod("foo").getAnnotation(TestAnnotation.class));
+ }
+}
\ No newline at end of file
import org.aspectj.testing.XMLBasedAjcTestCase;
public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
-
+
+ public void testAnnotationsAndItds_pr98901() { runTest("annotations and itds");}
+ public void testAnnotationsAndItds_pr98901_2() { runTest("annotations and itds - 2");}
public void testCircularGenerics_pr133307() { runTest("circular generics");}
// public void testDeca() { runTest("doubly annotating a method with declare");}
// public void testDeca2() { runTest("doubly annotating a method with declare - 2");}
<!-- AspectJ v1.5.1 Tests -->
<suite>
+ <ajc-test dir="bugs151/pr98901" title="annotations and itds">
+ <compile files="Failing.java" options="-1.5"/>
+ <run class="Failing">
+ <stderr>
+ <line text="On TestInterface:@TestAnnotation(value=true)"/>
+ <line text="On Failing:@TestAnnotation(value=true)"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs151/pr98901" title="annotations and itds - 2">
+ <compile files="Failing2.java" options="-1.5"/>
+ <run class="Failing2">
+ <stderr>
+ <line text="On TestInterface:@TestAnnotation(value=true)"/>
+ <line text="On Failing2:@TestAnnotation(value=true)"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
<ajc-test dir="bugs151/pr132926" pr="132926" title="crashing on annotation type resolving with asm - 1">
<compile files="InputAnnotation.java,AffectedType.java" options="-1.5"/>
</ajc-test>
-
+
<ajc-test dir="bugs151/pr132926" pr="132926" title="crashing on annotation type resolving with asm - 2">
<compile files="InputAnnotation.java" outjar="foo.jar" options="-1.5"/>
<compile files="AffectedType.java" classpath="foo.jar" options="-1.5"/>
ResolvedMember mangledInterMethod =
AjcMemberMaker.interMethod(unMangledInterMethod, aspectType, false);
-
+
LazyMethodGen mg = makeMethodGen(gen, mangledInterMethod);
+
+ // From 98901#29 - need to copy annotations across
+ if (weaver.getWorld().isInJava5Mode()){
+ AnnotationX annotationsOnRealMember[] = null;
+ ResolvedType toLookOn = aspectType;
+ if (aspectType.isRawType()) toLookOn = aspectType.getGenericType();
+ ResolvedMember realMember = getRealMemberForITDFromAspect(toLookOn,memberHoldingAnyAnnotations,false);
+ if (realMember==null) throw new BCException("Couldn't find ITD holder member '"+
+ memberHoldingAnyAnnotations+"' on aspect "+aspectType);
+ annotationsOnRealMember = realMember.getAnnotations();
+
+ if (annotationsOnRealMember!=null) {
+ for (int i = 0; i < annotationsOnRealMember.length; i++) {
+ AnnotationX annotationX = annotationsOnRealMember[i];
+ Annotation a = annotationX.getBcelAnnotation();
+ AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true);
+ mg.addAnnotation(new AnnotationX(ag.getAnnotation(),weaver.getWorld()));
+ }
+ }
+ }
+
if (mungingInterface) {
// we want the modifiers of the ITD to be used for all *implementors* of the
// interface, but the method itself we add to the interface must be public abstract