Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Question on args()

Wim,
 
If you know the arguments that you want, then I think you are better served by using args because then the parameters you need are directly exposed and it eliminates the reflective call to thisJoinPoint.getArgs().  Also, this helps to limit your point cut to the specific parameter type if I read the following correctly, mean that instead of the casting you will get an actual int passed to your advice.
 
http://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html
 
Ron

________________________________

From: aspectj-users-bounces@xxxxxxxxxxx on behalf of Wim Deblauwe
Sent: Fri 9/8/2006 10:24 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Question on args()


Hi,

reading through http://www.eclipse.org/aspectj/doc/released/progguide/language-joinPoints.html#pointcut-parameters , I can understand the difference between target() and args() pointcuts. Is it correct to say that in stead of using this:

pointcut setter(Point p, int newval): target(p) && 
                                      args(newval) &&
                                      (call(void setX(int)) ||
                                       call(void setY(int))); 

I use this:

pointcut setter(Point p): target(p) &&
                                      (call(void setX(int)) ||
                                       call(void setY(int))); 

and then I can also get the 'newval' by using (in the corresponding advice):

int newval = (Integer)thisJoinPoint.getArgs()[0];

I know this is not so nice, but I just want to know if they are the same. Because now I'm always using the getArgs() method, but it would be better to use the args() pointcut then (if my assumpions are right) 

regards,

Wim

<<winmail.dat>>


Back to the top