AttributeMapper (Java SE 23 & JDK 23)
Description: declaration: module: java.base, package: java.lang.classfile, interface: AttributeMapper
Keywords: java.lang.classfile.AttributeMapper interface

# Interface AttributeMapper<A>

Type Parameters:
  `A` - the attribute type

public interface AttributeMapper<A>
`AttributeMapper` is a preview API of the Java platform.
Programs can only use `AttributeMapper` when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Bidirectional mapper between the classfile representation of an attribute and how that attribute is modeled in the API. The attribute mapper is used to parse the classfile representation into a model, and to write the model representation back to a classfile. For each standard attribute, there is a predefined attribute mapper defined in `Attributes`PREVIEW. For nonstandard attributes, clients can define their own AttributeMapperPREVIEW. Classes that model nonstandard attributes should extend `CustomAttribute`PREVIEW.

Since:
  22

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Interface
  Description
  `static enum`
  `AttributeMapper.AttributeStabilityPREVIEW`
  Preview.
  Attribute stability indicator

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default boolean`
  `allowMultiple()`
  Returns whether this attribute may appear more than once in a given location.
  `String`
  `name()`
  Returns the name of the attribute.
  `A`
  `readAttribute(AttributedElementPREVIEW enclosing, ClassReaderPREVIEW cf, int pos)`
  Create an `Attribute`PREVIEW instance from a classfile.
  `AttributeMapper.AttributeStabilityPREVIEW`
  `stability()`
  Returns attribute stability indicator.
  `void`
  `writeAttribute(BufWriterPREVIEW buf, A attr)`
  Write an `Attribute`PREVIEW instance to a classfile.

- ## Method Details

  - ### name

    String name()
    Returns the name of the attribute.
    Returns:
      the name of the attribute

  - ### readAttribute

    A readAttribute(AttributedElementPREVIEW enclosing, ClassReaderPREVIEW cf, int pos)
    Create an `Attribute`PREVIEW instance from a classfile.
    Parameters:
      `enclosing` - The class, method, field, or code attribute in which this attribute appears
      `cf` - The `ClassReader`PREVIEW describing the classfile to read from
      `pos` - The offset into the classfile at which the attribute starts
    Returns:
      the new attribute

  - ### writeAttribute

    void writeAttribute(BufWriterPREVIEW buf, A attr)
    Write an `Attribute`PREVIEW instance to a classfile.
    Parameters:
      `buf` - The `BufWriter`PREVIEW to which the attribute should be written
      `attr` - The attribute to write

  - ### allowMultiple

    default boolean allowMultiple()
    Returns whether this attribute may appear more than once in a given location.
    Implementation Requirements:
      The default implementation returns `false`
    Returns:
      whether this attribute may appear more than once in a given location

  - ### stability

    AttributeMapper.AttributeStabilityPREVIEW stability()
    Returns attribute stability indicator.
    Returns:
      attribute stability indicator