diff options
author | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
commit | 144143c2970a1e874d74cdbd0f8c622d4282a3c3 (patch) | |
tree | b12383d3d9e76c7e1f25f7fbec83051ef17f81fb /tests/new/AroundChangeThis.java | |
parent | fafae443719b26159ab2d7dac1c9b46b5e00b671 (diff) | |
download | aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip |
initial version
Diffstat (limited to 'tests/new/AroundChangeThis.java')
-rw-r--r-- | tests/new/AroundChangeThis.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/new/AroundChangeThis.java b/tests/new/AroundChangeThis.java new file mode 100644 index 000000000..bf96cdd9b --- /dev/null +++ b/tests/new/AroundChangeThis.java @@ -0,0 +1,61 @@ +import org.aspectj.testing.Tester; + +public class AroundChangeThis { + public static void main(String[] args) { + C c1 = new C("c1"); + C c2 = new C("c2"); + SubC sc = new SubC("sc"); + + c1.m(c2); + Tester.checkAndClearEvents(new String[] { "c1.m(c2)", "c2.m(c1)" }); + + c1.m(sc); + Tester.checkAndClearEvents(new String[] { "c1.m(sc)", "sc.m(c1)" }); + + sc.m(c1); + Tester.checkAndClearEvents(new String[] { "sc.m(c1)", "c1.m(sc)" }); + + try { + sc.m1(c1); + } catch (ClassCastException e) { + Tester.event("ClassCastException"); + } + Tester.checkAndClearEvents(new String[] { "ClassCastException" }); + + Tester.printEvents(); + } +} + +class C { + private String name; + + public C(String name) { this.name = name; } + + public String toString() { return name; } + + public void m(Object other) { + Tester.event(this + ".m(" + other + ")"); + } +} + +class SubC extends C { + public SubC(String name) { super(name); } + + public void m1(Object other) { + Tester.event(this + ".m1(" + other + ")"); + } +} + + +aspect A { + /* Swaps this with arg for calls of C.m(C) */ + void around(C thisC, C argC): execution(void m*(*)) && this(thisC) && args(argC) { + proceed(argC, thisC); + proceed(thisC, argC); + } + + + void around(C thisC, C argC): call(void m*(*)) && target(thisC) && args(argC) { + proceed(argC, thisC); + } +} |