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.

IndeterminateArgs.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import org.aspectj.testing.Tester;
  2. import org.aspectj.lang.*;
  3. import org.aspectj.lang.reflect.*;
  4. import java.util.Arrays;
  5. /** @testcase PR#764 binding args with indeterminate prefix and suffix */
  6. public class IndeterminateArgs {
  7. public static void main (String[] args) {
  8. C c;
  9. c = new C();
  10. c = new C("s1");
  11. c = new C("s1", "s2");
  12. c = new C("s1", "s2", "s3");
  13. c.f();
  14. c.f("s1");
  15. c.f("s1", "s2");
  16. c.f("s1", "s2", "s3");
  17. Tester.checkEventsFromFile("IndeterminateArgs.events");
  18. }
  19. }
  20. class T {
  21. static void e(String s) {
  22. Tester.event(s);
  23. }
  24. static void ee(String s) { Tester.expectEvent(s); }
  25. }
  26. class C {
  27. C() { T.e("C()"); }
  28. C(String s1) { T.e("C(" + s1 + ")"); }
  29. C(String s1, String s2) { T.e("C(" + s1 + ", " + s2 + ")"); }
  30. C(String s1, String s2, String s3) { T.e("C(" + s1 + ", " + s2 + ", " + s3 + ")"); }
  31. void f() { T.e("f()"); }
  32. void f(String s1) { T.e("f(" + s1 + ")"); }
  33. void f(String s1, String s2) { T.e("f(" + s1 + ", " + s2 + ")"); }
  34. void f(String s1, String s2, String s3) { T.e("f(" + s1 + ", " + s2 + ", " + s3 + ")"); }
  35. }
  36. aspect A {
  37. void check(String pc, JoinPoint jp) {
  38. Class[] types = ((CodeSignature) jp.getSignature()).getParameterTypes();
  39. T.e(pc + ": " + Arrays.asList(types));
  40. }
  41. pointcut safe() : target(C) && (call(new(..)) || call(* *(..)));
  42. pointcut o1() : args(Object);
  43. pointcut o2() : args(Object, Object);
  44. pointcut o1Start() : args(Object,..);
  45. pointcut o1End() : args(..,Object);
  46. pointcut o2Start() : args(Object, Object,..);
  47. pointcut o2End() : args(..,Object, Object);
  48. pointcut s1() : args(String);
  49. pointcut s2() : args(String, String);
  50. pointcut s1Start() : args(String,..);
  51. pointcut s1End() : args(..,String);
  52. pointcut s2Start() : args(String, String,..);
  53. pointcut s2End() : args(..,String, String);
  54. // bind
  55. pointcut bo1(Object o1) : args(o1);
  56. pointcut bo2(Object o1, Object o2) : args(o1, o2);
  57. pointcut bo1Start(Object o1) : args(o1,..);
  58. pointcut bo1End(Object o1) : args(..,o1);
  59. pointcut bo2Start(Object o1, Object o2) : args(o1, o2,..);
  60. pointcut bo2End(Object o1, Object o2) : args(..,o1, o2);
  61. pointcut bs1(String s1) : args(s1);
  62. pointcut bs2(String s1, String s2) : args(s1, s2);
  63. pointcut bs1Start(String s1) : args(s1,..);
  64. pointcut bs1End(String s1) : args(..,s1);
  65. pointcut bs2Start(String s1, String s2) : args(s1, s2,..);
  66. pointcut bs2End(String s1, String s2) : args(..,s1, s2);
  67. before() : safe() && o1() { check ("o1()", thisJoinPoint); }
  68. before() : safe() && o2() { check ("o2()", thisJoinPoint); }
  69. before() : safe() && o1Start() { check ("o1Start()", thisJoinPoint); }
  70. before() : safe() && o1End() { check ("o1End()", thisJoinPoint); }
  71. before() : safe() && o2Start() { check ("o2Start()", thisJoinPoint); }
  72. before() : safe() && o2End() { check ("o2End()", thisJoinPoint); }
  73. before() : safe() && s1() { check ("s1()", thisJoinPoint); }
  74. before() : safe() && s2() { check ("s2()", thisJoinPoint); }
  75. before() : safe() && s1Start() { check ("s1Start()", thisJoinPoint); }
  76. before() : safe() && s1End() { check ("s1End()", thisJoinPoint); }
  77. before() : safe() && s2Start() { check ("s2Start()", thisJoinPoint); }
  78. before() : safe() && s2End() { check ("s2End()", thisJoinPoint); }
  79. before(Object o1) : safe() && bo1(o1) { check ("bo1()", thisJoinPoint); }
  80. before(Object o1, Object o2) : safe() && bo2(o1, o2) { check ("bo2()", thisJoinPoint); }
  81. before(Object o1) : safe() && bo1Start(o1) { check ("bo1Start()", thisJoinPoint); }
  82. before(Object o1) : safe() && bo1End(o1) { check ("bo1End()", thisJoinPoint); }
  83. before(Object o1, Object o2) : safe() && bo2Start(o1, o2) { check ("bo2Start()", thisJoinPoint); }
  84. before(Object o1, Object o2) : safe() && bo2End(o1, o2) { check ("bo2End()", thisJoinPoint); }
  85. before(String s1) : safe() && bs1(s1) { check ("bs1()", thisJoinPoint); }
  86. before(String s1, String s2) : safe() && bs2(s1, s2) { check ("bs2()", thisJoinPoint); }
  87. before(String s1) : safe() && bs1Start(s1) { check ("bs1Start()", thisJoinPoint); }
  88. before(String s1) : safe() && bs1End(s1) { check ("bs1End()", thisJoinPoint); }
  89. before(String s1, String s2) : safe() && bs2Start(s1, s2) { check ("bs2Start()", thisJoinPoint); }
  90. before(String s1, String s2) : safe() && bs2End(s1, s2) { check ("bs2End()", thisJoinPoint); }
  91. }