Hi Andrew, Thanks for the clarification. You are right. What I need is all add's and deletes to the set object pointed by S. I think the way to do it right is to track the object held by s and at every add call on a set check if we are adding to the right set pointed to by s or not. While this approach always works, the performance impact depends on how many sets you are tracking versus how many sets you have in your application.
But I am unsure how many times the case you mentioned happens (s = dummy_set) in the applications I am looking at. Thanks, -S- On Fri, Jan 9, 2009 at 12:01 AM, Andrew Eisenberg <[email protected]>wrote: > Hmmm...this gets a little tricky because what if somewhere in the code > there is: > s = dummy_set; > Should future calls to s still be advised? > > What you are trying to do is based on the lexical structure of the > code, so I think you will need to examine the joinpoint. You could > try: > > before(Set maybe_s, TestClass test) : call(* java.util.Set.add(*)) && > target(maybe_s) && this(test) && within(TestClass) && if > (maybe_s.equals(test.s)) { > // do something > } > > but this fails if you have the above line (s = dummy_set). > > You could also try reflection, using thisJoinPoint or > thisJoinPointStaticPart. One of these two fields might be able to > provide you with information about the joinpoint's signature that you > can use to determine the field name. But I am a little rusty here and > don't have time to try it out. > > Hope this helps, > --a > > > On Thu, Jan 8, 2009 at 2:43 PM, 100ji <[email protected]> wrote: > > Hi all, > > > > I am writing a pointcut whose spec is as follows: "Instrument all add and > > remove calls on a field f of type java.util.Set in class C". > > > > So for example if I have a TestClass like the one below, > > > > public class TestClass { > > > > Event e; > > TestInnerClass ic ; > > Set<Event> s; > > Set<Event> dummy_set; > > > > public boolean addToSet(Event e) { > > s.add(e); > > return dummy_set.add(e); > > } > > } > > > > I want to track all the adds to the field s but not to dummy set. I have > > tried the following approaches: > > > > pointcut p2(Object o) : call(* java.util.Set.add(..)) && > > target(TestClass.s); > > > > pointcut p2(Object o, Object newValue) : > > args(newValue) && this(o) && > > target(TestClass.s) && > > call(* java.util.Set.add(..)); > > > > pointcut p2(Object o, Object newValue) : > > args(newValue) && this(o) && > > call(java.util.Set TestClass.s.add(..)); > > > > Obviously, None of these approaches work as expected. Can anyone tell me > > what I am missing? > > > > TIA, > > -S- > > > > _______________________________________________ > > aspectj-users mailing list > > [email protected] > > https://dev.eclipse.org/mailman/listinfo/aspectj-users > > > > > _______________________________________________ > aspectj-users mailing list > [email protected] > https://dev.eclipse.org/mailman/listinfo/aspectj-users >
_______________________________________________ aspectj-users mailing list [email protected] https://dev.eclipse.org/mailman/listinfo/aspectj-users
