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.

Within.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import org.aspectj.testing.Tester;
  2. public class Within {
  3. public static void main(String[] args) {
  4. C c = new C();
  5. c.mi();
  6. Tester.check("I.mi within A1");
  7. Tester.check("I.mi instanceof C");
  8. Tester.check("I.mi instanceof I");
  9. c.mc();
  10. }
  11. }
  12. class C {
  13. void mc() {}
  14. }
  15. interface I {}
  16. aspect A1 {
  17. void I.mi() {}
  18. }
  19. aspect A2 {
  20. declare parents: C implements I;
  21. }
  22. aspect Test {
  23. before (): execution(* I.*(..)) && within(C) {
  24. Tester.checkFailed(thisJoinPoint + " I.* within C");
  25. }
  26. before (): execution(* I.*(..)) && within(I) {
  27. Tester.checkFailed(thisJoinPoint + " I.* within I");
  28. }
  29. before (): execution(* I.*(..)) && within(A1) {
  30. Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi",
  31. thisJoinPoint + " I.* within A1");
  32. Tester.note("I.mi within A1");
  33. }
  34. before (): execution(* I.*(..)) && within(A2) {
  35. }
  36. before (): execution(* I.*(..)) && this(C) {
  37. Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi",
  38. thisJoinPoint + " I.* instanceof C");
  39. Tester.note("I.mi instanceof C");
  40. }
  41. before (): execution(* I.*(..)) && this(I) {
  42. Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi",
  43. thisJoinPoint + " I.* instanceof I");
  44. Tester.note("I.mi instanceof I");
  45. }
  46. before (): execution(* I.*(..)) && this(A1) {
  47. Tester.checkFailed(thisJoinPoint + " I.* instanceof A1");
  48. }
  49. before (): execution(* I.*(..)) && this(A2) {
  50. Tester.checkFailed(thisJoinPoint + " I.* instanceof A2");
  51. }
  52. }