[External] : RE: modifying a newly added method
Chen Liang
chen.l.liang at oracle.com
Thu Apr 24 22:23:40 UTC 2025
Hi Mark,
No, accept and atEnd are both the first transform. No-op accept just drops elements of the transformed objects; atEnd is called when all accept calls are done, so here you are actually operating on a new class.
I am thinking of adding transforming like that in CodeBuilder to other builders - CodeBuilder has this because CodeBuilder creation required no extra arguments. For other builders, I think we can just inherit arguments from the called builder.
Chen
________________________________
From: Mark Roberts <markro at cs.washington.edu>
Sent: Thursday, April 24, 2025 5:07 PM
To: Chen Liang <chen.l.liang at oracle.com>; classfile-api-dev at openjdk.org <classfile-api-dev at openjdk.org>
Subject: [External] : RE: modifying a newly added method
This approach looks interesting. Just want to make sure I understand the control flow.
The empty ‘accept’ is the first transform that does nothing.
‘atEnd’ is the second transform
‘andThen is the third transform which will see any changes made by the second transform
Correct?
Thank you,
Mark
From: Chen Liang <chen.l.liang at oracle.com<mailto:chen.l.liang at oracle.com>>
Sent: Tuesday, April 15, 2025 10:33 AM
To: Mark Roberts <markro at cs.washington.edu<mailto:markro at cs.washington.edu>>; classfile-api-dev at openjdk.org<mailto:classfile-api-dev at openjdk.org>
Subject: Re: modifying a newly added method
Hi Mark,
Unfortunately there is no easy way to do this, but it is doable.
One way can be that you start with a class transform with a dummy class model, and move your original class builder code into the atEnd of your first transform. Then, you can call andThen with the 2nd transform, which can get MethodModel views of methods built by your first transform.
Pseudocode:
Original:
cf.build(name, clb -> /* oldLambdaCode */)
Updated:
cf.build(clb -> clb.transform(dummyClassModel, new ClassTransform() {
@Override public void accept(ClassBuilder b, ClassEement e) {} // throw away
@Override public void atEnd(ClassBuilder clb) { /* oldLambdaCode */ }
}.andThen(/* your actual transform that can see your old lambda's methods as MethodModel*/))
That said, I had previously proposed to introduce something like CodeBuilder::transforming to other models, which could have probably covered your use case; however, other builders require extra arguments to be constructed (class name, field/method name and types) so we did not add these APIs back.
If you have an idea how such additions can be done, feel free to share your ideas.
Regards, Chen
________________________________
From: classfile-api-dev <classfile-api-dev-retn at openjdk.org<mailto:classfile-api-dev-retn at openjdk.org>> on behalf of Mark Roberts <markro at cs.washington.edu<mailto:markro at cs.washington.edu>>
Sent: Tuesday, April 15, 2025 12:15 PM
To: classfile-api-dev at openjdk.org<mailto:classfile-api-dev at openjdk.org> <classfile-api-dev at openjdk.org<mailto:classfile-api-dev at openjdk.org>>
Subject: modifying a newly added method
If I have added a new method to my classfile with
ClassBuilder.withMethod(...) I know it is not added to ClassModel.methods()
as that is an immutable list from the original, unmodified classfile. Is
there any way to get a MethodModel for this new method in order to modify it
further?
Thank you,
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20250424/fd2824aa/attachment.htm>
More information about the classfile-api-dev
mailing list