]> source.dussan.org Git - aspectj.git/commitdiff
due fix and test for @AJ ITD reweavable, serialization of the method delegate munger
authoravasseur <avasseur>
Tue, 18 Oct 2005 15:52:50 +0000 (15:52 +0000)
committeravasseur <avasseur>
Tue, 18 Oct 2005 15:52:50 +0000 (15:52 +0000)
tests/java5/ataspectj/ajc-ant.xml
tests/java5/ataspectj/ataspectj/DeclareParentsImplementsReweavableTest.java [new file with mode: 0644]
tests/java5/ataspectj/ataspectj/DeclareParentsImplementsReweavableTestAspect.java [new file with mode: 0644]
tests/java5/ataspectj/ataspectj/aop-decptest.xml [new file with mode: 0644]
tests/java5/ataspectj/ataspectj/aop-decptest2.xml [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjLTWTests.java
tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml
weaver/src/org/aspectj/weaver/MethodDelegateTypeMunger.java
weaver/src/org/aspectj/weaver/NewMethodTypeMunger.java
weaver/src/org/aspectj/weaver/ResolvedTypeMunger.java

index 393b92f306b39851a8ccd7fbf78eb7811680a729..6d0dcee0ef01b4c41d05e2c9fd6da6a979e5ac6f 100644 (file)
             <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
diff --git a/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsReweavableTest.java b/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsReweavableTest.java
new file mode 100644 (file)
index 0000000..5e1a7d3
--- /dev/null
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * 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);
+    }
+
+}
diff --git a/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsReweavableTestAspect.java b/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsReweavableTestAspect.java
new file mode 100644 (file)
index 0000000..c75585f
--- /dev/null
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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();
+
+}
diff --git a/tests/java5/ataspectj/ataspectj/aop-decptest.xml b/tests/java5/ataspectj/ataspectj/aop-decptest.xml
new file mode 100644 (file)
index 0000000..fe04e96
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<aspectj>
+    <weaver options="-XmessageHandlerClass:ataspectj.TestHelper"/>
+    <aspects>
+        <aspect name="ataspectj.DeclareParentsImplementsTest.TestAspect"/>
+        <aspect name="ataspectj.DeclareParentsInterfaceTest.TestAspect"/>
+    </aspects>
+</aspectj>
diff --git a/tests/java5/ataspectj/ataspectj/aop-decptest2.xml b/tests/java5/ataspectj/ataspectj/aop-decptest2.xml
new file mode 100644 (file)
index 0000000..2fc5016
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<aspectj>
+    <weaver options="-XmessageHandlerClass:ataspectj.TestHelper"/>
+    <aspects>
+        <aspect name="ataspectj.DeclareParentsImplementsReweavableTest.TestAspect"/>
+        <aspect name="ataspectj.DeclareParentsImplementsReweavableTestAspect"/>
+    </aspects>
+</aspectj>
index d7af9679ab4d597d965f787a6a5efaca28e5741c..431232ff59eb48d549f53a239b8465600980a0ed 100644 (file)
@@ -82,4 +82,11 @@ public class AtAjLTWTests extends XMLBasedAjcTestCase {
         runTest("LTW Unweavable");
     }
 
+    public void testLTWDecp() {
+        runTest("LTW Decp");
+    }
+
+    public void testLTWDecp2() {
+        runTest("LTW Decp2");
+    }
 }
index aaa2c97e46c53fb94c6e7041ecd2f63b63724500..11dd7e656cfc2023d9d20a72a02a25c8d9ede9fd 100644 (file)
         <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
index 797e7ae7b497a28baefce3079db98bad42ced797..26ae5b21dda3863539e1a64b69e4723f249bdd7e 100644 (file)
@@ -65,22 +65,31 @@ public class MethodDelegateTypeMunger extends ResolvedTypeMunger {
         }
     }
 
+    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
index 6f60d9965dfab27c1c5c00f90ee260c53e0547d2..f4fdeafca1cb8cd34960ecb2dfcc90eed44ba093 100644 (file)
@@ -47,8 +47,7 @@ public class NewMethodTypeMunger extends ResolvedTypeMunger {
        }
        
        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);
index 06ae53554a907bf2decab48026362aa9990a03bb..73588f89cf4dc926c96ec778bfb0c863a19fd01e 100644 (file)
@@ -123,10 +123,11 @@ public abstract class ResolvedTypeMunger {
                        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");
                }
        }
@@ -227,7 +228,8 @@ public abstract class ResolvedTypeMunger {
                    case 1: return Field;
                    case 2: return Method;
                    case 5: return Constructor;
-               }
+                case 9: return MethodDelegate;
+            }
                throw new BCException("bad kind: " + key);
            }
        }
@@ -247,7 +249,7 @@ public abstract class ResolvedTypeMunger {
        
        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";