[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [aspectj-users] A newbie writes
|
Title: RE: [aspectj-users] A newbie writes
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.