Spec-Zone.ru › OpenJDK 27

Interface CodeModel

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). 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(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

Method Summary

Modifier and Type Method Description
List<ExceptionCatch> exceptionHandlers()
Returns the exception table of the method.
Optional<MethodModel> parent()
Returns the enclosing method, if known.

Methods declared in interface AttributedElement

attributes, findAttribute, findAttributes
Modifier and Type Method Description
List<Attribute<?>> attributes()
Returns the attributes of this structure.
default <T extends Attribute<T>>
Optional<T>
findAttribute(AttributeMapper<T> attr)
Finds an attribute by name.
default <T extends Attribute<T>>
List<T>
findAttributes(AttributeMapper<T> attr)
Finds attributes by name.

Methods declared in interface CompoundElement

elementList, elementStream, forEach, iterator, toDebugString
Modifier and Type Method Description
default List<CodeElement> elementList()
Returns a List containing all member elements in this compound element.
default Stream<CodeElement> elementStream()
Returns a Stream containing all member elements in this compound element.
void forEach(Consumer<? super CodeElement> consumer)
Invokes the provided handler with each member element in this compound element.
default Iterator<CodeElement> iterator()
Returns an Iterator describing all member elements in this compound element.
default String toDebugString()
Returns a text representation of the compound element and its contents for debugging purposes.

Methods declared in interface Iterable

spliterator
Modifier and Type Method Description
default Spliterator<CodeElement> spliterator()
Creates a Spliterator over the elements described by this Iterable.

Method Details

parent

Optional<MethodModel> parent()
Returns the enclosing method, if known.
Returns:
the enclosing method, if known

exceptionHandlers

List<ExceptionCatch> exceptionHandlers()
Returns the exception table of the method. The exception table is also modeled by ExceptionCatch elements in the streaming view.
Returns:
the exception table of the method

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2026, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API