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>
static interface Introduced {
final static int field1 = 1;
+ @Some
void intro();
}
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());
}
public static junit.framework.Test suite() {
return new junit.framework.TestSuite(DeclareParentsImplementsTest.class);
}
+
+ @Retention(RetentionPolicy.RUNTIME)
+ static @interface Some {
+ }
}
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;
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();
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();
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())