APIdia Launch Partner
Top Description Methods
java.lang.classfile

public sealed Interface AttributedElement

extends ClassFileElement
permits ClassModel, CodeModel, FieldModel, MethodModel, RecordComponentInfo, AbstractUnboundModel<E>
Known Direct Subinterfaces
java.lang.classfile.ClassModel, java.lang.classfile.CodeModel, java.lang.classfile.FieldModel, java.lang.classfile.MethodModel, java.lang.classfile.attribute.RecordComponentInfo
Known Direct Implementers
jdk.internal.classfile.impl.AbstractUnboundModel
Imports
java.lang.classfile.attribute.CodeAttribute, .RecordComponentInfo, java.util.ArrayList, .Collections, .List, .Optional, jdk.internal.classfile.impl.AbstractUnboundModel

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.

Since
24
Java Virtual Machine Specification
4.7 Attributes
See Also
java.lang.classfile.attribute

Method Summary

Modifier and TypeMethod and Description
public List<Attribute<?>>

Returns:

the attributes of this structure
attributes
()

Returns the attributes of this structure.

public default <
the type of the attribute
T extends Attribute<T>
>
Optional<T>

Returns:

the attribute, or Optional.empty() if the attribute is not present
findAttribute
(AttributeMapper<T>
the attribute mapper
attr
)

Finds an attribute by name.

public default <
the type of the attribute
T extends Attribute<T>
>
List<T>

Returns:

the attributes, or an empty List if the attribute is not present
findAttributes
(AttributeMapper<T>
the attribute mapper
attr
)

Finds attributes by name.

Method Detail

attributesback to summary
public List<Attribute<?>> attributes()

Returns the attributes of this structure.

Returns:List<Attribute<?>>

the attributes of this structure

findAttributeback to summary
public 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 = null; MethodBuilder mb = null; method.findAttribute(Attributes.code()).ifPresent(mb);
MethodModel method = ...
MethodBuilder mb = ...
method.findAttribute(Attributes.code()).ifPresent(mb);
Parameters
<T>
the type of the attribute
attr:AttributeMapper<T>

the attribute mapper

Returns:Optional<T>

the attribute, or Optional.empty() if the attribute is not present

findAttributesback to summary
public 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.

Parameters
<T>
the type of the attribute
attr:AttributeMapper<T>

the attribute mapper

Returns:List<T>

the attributes, or an empty List if the attribute is not present