-// 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() {
--- /dev/null
+// 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");
+ }
+}
--- /dev/null
+// 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");
+ }
+}
* <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
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() {
<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