Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » Joinpoint for java.util.List
Joinpoint for java.util.List [message #658095] Sun, 06 March 2011 10:36 Go to next message
Pascal  is currently offline Pascal Friend
Messages: 7
Registered: September 2010
Junior Member
Hello everyone,
i have a problem and i don't know if it's even possible to solve it the way i have thought of.

I have a class variable mList which is of the type java.util.List. What i want to do is to execute an advice before mList.add() is called.

The variable mList is part of the class foo and i have tried to different approaches but i get an "advice did not macth error".

Here is what i have so far:
pointcut getContext():call(* java.util.List.add(..));
before(): getContext() && within(*.foo..*){
		System.out.println("Aspect works");

I have even tried to put the variable as parameter for the joinpoint as:
pointcut getContext():call(*foo.mList.add(..))

but without success.
Can anyone tell if it is even possible what i am doing here and if it is what am i doing wrong?

Regards pascal

Re: Joinpoint for java.util.List [message #658368 is a reply to message #658095] Tue, 08 March 2011 08:51 Go to previous messageGo to next message
shadowlaw  is currently offline shadowlaw Friend
Messages: 1
Registered: March 2011
Junior Member
hi pascal,

try to change the pointcut expression to this
call(* ArrayList.add(..))

there's certeinly something wrong with your aspect but i unable to find what Embarrassed
Re: Joinpoint for java.util.List [message #658525 is a reply to message #658368] Tue, 08 March 2011 20:17 Go to previous message
Andrew Eisenberg is currently offline Andrew EisenbergFriend
Messages: 382
Registered: July 2009
Senior Member
The second suggestion is not possible. You are looking for all calls to add that originate from the field mList. However, AspectJ works on instances at runtime and what you want to do is not defined at runtime.

For example:
Foo f = new Foo();
List newList = f.mList();
newList.add(null);  // should the advice be triggered here?

This is just not something that AspectJ does.

However, your first suggestion seems like it should work. There are a few reasons why it may not. For example, is the "foo" package binary and is it on your Aspect/In path?

Also, try:
pointcut getContext():call(public  java.util.List.add(..));

instead of what you have.
Previous Topic:No development time feedback with Equinox Aspects?
Next Topic:How to obtain org.aspectj.(runtime|weaver) from update site?
Goto Forum:

Current Time: Mon Oct 15 21:12:40 GMT 2018

Powered by FUDForum. Page generated in 0.02232 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top