Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] how do I define around advice that works for methods with differe nt return types.

Hi,
 
I am trying to write an around advice that applies to functions with different return types. When I try the following, I get a compilation error "applying to join point that doesn't return void".
 
public class A
{
    public int foo()
    {
        return 0;
    }
 
    public void bar()
    {
        x();
    }
 
    public void x()
    {
    }
};
 
aspect LogExecutionTime
{
    pointcut allMethods() : execution(public * A.*(..));
    void around() : allMethods()
    {
        long startTime = System.currentMilliSeconds();
        proceed();
        long time = System.currentMilliSeconds() - startTime;
        System.out.println("Time taken by method " + thisJoinPoint.getSignature() + " " + time "ms"); 
    }
}
 
There also seems to be a bug filed for this issue.  Is it a limitation of the current version of aspectj (I am using 1.2) which will be resolved in a later version. Or is there a fundamental problem in supporting this.  Are there any other ways of getting this to work.  It is difficult to achieve this using a pair of before and after advices as that would require me to maintain a stack to trace the start times.
 
Thanks,
Kamal.
 
 

Back to the top