Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Pointcut to a Collection.add() method on a particular type of argument?

I think this is not possible. But maybe Andy Clement knows better. It would not be the first time he surprised me. Meanwhile, check out my workaround at http://stackoverflow.com/a/24797868/1082681.

-- 
Alexander Kriegisch
http://scrum-master.de


Eric B schrieb am 17.07.2014 07:12:

> Thanks.  What if want to advise based on an annotation rather than a type?  I tried
> 
> pointcut addEntity(@MyAnnotation * s):
>         call( * java.util.Collection+.add( * ))
>         && args(s);
> 
> But got syntax error that @MyAnnotation is not allowed.
> 
> 
> On Jul 17, 2014 1:05 AM, "Ulises Juárez Martínez" <ujuarez71@xxxxxxxxx <mailto:ujuarez71@xxxxxxxxx> > wrote:
>> add() signature is:
>> 
>> add(E e)
>> 
>> Thus, * matches anything, but java.lang.String is not E.
>> 
>> Change your pointcut to:
>> 
>>     pointcut addEntity(String s):
>>         call( * java.util.Collection+.add( * ))
>>         && args(s);
>> 
>> 
>> 
>> On Wed, Jul 16, 2014 at 10:31 PM, Eric B <ebenzacar@xxxxxxxxx <mailto:ebenzacar@xxxxxxxxx> > wrote:
>> > I'm trying to write a pointcut against a Collection.add() method given a
>> > specific type of argument, but everytime I specify the argument type the
>> > pointcut fails to advise.
>> >
>> > Given the following code:
>> > List<String> x = new ArrayList<String>();
>> > x.add("Some String)";
>> >
>> > This works:
>> >
>> > pointcut addEntity():  call( * java.util.Collection+.add( * ));
>> >
>> > However, this does not:
>> >
>> > pointcut addEntity():  call( * java.util.Collection+.add( java.util.String
>> > ));
>> >
>> >
>> > Is there a specific reason why I cannot specify the type of argument I want
>> > to advise against?


Back to the top