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/base/test121 | |
parent | fafae443719b26159ab2d7dac1c9b46b5e00b671 (diff) | |
download | aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip |
initial version
Diffstat (limited to 'tests/base/test121')
-rw-r--r-- | tests/base/test121/Driver.java | 95 | ||||
-rw-r--r-- | tests/base/test121/Readme.txt | 8 |
2 files changed, 103 insertions, 0 deletions
diff --git a/tests/base/test121/Driver.java b/tests/base/test121/Driver.java new file mode 100644 index 000000000..ff9fffb28 --- /dev/null +++ b/tests/base/test121/Driver.java @@ -0,0 +1,95 @@ +import org.aspectj.testing.Tester; +public class Driver { + + public static void main(String[] args) { test(); } + + public static void test() { + Foo.staticMethod(); + Foo.introducedStaticMethod(); + + Foo foo = new Foo(10); + + foo.nonStaticMethod(); + foo.introducedNonStaticMethod(); + + Tester.checkEqual(A.fooStaticCounter, 1, "A.fooStaticCounter"); + Tester.checkEqual(A.fooCounter, 1, "A.fooCounter"); + Tester.checkEqual(A.aStaticCounter, 1, "A.aStaticCounter"); + Tester.checkEqual(A.aCounter, 1, "A.aCounter"); + // these is only one constructor call, for Foo + Tester.checkEqual(A.constructorCounter, 1, "constructor calls"); + // one for Foo, one for A + Tester.checkEqual(A.initializationCounter, 2, "initializations"); + Tester.check(A.ranIntroducedConstructor, + "no overriding of the real thing"); + } +} + +class Foo { + + static void staticMethod() { } + void nonStaticMethod() { } +} + +aspect A0_8beta1 { + after() returning(): /*target(*) &&*/ call(new(int)) { + A.constructorCounter++; + } + after() returning(): /*target(*) &&*/ initialization(new(..)) && !within(A0_8beta1) { + System.out.println("init at " + thisJoinPoint); + A.initializationCounter++; + } + + before(): within(Foo) && execution(static * Foo.*(..)) { + A.fooStaticCounter++; + } + + before(): within(A) && execution(static * Foo.*(..)) { + A.aStaticCounter++; + } + + before(): within(A) && execution(!static * Foo.*(..)) { + A.aCounter++; + System.out.println("external before advise on " + thisJoinPoint); + } +} + +aspect A pertarget(target(Foo)){ + + static int constructorCounter = 0; + static int initializationCounter = 0; + static int aStaticCounter = 0; + static int aCounter = 0; + static int fooStaticCounter = 0; + static int fooCounter = 0; + + static boolean ranIntroducedConstructor = false; + + //introduction Foo { + static void Foo.introducedStaticMethod() { + // System.out.println(thisJoinPoint.className +"."+ + // thisJoinPoint.methodName); + } + void Foo.introducedNonStaticMethod() { + // System.out.println(thisJoinPoint.className +"."+ + // thisJoinPoint.methodName); + } + Foo.new(int n) { ranIntroducedConstructor = true; } + + // make sure advice doesn't go on the toString() method + // this would result in an infinite recursion + before(): within(Foo) && execution(!static * Foo.*(..)) { + fooCounter++; + //System.out.println("before advise on " + + //thisJoinPoint.className +"."+ thisJoinPoint.methodName); + } + + public A() { System.err.println("creating: " + this); } + + //XXX moved to other aspect, need to think about this... + //before(): within(A) && executions(!static * Foo.*(..)) { + //aCounter++; + //System.out.println("before advise on " + thisJoinPoint); + //} +} + diff --git a/tests/base/test121/Readme.txt b/tests/base/test121/Readme.txt new file mode 100644 index 000000000..957fe1c44 --- /dev/null +++ b/tests/base/test121/Readme.txt @@ -0,0 +1,8 @@ +Mode: VM run +Title: advises on introduced methods + +This test checks three things: + + - ! pattern in modifiers + - advice can apply to introduced methods + |