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.

C.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package p;
  2. import a.X;
  3. public class C {
  4. public C() {
  5. }
  6. public static void main(String[] argv) {
  7. C c = new C();
  8. c.sayhi();
  9. c.sayhi();
  10. c.sayhi();
  11. c.sayhi();
  12. if (a.X.aspectOf(A.class)==null) {
  13. throw new RuntimeException("aspectOf(A.class) should not be null");
  14. }
  15. if (a.X.aspectOf(B.class)==null) {
  16. throw new RuntimeException("aspecfOf(B.class) should not be null");
  17. }
  18. try {
  19. Object o = a.X.aspectOf(q.D.class);
  20. throw new RuntimeException("aspectOf(D.class) should be null");
  21. } catch (org.aspectj.lang.NoAspectBoundException nabe) {
  22. }
  23. a.X instanceForA = a.X.aspectOf(A.class);
  24. a.X instanceForB = a.X.aspectOf(B.class);
  25. if (instanceForA.equals(instanceForB)) {
  26. throw new RuntimeException("Instances for A("+instanceForA+") and for B("+instanceForB+") should not be the same!");
  27. }
  28. // Now lets check the counts don't interfere
  29. A aa = new A();
  30. B b = new B();
  31. c = new C();
  32. X.aspectOf(A.class).setI(0);
  33. X.aspectOf(B.class).setI(0);
  34. X.aspectOf(C.class).setI(0);
  35. aa.sayhi();
  36. b.sayhi();
  37. aa.sayhi();
  38. c.sayhi();
  39. b.sayhi();
  40. aa.sayhi();
  41. aa.sayhi();
  42. if (a.X.aspectOf(A.class).getI()!=4) {
  43. throw new RuntimeException("For A, i should be 4 but it is "+a.X.aspectOf(A.class).getI());
  44. }
  45. if (a.X.aspectOf(B.class).getI()!=2) {
  46. throw new RuntimeException("For B, i should be 2 but it is "+a.X.aspectOf(B.class).getI());
  47. }
  48. if (a.X.aspectOf(C.class).getI()!=1) {
  49. throw new RuntimeException("For C, i should be 1 but it is "+a.X.aspectOf(C.class).getI());
  50. }
  51. }
  52. public void sayhi() { System.err.println("hi C"); }
  53. }