RFR: 8355658: Allow transforms to run on elements generated by a builder
Chen Liang
liach at openjdk.org
Mon Apr 28 01:49:34 UTC 2025
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.
-------------
Commit messages:
- 8355658: Allow transforms to run on elements generated by a builder
Changes: https://git.openjdk.org/jdk/pull/24908/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=24908&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8355658
Stats: 301 lines in 11 files changed: 206 ins; 26 del; 69 mod
Patch: https://git.openjdk.org/jdk/pull/24908.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/24908/head:pull/24908
PR: https://git.openjdk.org/jdk/pull/24908
More information about the compiler-dev
mailing list