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.

CallTypes.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import org.aspectj.testing.Tester;
  2. import java.util.*;
  3. public class CallTypes {
  4. public static void main(String[] args) {
  5. C1 c1 = new C1();
  6. preTest("c1.foo()");
  7. c1.foo();
  8. test("static c, static c1, instanceof c, instanceof c1, ");
  9. C c = c1;
  10. preTest("(C c = c1).foo()");
  11. c.foo();
  12. test("static c, instanceof c, instanceof c1, ");
  13. c = new C();
  14. preTest("new C().foo()");
  15. c.foo();
  16. test("static c, instanceof c, ");
  17. C2 c2 = new C2();
  18. preTest("new C2().foo()");
  19. c2.foo();
  20. test("static c, static c2, instanceof c, instanceof c2, ");
  21. preTest("c1.foo1()");
  22. c1.foo1();
  23. test("", "static c1, instanceof c, instanceof c1, ");
  24. }
  25. public static void preTest(String str) {
  26. A.noteAdvice = A.noteAdviceStar = "";
  27. msg = str;
  28. }
  29. static String msg;
  30. public static void test(String t1) {
  31. test(t1, t1);
  32. }
  33. public static void test(String baseString, String starString) {
  34. Tester.checkEqual(sort(A.noteAdvice), sort(baseString), "base: "+msg);
  35. Tester.checkEqual(sort(A.noteAdviceStar), sort(starString), "star: "+msg);
  36. }
  37. private final static Collection sort(String str) {
  38. SortedSet sort = new TreeSet();
  39. for (StringTokenizer t = new StringTokenizer(str, ",", false);
  40. t.hasMoreTokens();) {
  41. String s = t.nextToken().trim();
  42. if (s.length() > 0) sort.add(s);
  43. }
  44. return sort;
  45. }
  46. }
  47. class C {
  48. public void foo() { }
  49. }
  50. class C1 extends C {
  51. public void foo1() { }
  52. }
  53. class C2 extends C {
  54. public void foo() { }
  55. }
  56. aspect A {
  57. static String noteAdvice = "";
  58. static String noteAdviceStar = "";
  59. before(C c): target(c) && call(void C.foo()) {
  60. noteAdvice += "static c, ";
  61. }
  62. before(C1 c1): target(c1) && call(void C1.foo()) {
  63. noteAdvice += "static c1, ";
  64. }
  65. before(C2 c2): target(c2) && call(void C2.foo()) {
  66. noteAdvice += "static c2, ";
  67. }
  68. before(C c): target(c) && call(void foo()) {
  69. noteAdvice += "instanceof c, ";
  70. }
  71. before(C1 c1): target(c1) && call(void foo()) {
  72. noteAdvice += "instanceof c1, ";
  73. }
  74. before(C2 c2): target(c2) && call(void foo()) {
  75. noteAdvice += "instanceof c2, ";
  76. }
  77. before(C c): target(c) && call(void C.foo*()) {
  78. noteAdviceStar += "static c, ";
  79. }
  80. before(C1 c1): target(c1) && call(void C1.foo*()) {
  81. noteAdviceStar += "static c1, ";
  82. }
  83. before(C2 c2): target(c2) && call(void C2.foo*()) {
  84. noteAdviceStar += "static c2, ";
  85. }
  86. before(C c): target(c) && call(void foo*()) {
  87. noteAdviceStar += "instanceof c, ";
  88. }
  89. before(C1 c1): target(c1) && call(void foo*()) {
  90. noteAdviceStar += "instanceof c1, ";
  91. }
  92. before(C2 c2): target(c2) && call(void foo*()) {
  93. noteAdviceStar += "instanceof c2, ";
  94. }
  95. }