From d9757d7c41bf2661455422ce3234e4794c9f533e Mon Sep 17 00:00:00 2001 From: aclement Date: Tue, 8 Nov 2005 12:13:05 +0000 Subject: testcode and fix for pr114005: copying annotations to ITDfs on interfaces. --- tests/bugs150/pr114005/Declaration1.java | 32 ++++++++++++++++++++++ tests/bugs150/pr114005/Declaration2.java | 32 ++++++++++++++++++++++ .../org/aspectj/systemtest/ajc150/Ajc150Tests.java | 4 ++- tests/src/org/aspectj/systemtest/ajc150/ajc150.xml | 19 +++++++++++++ .../org/aspectj/weaver/bcel/BcelTypeMunger.java | 16 +++++++++-- 5 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 tests/bugs150/pr114005/Declaration1.java create mode 100644 tests/bugs150/pr114005/Declaration2.java 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 @@ + + + + + + + + + + + + + + + + + + + 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(); -- cgit v1.2.3