APIdia Launch Partner
Top Description Methods
java.lang.classfile

public sealed Interface CodeModel

extends CompoundElement<CodeElement>, AttributedElement, MethodElement
permits CodeAttribute, Model
Known Direct Subinterfaces
java.lang.classfile.attribute.CodeAttribute
Known Direct Implementers
jdk.internal.classfile.impl.BufferedCodeBuilder.Model
Imports
java.lang.classfile.ClassFile.DeadLabelsOption, .ClassFile.DebugElementsOption, .ClassFile.LineNumbersOption, java.lang.classfile.attribute.BootstrapMethodsAttribute, .CodeAttribute, .StackMapTableAttribute, java.lang.classfile.instruction.ExceptionCatch, java.util.List, .Optional, java.util.function.Consumer, jdk.internal.classfile.impl.BufferedCodeBuilder

Models the body of a method (the Code attribute). A Code attribute is viewed as a composition of CodeElements, which is the only way to access Instructions; 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 is the main way to build code models. MethodBuilder#transformCode and CodeBuilder#transforming 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 DeadLabelsOption, DebugElementsOption, and LineNumbersOption. StackMapTableAttribute can only be accessed via explicit attribute reading, as it is considered a derived property from the code body.

Since
24
Java Virtual Machine Specification
4.7.3 The Code Attribute
See Also
MethodModel#code(), CodeTransform, CodeAttribute

Method Summary

Modifier and TypeMethod and Description
public List<ExceptionCatch>

Returns:

the exception table of the method
exceptionHandlers
()

Returns the exception table of the method.

public Optional<MethodModel>

Returns:

the enclosing method, if known
parent
()

Returns the enclosing method, if known.

Inherited from java.lang.classfile.AttributedElement:
attributesfindAttributefindAttributes
Inherited from java.lang.classfile.CompoundElement:
elementListelementStreamforEachiteratortoDebugString

Method Detail

exceptionHandlersback to summary
public List<ExceptionCatch> exceptionHandlers()

Returns the exception table of the method. The exception table is also modeled by ExceptionCatch elements in the streaming view.

Returns:List<ExceptionCatch>

the exception table of the method

parentback to summary
public Optional<MethodModel> parent()

Returns the enclosing method, if known.

Returns:Optional<MethodModel>

the enclosing method, if known