diff options
author | aclement <aclement> | 2005-11-08 12:13:05 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-11-08 12:13:05 +0000 |
commit | d9757d7c41bf2661455422ce3234e4794c9f533e (patch) | |
tree | ba4352377521fb1e27930948371577505b5a6d71 | |
parent | 9905334cb7e47e8c0fc78d624e0f8c06cd79baee (diff) | |
download | aspectj-d9757d7c41bf2661455422ce3234e4794c9f533e.tar.gz aspectj-d9757d7c41bf2661455422ce3234e4794c9f533e.zip |
testcode and fix for pr114005: copying annotations to ITDfs on interfaces.
-rw-r--r-- | tests/bugs150/pr114005/Declaration1.java | 32 | ||||
-rw-r--r-- | tests/bugs150/pr114005/Declaration2.java | 32 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java | 4 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc150/ajc150.xml | 19 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java | 16 |
5 files changed, 99 insertions, 4 deletions
diff --git a/tests/bugs150/pr114005/Declaration1.java b/tests/bugs150/pr114005/Declaration1.java new file mode 100644 index 000000000..787be727b --- /dev/null +++ b/tests/bugs150/pr114005/Declaration1.java @@ -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 index 000000000..0e0b959c5 --- /dev/null +++ b/tests/bugs150/pr114005/Declaration2.java @@ -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 diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index 9faf3872f..3f7d593b2 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -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");} diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index a10ee734e..ea7922081 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -17,6 +17,25 @@ </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"/> diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index 464f1e65a..0bc377fd4 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -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(); |