The line:
test.address.postal_code = "12345";
will result in a flow like:
before-get test.address
return test.address
after-get test.address
before-set test.address.postal_code
set postal_code
after-set test.address.postal_code
in AspectJ. Is there a pointcut that will have test as target (like before-get test.adddres and after-get test.address) but will occur after "after-set test.address.postal_code" ?
No, because your line of code is equivalent to:
Object address = test.address;
address.postal_code = "12345";
I.e. the two field accesses (first read, then write) are done one after another. Chaining them as you did in a "fluent" way is just syntactic sugar. BTW, if your Test
class can directly access Address
members, you have an encapsulation problem anyway, but this is just a personal remark.
If you want to know if the address is assigned to a member of another class you need to keep state within the aspect, which is possible but a bit dirty. Maybe you want to change the application design instead of patching up bad design with hacky aspects. ;-)