]> source.dussan.org Git - aspectj.git/commitdiff
testcode and fix for pr114005: copying annotations to ITDfs on interfaces.
authoraclement <aclement>
Tue, 8 Nov 2005 12:13:05 +0000 (12:13 +0000)
committeraclement <aclement>
Tue, 8 Nov 2005 12:13:05 +0000 (12:13 +0000)
tests/bugs150/pr114005/Declaration1.java [new file with mode: 0644]
tests/bugs150/pr114005/Declaration2.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java

diff --git a/tests/bugs150/pr114005/Declaration1.java b/tests/bugs150/pr114005/Declaration1.java
new file mode 100644 (file)
index 0000000..787be72
--- /dev/null
@@ -0,0 +1,32 @@
+import java.lang.annotation.*;
+import java.lang.reflect.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface SampleAnnotation { }
+
+interface TestInterface { }
+
+class Test implements TestInterface{}
+
+// First case: the ITD on the interface is annotated, it should make it through 
+// to the member added to the implementor
+public aspect Declaration1 {
+
+       // ITD directly on the implementor
+    @SampleAnnotation 
+       public String Test.firstProperty;
+       
+    // ITD on the interface
+       @SampleAnnotation
+       public String TestInterface.secondProperty;
+
+       public static void main(String[] args) {
+               for (Field field: Test.class.getFields()) {
+                       StringBuffer sb = new StringBuffer();
+                       sb.append(field.toString());
+                       boolean b = field.isAnnotationPresent(SampleAnnotation.class);
+                       sb.append(" has annotation:").append(b);
+                       System.out.println(sb.toString());
+               }
+       }
+}
\ No newline at end of file
diff --git a/tests/bugs150/pr114005/Declaration2.java b/tests/bugs150/pr114005/Declaration2.java
new file mode 100644 (file)
index 0000000..0e0b959
--- /dev/null
@@ -0,0 +1,32 @@
+import java.lang.annotation.*;
+import java.lang.reflect.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface SampleAnnotation { }
+
+interface TestInterface { }
+
+class Test implements TestInterface{}
+
+// Second case: the ITD is annotated via a declare @field.
+public aspect Declaration2 {
+
+       declare @field: * TestInterface.secondProperty: @SampleAnnotation;
+       
+       // ITD directly on the implementor
+    @SampleAnnotation 
+       public String Test.firstProperty;
+       
+    // ITD on the interface
+       public String TestInterface.secondProperty;
+
+       public static void main(String[] args) {
+               for (Field field: Test.class.getFields()) {
+                       StringBuffer sb = new StringBuffer();
+                       sb.append(field.toString());
+                       boolean b = field.isAnnotationPresent(SampleAnnotation.class);
+                       sb.append(" has annotation:").append(b);
+                       System.out.println(sb.toString());
+               }
+       }
+}
\ No newline at end of file
index 9faf3872fb853ec51fbf5c3cfbdb3354af78724a..3f7d593b22d0d4583172e10f9cfb285d49ee86e4 100644 (file)
@@ -52,7 +52,9 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testPossibleStaticImports_pr113066_1() { runTest("possible static imports bug - 1");}
   public void testPossibleStaticImports_pr113066_2() { runTest("possible static imports bug - 2");}
   public void testPossibleStaticImports_pr113066_3() { runTest("possible static imports bug - 3");}
-  public void testITDCtor_pr112783()          { runTest("Problem with constructor ITDs");}
+  public void testITDCtor_pr112783()                 { runTest("Problem with constructor ITDs");}
+  public void testAnnotatedITDFs_pr114005_1()        { runTest("Annotated ITDFs - 1");}
+  public void testAnnotatedITDFs_pr114005_2()        { runTest("Annotated ITDFs - 2");}
   public void testCantCallSuperMethods_pr90143() { runTest("cant call super methods");}
   public void testBrokenDecp_pr112476()       { runTest("binary weaving decp broken");}
   public void testUnboundFormal_pr112027()    { runTest("unexpected error unboundFormalInPC");}
index a10ee734e0688cc91a49304048fda1cacff54330..ea79220811f215eec1f8b8d963247c87a6dbf0a5 100644 (file)
         </run>
     </ajc-test>
     
+    <ajc-test dir="bugs150/pr114005" title="Annotated ITDFs - 1">
+      <compile files="Declaration1.java" options="-1.5"/>
+      <run class="Declaration1">
+        <stdout>
+          <line text="public java.lang.String Test.firstProperty has annotation:true"/>
+          <line text="public java.lang.String Test.ajc$interField$Declaration1$TestInterface$secondProperty has annotation:true"/>
+        </stdout>
+      </run>
+    </ajc-test>
+    
+    <ajc-test dir="bugs150/pr114005" title="Annotated ITDFs - 2">
+      <compile files="Declaration2.java" options="-1.5"/>
+      <run class="Declaration2">
+        <stdout>
+          <line text="public java.lang.String Test.firstProperty has annotation:true"/>
+          <line text="public java.lang.String Test.ajc$interField$Declaration2$TestInterface$secondProperty has annotation:true"/>
+        </stdout>
+      </run>
+    </ajc-test>
     
     <ajc-test dir="bugs150/pr113066" title="possible static imports bug - 1">
         <compile files="Consts.java,TestNPE.java" options="-1.5"/>
index 464f1e65a05cf7e477aeefadb90be8cab9e16947..0bc377fd4fbbeeb65167315d07395c0d5a289dbc 100644 (file)
@@ -1473,12 +1473,22 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        Type fieldType =        BcelWorld.makeBcelType(field.getType());
 
                        FieldGen fg = makeFieldGen(gen,AjcMemberMaker.interFieldInterfaceField(field, onType, aspectType));
-               gen.addField(fg.getField(),getSourceLocation());
                        
+               
+                       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);     
+                                       fg.addAnnotation(ag);
+                               }
+                       }
+                       
+               gen.addField(fg.getField(),getSourceLocation());
                //this uses a shadow munger to add init method to constructors
                //weaver.getShadowMungers().add(makeInitCallShadowMunger(initMethod));
-               
-               ResolvedMember itdfieldGetter = AjcMemberMaker.interFieldInterfaceGetter(field, gen.getType()/*onType*/, aspectType);
+
+                       ResolvedMember itdfieldGetter = AjcMemberMaker.interFieldInterfaceGetter(field, gen.getType()/*onType*/, aspectType);
                        LazyMethodGen mg = makeMethodGen(gen, itdfieldGetter);
                        InstructionList il = new InstructionList();
                        InstructionFactory fact = gen.getFactory();