diff options
author | avasseur <avasseur> | 2005-10-17 14:14:28 +0000 |
---|---|---|
committer | avasseur <avasseur> | 2005-10-17 14:14:28 +0000 |
commit | 891821ce61818e6aebd82ab3cc59f6ee094e3b2a (patch) | |
tree | 2af0f077fb38ef55413bb93119b3bdca7334f162 | |
parent | 65c2eca9149bcdccfa09cf078b364d750b109933 (diff) | |
download | aspectj-891821ce61818e6aebd82ab3cc59f6ee094e3b2a.tar.gz aspectj-891821ce61818e6aebd82ab3cc59f6ee094e3b2a.zip |
due fix for @AJ ITD annotation copy from ITD intf methods
-rw-r--r-- | tests/java5/ataspectj/ataspectj/DeclareParentsImplementsTest.java | 15 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java | 58 |
2 files changed, 39 insertions, 34 deletions
diff --git a/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsTest.java b/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsTest.java index aee12280e..8b701a28e 100644 --- a/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsTest.java +++ b/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsTest.java @@ -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 { + } } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index 2ed9e71fe..c0474a376 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -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()) |