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.

DoubleAnnotationMatching.aj 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import java.lang.annotation.*;
  2. @Retention(RetentionPolicy.RUNTIME) @interface Tx {boolean value() default false;}
  3. public aspect DoubleAnnotationMatching {
  4. pointcut methodInTxType(Tx tx) :
  5. execution(* *(..)) && @this(tx) && if(tx.value());
  6. pointcut txMethod(Tx tx) :
  7. execution(* *(..)) && @annotation(tx) && if(tx.value());
  8. pointcut transactionalOperation() :
  9. methodInTxType(Tx) || txMethod(Tx);
  10. before() : transactionalOperation() {
  11. System.err.println("advice running at "+thisJoinPoint);
  12. }
  13. public static void main(String [] argv) {
  14. new Foo().a();
  15. new Foo().b();
  16. new Foo().c();
  17. new TxTrueFoo().a();
  18. new TxTrueFoo().b();
  19. new TxTrueFoo().c();
  20. new TxFalseFoo().a();
  21. new TxFalseFoo().b();
  22. new TxFalseFoo().c();
  23. }
  24. }
  25. @Tx(true) class TxTrueFoo {
  26. @Tx(true) public void a() {}
  27. @Tx(false) public void b() {}
  28. public void c() {}
  29. }
  30. @Tx(false) class TxFalseFoo {
  31. @Tx(true) public void a() {}
  32. @Tx(false) public void b() {}
  33. public void c() {}
  34. }
  35. class Foo {
  36. @Tx(true) public void a() {}
  37. @Tx(false) public void b() {}
  38. public void c() {}
  39. }