[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] non-initialization set/get join points
|
Hi -
> I want to capture all set/get join points which are not part
> of the initialization of the target object.
"part of the initialization" == "not run during the
execution of an initialization join point"
This is doable (ignoring "target" for the moment):
(get(* *) || set(* *)) && !cflow(initialization(new(..))
Optimized a bit:
(get(* *) || set(* *)) && !cflow(initialization(new(..))
&& !withincode(new(..))
&& within(com.mypackages..*)
Consider also cases like setting or getting a field in another
object during initialization, getter and setter methods, and
things like System.out.println("hi") ("System.out" translating
to a field-get). For sample code on point, see the samples
linked off the documentation page on the AspectJ web site
(from the inoculated article) titled...
- Warn when setting non-public field
- Prohibit field writes by other instances
- Prohibit writes by other instances and static methods
- Prohibit writes by subclasses
- Prohibit field writes after construction
To explain a bit, the problem with your code
!cflow(*.new(..))
is that cflow takes a pointcut, not a signature. Also, you might
want to use initialization instead of constructor-execution
(see the FAQ for an explanation of the differences), so try
!cflow(initialization(com.packages..*.new(..)))
Now, about my suggestion to use "com.packages..*" rather than "*":
the programming guide implementation section describes what code is
affected by ajc. Advising java.* classes would require weaving
Sun's rt.jar and ensuring those are loaded, so you probably don't
want to do that.
Style-wise, it is often a mistake to use * for a type pattern
(unless you are otherwise constraining the target types), since
you're simply saying "everything the compiler/weaver can get its
hands on" - i.e., deferring the crosscutting specification
to some build configuration. We advise folks to write pointcuts
as if the whole world were available, so your code can make sense
and work in implementations where "code the implementation controls"
is everything.
Hope this helps -
Wes
> ------------Original Message------------
> From: David Pearce <david.pearce@xxxxxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Thu, Nov-11-2004 4:50 PM
> Subject: [aspectj-users] non-initialization set/get join points
>
> Hi all,
>
> I have another interesting situation I want express, which I believe is
>
> not possible and I just want to check:
>
> Basically, I want to capture all set/get join points which are not part
>
> of the initialization of the target object. e.g.
>
> class test {
> private int x;
> test() {
> x = 0; // don't want to catch this
> }
> }
>
> So, I first thought of the following advice:
>
> before(): (get(* *.*) || set(* *.*)) && !withincode(*.new(..)) {
> ...
> }
>
> But. there are two distinct issues with this:
>
> 1) it hides sets/gets to one object from within the constructor of
> another.
>
> 2) it does not help in the following case:
>
> class test {
> private int x;
> test() { helperfn(); }
> private helperfn() { x = 0; } // will be caught
> }
>
> So. ignoring the first problem, I thought to try and extend my pointcut
>
> as follows:
>
> before(): (get(* *.*) || set(* *.*)) && !withincode(*.new(..)) &&
> !cflow(*.new(..)) {
> ...
> }
>
> But. I was surprised to find that this does not compile, because (I
> believe) cflow needs a definite function (i.e. no "*.").
>
> So, at this point I'm out of ideas. But, is there anything I've
> missed?
>
> Cheers,
>
> David J. Pearce
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>