<jvmarg value="-Daj5.def=ataspectj/aop-unweavabletest.xml"/>
</java>
</target>
+
+ <target name="ltw.Decp">
+ <java fork="yes" classname="ataspectj.DeclareParentsInterfaceTest" failonerror="yes">
+ <classpath>
+ <path refid="aj.path"/>
+ </classpath>
+ <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
+ <jvmarg value="-Daj5.def=ataspectj/aop-decptest.xml"/>
+ </java>
+ <java fork="yes" classname="ataspectj.DeclareParentsImplementsTest" failonerror="yes">
+ <classpath>
+ <path refid="aj.path"/>
+ </classpath>
+ <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
+ <jvmarg value="-Daj5.def=ataspectj/aop-decptest.xml"/>
+ </java>
+ </target>
+
+ <target name="ltw.Decp2">
+ <!-- javac compile the 2nd aspect -->
+ <javac destdir="${aj.sandbox}"
+ srcdir="${basedir}"
+ includes="ataspectj/DeclareParentsImplementsReweavableTestAspect.java"
+ debug="true">
+ <classpath>
+ <path refid="aj.path"/>
+ <pathelement path="${aj.sandbox}"/>
+ </classpath>
+ </javac>
+
+ <java fork="yes" classname="ataspectj.DeclareParentsImplementsReweavableTest" failonerror="yes">
+ <classpath>
+ <path refid="aj.path"/>
+ </classpath>
+ <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
+ <jvmarg value="-Daj5.def=ataspectj/aop-decptest2.xml"/>
+ <jvmarg line="${jdwp}"/>
+ </java>
+ </target>
</project>
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Vasseur initial implementation
+ *******************************************************************************/
+package ataspectj;
+
+import junit.framework.TestCase;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.DeclareParents;
+
+import java.util.Arrays;
+
+/**
+ * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
+ */
+public class DeclareParentsImplementsReweavableTest extends TestCase {
+
+ static class Target {}
+
+ static interface I1 { int do1(); }
+
+ static class Imp1 implements I1 {
+ public int do1() {return 1;}
+ }
+
+ public static interface I2 { int do2(); }
+
+ public static class Imp2 implements I2 {
+ public int do2() {return 2;}
+ }
+
+ @Aspect
+ static class TestAspect {
+
+ @DeclareParents("ataspectj.DeclareParentsImplementsReweavableTest.Target")
+ public static I1 i1 = new Imp1();
+ }
+
+ public void testDecPInt() {
+ Class[] intfs = Target.class.getInterfaces();
+ assertTrue("I1 was not introduced", Arrays.asList(intfs).contains(I1.class));
+ assertEquals(1, ((I1)new Target()).do1());
+
+ // test stuff weaved in by DeclareParentsImplementsReweavableAspect
+ // thru reweable mode
+ assertTrue("I2 was not introduced", Arrays.asList(intfs).contains(I2.class));
+ assertEquals(2, ((I2)new Target()).do2());
+ }
+
+ public static void main(String[] args) {
+ TestHelper.runAndThrowOnFailure(suite());
+ }
+
+ public static junit.framework.Test suite() {
+ return new junit.framework.TestSuite(DeclareParentsImplementsReweavableTest.class);
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Vasseur initial implementation
+ *******************************************************************************/
+package ataspectj;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.DeclareParents;
+
+/**
+ * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
+ */
+@Aspect
+public class DeclareParentsImplementsReweavableTestAspect {
+
+ @DeclareParents("ataspectj.DeclareParentsImplementsReweavableTest.Target")
+ public static DeclareParentsImplementsReweavableTest.I2 i2 = new DeclareParentsImplementsReweavableTest.Imp2();
+
+}
--- /dev/null
+<?xml version="1.0"?>
+<aspectj>
+ <weaver options="-XmessageHandlerClass:ataspectj.TestHelper"/>
+ <aspects>
+ <aspect name="ataspectj.DeclareParentsImplementsTest.TestAspect"/>
+ <aspect name="ataspectj.DeclareParentsInterfaceTest.TestAspect"/>
+ </aspects>
+</aspectj>
--- /dev/null
+<?xml version="1.0"?>
+<aspectj>
+ <weaver options="-XmessageHandlerClass:ataspectj.TestHelper"/>
+ <aspects>
+ <aspect name="ataspectj.DeclareParentsImplementsReweavableTest.TestAspect"/>
+ <aspect name="ataspectj.DeclareParentsImplementsReweavableTestAspect"/>
+ </aspects>
+</aspectj>
runTest("LTW Unweavable");
}
+ public void testLTWDecp() {
+ runTest("LTW Decp");
+ }
+
+ public void testLTWDecp2() {
+ runTest("LTW Decp2");
+ }
}
<ant file="ajc-ant.xml" target="ltw.Unweavable" verbose="true"/>
</ajc-test>
+ <ajc-test dir="java5/ataspectj" title="LTW Decp">
+ <!-- ajc compile them to test reweable as well -->
+ <compile
+ files="ataspectj/DeclareParentsInterfaceTest.java,ataspectj/DeclareParentsImplementsTest.java,ataspectj/TestHelper.java"
+ options="-1.5"
+ />
+ <ant file="ajc-ant.xml" target="ltw.Decp" verbose="true"/>
+ </ajc-test>
+
+ <ajc-test dir="java5/ataspectj" title="LTW Decp2">
+ <!-- ajc compile them but with only one aspect -->
+ <compile
+ files="ataspectj/DeclareParentsImplementsReweavableTest.java,ataspectj/TestHelper.java"
+ options="-1.5"
+ />
+ <!-- compile the other aspect alone (won't be applied) -->
+ <ant file="ajc-ant.xml" target="ltw.Decp2" verbose="true"/>
+ </ajc-test>
</suite>
\ No newline at end of file
}
}
+ private MethodDelegateTypeMunger(ResolvedMember signature, ResolvedMember fieldDelegate, TypePattern typePattern) {
+ super(MethodDelegate, signature);
+ this.aspectFieldDelegate = fieldDelegate;
+ this.typePattern = typePattern;
+ }
+
public ResolvedMember getDelegate() {
return aspectFieldDelegate;
}
public void write(DataOutputStream s) throws IOException {
- ;//FIXME AVITD needed as changes public signature throw new RuntimeException("unimplemented");
+ kind.write(s);
+ signature.write(s);
+ aspectFieldDelegate.write(s);
+ typePattern.write(s);
}
-// public static ResolvedTypeMunger readMethod(VersionedDataInputStream s, ISourceContext context) throws IOException {
-// ResolvedMemberImpl rmi = ResolvedMemberImpl.readResolvedMember(s, context);
-// Set superMethodsCalled = readSuperMethodsCalled(s);
-// ISourceLocation sLoc = readSourceLocation(s);
-// ResolvedTypeMunger munger = new MethodDelegateTypeMunger(rmi, superMethodsCalled);
-// if (sLoc != null) munger.setSourceLocation(sLoc);
-// return munger;
-// }
+
+
+ public static ResolvedTypeMunger readMethod(VersionedDataInputStream s, ISourceContext context) throws IOException {
+ ResolvedMemberImpl signature = ResolvedMemberImpl.readResolvedMember(s, context);
+ ResolvedMemberImpl field = ResolvedMemberImpl.readResolvedMember(s, context);
+ TypePattern tp = TypePattern.read(s, context);
+ return new MethodDelegateTypeMunger(signature, field, tp);
+ }
/**
* Match based on given type pattern, only classes can be matched
}
public static ResolvedTypeMunger readMethod(VersionedDataInputStream s, ISourceContext context) throws IOException {
-
- ISourceLocation sloc = null;
+ ISourceLocation sloc = null;
ResolvedMemberImpl rmImpl = ResolvedMemberImpl.readResolvedMember(s, context);
Set superMethodsCalled = readSuperMethodsCalled(s);
sloc = readSourceLocation(s);
return NewFieldTypeMunger.readField(s, context);
} else if (kind == Method) {
return NewMethodTypeMunger.readMethod(s, context);
-
} else if (kind == Constructor) {
return NewConstructorTypeMunger.readConstructor(s, context);
- } else {
+ } else if (kind == MethodDelegate) {
+ return MethodDelegateTypeMunger.readMethod(s, context);
+ } else {
throw new RuntimeException("unimplemented");
}
}
case 1: return Field;
case 2: return Method;
case 5: return Constructor;
- }
+ case 9: return MethodDelegate;
+ }
throw new BCException("bad kind: " + key);
}
}
public static final Kind AnnotationOnType = new Kind("AnnotationOnType",8); // not serialized
- public static final Kind MethodDelegate = new Kind("MethodDelegate", 9);// not serialized, @AJ ITDs
+ public static final Kind MethodDelegate = new Kind("MethodDelegate", 9);// serialized, @AJ ITDs
public static final String SUPER_DISPATCH_NAME = "superDispatch";