public final class AnnotationElement extends Object
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();
Constructor | Description |
---|---|
AnnotationElement |
Creates an annotation element to use for dynamically defined events. |
AnnotationElement |
Creates an annotation element to use for dynamically defined events. |
AnnotationElement |
Creates an annotation element to use for dynamically defined events. |
Modifier and Type | Method | Description |
---|---|---|
final <A> A |
getAnnotation |
Returns the first annotation for the specified type if an AnnotationElement with the same name exists, else null . |
List |
getAnnotationElements() |
Returns an immutable list of annotation elements for this AnnotationElement . |
long |
getTypeId() |
Returns the type ID for this AnnotationElement . |
String |
getTypeName() |
Returns the fully qualified name of the annotation type that corresponds to this AnnotationElement (for example, "jdk.jfr.Label" ). |
Object |
getValue |
Returns a value for this AnnotationElement . |
List |
getValueDescriptors() |
Returns an immutable list of descriptors that describes the annotation values for this AnnotationElement . |
List |
getValues() |
Returns an immutable list of annotation values in an order that matches the value descriptors for this AnnotationElement . |
boolean |
hasValue |
Returns true if an annotation value with the specified name exists in this AnnotationElement . |
public AnnotationElement(Class<? extends Annotation> annotationType, Map<String,Object> values)
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.
annotationType
- interface extending java.lang.annotation.Annotation
, not null
values
- a Map
with keys that match method names of the specified annotation interfaceIllegalArgumentException
- 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
public AnnotationElement(Class<? extends Annotation> annotationType, Object value)
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.
annotationType
- interface extending java.lang.annotation.Annotation,
not null
value
- the value that matches the value
method of the specified annotationType
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
public AnnotationElement(Class<? extends Annotation> annotationType)
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.
annotationType
- interface extending java.lang.annotation.Annotation, not null
public List<Object> getValues()
AnnotationElement
.null
public List<ValueDescriptor> getValueDescriptors()
AnnotationElement
.Annotation
, not null
public List<AnnotationElement> getAnnotationElements()
AnnotationElement
.null
public String getTypeName()
AnnotationElement
(for example, "jdk.jfr.Label"
).null
public Object getValue(String name)
AnnotationElement
.name
- the name of the method in the annotation interface, not null
.null
.IllegalArgumentException
- if a method with the specified name does not exist in the annotationpublic boolean hasValue(String name)
true
if an annotation value with the specified name exists in this AnnotationElement
.name
- name of the method in the annotation interface to find, not null
true
if method exists, false
otherwisepublic final <A> A getAnnotation(Class<? extends Annotation> annotationType)
AnnotationElement
with the same name exists, else null
.A
- the type of the annotation to query for and return if it existsannotationType
- the Class object
corresponding to the annotation type, not null
null
public long getTypeId()
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.
© 1993, 2023, 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/21/docs/api/jdk.jfr/jdk/jfr/AnnotationElement.html