Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Logging variables

Hi Rashid,
you should have a look at the complete list of pointcuts in AspectJ and
relative join points [1]. Access (both in read and write) to a member
variable IS a join point, and can be intercepted using the get() and
set() pointcuts [2], while calling a getter and setter is a method call,
so it IS a join point and can be matched both with execution() and
call() pointcuts [2].

Assignment and read of a local variable is not a join point, so cannot
be intercepted by any pointcut. This is because variables internal to a
method may exist only in code, and can be completely removed by the
compiler, their name is not retained in the class file, and more
generally is a bad idea to anchor your logic to an internal variable.

In you case, like A obj = new B(); you can intercept the call to new B()
(as it is a method/constructor call) using the execution() and the
call() pointcuts. [3] Using an after advice you can modify properties of
the newly created B instance, and using an around advice you can even
return another class (as long as it is a subclass of B)

Hope this helps,
Simone

[1] Join points :
http://www.eclipse.org/aspectj/doc/released/progguide/semantics-joinPoints.html
[2] get() and set(), call() and execution() :
http://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html#primitive-pointcuts
[3] constructors :
http://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html#type-patterns
(the last section)

Rashid Mahmood wrote:
> Thanks Jochen.
>
> By Late binding means dynamic binding like
>           A obj = new B();
>
> So there is no possibility to weave local variables assignments with
> AspectJ.
>
> And for member variables, Advicing Setter method is the only way?
>
> --- On *Fri, 10/10/08, Jochen Wuttke /<jochen.wuttke@xxxxxx>/* wrote:
>
>     From: Jochen Wuttke <jochen.wuttke@xxxxxx>
>     Subject: Re: [aspectj-users] Logging variables
>     To: aspectj-users@xxxxxxxxxxx
>     Date: Friday, October 10, 2008, 6:32 AM
>
>     On Oct 10, 2008, at 2:41 PM, rmahmood wrote:
>
>     >
>     > Hi All,
>     >
>     > i am looking for some way to weave variable assignment statements.
>     >>> From different
>      discussions it seems that the only possibility is
>     to
>     > advice Setter methods for member variable assignment.
>     >
>     > But what about local variables within a method or assignment to
>     > a variable by a method return value.
>     >
>     > For assignments with late bindings it looks that this is not possible
>     > with AspectJ as it provides load time weaving.
>
>     I'm not sure what you mean by "late bindings". But the problem
>     with AJ  
>     is, AFAIK, that the names of local variables are not stored in class  
>     files, i.e. they are not available for weaving. Instead the Java  
>     compiler assigns them numbers (which show up in the class file for  
>     LOAD instructions), but since there is no mapping between these  
>     numbers and the named variables in the source that the AspectJ weaver  
>     has access to, it is not possible to weave into local variable
>      accesses.
>
>     Jochen
>     _______________________________________________
>     aspectj-users mailing list
>     aspectj-users@xxxxxxxxxxx
>     https://dev.eclipse.org/mailman/listinfo/aspectj-users
>               
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>   


-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
MALE human being programming a computer   http://www.simonegianni.it/



Back to the top