APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.jfr

public final Class AnnotationElement

extends Object
Class Inheritance
Imports
java.lang.annotation.Annotation, java.lang.reflect.Method, java.util.ArrayList, .Collections, .HashMap, .HashSet, .List, .Map, .Objects, .Set, .StringJoiner, jdk.jfr.internal.Type, .TypeLibrary, jdk.jfr.internal.util.Utils

Describes event metadata, such as labels, descriptions and units.

The following example shows how AnnotationElement can be used to dynamically define events.

List<AnnotationElement> typeAnnotations = new ArrayList<>(); typeAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld")); typeAnnotations.add(new AnnotationElement(Label.class, "Hello World")); typeAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started")); List<AnnotationElement> fieldAnnotations = new ArrayList<>(); fieldAnnotations.add(new AnnotationElement(Label.class, "Message")); List<ValueDescriptor> fields = new ArrayList<>(); fields.add(new ValueDescriptor(String.class, "message", fieldAnnotations)); EventFactory f = EventFactory.create(typeAnnotations, fields); Event event = f.newEvent(); event.commit();
List<AnnotationElement> typeAnnotations = new ArrayList<>();
typeAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
typeAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
typeAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));

List<AnnotationElement> fieldAnnotations = new ArrayList<>();
fieldAnnotations.add(new AnnotationElement(Label.class, "Message"));

List<ValueDescriptor> fields = new ArrayList<>();
fields.add(new ValueDescriptor(String.class, "message", fieldAnnotations));

EventFactory f = EventFactory.create(typeAnnotations, fields);
Event event = f.newEvent();
event.commit();
Since
9

Field Summary

Modifier and TypeField and Description
private final List<Object>
private final boolean
private final Type

Constructor Summary

AccessConstructor and Description
pack-priv
AnnotationElement(Type type, List<Object> objects, boolean boot)

public
AnnotationElement(Class<? extends Annotation>
interface extending java.lang.annotation.Annotation, not null
annotationType
,
Map<String, Object>
a Map with keys that match method names of the specified annotation interface
values
)

Creates an annotation element to use for dynamically defined events.

public
AnnotationElement(Class<? extends Annotation>
interface extending java.lang.annotation.Annotation, not null
annotationType
,
Object
the value that matches the value method of the specified annotationType
value
)

Creates an annotation element to use for dynamically defined events.

public
AnnotationElement(Class<? extends Annotation>
interface extending java.lang.annotation.Annotation, not null
annotationType
)

Creates an annotation element to use for dynamically defined events.

Method Summary

Modifier and TypeMethod and Description
private static void
checkType(Class<?> type)

public final <
the type of the annotation to query for and return if it exists
A
>
A

Returns:

this element's annotation for the specified annotation type if it exists, else null
getAnnotation
(Class<? extends Annotation>
the Class object corresponding to the annotation type, not null
annotationType
)

Returns the first annotation for the specified type if an AnnotationElement with the same name exists, else null.

public List<AnnotationElement>

Returns:

a list of meta annotation, not null
getAnnotationElements
()

Returns an immutable list of annotation elements for this AnnotationElement.

pack-priv Type
public long

Returns:

the type ID, not negative
getTypeId
()

Returns the type ID for this AnnotationElement.

public String

Returns:

type name, not null
getTypeName
()

Returns the fully qualified name of the annotation type that corresponds to this AnnotationElement (for example, "jdk.jfr.Label").

public Object

Returns:

the annotation value, not null.
getValue
(String
the name of the method in the annotation interface, not null.
name
)

Returns a value for this AnnotationElement.

public List<ValueDescriptor>

Returns:

the list of value descriptors for this Annotation, not null
getValueDescriptors
()

Returns an immutable list of descriptors that describes the annotation values for this AnnotationElement.

public List<Object>

Returns:

list of values, not null
getValues
()

Returns an immutable list of annotation values in an order that matches the value descriptors for this AnnotationElement.

public boolean

Returns:

true if method exists, false otherwise
hasValue
(String
name of the method in the annotation interface to find, not null
name
)

Returns true if an annotation value with the specified name exists in this AnnotationElement.

pack-priv boolean
private static boolean
isKnownJFRAnnotation(Class<? extends Annotation> annotationType)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationValuesback to summary
private final List<Object> annotationValues
inBootClassLoaderback to summary
private final boolean inBootClassLoader
typeback to summary
private final Type type

Constructor Detail

