[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] how do I define around advice that works for methods with differe nt return types.
|
Just change your around advice as follows:
Object around() : allMethods()
{
long startTime = System.currentMilliSeconds();
Object retVal = proceed();
long time = System.currentMilliSeconds() - startTime;
System.out.println("Time taken by method " +
thisJoinPoint.getSignature() + " " + time "ms");
return retVal;
}
-Ramnivas
Ramnivas Laddad,
Author, AspectJ in Action
http://ramnivas.com
Check out my aspect-oriented refactoring articles:
http://tinyurl.com/yqm96
http://tinyurl.com/288nn
Kamal Govindraj wrote:
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.