]> source.dussan.org Git - aspectj.git/commitdiff
test and fixes for 98901, comment 29
authoraclement <aclement>
Mon, 27 Mar 2006 21:16:39 +0000 (21:16 +0000)
committeraclement <aclement>
Mon, 27 Mar 2006 21:16:39 +0000 (21:16 +0000)
tests/bugs151/pr98901/Failing.java [new file with mode: 0644]
tests/bugs151/pr98901/Failing2.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java

diff --git a/tests/bugs151/pr98901/Failing.java b/tests/bugs151/pr98901/Failing.java
new file mode 100644 (file)
index 0000000..b4103f9
--- /dev/null
@@ -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 (file)
index 0000000..1daeb44
--- /dev/null
@@ -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
index f078ae9d2c0440cb7258667984a1f6cd24cefea0..67b7496776b6de848a800332227bb98dcdf299b0 100644 (file)
@@ -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");}       
index c1d6610d90a65034625591ca898495f75fac6ea9..96e6d9313a17f83c590d9a50a6694bf37691274d 100644 (file)
@@ -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"/>
index 540ad809907184f03b6129246c60c34815d0c77f..f055002f972039bd685dcc7693e1526d86f33c48 100644 (file)
@@ -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