|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import org.aspectj.testing.Tester;
-
- // we want to be doing tests based on dynamic type in if
- public class StaticTypeInIf {
- public static void main(String[] args) {
- D d = new D();
- C c = new C();
-
- c.foo(c);
- Tester.checkAndClearEvents(new String[] {});
-
- A.setF(d, false);
- c.foo(d);
- Tester.checkAndClearEvents(new String[] {});
- A.setF(d, true);
- c.foo(d);
- Tester.checkAndClearEvents(new String[] {"args"});
-
- A.setF(d, false);
- d.foo(c);
- Tester.checkAndClearEvents(new String[] {});
- A.setF(d, true);
- d.foo(c);
- Tester.checkAndClearEvents(new String[] {"this", "target"});
-
- A.setF(d, false);
- d.foo(d);
- Tester.checkAndClearEvents(new String[] {});
- A.setF(d, true);
- d.foo(d);
- Tester.checkAndClearEvents(new String[] {"args", "this", "target"});
-
- }
-
- }
-
- class C {
- void foo(C c) {}
- }
-
- class D extends C {
- void foo(C c) {}
- }
-
-
- aspect A {
- private boolean D.f = false;
-
- static void setF(D d, boolean b) { d.f = b; }
-
- pointcut foo(D d): call(void C.foo(C)) && target(d) && if(d.f);
-
- before (C c): foo(c) {
- Tester.event("target");
- }
-
- before (D d): if(d.f) && call(void C.foo(C)) && args(d) {
- Tester.event("args");
-
- }
-
- before (D d): execution(void C.foo(C)) && this(d) && if(d.f) {
- Tester.event("this");
- }
- }
|