Re: [abc-users] Tracematch vs aspect variable binding

From: Alan Teoh <alan.teoh07_at_imperial.ac.uk>
Date: Thu, 14 Feb 2008 15:35:05 +0000

Hi Pavel,

Thanks for the answer, I find it to be very helpful. Now I can
appreciate how much more cumbersome aspects in practice are when it
comes to this issue.

Pavel Avgustinov wrote:
> Hi Alan,
>
>
>> What changes do I need to make to the aspect so that it is equivalent to
>> the tracematch? I was thinking of writing code to compare the object
>> that is currently being evaluated on the aspect (i.e. compare
>> a2.equals(a1) ), but that looks a bit naive to me. I am fairly new to
>> aspect oriented programming, so I might have made a elementary mistake
>> somewhere in my aspect, and I would appreciate some help on this matter.
>>
>
> As you see, the code generated by the tracematch implementation results in the
> kind of matching you expect -- all the symbols in a particular filtered trace
> have the same binding of the 'a' variable. In AspectJ, there is no such
> restriction, and each piece of advice matches independently to all others. In
> particular, this means that while you have '&& target(a)' in both pointcuts
> in the aspect, that just associates the name 'a' with the target of the
> method call, but doesn't impose any further conditions.
>
> Thus, essentially your aspect maintains one withdrawal counter and one deposit
> counter *for all Account instances*, rather than a separate pair of counters
> for each instance.
>
> The way to achieve tracematch-like behaviour is to store the counters in a
> Map, say, associated with the Account for which they are. Each piece of
> advice would then look up the relevant counters to 'a' and update/read them.
> Alternatively, you could introduce the counters as intertype fields onto the
> Account class, and use a.countwd and a.countdp in your advice.
>
> Hope this helps,
> - Pavel
>
>
Received on Thu Feb 14 2008 - 15:35:11 GMT

This archive was generated by hypermail 2.2.0 : Thu Feb 14 2008 - 16:30:11 GMT