-
CSR
-
Resolution: Withdrawn
-
P4
-
None
-
source
-
low
-
-
Java API
-
SE
Summary
Modify the generic signature of ClassFileBuilder, and add API to it to allow transforming elements produced by a builder handler.
Problem
In ASM there is a pattern where a user builds to a builder that immediately delegates all its output through a transform:
// ASM
ClassVisitor cv = new DelegateClassVisitor(new ClassWriter(...));
cv.visitXxx(); // write elements through the delegate
Such a pattern is not possible with current ClassFile API without advanced hacks.
A workaround for CodeBuilder
for such usages exist: it is CodeBuilder::transforming(CodeTransform, Consumer)
. We can base the new API off this one.
We wish to introduce this to the base ClassFileBuilder
class, yet the signature must represent a ClassFileTransform
with a type variable to support this covariant overriding type such as CodeBuilder
.
Solution
Expand the
CodeBuilder::transforming
API to the baseClassFileBuilder
so all builders can enjoy this facility and cover this use pattern.Declare a new type parameter in
ClassFileBuilder
that represents the integrated transform type, soCodeBuilder::transforming
is actually overridden.Provide migration helps in a release note on the original issue.
With this solution, we can emulate the ASM pattern with:
// ClassFile API
cf.build(..., clb0 -> clb0.transforming((clb, cle) -> /*process */, clb -> {
// write elements through delegate
}));
Specification
See attachment.
- csr of
-
JDK-8355658 Allow transforms to run on elements generated by a builder
-
- Open
-