Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] A newbie writes

I think that there are two separate issues that got mixed together. The first is a possible bug, and the second is a possible language extension.

I have some code that uses the set join point a lot in order to monitor strings. It looks something like this:

pointcut setStrings (String newString): set (String *.*) && args (newString).

In this case, it works well and find all the places where a string is being set.

The corresponding pointcut for get doesn't work for me.

pointcut getStrings (String s): get (String *.*) && args (string).

I don't think this is a language extension. I think this is a bug. I expect get and args to work in orchestration just like set and args.

The post below also mentions the possibility that a user would like to find the old value of a string before it is being set. I agree that this could be a possible language extension.

Echlin Harmer, Elizabeth wrote:

From my experimenting, if I have a class Foo with a String member str, in order to match a get, I have to use the pointcut get(String *.*) && target(foo). For sets, you could use set(String) && args(str), but that gets the new value of the string, not the old value. It looks like you can't do a wildcard to get any or all the string members. Best I could find is a series
pointcut fieldTest1(Foo foo): get(String str1) && target(foo);
pointcut fieldTest2(Foo foo): get(String str2) && target(foo);
and so on. Then in the advice, once you have the class instance, use it to 'get' the desired get e.g.
before (Foo foo): fieldTest1(foo) { System.out.println( foo.str1 ); }
before (Foo foo): fieldTest2(foo) { System.out.println( foo.str2); }
That would really suck if you have a lot of Strings.
Currently AspectJ support the caller (this), the callee (target), and the parameters for a call or set (args), but nothing directly for getting an accessed field. Would it make sense to extend args in this case to return the accessed field value? That could work, but only for gets, and I bet as soon as it works for gets, somebody is going to want it for set, to get the old value before the set takes effect. Looks like a possible language extension... -----Original Message-----
*From:* Robbie Baldock [mailto:robbie.baldock@xxxxxxxxxxx]
*Sent:* September 13, 2004 10:13 AM
*To:* 'aspectj-users@xxxxxxxxxxx'
*Subject:* RE: [aspectj-users] A newbie writes

    Antti wrote:

    Thanks for the response.
> Your pointcut catches the access to instance and static variables
    of type string
     > (not access to local variables (access to which is not possible
    to catch) nor to arguments).

    That's not a problem - it's an instance variable I'm trying to watch.

     > If this is what you intended, there's still a gotcha: the get(*
    *.*) catches the
     > accesses that are in types visible to the aspect (either in the
    same package or imported).

    The aspect and the class are in the same package.

     > If you want your aspect to catch accesses in classes that are in
    different packages,
     > try something like pointcut fieldtest(String s) : target(s) &&
    get(String com.mycompany..*.*);

    I tried specifying the package in this way and still it still isn't
    noticing when my code accesses the field.  If I take out the "&&
    get()" the pointcut does trigger so it can definitely see the String
    field I'm trying to monitor.

    Can you think of any other reason why this pointcut might not be
    working?


    Robbie


    __________________________________________________
    This electronic message contains information which may be privileged
    and confidential.  The information is intended to be for the use of
    the individual(s) or entity named above.  If you are not the
    intended recipient, be aware that any disclosure, copying,
    distribution or use of the contents of this information is
    prohibited.  If you have received this electronic message in error,
    please notify us by telephone on 0131 476 6000 and delete the
    material from your computer.



Back to the top