[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Use null for args in pointcut

I agree with Wes's question about the contract. To me, it's a little
doubtful what you are trying to accomplish with args in your observer. It
seems like you are writing special-case logic for thisJoinPoint.getArgs(),
to match zero or one argument. What do you expect to do with the first
argument, if any? What would you do in a case with more than one argument?
Would thisJoinPoint.getArgs() meet your needs?

There have been a number of requests for enhancement relating to pointcut
bindings. One that seems relevant for this request is
https://bugs.eclipse.org/bugs/show_bug.cgi?id=92889, which would allow
binding constants (so you could supply a constant value in cases where e.g.,
null makes sense). In general, I think AspectJ 1.6.0 could benefit from
providing more power in unifying (binding and matching) for user pointcuts,
e.g., also bug #108895 and bug #106166. 

HTH,
Ron

-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Wes
Sent: Monday, August 21, 2006 10:57 AM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Use null for args in pointcut

Hi -

If the variable is declared in the pointcut, it must be bound,
but you don't have to bind it using args(..), e.g.,

  target(subject) && target(arg)

But that sort of begs the question.  The abstract pointcut is supposed
to define a contract that implementors comply with, and you have no way
to comply with it since there is no argument for your join point.  If
you pretend to comply, it's not clear what's going to happen.  Here you
might have the source for the abstract aspect and understand the advice
on the join points picked out by the abstract pointcuts, but often 
programmers don't, and they don't know what would be the effect of not
complying.  

hmm.  Interesting!

Wes

------------Original Message------------
From: "Conway. Fintan (IT Solutions)" <Fintan.Conway@xxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Mon, Aug-21-2006 7:31 AM
Subject: [aspectj-users] Use null for args in pointcut
Hi *,

I have a problem where I have to extend a pointcut in a super aspect.  The
signature of this pointcut is as follows :
protected abstract pointcut subjectChange(Subject s, Object args); 
One of the aspects which extends this super aspect does not require the
'args'  parameter.
My overriding pointcut looks like :
protected pointcut subjectChange(Subject subj, Object arg) :
(
call(* Pot.add(..))
|| 
call(* Pot.refresh())
)
&& !within(PotObserverUtilTest)
&& target(subj)
&& args(arg); 
This pointcut matches the Pot.add method, since it does have an argument.
However the Pot.refresh() method is not advised since it does not have any
arguments.  I have to override the abstract pointcut.
Is there any way to get the Pot.refresh() advised in this scenario?  (args =
null?)
Any advice gratefully appreciated,
Fintan