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.

UnderscoreInPointcutAspect.aj 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. public aspect UnderscoreInPointcutAspect {
  2. public static void main(String[] args) {
  3. UnderTest u = new UnderTest();
  4. System.out.println(u._add(12, 4));
  5. System.out.println(u._subtract(12, 4));
  6. System.out.println(u.multiply_(12, 4));
  7. System.out.println(u.divide_(12, 4));
  8. System.out.println(u.power_of(3, 3));
  9. System.out.println(u.squareRoot(49));
  10. }
  11. before(int a, int b) : execution(* _*(..)) && args(a, b) {
  12. System.out.println("[starts with underscore] " + thisJoinPoint + " -> " + a + ", " + b);
  13. }
  14. before(int a, int b) : execution(* *_(..)) && args(a, b) {
  15. System.out.println("[ends with underscore] " + thisJoinPoint + " -> " + a + ", " + b);
  16. }
  17. before(int a, int b) : execution(* *_*(..)) && args(a, b) {
  18. System.out.println("[contains underscore] " + thisJoinPoint + " -> " + a + ", " + b);
  19. }
  20. before(int a) : execution(* *(..)) && !execution(* *_*(..)) && args(a) {
  21. System.out.println("[no underscore] " + thisJoinPoint + " -> " + a);
  22. }
  23. }
  24. class UnderTest {
  25. int _add(int a, int b) {
  26. return a + b;
  27. }
  28. int _subtract(int a, int b) {
  29. return a - b;
  30. }
  31. int multiply_(int a, int b) {
  32. return a * b;
  33. }
  34. int divide_(int a, int b) {
  35. return a / b;
  36. }
  37. int power_of(int base, int exponent) {
  38. return (int) Math.pow(base, exponent);
  39. }
  40. int squareRoot(int a) {
  41. return (int) Math.sqrt(a);
  42. }
  43. }