--- /dev/null
+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
--- /dev/null
+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
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");}
</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"/>
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();