hi, Any update on this please.
*Issue:* 1. I have a variable defined with annotation 2, This variable is being assigned to an ArrayList *Now, i want to intercept this call *and execute a logic by AOP. In the interception 1. I should be able to access the annotated value 2. Return a new object called MYLIst The below mail therad is abt the same, 1. If i use set(* *List) then i cant access the annotation 2. If i use the below its (in eclipse) is throwing compilation errors pointcut listCut(LIST in) : set(@LIST* (*) * ) && @annotation(in); ArrayList around( LIST in) :listCut(in){ System.out.println("**annotation " + thisJoinPoint + " ann:" + in.value()); return new MyList(); } *The java class i want to intercept::* public static void main(String[] argv) { UserAttributes u = new UserAttributes(); u.alias = new ArrayList(); } *Any ideas where i am going wrong? Please help.* Regards, Ravi ---------- Forwarded message ---------- From: Ravi Chandra <ravi....@gmail.com> Date: Sun, Jun 21, 2009 at 7:23 PM Subject: Re: [aspectj-users] (no subject) To: aspectj-users@eclipse.org hi, That was an intelligent soln. But, I have annotations on each of the fields( i didnt mention this previously) and during the interception by AOP i would like to access the annotated info also. *Original Class:* public class UserAttributes implements Interceptable { @IN(3) private List<String> alias; public int getAge() { return age; } public static void main(String[] argv) { UserAttributes u = new UserAttributes(); u.alias = new ArrayList(); u.children = new HashMap<String, String>(); } } *and i tried:* pointcut annCut(Interceptable m, IN in):target(m) && set(@IN* (*) * ) && @annotation(in); pointcut annListCut(Interceptable m, IN in) : cflow(annCut(m,in)) && cflow(listCut()) && target(Interceptable+); after/ Around (Interceptable m, IN in): annListCut(m,in){ * //here i should be able to get the fields annotation + return MYList object* System.out.println("point cut + annotation is.." + in.value()); } *But this is cutting off * * public int* getAge() { return age; } method also, *which is not intended. * Any ideas please.. regards, ravi On Sun, Jun 21, 2009 at 3:40 PM, Simone Gianni <simo...@apache.org> wrote: > 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@eclipse.org >> https://dev.eclipse.org/mailman/listinfo/aspectj-users >> >> > > > -- > Simone Gianni CEO Semeru s.r.l. Apache Committer > http://www.simonegianni.it/ > > _______________________________________________ > aspectj-users mailing list > aspectj-users@eclipse.org > https://dev.eclipse.org/mailman/listinfo/aspectj-users >
_______________________________________________ aspectj-users mailing list aspectj-users@eclipse.org https://dev.eclipse.org/mailman/listinfo/aspectj-users