8335290: Rename ClassFile::transform to ClassFile::transformClass

Reviewed-by: asotona
This commit is contained in:
Chen Liang 2024-07-03 05:03:56 +00:00
parent d51141e5fc
commit 0db9bc57de
58 changed files with 171 additions and 174 deletions

View file

@ -54,13 +54,9 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.lang.classfile.AccessFlags;
import java.lang.classfile.Attribute;
import java.lang.classfile.ClassModel;
import java.lang.classfile.ClassTransform;
import java.lang.classfile.ClassFile;
import java.lang.classfile.attribute.ModuleAttribute;
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
import jdk.internal.javac.PreviewFeature;
import jdk.internal.loader.BuiltinClassLoader;
import jdk.internal.loader.BootLoader;
import jdk.internal.loader.ClassLoaders;
@ -1588,7 +1584,7 @@ public final class Module implements AnnotatedElement {
private Class<?> loadModuleInfoClass(InputStream in) throws IOException {
final String MODULE_INFO = "module-info";
var cc = ClassFile.of(ClassFile.ConstantPoolSharingOption.NEW_POOL);
byte[] bytes = cc.transform(cc.parse(in.readAllBytes()), (clb, cle) -> {
byte[] bytes = cc.transformClass(cc.parse(in.readAllBytes()), (clb, cle) -> {
switch (cle) {
case AccessFlags af -> clb.withFlags(AccessFlag.INTERFACE,
AccessFlag.ABSTRACT, AccessFlag.SYNTHETIC);

View file

@ -32,7 +32,6 @@ import java.util.function.Consumer;
import java.util.function.Function;
import java.lang.classfile.attribute.ModuleAttribute;
import java.lang.classfile.attribute.UnknownAttribute;
import java.lang.classfile.constantpool.ClassEntry;
import java.lang.classfile.constantpool.ConstantPoolBuilder;
import java.lang.classfile.constantpool.Utf8Entry;
@ -435,15 +434,15 @@ public sealed interface ClassFile
* This method behaves as if:
* {@snippet lang=java :
* this.build(model.thisClass(), ConstantPoolBuilder.of(model),
* b -> b.transform(model, transform));
* clb -> clb.transform(model, transform));
* }
*
* @param model the class model to transform
* @param transform the transform
* @return the bytes of the new class
*/
default byte[] transform(ClassModel model, ClassTransform transform) {
return transform(model, model.thisClass(), transform);
default byte[] transformClass(ClassModel model, ClassTransform transform) {
return transformClass(model, model.thisClass(), transform);
}
/**
@ -458,8 +457,8 @@ public sealed interface ClassFile
* @param transform the transform
* @return the bytes of the new class
*/
default byte[] transform(ClassModel model, ClassDesc newClassName, ClassTransform transform) {
return transform(model, TemporaryConstantPool.INSTANCE.classEntry(newClassName), transform);
default byte[] transformClass(ClassModel model, ClassDesc newClassName, ClassTransform transform) {
return transformClass(model, TemporaryConstantPool.INSTANCE.classEntry(newClassName), transform);
}
/**
@ -473,7 +472,7 @@ public sealed interface ClassFile
* This method behaves as if:
* {@snippet lang=java :
* this.build(newClassName, ConstantPoolBuilder.of(model),
* b -> b.transform(model, transform));
* clb -> clb.transform(model, transform));
* }
*
* @param model the class model to transform
@ -481,7 +480,7 @@ public sealed interface ClassFile
* @param transform the transform
* @return the bytes of the new class
*/
byte[] transform(ClassModel model, ClassEntry newClassName, ClassTransform transform);
byte[] transformClass(ClassModel model, ClassEntry newClassName, ClassTransform transform);
/**
* Verify a classfile. Any verification errors found will be returned.

View file

@ -33,7 +33,7 @@ import jdk.internal.javac.PreviewFeature;
/**
* A transformation on streams of elements. Transforms are used during
* transformation of classfile entities; a transform is provided to a method like
* {@link ClassFile#transform(ClassModel, ClassTransform)}, and the elements of the class,
* {@link ClassFile#transformClass(ClassModel, ClassTransform)}, and the elements of the class,
* along with a builder, are presented to the transform.
*
* <p>The subtypes of {@linkplain

View file

@ -107,6 +107,6 @@ public sealed interface ClassRemapper extends ClassTransform permits ClassRemapp
* @return re-mapped class file bytes
*/
default byte[] remapClass(ClassFile context, ClassModel clm) {
return context.transform(clm, map(clm.thisClass().asSymbol()), this);
return context.transformClass(clm, map(clm.thisClass().asSymbol()), this);
}
}

View file

@ -130,7 +130,7 @@ class PackageSnippets {
void codeLocalsShifting(ClassModel classModel) {
// @start region="codeLocalsShifting"
byte[] newBytes = ClassFile.of().transform(
byte[] newBytes = ClassFile.of().transformClass(
classModel,
(classBuilder, classElement) -> {
if (classElement instanceof MethodModel method)
@ -145,7 +145,7 @@ class PackageSnippets {
void codeRelabeling(ClassModel classModel) {
// @start region="codeRelabeling"
byte[] newBytes = ClassFile.of().transform(
byte[] newBytes = ClassFile.of().transformClass(
classModel,
ClassTransform.transformingMethodBodies(
CodeTransform.ofStateful(CodeRelabeler::of)));
@ -160,7 +160,7 @@ class PackageSnippets {
var targetFieldNames = target.fields().stream().map(f -> f.fieldName().stringValue()).collect(Collectors.toSet());
var targetMethods = target.methods().stream().map(m -> m.methodName().stringValue() + m.methodType().stringValue()).collect(Collectors.toSet());
var instrumentorClassRemapper = ClassRemapper.of(Map.of(instrumentor.thisClass().asSymbol(), target.thisClass().asSymbol()));
return ClassFile.of().transform(target,
return ClassFile.of().transformClass(target,
ClassTransform.transformingMethods(
instrumentedMethodsFilter,
(mb, me) -> {
@ -191,7 +191,7 @@ class PackageSnippets {
//inlined target locals must be shifted based on the actual instrumentor locals
codeBuilder.block(inlinedBlockBuilder -> inlinedBlockBuilder
.transform(targetCodeModel, CodeLocalsShifter.of(mm.flags(), mm.methodTypeSymbol())
.transform(targetCodeModel, CodeLocalsShifter.of(mm.flags(), mm.methodTypeSymbol())
.andThen(CodeRelabeler.of())
.andThen((innerBuilder, shiftedTargetCode) -> {
//returns must be replaced with jump to the end of the inlined method

View file

@ -195,7 +195,7 @@ class PackageSnippets {
builder.with(element);
};
var cc = ClassFile.of();
byte[] newBytes = cc.transform(cc.parse(bytes), ct);
byte[] newBytes = cc.transformClass(cc.parse(bytes), ct);
// @end
}
@ -346,7 +346,7 @@ class PackageSnippets {
void codeRelabeling(ClassModel classModel) {
// @start region="codeRelabeling"
byte[] newBytes = ClassFile.of().transform(classModel,
byte[] newBytes = ClassFile.of().transformClass(classModel,
ClassTransform.transformingMethodBodies(
CodeTransform.ofStateful(CodeRelabeler::of)));
// @end
@ -360,7 +360,7 @@ class PackageSnippets {
var targetFieldNames = target.fields().stream().map(f -> f.fieldName().stringValue()).collect(Collectors.toSet());
var targetMethods = target.methods().stream().map(m -> m.methodName().stringValue() + m.methodType().stringValue()).collect(Collectors.toSet());
var instrumentorClassRemapper = ClassRemapper.of(Map.of(instrumentor.thisClass().asSymbol(), target.thisClass().asSymbol()));
return ClassFile.of().transform(target,
return ClassFile.of().transformClass(target,
ClassTransform.transformingMethods(
instrumentedMethodsFilter,
(mb, me) -> {