RFR: 8355658: Allow transforms to run on elements generated by a builder
Chen Liang
liach at openjdk.org
Mon Apr 28 04:33:49 UTC 2025
On Mon, 28 Apr 2025 01:43:32 GMT, Chen Liang <liach at openjdk.org> wrote:
> Transforms can run on a stream of class file elements. Currently, that stream can only be from a CompoundElement. We can allow a ClassFileBuilder to provide such a stream too; a recent request https://mail.openjdk.org/pipermail/classfile-api-dev/2025-April/000698.html asks for this as well.
>
> With this patch, we can now emulate this ASM pattern easily:
>
>
> // ASM
> ClassVisitor cv = new DelegateClassVisitor(new ClassWriter(...));
> cv.visitXxx(); // write elements through the delegate
>
> // ClassFile API
> cf.build(..., clb0 -> clb0.transforming((clb, cle) -> /*process */, clb -> {
> // write elements through delegate
> }));
>
>
> Notably, this patch introduces a source incompatibility (but not binary) in order to allow users to call `transform(model, (xb, xe) -> {})` or `transforming((xb1, xe) -> {}, xb1 -> {})`. This has little impact if users don't use `ClassFileBuilder` as a type directly (which according to grep.app, there are only two sites on whole GitHub, both updated in this PR). A release note has been created for this incompatibility at https://bugs.openjdk.org/browse/JDK-8355665; please review too.
Testing: tier 1-3 passed
-------------
PR Comment: https://git.openjdk.org/jdk/pull/24908#issuecomment-2833954434
More information about the compiler-dev
mailing list