I need to get trace (value before and after the field is set) when a field of a Java class is written each time. I think AspectJ pointcuts could perform this operation. I've the code that works for all method calls in runtime. Now I need similar stuff for class attribute. I know I can use setter methods to get it. However, I'm wondering is there any other way in AspectJ that can track the attribute value directly when it is written each time (may be in constructor, or anywhere in the code). Thanks in advance.
I recommend to read the AspectJ documentation before asking general questions like these here, e.g. the chapter on pointcuts. There you will find get(FieldPattern)
and set(FieldPattern)
pointcuts. Examples:
get(* *)
set(private my.package..*)
get(* org.foo.MyClass.*)
set(* *..*User.*Name)