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

# Interface CodeRelabeler

All Superinterfaces:
  `ClassFileTransformPREVIEW<CodeTransformPREVIEW,CodeElementPREVIEW,CodeBuilderPREVIEW>`, `CodeTransformPREVIEW`

public sealed interface CodeRelabeler extends CodeTransformPREVIEW
`CodeRelabeler` is a preview API of the Java platform.
Programs can only use `CodeRelabeler` when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A code relabeler is a `CodeTransform`PREVIEW replacing all occurrences of `Label`PREVIEW in the transformed code with new instances. All `LabelTarget`PREVIEW instructions are adjusted accordingly. Relabeled code graph is identical to the original.

Primary purpose of CodeRelabeler is for repeated injections of the same code blocks. Repeated injection of the same code block must be relabeled, so each instance of `Label`PREVIEW is bound in the target bytecode exactly once.

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.CodeTransformPREVIEW

  `ACCEPT_ALL`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static CodeRelabelerPREVIEW`
  `of()`
  Creates a new instance of CodeRelabeler.
  `static CodeRelabelerPREVIEW`
  `of(BiFunction<LabelPREVIEW,CodeBuilderPREVIEW,LabelPREVIEW> mapFunction)`
  Creates a new instance of CodeRelabeler using provided `BiFunction` to re-label the code.
  `static CodeRelabelerPREVIEW`
  `of(Map<LabelPREVIEW,LabelPREVIEW> map)`
  Creates a new instance of CodeRelabeler storing the label mapping into the provided map.
  `LabelPREVIEW`
  `relabel(LabelPREVIEW label, CodeBuilderPREVIEW codeBuilder)`
  Access method to internal re-labeling function.

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

  `accept, atEnd, atStart`

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

  `andThen, resolve`

- ## Method Details

  - ### of

    static CodeRelabelerPREVIEW of()
    Creates a new instance of CodeRelabeler.
    Returns:
      a new instance of CodeRelabeler

  - ### of

    static CodeRelabelerPREVIEW of(Map<LabelPREVIEW,LabelPREVIEW> map)
    Creates a new instance of CodeRelabeler storing the label mapping into the provided map.
    Parameters:
      `map` - label map actively used for relabeling
    Returns:
      a new instance of CodeRelabeler

  - ### of

    static CodeRelabelerPREVIEW of(BiFunction<LabelPREVIEW,CodeBuilderPREVIEW,LabelPREVIEW> mapFunction)
    Creates a new instance of CodeRelabeler using provided `BiFunction` to re-label the code.
    Parameters:
      `mapFunction` - function remapping labels
    Returns:
      a new instance of CodeRelabeler

  - ### relabel

    LabelPREVIEW relabel(LabelPREVIEW label, CodeBuilderPREVIEW codeBuilder)
    Access method to internal re-labeling function.
    Parameters:
      `label` - source label
      `codeBuilder` - builder to create new labels
    Returns:
      target label