diff options
author | aclement <aclement> | 2006-03-27 21:16:39 +0000 |
---|---|---|
committer | aclement <aclement> | 2006-03-27 21:16:39 +0000 |
commit | 638db357bdf26a8afb6699c84002762fa7d4e518 (patch) | |
tree | c5d0b3916c49dc856dd0a5e1d50b1840575e0364 | |
parent | 6c4770cba1ff07c1d5a406b34f0cfc44a3e05ebe (diff) | |
download | aspectj-638db357bdf26a8afb6699c84002762fa7d4e518.tar.gz aspectj-638db357bdf26a8afb6699c84002762fa7d4e518.zip |
test and fixes for 98901, comment 29
-rw-r--r-- | tests/bugs151/pr98901/Failing.java | 28 | ||||
-rw-r--r-- | tests/bugs151/pr98901/Failing2.java | 28 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java | 4 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc151/ajc151.xml | 22 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java | 23 |
5 files changed, 102 insertions, 3 deletions
diff --git a/tests/bugs151/pr98901/Failing.java b/tests/bugs151/pr98901/Failing.java new file mode 100644 index 000000000..b4103f9e1 --- /dev/null +++ b/tests/bugs151/pr98901/Failing.java @@ -0,0 +1,28 @@ +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 diff --git a/tests/bugs151/pr98901/Failing2.java b/tests/bugs151/pr98901/Failing2.java new file mode 100644 index 000000000..1daeb4498 --- /dev/null +++ b/tests/bugs151/pr98901/Failing2.java @@ -0,0 +1,28 @@ +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 diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java index f078ae9d2..67b749677 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java @@ -24,7 +24,9 @@ import org.aspectj.systemtest.ajc150.GenericsTests; 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");} diff --git a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml index c1d6610d9..96e6d9313 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml +++ b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml @@ -3,10 +3,30 @@ <!-- 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"/> diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index 540ad8099..f055002f9 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -875,8 +875,29 @@ public class BcelTypeMunger extends ConcreteTypeMunger { 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 |