You have to use the AspectJ reflection API. Here's a snippet of code from Contract4J (InvariantFieldConditions.aj, to be specific). This would appear in your advice:

                Signature sig = thisJoinPoint.getSignature();
                String fieldName     = sig.getName();
                Class<?> clazz       = sig.getDeclaringType();
                SourceLocation loc   = thisJoinPoint.getSourceLocation();
                // Get the "old" value of the field.
                Field  field        = ((FieldSignature) sig).getField();
                Class<?> fieldClass = field.getType();

H.T.H.

dean

On Jun 24, 2008, at 1:37 PM, [EMAIL PROTECTED] wrote:

I want to intercept all field modifications on a class:

pointcut fieldMutator(TestObject o, Object v): set(* TestObject.*) &&
this(o) && args(v);

This gets me the object and the new value, but how do I get which
field is being modified?

Thanks.
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Dean Wampler, Ph.D.
dean at objectmentor.com
http://www.objectmentor.com
See also:
http://www.aspectprogramming.com  AOP advocacy site
http://aquarium.rubyforge.org     AOP for Ruby
http://www.contract4j.org         Design by Contract for Java5




_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to