Spec-Zone.ru › OpenJDK 25

Interface AttributedElement

All Superinterfaces:
ClassFileElement
All Known Subinterfaces:
ClassModel, CodeAttribute, CodeModel, FieldModel, MethodModel, RecordComponentInfo
public sealed interface AttributedElement extends ClassFileElement permits ClassModel, CodeModel, FieldModel, MethodModel, RecordComponentInfo (not exhaustive)
A ClassFileElement describing a class file structure that has attributes, such as a class file, a field, a method, a Code attribute, or a record component.

Unless otherwise specified, most attributes that can be discovered in a CompoundElement implements the corresponding membership subinterface of ClassFileElement, and can be sent to a ClassFileBuilder to be integrated into the built structure.

See Java Virtual Machine Specification:
4.7 Attributes
Sealed Class Hierarchy Graph:
Sealed class hierarchy graph for AttributedElementSealed class hierarchy graph for AttributedElement
Since:
24
See Also:
  • java.lang.classfile.attribute

Method Summary

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.

Method Details

attributes

List<Attribute<?>> attributes()
Returns the attributes of this structure.
Returns:
the attributes of this structure

findAttribute

default <T extends Attribute<T>> Optional<T> findAttribute(AttributeMapper<T> attr)
Finds an attribute by name. This is suitable to find attributes that allow at most one instance in one structure. If this is used to find attributes that allow multiple instances in one structure, the first matching instance is returned.
API Note:
This can easily find an attribute and send it to another ClassFileBuilder, which is a Consumer:
MethodModel method = ...
MethodBuilder mb = ...
method.findAttribute(Attributes.code()).ifPresent(mb);
Type Parameters:
T - the type of the attribute
Parameters:
attr - the attribute mapper
Returns:
the attribute, or Optional.empty() if the attribute is not present

findAttributes

default <T extends Attribute<T>> List<T> findAttributes(AttributeMapper<T> attr)
Finds attributes by name. This is suitable to find attributes that allow multiple instances in one structure.
Type Parameters:
T - the type of the attribute
Parameters:
attr - the attribute mapper
Returns:
the attributes, or an empty List if the attribute is not present

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, 2025, 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.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/classfile/AttributedElement.html

Spec-Zone.ru

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