Module proto4j.swing
Package org.proto4j.swing.annotation
Class AnnotationContext<A extends java.lang.annotation.Annotation>
java.lang.Object
org.proto4j.swing.annotation.AnnotationContext<A>
- Type Parameters:
A
- the annotation type
public abstract class AnnotationContext<A extends java.lang.annotation.Annotation>
extends java.lang.Object
The base class for the internal
Annotation
handling. Two implementations
are provided by default: SingleAnnotationContext
and
MultipleAnnotationContext
.
This interface provides some utility methods when working with annotated elements and their annotations.
- Since:
- 1.0
-
Constructor Summary
Constructors Constructor Description AnnotationContext(java.lang.Class<A> type)
-
Method Summary
Modifier and Type Method Description java.lang.Class<A>
annotationType()
abstract A
annotationValue()
static AnnotationContext<?>[]
collect(java.lang.reflect.AnnotatedElement ae)
Collects allAnnotationContext
instances from the given annotated element nad stores them into an array.static <R extends java.lang.annotation.Annotation>
AnnotationContext<R>exchange(java.lang.Class<R> cls, java.lang.reflect.AnnotatedElement ae)
Retrieves anAnnotationContext
from the given annotation type and the dedicatedAnnotatedElement
.void
ifPresent(java.util.function.Consumer<? super A> consumer)
If a value is present, performs the given action with the value, otherwise does nothing.void
ifPresentProcess(java.util.function.Consumer<? super A> consumer)
If a value array is present, performs the given action with every value in that array, otherwise does nothing.abstract boolean
isPresent()
abstract void
requireNonNull()
Checks that the stored annotation value or array is not null.abstract A[]
toArray()
-
Constructor Details
-
Method Details
-
exchange
public static <R extends java.lang.annotation.Annotation> AnnotationContext<R> exchange(java.lang.Class<R> cls, java.lang.reflect.AnnotatedElement ae) throws java.lang.ReflectiveOperationExceptionRetrieves anAnnotationContext
from the given annotation type and the dedicatedAnnotatedElement
.- Type Parameters:
R
- the type of the annotation- Parameters:
cls
- the annotation typeae
- the annotated element- Returns:
- a new Single- or MultipleAnnotationContext
- Throws:
java.lang.ReflectiveOperationException
- if an error occurs
-
collect
Collects allAnnotationContext
instances from the given annotated element nad stores them into an array.- Parameters:
ae
- the annotated element- Returns:
- a new array storing all
AnnotationContext
instances.
-
annotationType
- Returns:
- The annotation type of this context
-
annotationValue
- Returns:
- the stored annotation instance
-
toArray
- Returns:
- the stored annotations as an array
-
isPresent
public abstract boolean isPresent()- Returns:
- true when the annotation value is not null or the array length
is greater that
0
; false otherwise
-
requireNonNull
public abstract void requireNonNull() throws java.lang.NullPointerExceptionChecks that the stored annotation value or array is not null.- Throws:
java.lang.NullPointerException
- if no value is present
-
ifPresent
If a value is present, performs the given action with the value, otherwise does nothing.- Parameters:
consumer
- the action to be performed, if a value is present- Throws:
java.lang.NullPointerException
- if value is present and the given action isnull
-
ifPresentProcess
If a value array is present, performs the given action with every value in that array, otherwise does nothing.- Parameters:
consumer
- the action to be performed, if a value is present- Throws:
java.lang.NullPointerException
- if value is present and the given action isnull
-