12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import org.aspectj.testing.Tester;
-
- public class Within {
- public static void main(String[] args) {
- C c = new C();
- c.mi();
-
- Tester.check("I.mi within A1");
- Tester.check("I.mi instanceof C");
- Tester.check("I.mi instanceof I");
-
- c.mc();
- }
- }
-
-
- class C {
- void mc() {}
- }
-
- interface I {}
-
- aspect A1 {
- void I.mi() {}
- }
-
- aspect A2 {
- declare parents: C implements I;
- }
-
-
-
- aspect Test {
- before (): execution(* I.*(..)) && within(C) {
- Tester.checkFailed(thisJoinPoint + " I.* within C");
- }
- before (): execution(* I.*(..)) && within(I) {
- Tester.checkFailed(thisJoinPoint + " I.* within I");
- }
- before (): execution(* I.*(..)) && within(A1) {
- Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi",
- thisJoinPoint + " I.* within A1");
- Tester.note("I.mi within A1");
- }
- before (): execution(* I.*(..)) && within(A2) {
- }
-
- before (): execution(* I.*(..)) && this(C) {
- Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi",
- thisJoinPoint + " I.* instanceof C");
- Tester.note("I.mi instanceof C");
- }
- before (): execution(* I.*(..)) && this(I) {
- Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi",
- thisJoinPoint + " I.* instanceof I");
- Tester.note("I.mi instanceof I");
- }
- before (): execution(* I.*(..)) && this(A1) {
- Tester.checkFailed(thisJoinPoint + " I.* instanceof A1");
- }
- before (): execution(* I.*(..)) && this(A2) {
- Tester.checkFailed(thisJoinPoint + " I.* instanceof A2");
- }
- }
|