Package org.linkki.util.reflection
Class MetaAnnotation<META extends Annotation>
java.lang.Object
org.linkki.util.reflection.MetaAnnotation<META>
- Type Parameters:
META- the meta-annotation
-
Method Summary
Modifier and TypeMethodDescriptionfindAllOn(Annotation annotation) Returns all meta-annotations present on the givenAnnotation.findAnnotatedAnnotationsOn(AnnotatedElement annotatedElement) Finds allAnnotationson the givenAnnotatedElementthat are annotated with the meta-annotation.findOn(Annotation annotation) Returns the meta-annotation if it is present on the givenAnnotation.booleanisPresentOn(Annotation annotation) booleanisPresentOnAnyAnnotationOn(AnnotatedElement annotatedElement) Returnstrueif the meta-annotation is present on anyAnnotationon the givenAnnotatedElement, otherwisefalse;booleanReturnstrueif the meta-annotation is@Repeatable.Supplier<? extends IllegalArgumentException>missingAnnotation(Annotation annotation, AnnotatedElement annotatedElement, String checkerMethod) Creates aSupplierfor anIllegalArgumentExceptionthat names the givenAnnotationon theAnnotatedElementas not having the meta-annotation and suggests using thecheckerMethodto safeguard against this exception.static <META extends Annotation>
MetaAnnotation<META>Creates a newMetaAnnotation<META>from the givenAnnotationclass.<A extends Annotation>
BinaryOperator<A>onlyOneOn(AnnotatedElement annotatedElement) Creates aBinaryOperatorusable for aStream.reduce(BinaryOperator)operation on a stream of annotations as returned byfindAnnotatedAnnotationsOn(AnnotatedElement)that throws anIllegalArgumentExceptionif there is more than one annotation in the stream.
-
Method Details
-
of
Creates a newMetaAnnotation<META>from the givenAnnotationclass.- Type Parameters:
META- the meta-annotation class- Parameters:
metaAnnotationClass- the meta-annotation class- Returns:
- a
MetaAnnotationfor themetaAnnotationClass - Throws:
IllegalArgumentException- if the givenAnnotationclass is not a meta-annotation
-
isRepeatable
public boolean isRepeatable()Returnstrueif the meta-annotation is@Repeatable.- Returns:
- whether the meta-annotation is
@Repeatable
-
isPresentOnAnyAnnotationOn
Returnstrueif the meta-annotation is present on anyAnnotationon the givenAnnotatedElement, otherwisefalse;- Parameters:
annotatedElement- anAnnotatedElementto be checked for meta-annotations on its annotations- Returns:
- whether the meta-annotation is present on any
Annotationon the givenAnnotatedElement
-
isPresentOn
- Parameters:
annotation- anAnnotationto be checked for the meta-annotation- Returns:
- whether the meta-annotation is present on the given
Annotation
-
findOn
Returns the meta-annotation if it is present on the givenAnnotation.If this meta-annotation
is repeatable, this method returns anOptionalwith the single meta-annotation if it was not repeated but throws anIllegalArgumentExceptionif it was.- Parameters:
annotation- anAnnotation- Returns:
- the meta-annotation instance, if the annotation is annotated with it
- Throws:
IllegalArgumentException- if the meta-annotation is repeatable and present multiple times.- See Also:
-
findAllOn
Returns all meta-annotations present on the givenAnnotation.- Parameters:
annotation- anAnnotation- Returns:
- the meta-annotation instance, if the annotation is annotated with it
-
findAnnotatedAnnotationsOn
Finds allAnnotationson the givenAnnotatedElementthat are annotated with the meta-annotation.- Parameters:
annotatedElement- anAnnotatedElement- Returns:
- a
Streamof theAnnotationsannotated with the meta-annotation - See Also:
-
onlyOneOn
Creates aBinaryOperatorusable for aStream.reduce(BinaryOperator)operation on a stream of annotations as returned byfindAnnotatedAnnotationsOn(AnnotatedElement)that throws anIllegalArgumentExceptionif there is more than one annotation in the stream.- Parameters:
annotatedElement- theAnnotatedElementthat was passed tofindAnnotatedAnnotationsOn(AnnotatedElement); will be included in the exception message- Returns:
- a
BinaryOperatorusable for aStream.reduce(BinaryOperator)operation on a stream of annotations as returned byfindAnnotatedAnnotationsOn(AnnotatedElement)
-
missingAnnotation
public Supplier<? extends IllegalArgumentException> missingAnnotation(Annotation annotation, AnnotatedElement annotatedElement, String checkerMethod) Creates aSupplierfor anIllegalArgumentExceptionthat names the givenAnnotationon theAnnotatedElementas not having the meta-annotation and suggests using thecheckerMethodto safeguard against this exception.- Parameters:
annotation- anAnnotationon theAnnotatedElementannotatedElement- anAnnotatedElementcheckerMethod- description of a method to be called before the method that throws this exception to safeguard against it- Returns:
- a
Supplierfor anIllegalArgumentException
-