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.

C.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import org.aspectj.lang.annotation.Aspect;
  2. import org.aspectj.lang.annotation.Before;
  3. import org.aspectj.lang.annotation.Pointcut;
  4. /**
  5. * This test is exploring situations where an if() pointcut is used with a parameter
  6. * and yet a reference pointcut referring to it is not binding the parameter.
  7. */
  8. public class C {
  9. int i;
  10. C(int i) {
  11. this.i = i;
  12. }
  13. public static void main(String []argv) {
  14. new C(1).run();
  15. }
  16. public void run() {
  17. System.out.println("C.run() executing");
  18. }
  19. public String toString() {
  20. return "C("+i+")";
  21. }
  22. }
  23. @Aspect
  24. abstract class Azpect1 {
  25. @Pointcut("if(false)")
  26. public void isCondition() {}
  27. @Before("isCondition() && execution(* C.run(..))")
  28. public void beforeAdvice() {
  29. System.out.println("Azpect1.beforeAdvice executing");
  30. }
  31. }
  32. @Aspect
  33. class Azpect2 extends Azpect1 {
  34. @Pointcut("check(*)")
  35. public void isCondition() { }
  36. @Pointcut("this(c) && if()")
  37. public static boolean check(C c) {
  38. System.out.println("check if() pointcut running on "+c.toString());
  39. return true;
  40. }
  41. }
  42. //
  43. //abstract aspect A {
  44. // pointcut isCondition(): if(false);
  45. // before(): isCondition() && execution(* C.run(..)) { System.out.println("A.before"); }
  46. //}
  47. //
  48. //aspect B extends A {
  49. // pointcut isCondition(): check(*);
  50. // pointcut check(Object o): this(o) && if(o.toString().equals("abc"));
  51. //}