AnnotationElementback to summary
pack-priv AnnotationElement(Type type, List<Object> objects, boolean boot)
AnnotationElementback to summary
public AnnotationElement(Class<? extends Annotation> annotationType, Map<String, Object> values)

Creates an annotation element to use for dynamically defined events.

Supported value types are byte, int, short, long, double, float, boolean, char, and String. Enums, arrays and classes, are not supported.

If annotationType has annotations (directly present, indirectly present, or associated), then those annotation are recursively included. However, both the annotationType and any annotation found recursively must have the MetadataDefinition annotation.

To statically define events, see Event class.

Parameters
annotationType:Class<? extends Annotation>

interface extending java.lang.annotation.Annotation, not null

values:Map<String, Object>

a Map with keys that match method names of the specified annotation interface

Exceptions
IllegalArgumentException:
if value/key is null, an unsupported value type is used, or a value/key is used that doesn't match the signatures in the annotationType
AnnotationElementback to summary
public AnnotationElement(Class<? extends Annotation> annotationType, Object value)

Creates an annotation element to use for dynamically defined events.

Supported value types are byte, int, short, long, double, float, boolean, char, and String. Enums, arrays, and classes are not supported.

If annotationType has annotations (directly present, indirectly present, or associated), then those annotations are recursively included. However, both annotationType and any annotation found recursively must have the MetadataDefinition annotation.

To statically define events, see Event class.

Parameters
annotationType:Class<? extends Annotation>

interface extending java.lang.annotation.Annotation, not null

value:Object

the value that matches the value method of the specified annotationType

Exceptions
IllegalArgumentException:
if value/key is null, an unsupported value type is used, or a value/key is used that doesn't match the signatures in the annotationType
AnnotationElementback to summary
public AnnotationElement(Class<? extends Annotation> annotationType)

Creates an annotation element to use for dynamically defined events.

Supported value types are byte, short, int, long, double, float, boolean, char, and String. Enums, arrays, and classes are not supported.

If annotationType has annotations (directly present, indirectly present or associated), then those annotation are recursively included. However, both annotationType and any annotation found recursively must have the MetadataDefinition annotation.

To statically define events, see Event class.

Parameters
annotationType:Class<? extends Annotation>

interface extending java.lang.annotation.Annotation, not null

Method Detail

checkTypeback to summary
private static void checkType(Class<?> type)
getAnnotationback to summary
public final <A> A getAnnotation(Class<? extends Annotation> annotationType)

Returns the first annotation for the specified type if an AnnotationElement with the same name exists, else null.

Parameters
<A>
the type of the annotation to query for and return if it exists
annotationType:Class<? extends Annotation>

the Class object corresponding to the annotation type, not null

Returns:A

this element's annotation for the specified annotation type if it exists, else null

getAnnotationElementsback to summary
public List<AnnotationElement> getAnnotationElements()

Returns an immutable list of annotation elements for this AnnotationElement.

Returns:List<AnnotationElement>

a list of meta annotation, not null

getTypeback to summary
pack-priv Type getType()
getTypeIdback to summary
public long getTypeId()

Returns the type ID for this AnnotationElement.

The ID is a unique identifier for the type in the Java Virtual Machine (JVM). The ID might not be the same between JVM instances.

Returns:long

the type ID, not negative

getTypeNameback to summary
public String getTypeName()

Returns the fully qualified name of the annotation type that corresponds to this AnnotationElement (for example, "jdk.jfr.Label").

Returns:String

type name, not null

getValueback to summary
public Object getValue(String name)

Returns a value for this AnnotationElement.

Parameters
name:String

the name of the method in the annotation interface, not null.

Returns:Object

the annotation value, not null.

Exceptions
IllegalArgumentException:
if a method with the specified name does not exist in the annotation
getValueDescriptorsback to summary
public List<ValueDescriptor> getValueDescriptors()

Returns an immutable list of descriptors that describes the annotation values for this AnnotationElement.

Returns:List<ValueDescriptor>

the list of value descriptors for this Annotation, not null

getValuesback to summary
public List<Object> getValues()

Returns an immutable list of annotation values in an order that matches the value descriptors for this AnnotationElement.

Returns:List<Object>

list of values, not null

hasValueback to summary
public boolean hasValue(String name)

Returns true if an annotation value with the specified name exists in this AnnotationElement.

Parameters
name:String

name of the method in the annotation interface to find, not null

Returns:boolean

true if method exists, false otherwise

isInBootback to summary
pack-priv boolean isInBoot()
isKnownJFRAnnotationback to summary
private static boolean isKnownJFRAnnotation(Class<? extends Annotation> annotationType)