import org.aspectj.testing.Tester; public class CflowInitInAspectVariantsAfter { public static void main(String[] args) { new C().a(); Tester.checkAllEventsIgnoreDups(); } static { Tester.expectEvent("cflow after pc()"); Tester.expectEvent("cflow after execution(void C.a())"); Tester.expectEvent("cflowbelow after pc()"); Tester.expectEvent("cflowbelow after execution(void C.a())"); } } class C { void a() {b();} private void b() {int i = 1;} // avoid later optimizations } aspect A { pointcut safety() : !within(A); pointcut pc() : execution(void C.a()); after() : safety() && cflow(pc()) { Tester.event("cflow after pc()"); } after() : safety() && cflow(execution(void C.a())) { Tester.event("cflow after execution(void C.a())"); } after() : safety() && cflowbelow(pc()) { Tester.event("cflowbelow after pc()"); } after() : safety() && cflowbelow(execution(void C.a())) { Tester.event("cflowbelow after execution(void C.a())"); } } /option> A seamless aspect-oriented extension to the Java programming language: https://github.com/eclipse-aspectj/aspectjwww-data
summaryrefslogtreecommitdiffstats
path: root/tests/new/AroundInnerCalls.java
blob: 64a55caf8a0544ab639404d45712ddb74f1f3289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import org.aspectj.testing.Tester;

public class AroundInnerCalls {
    public static void main(String[] args) {
	new Outer().foo();

	Tester.check("Outer.foo() calls Outer.Inner.mi()");
	Tester.check("Outer.foo() calls Outer.InnerRandom.nextHook(..)");
	Tester.check("Outer.InnerRandom.nextHook(..) calls Outer.InnerRandom.next(..)");
	Tester.check("Outer.Inner.mi() calls PrintStream.println(..)");

        Tester.check("X.toString()");
	Tester.check("Outer.foo() calls Outer.1.nextInt(..)");
    }
}

class Outer {
    private class Inner extends Object {
	public void mi() {
	    System.out.println(".");
	}
    }

    public void foo() {
	new Inner().mi();
	new InnerRandom().nextHook(2);

        new java.util.Random() { public String toString() { Tester.note("X.toString()"); return "X"; } }.nextInt(2);
    }

    private class InnerRandom extends java.util.Random {
	public int nextHook(int bits) {
	    return next(bits);
	}
    }
}

aspect A {
    Object around(): call(* *(..)) && !within(A) {
//	System.out.println
        Tester.note
            (thisEnclosingJoinPointStaticPart.getSignature().toShortString() +
             " calls " + thisJoinPointStaticPart.getSignature().toShortString());
	return proceed();
    }
    
    before(Object caller, Object callee):
       this(caller) && target(callee) && call(* *(..)) && !within(A)
    {
        System.out.println(thisEnclosingJoinPointStaticPart.getSignature().toShortString() +
             " calls " + thisJoinPointStaticPart.getSignature().toShortString());
	System.out.println
            (caller + "." + thisEnclosingJoinPointStaticPart.getSignature().getName() + 
             " calls " + callee + "." + thisJoinPoint.getSignature().getName());
    }
}