From 596406d0d78771524f4176d807a6791418bfb7b5 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 9 Mar 2009 22:09:13 +0000 Subject: [PATCH] declareMixin --- tests/features164/declareMixin/CaseR.java | 26 +++++--------- tests/features164/declareMixin/CaseS.java | 36 +++++++++++++++++++ tests/features164/declareMixin/CaseT.java | 27 ++++++++++++++ .../systemtest/ajc164/DeclareMixinTests.java | 19 ++++++++-- .../systemtest/ajc164/declareMixin.xml | 22 ++++++++++++ 5 files changed, 111 insertions(+), 19 deletions(-) create mode 100644 tests/features164/declareMixin/CaseS.java create mode 100644 tests/features164/declareMixin/CaseT.java 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; * * *

Still to test/explore:


* * * @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 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.39.5