]> source.dussan.org Git - aspectj.git/commitdiff
declareMixin
authoraclement <aclement>
Mon, 9 Mar 2009 22:09:13 +0000 (22:09 +0000)
committeraclement <aclement>
Mon, 9 Mar 2009 22:09:13 +0000 (22:09 +0000)
tests/features164/declareMixin/CaseR.java
tests/features164/declareMixin/CaseS.java [new file with mode: 0644]
tests/features164/declareMixin/CaseT.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc164/DeclareMixinTests.java
tests/src/org/aspectj/systemtest/ajc164/declareMixin.xml

index dc12baa4eac5da0e3ddd40286f9b5a8ec635bc06..854037962c8006e6a44b90bbfdeb51e17056e225 100644 (file)
@@ -1,29 +1,21 @@
-// TESTING: interface subsetting used (factory returns class) - but only one method should be delegated
+// TESTING: testing a pure marker interface - no methods added
 import org.aspectj.lang.annotation.*;
 
-public class CaseP {
+public class CaseR {
   public static void main(String[]argv) { 
-    ((I)new CaseP()).foo();
-    CaseP cp = new CaseP();
-    if (cp instanceof J) { // should not have been mixed in
-      throw new RuntimeException();
-    }
+         CaseR cr = new CaseR();
+         System.out.println(cr instanceof I);
+         System.out.println(cr instanceof J);
   }
 }
 
 aspect X {
-  @DeclareMixin(value="CaseP",interfaces={I.class})
-  public static C createImplementation1() {return new C();}
-
-}
-
-interface I {
-  void foo();
+  @DeclareMixin(value="CaseR",interfaces={I.class})
+  public static C createImplementation1() {return null;}
 }
 
-interface J {
-  void goo();
-}
+interface I {}
+interface J {}
 
 class C implements I,J {
   public void foo() {
diff --git a/tests/features164/declareMixin/CaseS.java b/tests/features164/declareMixin/CaseS.java
new file mode 100644 (file)
index 0000000..aef8492
--- /dev/null
@@ -0,0 +1,36 @@
+// TESTING: factory method has incompatible return type - verifyerror if we did use that factory
+import org.aspectj.lang.annotation.*;
+
+public class CaseS {
+  public static void main(String[]argv) {
+    CaseS cc = new CaseS();
+    ((I)cc).methodOne(); // will only succeed if mixin applied
+  }
+
+  public String toString() {
+    return "CaseS instance";
+  }
+}
+
+aspect X {
+  @DeclareMixin("CaseS")
+  public static I createImplementation(FooI cf) {
+       System.out.println(cf instanceof FooI);
+    System.out.println("Delegate factory invoked for "+cf.toString());
+    return new Implementation();
+  }
+}
+
+class FooI {
+       
+}
+
+interface I {
+  void methodOne();
+}
+
+class Implementation implements I {
+  public void methodOne() {
+    System.out.println("methodOne running");
+  }
+}
diff --git a/tests/features164/declareMixin/CaseT.java b/tests/features164/declareMixin/CaseT.java
new file mode 100644 (file)
index 0000000..cfddaae
--- /dev/null
@@ -0,0 +1,27 @@
+// TESTING: testing a pure marker interface - no methods added
+import org.aspectj.lang.annotation.*;
+
+public class CaseT {
+  public static void main(String[]argv) { 
+         CaseT ct = new CaseT();
+         System.out.println(ct instanceof I);
+         System.out.println(ct instanceof J);
+  }
+}
+
+aspect X {
+  @DeclareMixin(value="CaseT",interfaces={I.class})
+  public static C createImplementation1() {return null;}
+}
+
+interface I {}
+interface J {}
+
+class C implements I,J {
+  public void foo() {
+    System.out.println("foo() running");
+  }
+  public void goo() {
+    System.out.println("goo() running");
+  }
+}
index 5651913d6bfcaa2eb9deb582e73c1a47e94b3e96..ec5030f1497b634ff8b366ac8d6446a733b90554 100644 (file)
@@ -25,18 +25,18 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
  * <ul>
  * <li>Factory method with void or primitive return value
  * <li>Check the factory method has at most one parameter
+ * <li>incremental compilation
+ * <li>error message if mixin target instance not compatible with factory method parameter
  * </ul>
  * 
  * <h4>Still to test/explore:</h4><br>
  * <ul>
  * <li>model relationships
- * <li>incremental compilation
  * <li>ltw
  * <li>generic factory methods
  * <li>showWeaveInfo
  * <li>Clashing with existing methods
  * <li>varying parameter type on the factory method
- * <li>See CaseF - what if mixin target is not assignable to the parameter type? create cast?
  * </ul>
  * 
  * @author Andy Clement
@@ -129,6 +129,21 @@ public class DeclareMixinTests extends org.aspectj.testing.XMLBasedAjcTestCase {
                runTest("caseq");
        }
 
+       // testing a pure marker interface - no methods added
+       public void testCaseR() {
+               runTest("caser");
+       }
+
+       // factory method has incompatible return type - verifyerror if we did use that factory
+       public void testCaseS() {
+               runTest("cases");
+       }
+
+       // weave info - what happens?
+       public void testCaseT() {
+               runTest("caset");
+       }
+
        // --
 
        public static Test suite() {
index cb229374c7d78d171781ddb5485d6632633635a9..02853f93a667571de6a4b426cd828cd22a8154bd 100644 (file)
          <line text="goo() running"/>
        </stdout>
      </run>
+   </ajc-test>   
+     
+   <ajc-test dir="features164/declareMixin" title="caser">
+     <compile files="CaseR.java" options="-1.5"/>
+     <run class="CaseR">
+       <stdout>
+         <line text="true"/>
+         <line text="false"/>
+       </stdout>
+     </run>
+   </ajc-test>    
+    
+   <ajc-test dir="features164/declareMixin" title="cases">
+     <compile files="CaseS.java" options="-1.5">
+       <message kind="error" text="not compatible"/>
+     </compile>
    </ajc-test>     
+   
+   <ajc-test dir="features164/declareMixin" title="caset">
+     <compile files="CaseT.java" options="-1.5 -showWeaveInfo">
+       <message kind="weave" text="Mixing interface 'I' (CaseT.java) into type 'CaseT' (CaseT.java)"/>
+     </compile>
+   </ajc-test>    
 </suite>
\ No newline at end of file