Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] declaring a pointcut

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-

Back to the top