Support for accessing fiels on fields/method calls
Currently, there is no way to do a chain of field accesses. Like it is possible with method calls e.g.
.withMethodCall(MethodCall.invoke(...).onMethodCall())
So for instance, if I want to do something like
.withField("someFieldName").onMethodCall()
or
.withField("someFieldName").onField()
There is an option to provide a FieldLocator.Factory but it only operates within the current class.
There is one way it can be done in my mind, it's by using FieldAccessor e.g. like
.withMethodCall(FieldAccessor.ofField("someFieldName"))
and hence it can be chained as any other MethodCall.
But the problem is that FieldAccessor is an Implementation, not MethodCall :)
Yeah, I have been experimenting a bit with better DSLs but the complexity quickly explodes, so I am always wondering if a custom built StackManipulation is not an easier option in many of the more complex cases. Often, a MethodDelegation can also be a good substitute as it is easier to debug.
I'll review this another time, though, to see if there are some common patterns that are not supported. I cannot promise you a time-line for now, though, so I'd recommend you a custom stack manipulation or delegation for now.
@raphw Yeah, no rush. Thanks for spending time on this.
I will look into writing some custom stack manipulation. Am I right in assuming that it's easiest by making my own Implementation and ByteCodeAdapter?
Exactly. It really depends on how dynamic you want those things to be. You can create a custom implementation and resolve names and properties from each instrumented method. Or you can hardcode it in the stack manipulations using Implementation.Simple.