Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for accessing fiels on fields/method calls #1149

Open
avshenuk opened this issue Nov 11, 2021 · 3 comments
Open

Support for accessing fiels on fields/method calls #1149

avshenuk opened this issue Nov 11, 2021 · 3 comments
Assignees
Milestone

Comments

@avshenuk
Copy link

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 :)

@raphw
Copy link
Owner

raphw commented Nov 11, 2021

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 raphw self-assigned this Nov 11, 2021
@raphw raphw added this to the 1.12.1 milestone Nov 11, 2021
@avshenuk
Copy link
Author

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

@raphw
Copy link
Owner

raphw commented Nov 11, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants