Classfile API improve chaining of end handlers of transformations

Adam Sotona adam.sotona at oracle.com
Fri Aug 11 10:02:39 UTC 2023


Hi,
I found one transformation pattern frequent – to drop and add an element, or more generally to add end handler to an existing transformation.
One common example; to replace a class element with a new one (no matter if present in the source classfile or not) can be implemented as:
ClassTransform.dropping(e -> e instanceof WhateverElement).andThen(ClassTransform.endHandler(clb -> clb.with(newWhateverElement)));

However this pattern compose heavy-weight chain of transformations (just to add an extra building code at the end).

I propose to allow light-weight chaining of end handlers to the existing transformations. For example ClassTransform::endHandler instance method may produce a copy of the transformation with attached additional end handler. The example above may then look like:
ClassTransform.dropping(e -> e instanceof WhateverElement).endHandler(clb -> clb.with(newWhateverElement));

Actual static factory method ClassTransform.endHandler(… use can be refactored into ClassTransform.ACCEPT_ALL.endHandler(…


What do you think?

Thanks,
Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20230811/acd77924/attachment.htm>


More information about the classfile-api-dev mailing list