You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NotThis.java 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import org.aspectj.testing.Tester;
  2. /** From PR #496 from Mark Skipper
  3. */
  4. public class NotThis {
  5. public static void main(String[] args){
  6. new NotThis().go();
  7. }
  8. void go(){
  9. A a = new A(this);
  10. a.go();
  11. Tester.checkEqual(Q.buf.toString(), "foo:within(A):this(A):!within(B):!this(B):");
  12. Q.buf = new StringBuffer();
  13. B b = new B(this);
  14. b.go();
  15. Tester.checkEqual(Q.buf.toString(), "foo:");
  16. }
  17. public void foo(Object o){
  18. Q.buf.append("foo:");
  19. }
  20. }
  21. class A {
  22. NotThis t;
  23. A(NotThis n){ t = n; }
  24. void go(){ t.foo(this); }
  25. }
  26. class B{
  27. NotThis t;
  28. B(NotThis n){ t = n; }
  29. void go(){ t.foo(this); }
  30. }
  31. aspect Q {
  32. static StringBuffer buf = new StringBuffer();
  33. after(): call(void NotThis.foo(Object)) && within(A) {
  34. buf.append("within(A):");
  35. }
  36. after(): call(void NotThis.foo(Object)) && this(A) {
  37. buf.append("this(A):");
  38. }
  39. after(): call(void NotThis.foo(Object)) && !within(B) {
  40. buf.append("!within(B):");
  41. }
  42. after(): call(void NotThis.foo(Object)) && !this(B) {
  43. buf.append("!this(B):");
  44. }
  45. }