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.

CallTypesI.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import org.aspectj.testing.Tester;
  2. import java.util.*;
  3. public class CallTypesI {
  4. public static void main(String[] args) {
  5. C1a c1a = new C1a();
  6. preTest("c1a.mI()");
  7. c1a.mI();
  8. test("static c1a, static i0, static i1a, instanceof c0, instanceof c1a, instanceof i0, instanceof i1a, ");
  9. preTest("c1a.mC()");
  10. c1a.mC();
  11. test("static c0, static c1a, instanceof c0, instanceof c1a, instanceof i0, instanceof i1a, ");
  12. C0 c0 = c1a;
  13. preTest("(C c = c1a).mC()");
  14. c0.mC();
  15. test("static c0, instanceof c0, instanceof c1a, instanceof i0, instanceof i1a, ");
  16. }
  17. public static void preTest(String str) {
  18. A.noteAdvice = A.noteAdviceStar = "";
  19. msg = str;
  20. }
  21. static String msg;
  22. public static void test(String t1) {
  23. test(t1, t1);
  24. }
  25. public static void test(String baseString, String starString) {
  26. Tester.checkEqual(sort(A.noteAdvice), sort(baseString), "base: "+msg);
  27. //Tester.checkEqual(sort(A.noteAdviceStar), sort(starString), "star: "+msg);
  28. }
  29. private final static Collection sort(String str) {
  30. SortedSet sort = new TreeSet();
  31. for (StringTokenizer t = new StringTokenizer(str, ",", false);
  32. t.hasMoreTokens();) {
  33. String s = t.nextToken().trim();
  34. if (s.length() > 0) sort.add(s);
  35. }
  36. return sort;
  37. }
  38. }
  39. interface I0 {
  40. public void mI();
  41. }
  42. interface I1a extends I0 { }
  43. interface I1b extends I0 { }
  44. ////interface I2 extends I1a, I1b {}
  45. class C0 {
  46. public void mC() { }
  47. }
  48. class C1a extends C0 implements I1a {
  49. public void mI() { }
  50. }
  51. class C1b extends C0 implements I1b {
  52. public void mI() { }
  53. }
  54. aspect A {
  55. static String noteAdvice = "";
  56. static String noteAdviceStar = "";
  57. before(): call(void C0.mC()) {
  58. noteAdvice += "static c0, ";
  59. }
  60. before(): call(void C1a.mC()) || call(void C1a.mI()) {
  61. noteAdvice += "static c1a, ";
  62. }
  63. before(): call(void C1b.mC()) || call(void C1b.mI()) {
  64. noteAdvice += "static c1b, ";
  65. }
  66. before(): call(void I0.mI()) {
  67. noteAdvice += "static i0, ";
  68. }
  69. before(): call(void I1a.mI()) {
  70. noteAdvice += "static i1a, ";
  71. }
  72. before(): call(void I1b.mI()) {
  73. noteAdvice += "static i1b, ";
  74. }
  75. before(): target(C0) && call(* *(..)) { noteAdvice += "instanceof c0, "; }
  76. before(): target(C1a) && call(* *(..)) { noteAdvice += "instanceof c1a, "; }
  77. before(): target(C1b) && call(* *(..)) { noteAdvice += "instanceof c1b, "; }
  78. before(): target(I0) && call(* *(..)) { noteAdvice += "instanceof i0, "; }
  79. before(): target(I1a) && call(* *(..)) { noteAdvice += "instanceof i1a, "; }
  80. before(): target(I1b) && call(* *(..)) { noteAdvice += "instanceof i1b, "; }
  81. }