[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [aspectj-users] A newbie writes
|
Title: A newbie writes
This is my first post to the list.
I'm just getting my head round AOP and have been making
reasonably good progress so far (I'm using the AJDT plugin for
Eclipse).
However, I can't seem to work out how to do a simple
pointcut.
I want to be able to inspect the value of Strings whenever
they are accessed.
I thought this would do it:
pointcut
fieldtest(String s) : target(s) && get(* *.*);
before(String s) :
fieldtest(s) {
System.out.println("String value read: " + s);
}
But it's not being triggered.
I can't find any examples in the documentation showing how to
do this sort of thing.
Any suggestions would be greatly appreciated.
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).
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). 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..*.*);
where you
substitute com.mycompany with whatever base package your classes live in. Note
the two dots after mycompany.
Let me know if
this helps.
-Antti-