JDK-8335359 : Rename ClassFile::transform to ClassFile::transformClass
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang.classfile
  • Priority: P4
  • Status: Finalized
  • Resolution: Unresolved
  • Fix Versions: 24
  • Submitted: 2024-06-28
  • Updated: 2024-07-01
Related Reports
CSR :  
Relates :  
Description
Summary
-------

Rename `ClassFile::transform` to `ClassFile::transformClass`.

Problem
-------

`ClassFile::transform` has a name too similar to `ClassBuilder::transform`; yet `ClassFile::transform` acts more like `ClassBuilder::transformMethod`, which transforms a subordinate class/method, while `ClassBuilder::transform` transform an equal object (the object of the built type) to this builder, allowing users to perform extra actions on the builder at the same time.

Solution
--------

Rename `ClassFile::transform` to `ClassFile::transformClass`, to match up with `ClassBuilder::transformMethod`, `ClassBuilder::transformField`, `MethodBuilder::transformCode`.

Specification
-------------

There are various updates of the method reference in other specifications; those are ignored.

    diff --git a/src/java.base/share/classes/java/lang/classfile/ClassFile.java b/src/java.base/share/classes/java/lang/classfile/ClassFile.java
    index 1997ffb487c..08745f7e1ba 100644
    --- a/src/java.base/share/classes/java/lang/classfile/ClassFile.java
    +++ b/src/java.base/share/classes/java/lang/classfile/ClassFile.java
    @@ -435,15 +434,15 @@ default void buildModuleTo(Path path,
          * 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 @@ default byte[] transform(ClassModel model, ClassTransform transform) {
          * @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 @@ default byte[] transform(ClassModel model, ClassDesc newClassName, ClassTransfor
          * 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 @@ default byte[] transform(ClassModel model, ClassDesc newClassName, ClassTransfor
          * @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..