]> source.dussan.org Git - aspectj.git/commitdiff
due fix for @AJ ITD annotation copy from ITD intf methods
authoravasseur <avasseur>
Mon, 17 Oct 2005 14:14:28 +0000 (14:14 +0000)
committeravasseur <avasseur>
Mon, 17 Oct 2005 14:14:28 +0000 (14:14 +0000)
tests/java5/ataspectj/ataspectj/DeclareParentsImplementsTest.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java

index aee12280e050970f5f831849c457600f701fcfcb..8b701a28e8d5b62f60cd4a2a10b16deab0389b5a 100644 (file)
@@ -17,6 +17,11 @@ import org.aspectj.lang.annotation.DeclareParents;
 import org.aspectj.lang.annotation.Before;
 
 import java.util.Arrays;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Method;
 
 /**
  * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
@@ -31,6 +36,7 @@ public class DeclareParentsImplementsTest extends TestCase {
 
     static interface Introduced {
         final static int field1 = 1;
+        @Some
         void intro();
     }
 
@@ -72,6 +78,11 @@ public class DeclareParentsImplementsTest extends TestCase {
         assertEquals("aop intro-1 ", s_log.toString());
     }
 
+    public void testAddedMethodKeepAnnotation() throws Throwable {
+        Method m = Target.class.getDeclaredMethod("intro");
+        assertTrue("annotation not retained", m.isAnnotationPresent(Some.class));
+    }
+
     public static void main(String[] args) {
         TestHelper.runAndThrowOnFailure(suite());
     }
@@ -79,4 +90,8 @@ public class DeclareParentsImplementsTest extends TestCase {
     public static junit.framework.Test suite() {
         return new junit.framework.TestSuite(DeclareParentsImplementsTest.class);
     }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    static @interface Some {
+    }
 }
index 2ed9e71fe09f500a397d9a522de30eceb1dbf62e..c0474a3763437d9fc041dd00312fb7c08f78d2e0 100644 (file)
@@ -61,6 +61,7 @@ import org.aspectj.weaver.WeaverMessages;
 import org.aspectj.weaver.WeaverStateInfo;
 import org.aspectj.weaver.MethodDelegateTypeMunger;
 import org.aspectj.weaver.World;
+import org.aspectj.weaver.ReferenceType;
 import org.aspectj.weaver.patterns.DeclareAnnotation;
 import org.aspectj.weaver.patterns.Pointcut;
 
@@ -891,9 +892,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
        
     private boolean mungeMethodDelegate(BcelClassWeaver weaver, MethodDelegateTypeMunger munger) {
         ResolvedMember introduced = munger.getSignature();
-
         LazyClassGen gen = weaver.getLazyClassGen();
-        boolean mungingInterface = gen.isInterface();
 
         ResolvedType fromType = weaver.getWorld().resolve(introduced.getDeclaringType(),munger.getSourceLocation());
         if (fromType.isRawType()) fromType = fromType.getGenericType();
@@ -913,38 +912,29 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                     BcelWorld.makeBcelTypesAsClassNames(introduced.getExceptions()),
                     gen
             );
-            //FIXME AVITD annotation copy from annotation on ITD interface
-            // but need the BcelObjectType for the ITD interface..
-            // how?
-            // For copying the annotations across, we have to discover the real type
-            // which is holding them.
-//            if (weaver.getWorld().isInJava5Mode()){
-//                AnnotationX annotationsOnRealMember[] = null;
-//                //ResolvedType toLookOn = fromType;
-//                //if (fromType.isRawType()) toLookOn = fromType.getGenericType();
-//                annotationsOnRealMember = introduced.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()));
-//                    }
-//                }
-////                // the below loop fixes the very special (and very stupid)
-////                // case where an aspect declares an annotation
-////                // on an ITD it declared on itself.
-////                List allDecams = weaver.getWorld().getDeclareAnnotationOnMethods();
-////                for (Iterator i = allDecams.iterator(); i.hasNext();){
-////                    DeclareAnnotation decaMC = (DeclareAnnotation) i.next();
-////                    if (decaMC.matches(unMangledInterMethod,weaver.getWorld())
-////                            && mg.getEnclosingClass().getType() == aspectType) {
-////                        mg.addAnnotation(decaMC.getAnnotationX());
-////                    }
-////                }
-//            }
 
+            //annotation copy from annotation on ITD interface
+            if (weaver.getWorld().isInJava5Mode()){
+                AnnotationX annotationsOnRealMember[] = null;
+                ResolvedType toLookOn = weaver.getWorld().lookupOrCreateName(introduced.getDeclaringType());
+                if (fromType.isRawType()) toLookOn = fromType.getGenericType();
+                // lookup the method
+                ResolvedMember[] ms = toLookOn.getDeclaredJavaMethods();
+                for (int i = 0; i < ms.length; i++) {
+                    ResolvedMember m = ms[i];
+                    if (introduced.getName().equals(m.getName()) && introduced.getSignature().equals(m.getSignature())) {
+                        annotationsOnRealMember = m.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()));
+                    }
+                }
+            }
 
             InstructionList body = new InstructionList();
             InstructionFactory fact = gen.getFactory();
@@ -959,7 +949,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                 body.append(InstructionFactory.createLoad(paramType, pos));
                 pos+=paramType.getSize();
             }
-            body.append(Utility.createInvoke(fact, weaver.getWorld(), introduced));
+            body.append(Utility.createInvoke(fact, Constants.INVOKEINTERFACE, introduced));
             body.append(
                 InstructionFactory.createReturn(
                     BcelWorld.makeBcelType(introduced.getReturnType())