0

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" ?

th3falc0n
  • 1,389
  • 1
  • 12
  • 33

1 Answers1

1

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. ;-)

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • Thanks for pointing this out. As I had 2 approaches of solving my problem your answer to http://stackoverflow.com/questions/27906712/get-the-value-of-the-accessed-field-within-a-get-pointcut has made this question kind of obsolete ;) – th3falc0n Jan 13 '15 at 18:14