ClassRemapper (Java SE 22 & JDK 22)
Description: declaration: module: java.base, package: java.lang.classfile.components, interface: ClassRemapper
Keywords: java.lang.classfile.components.ClassRemapper interface

Module java.base
Package java.lang.classfile.componentsPREVIEW

# Interface ClassRemapper

All Superinterfaces:
  `ClassFileTransformPREVIEW<ClassTransformPREVIEW,ClassElementPREVIEW,ClassBuilderPREVIEW>`, `ClassTransformPREVIEW`

public sealed interface ClassRemapper extends ClassTransformPREVIEW
`ClassRemapper` is a preview API of the Java platform.
Programs can only use `ClassRemapper` when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
`ClassRemapper` is a `ClassTransform`PREVIEW, `FieldTransform`PREVIEW, `MethodTransform`PREVIEW and `CodeTransform`PREVIEW deeply re-mapping all class references in any form, according to given map or map function.

The re-mapping is applied to superclass, interfaces, all kinds of descriptors and signatures, all attributes referencing classes in any form (including all types of annotations), and to all instructions referencing to classes.

Primitive types and arrays are never subjects of mapping and are not allowed targets of mapping.

Arrays of reference types are always decomposed, mapped as the base reference types and composed back to arrays.

Since:
  22

- ## Nested Class Summary

  ### Nested classes/interfaces declared in interface java.lang.classfile.ClassFileTransformPREVIEW

  `ClassFileTransform.ResolvedTransformPREVIEW<E extends ClassFileElementPREVIEW>`

- ## Field Summary

  ### Fields declared in interface java.lang.classfile.ClassTransformPREVIEW

  `ACCEPT_ALL`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `CodeTransformPREVIEW`
  `asCodeTransform()`
  Returns this `ClassRemapper` as `CodeTransform`PREVIEW instance.
  `FieldTransformPREVIEW`
  `asFieldTransform()`
  Returns this `ClassRemapper` as `FieldTransform`PREVIEW instance.
  `MethodTransformPREVIEW`
  `asMethodTransform()`
  Returns this `ClassRemapper` as `MethodTransform`PREVIEW instance.
  `ClassDesc`
  `map(ClassDesc desc)`
  Access method to internal class mapping function.
  `static ClassRemapperPREVIEW`
  `of(Function<ClassDesc,ClassDesc> mapFunction)`
  Creates new instance of `ClassRemapper` instructed with a map function.
  `static ClassRemapperPREVIEW`
  `of(Map<ClassDesc,ClassDesc> classMap)`
  Creates new instance of `ClassRemapper` instructed with a class map.
  `default byte[]`
  `remapClass(ClassFilePREVIEW context, ClassModelPREVIEW clm)`
  Remaps the whole ClassModel into a new class file, including the class name.

  ### Methods declared in interface java.lang.classfile.ClassFileTransformPREVIEW

  `accept, atEnd, atStart`

  ### Methods declared in interface java.lang.classfile.ClassTransformPREVIEW

  `andThen, resolve`

- ## Method Details

  - ### of

    static ClassRemapperPREVIEW of(Map<ClassDesc,ClassDesc> classMap)
    Creates new instance of `ClassRemapper` instructed with a class map. Map may contain only re-mapping entries, identity mapping is applied by default.
    Parameters:
      `classMap` - class map
    Returns:
      new instance of `ClassRemapper`

  - ### of

    static ClassRemapperPREVIEW of(Function<ClassDesc,ClassDesc> mapFunction)
    Creates new instance of `ClassRemapper` instructed with a map function. Map function must return valid `ClassDesc` of an interface or a class, even for identity mappings.
    Parameters:
      `mapFunction` - class map function
    Returns:
      new instance of `ClassRemapper`

  - ### map

    ClassDesc map(ClassDesc desc)
    Access method to internal class mapping function.
    Parameters:
      `desc` - source class
    Returns:
      target class

  - ### asFieldTransform

    FieldTransformPREVIEW asFieldTransform()
    Returns this `ClassRemapper` as `FieldTransform`PREVIEW instance.
    Returns:
      this `ClassRemapper` as `FieldTransform`PREVIEW instance

  - ### asMethodTransform

    MethodTransformPREVIEW asMethodTransform()
    Returns this `ClassRemapper` as `MethodTransform`PREVIEW instance.
    Returns:
      this `ClassRemapper` as `MethodTransform`PREVIEW instance

  - ### asCodeTransform

    CodeTransformPREVIEW asCodeTransform()
    Returns this `ClassRemapper` as `CodeTransform`PREVIEW instance.
    Returns:
      this `ClassRemapper` as `CodeTransform`PREVIEW instance

  - ### remapClass

    default byte[] remapClass(ClassFilePREVIEW context, ClassModelPREVIEW clm)
    Remaps the whole ClassModel into a new class file, including the class name.
    Parameters:
      `context` - ClassFile context
      `clm` - class model to re-map
    Returns:
      re-mapped class file bytes