Module java.base
Package java.lang.classfile

# Interface CodeModel

≠
public abstract sealed interface CodeModel
extends java.lang.classfile.AttributedElement, java.lang.classfile.CompoundElement<java.lang.classfile.CodeElement>, java.lang.classfile.MethodElement
permits java.lang.classfile.attribute.CodeAttribute, jdk.internal.classfile.impl.BufferedCodeBuilder.Model
Comparing master and cf

All Superinterfaces:
  `AttributedElement, ClassFileElement, CompoundElement<CodeElement>, Iterable<CodeElement>, MethodElement`

All Known Subinterfaces:
  `CodeAttribute`

public sealed interface CodeModel extends CompoundElement<CodeElement>, AttributedElement, MethodElement permits CodeAttribute (not exhaustive)
Models the body of a method (the `Code` attribute). The instructions of the method body are accessed via a streaming view.

Since:
  24

A `Code` attribute is viewed as a composition of `CodeElement` s, which is the only way to access `Instruction` s; the order of elements of a code model is significant.

A `CodeModel` is obtained from `MethodModel.code()` , or in the traversal of the member elements of a method.

`MethodBuilder.withCode(Consumer)` is the main way to build code models. `MethodBuilder.transformCode(CodeModel, CodeTransform)` and `CodeBuilder.transforming(CodeTransform, Consumer)` allow creating new `Code` attributes by selectively processing the original code elements and directing the results to a code builder.

A `Code` attribute holds attributes, but they are usually not member elements, but are decomposed to `PseudoInstruction` , accessible according to `ClassFile.DeadLabelsOption` , `ClassFile.DebugElementsOption` , and `ClassFile.LineNumbersOption` . `StackMapTableAttribute` can only be accessed via explicit attribute reading, as it is considered a derived property from the code body.

See Java Virtual Machine Specification:
  4.7.3 The `Code` Attribute
Since:
  24
See Also:
  - `MethodModel.code()`
  - `CodeTransform`
  - `CodeAttribute`

## Methods

- =
  public abstract java.util.List<java.lang.classfile.instruction.ExceptionCatch> exceptionHandlers()
- =
  public abstract java.util.Optional<java.lang.classfile.MethodModel> parent()

## Summary

Differences
| Elements | Comments | Descriptions | Total
Added | Changed | Removed | Added | Changed | Removed | Added | Changed | Removed
--- | --- | --- | --- | --- | --- | --- | --- | ---
CodeModel |  |  |  |  |  |  | 3 |  | 3 | 6
Total |  |  |  |  |  |  | 3 |  | 3 | 6