8335642: Hide Transform implementation for Class-File API

Reviewed-by: asotona
This commit is contained in:
Chen Liang 2024-07-15 12:11:53 +00:00
parent 2b0adfc2de
commit a253e0ff4b
9 changed files with 66 additions and 136 deletions

View file

@ -27,8 +27,9 @@ package java.lang.classfile;
import java.lang.constant.ClassDesc;
import java.util.function.Consumer;
import java.lang.classfile.constantpool.ConstantPool;
import java.lang.classfile.constantpool.ConstantPoolBuilder;
import jdk.internal.classfile.impl.TransformImpl;
import jdk.internal.javac.PreviewFeature;
/**
@ -71,25 +72,19 @@ public sealed interface ClassFileBuilder<E extends ClassFileElement, B extends C
*/
ConstantPoolBuilder constantPool();
/**
* {@return whether the provided constant pool is compatible with this builder}
* @param source the constant pool to test compatibility with
*/
default boolean canWriteDirect(ConstantPool source) {
return constantPool().canWriteDirect(source);
}
/**
* Apply a transform to a model, directing results to this builder.
* @param model the model to transform
* @param transform the transform to apply
* @return this builder
*/
default void transform(CompoundElement<E> model, ClassFileTransform<?, E, B> transform) {
default B transform(CompoundElement<E> model, ClassFileTransform<?, E, B> transform) {
@SuppressWarnings("unchecked")
B builder = (B) this;
var resolved = transform.resolve(builder);
var resolved = TransformImpl.resolve(transform, builder);
resolved.startHandler().run();
model.forEach(resolved.consumer());
resolved.endHandler().run();
return builder;
}
}