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

Feature request: customize some details about static fields used to store references #927

Open
ljnelson opened this issue Sep 17, 2020 · 1 comment
Assignees
Milestone

Comments

@ljnelson
Copy link
Contributor

Hello; thanks for a great product. I know from personal experience how hard it is to run an open source project and this one is just fantastic. Thanks for all the time you put into it.

I had a request for what I hope is a small feature. Currently, there is a nice little feature of MethodCall where you can specify that it should be supplied with existing object references. I confess that this works like magic for me (I haven't dug into the code to see how it is accomplished, and I'm not sure how it differs from the with(Object...) call…)!

The references, it turns out, are stored in static fields inside the generated class (I was surprised to note these fields are not final…). That of course makes sense.

The fields used to store these references are named something like this: methodCall$4BJ1aAKz. I think that the name is generated via a constant prefix and RandomString#make().

While I can see that I could probably somehow supply my own ArgumentLoader machinery to customize this, it would be nice if there were an easy way in the API/DSL to specify how these reference-storing static fields should be named and decorated.

@raphw
Copy link
Owner

raphw commented Sep 17, 2020

Thanks, your feedback is very appreciated.

There is already a facility to change the name of synthetic methods Byte Buddy generates for dispatching. It makes sense to supply a similar mechanism for random field names. I'll need to see how this can be done in a consistent manner but I see how this makes sense and if it is meaningful to add.

What you can however do already today: Simply define a static field on the dynamic type yourself using .defineField. Then dispatch the method call to this field using the MethodCall facility. Finally, add a LoadedTypeInitializer where you set the field's value. It's three lines of code instead of one but it already allows for the flexibility you are asking for. I'll look into making this more convenient.

@raphw raphw self-assigned this Sep 17, 2020
@raphw raphw added this to the 1.10.14 milestone Sep 17, 2020
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