Cflow Versus Withincode

The following example illustrates the difference between cflow and withincode.

public class Hello
{
    public void c()
    {
        System.out.println("C");
    }
 
    public void b()
    {
        System.out.println("B");
        c();                                   // <- pCflow()
    }
 
    public void a()
    {
        System.out.println("A");
        b();
    }
 
    public static void main(String[] args)
    {
        Hello test = new Hello();
 
        test.c();
    }
}
public aspect HelloAspect
{
    pointcut pWithincode() : 
        call( * Hello.c() ) && withincode( * Hello.a() );
 
    //advises nothing
    before() : pWithincode() 
    {
        System.out.println("call-within");
    }
 
    pointcut pCflow() : 
        call( * Hello.c() ) && cflow( call(* Hello.a()) );
 
    before() : 
        pCflow() 
        && !within(HelloAspect)
    {
        System.out.println("call-cflow");
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.