AttributedElement, ClassFileElement, CompoundElement<CodeElement>, Iterable<CodeElement>, MethodElementCodeAttributepublic sealed interface CodeModel extends CompoundElement<CodeElement>, AttributedElement, MethodElement permits CodeAttribute (not exhaustive)
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.
Code Attribute| Modifier and Type | Method | Description |
|---|---|---|
List |
exceptionHandlers() |
Returns the exception table of the method. |
Optional |
parent() |
Returns the enclosing method, if known. |
attributes, findAttribute, findAttributes
elementList, elementStream, forEach, iterator, toDebugString
spliterator
Optional<MethodModel> parent()
List<ExceptionCatch> exceptionHandlers()
ExceptionCatch elements in the streaming view.
© 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.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/classfile/CodeModel.html