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.

ParsingSubtypesIntroductions.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import org.aspectj.testing.Tester;
  2. public class ParsingSubtypesIntroductions {
  3. public static void main(String[] args) {
  4. new ParsingSubtypesIntroductions().realMain(args);
  5. }
  6. public void realMain(String[] args) {
  7. new D().f();
  8. new C().f();
  9. ((I)new C()).i();
  10. new E().f();
  11. ((I)new E()).i();
  12. Tester.checkAllEvents();
  13. }
  14. static {
  15. U.m(D.class, "f");
  16. U.m(C.class, "f");
  17. U.m(C.class, "i");
  18. U.m(E.class, "f");
  19. U.m(E.class, "i");
  20. }
  21. }
  22. class U {
  23. public static void a(Object o, Object m) {
  24. Tester.event(m + "." + type(o));
  25. }
  26. public static void m(Class t, Object m) {
  27. Tester.expectEvent(m + "." + name(t));
  28. }
  29. public static String type(Object o) {
  30. return name(o.getClass());
  31. }
  32. public static String name(Class t) {
  33. String str = t.getName();
  34. int i = str.lastIndexOf('.');
  35. if (i != -1) str = str.substring(i+1);
  36. return str;
  37. }
  38. }
  39. class D {
  40. public void f() { U.a(this, "f"); }
  41. }
  42. class C /*extends D implements I*/ {
  43. /*public void i() { U.a(this, "i"); }*/
  44. }
  45. class E extends C {}
  46. interface I {
  47. public void i();
  48. }
  49. aspect A {
  50. // subtypes(C) +implements I;
  51. // subtypes(C) +extends D;
  52. declare parents: C+ implements I;
  53. declare parents: C+ extends D;
  54. public void I.i() { U.a(this, "i"); }
  55. }