summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraclement <aclement>2009-03-09 22:09:13 +0000
committeraclement <aclement>2009-03-09 22:09:13 +0000
commit596406d0d78771524f4176d807a6791418bfb7b5 (patch)
treeb79a3403ffca0f4459b9aa84ea624d8ff206d39b
parent9c1e8c788a7b5f3856e65815e67bd9209a90ac32 (diff)
downloadaspectj-596406d0d78771524f4176d807a6791418bfb7b5.tar.gz
aspectj-596406d0d78771524f4176d807a6791418bfb7b5.zip
declareMixin
-rw-r--r--tests/features164/declareMixin/CaseR.java26
-rw-r--r--tests/features164/declareMixin/CaseS.java36
-rw-r--r--tests/features164/declareMixin/CaseT.java27
-rw-r--r--tests/src/org/aspectj/systemtest/ajc164/DeclareMixinTests.java19
-rw-r--r--tests/src/org/aspectj/systemtest/ajc164/declareMixin.xml22
5 files changed, 111 insertions, 19 deletions
diff --git a/tests/features164/declareMixin/CaseR.java b/tests/features164/declareMixin/CaseR.java
index dc12baa4e..854037962 100644
--- a/tests/features164/declareMixin/CaseR.java
+++ b/tests/features164/declareMixin/CaseR.java
@@ -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
index 000000000..aef84923d
--- /dev/null
+++ b/tests/features164/declareMixin/CaseS.java
@@ -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
index 000000000..cfddaae0e
--- /dev/null
+++ b/tests/features164/declareMixin/CaseT.java
@@ -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");
+ }
+}
diff --git a/tests/src/org/aspectj/systemtest/ajc164/DeclareMixinTests.java b/tests/src/org/aspectj/systemtest/ajc164/DeclareMixinTests.java
index 5651913d6..ec5030f14 100644
--- a/tests/src/org/aspectj/systemtest/ajc164/DeclareMixinTests.java
+++ b/tests/src/org/aspectj/systemtest/ajc164/DeclareMixinTests.java
@@ -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() {
diff --git a/tests/src/org/aspectj/systemtest/ajc164/declareMixin.xml b/tests/src/org/aspectj/systemtest/ajc164/declareMixin.xml
index cb229374c..02853f93a 100644
--- a/tests/src/org/aspectj/systemtest/ajc164/declareMixin.xml
+++ b/tests/src/org/aspectj/systemtest/ajc164/declareMixin.xml
@@ -147,5 +147,27 @@
<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