[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] (no subject)

Hi Ravi,
you can declare a pointcut around the creation of any ArrayList, returning MyArrayList as long as they are assign-compatible.


That means that as long as :

public class MyArrayList extends ArrayList { ...

you can write :

ArrayList around() : call(* ArrayList.new()) {
 return new MyArrayList();
}

This will replace do the trick. You can narrow it down to some classes using within, withincode etc..

ArrayList around() : call(* ArrayList.new()) && within(com.mycompany.*) {
  return new MyArrayList();
}

And you can add other advice to add parameters  :

ArrayList around(int size) : call(* ArrayList.new(int)) && args(size) {
  return new MyArrayList(size);
}

etc...

In my Apache Magma Lab I use this kind of advice extensively to offer a simpler alternative to the factory pattern/dependency injection/context pollution.

Hope this helps,
Simone





Ravi Chandra wrote:
hi,

I am trying hard to get a solution to this problem since last 4 days.. but no luck; the issue is as below:

I have java classes of this form

public class UserAttributes implements Interceptable {
private List<String> alias;
private void someMethod(){
*alias = new ArrayList(); // point 1*
.... etc etc
}
}


Now the problem is :

When ever a variable is assigned to new ArrayList() i want it to be changed to new MyArrayList() instead

i.e..: the point 1 above changes to an eqvivalent of

*alias = new MYArrayList();*

I am able to get this done

aspect abc {
pointcut listCut(Interceptable m, IN in):target(m) && set(java.util.List+ *);
after(Interceptable m, IN in):listCut(m,in){
*UserAttributes.setAlias( new MyArrayList());*
}
}


*but the point cut is getting very class specific. *I have abt 1000 classes which have to be modified this way where ever the ArrayList is being used, now with this approach i need to write 1000 files; isnt there a generic way to do this?

Any pointers/ help ? please suggest.

regards,
ravi

------------------------------------------------------------------------

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


--
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
http://www.simonegianni.it/