Package org.hibernate.models.spi
Interface AnnotationTarget
- All Known Subinterfaces:
AnnotationDescriptor<A>,AnnotationTargetSupport,ClassDetails,ClassDetailsSupport,FieldDetails,MemberDetails,MethodDetails,MutableAnnotationTarget,MutableClassDetails,MutableMemberDetails,RecordComponentDetails
- All Known Implementing Classes:
AbstractAnnotationTarget,AbstractAnnotationTarget,AbstractAnnotationTarget,AnnotationDescriptorImpl,AnnotationDescriptorOrmImpl,DynamicClassDetails,DynamicFieldDetails,DynamicMethodDetails,JandexClassDetails,JandexFieldDetails,JandexMethodDetails,JandexRecordComponentDetails,JdkClassDetails,JdkFieldDetails,JdkMethodDetails,JdkRecordComponentDetails,SimpleClassDetails
public interface AnnotationTarget
Abstract for something where an annotation can be used.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFunctional contract to process an annotation and return a value.static enumSubset of annotation targets supported for mapping annotations -
Method Summary
Modifier and TypeMethodDescriptiondefault voidforAllAnnotationUsages(Consumer<AnnotationUsage<?>> consumer) Allows to visit every annotation on the target.<X extends Annotation>
voidforEachAnnotationUsage(Class<X> type, Consumer<AnnotationUsage<X>> consumer) Form offorEachAnnotationUsage(AnnotationDescriptor, Consumer)accepting the annotation Classdefault <X extends Annotation>
voidforEachAnnotationUsage(AnnotationDescriptor<X> type, Consumer<AnnotationUsage<X>> consumer) default <T,A extends Annotation>
TfromAnnotations(Class<A> annotationType, AnnotationTarget.AnnotationUsageProcessor<T> processor) Returns a "matching value" using the passedprocessorfrom the annotations, of the passedannotationType, used on the target.Access to all the annotations used on this target.<A extends Annotation>
AnnotationUsage<A>getAnnotationUsage(Class<A> type) Form ofgetAnnotationUsage(AnnotationDescriptor)accepting the annotation Class<A extends Annotation>
AnnotationUsage<A>getAnnotationUsage(AnnotationDescriptor<A> descriptor) Get the usage of the given annotation on this target.getKind()The kind of target<A extends Annotation>
List<AnnotationUsage<? extends Annotation>>getMetaAnnotated(Class<A> metaAnnotationType) Returns all AnnotationUsage references from this target where the usage's annotation class is annotated with the givenmetaAnnotationType.getName()A descriptive name for the target used mostly for loggingdefault <X extends Annotation>
AnnotationUsage<X>getNamedAnnotationUsage(Class<X> type, String matchName) Helper form of getNamedAnnotationUsage(AnnotationDescriptor, String)<X extends Annotation>
AnnotationUsage<X>getNamedAnnotationUsage(Class<X> type, String matchName, String attributeToMatch) default <X extends Annotation>
AnnotationUsage<X>getNamedAnnotationUsage(AnnotationDescriptor<X> type, String matchName) Get a usage of the given annotationtypewhoseattributeToMatchattribute value matches the givenmatchName.<X extends Annotation>
AnnotationUsage<X>getNamedAnnotationUsage(AnnotationDescriptor<X> type, String matchName, String attributeToMatch) Get a usage of the given annotationtypewhoseattributeToMatchattribute value matches the givenmatchName.<A extends Annotation>
List<AnnotationUsage<A>>getRepeatedAnnotationUsages(Class<A> type) Form of getRepeatedAnnotationUsages(AnnotationDescriptor) accepting the annotation Class<A extends Annotation>
List<AnnotationUsage<A>>Get all usages of the specifiedannotationTypein this scope.default <A extends Annotation>
AnnotationUsage<A>getSingleAnnotationUsage(Class<A> type) Form ofgetSingleAnnotationUsage(AnnotationDescriptor)accepting the annotation Classdefault <A extends Annotation>
AnnotationUsage<A>getSingleAnnotationUsage(AnnotationDescriptor<A> descriptor) Form of getAnnotationUsage(AnnotationDescriptor) which returnsnullinstead of throwing AnnotationAccessException when more than one usage of the requested annotation exists.<A extends Annotation>
booleanhasAnnotationUsage(Class<A> type) Whether the given annotation is used on this target.<A extends Annotation>
booleanhasRepeatableAnnotationUsage(Class<A> type) Whether the given annotation is used on this target.<A extends Annotation>
AnnotationUsage<A>locateAnnotationUsage(Class<A> type) Form of getAnnotationUsage(org.hibernate.models.spi.AnnotationDescriptor<A>) which also considers meta-annotations - annotations on the classes of each local annotation.
-
Method Details
-
getKind
AnnotationTarget.Kind getKind()The kind of target -
getName
String getName()A descriptive name for the target used mostly for logging -
getAllAnnotationUsages
Collection<AnnotationUsage<?>> getAllAnnotationUsages()Access to all the annotations used on this target.- API Note:
- This returns the usages directly available on the target; it does not expand repeatable containers (e.g. NamedQueries -> *NamedQuery).
-
forAllAnnotationUsages
Allows to visit every annotation on the target.- API Note:
- Only visits the usages directly available on the target; it does not visit across repeatable containers (e.g. NamedQueries -> *NamedQuery).
-
hasAnnotationUsage
Whether the given annotation is used on this target.- See Also:
- API Note:
- This form does not check across repeatable containers. E.g., calling this
method with
NamedQuerywill returnfalsewhen the target directly has a NamedQueries.
-
hasRepeatableAnnotationUsage
Whether the given annotation is used on this target.- See Also:
- API Note:
- This forms does check across repeatable containers. E.g., calling this
method with
NamedQuerywill returntruewhen the target directly has a NamedQueries.
-
getAnnotationUsage
Get the usage of the given annotation on this target. For repeatable annotation types (e.g.@NamedQuery), this method will either-- if a single repeatable annotation itself is present, it is returned.
-
if the "containing annotation" is present (e.g.
@NamedQueries),- if the container contains just a single repeatable, that one is returned
-
if the container contains multiple repeatables,
AnnotationAccessExceptionwill be thrown
- Returns:
- The usage or
null
-
getAnnotationUsage
Form ofgetAnnotationUsage(AnnotationDescriptor)accepting the annotation Class -
getSingleAnnotationUsage
default <A extends Annotation> AnnotationUsage<A> getSingleAnnotationUsage(AnnotationDescriptor<A> descriptor) Form of getAnnotationUsage(AnnotationDescriptor) which returnsnullinstead of throwing AnnotationAccessException when more than one usage of the requested annotation exists. -
getSingleAnnotationUsage
Form ofgetSingleAnnotationUsage(AnnotationDescriptor)accepting the annotation Class -
locateAnnotationUsage
Form of getAnnotationUsage(org.hibernate.models.spi.AnnotationDescriptor<A>) which also considers meta-annotations - annotations on the classes of each local annotation. -
getRepeatedAnnotationUsages
<A extends Annotation> List<AnnotationUsage<A>> getRepeatedAnnotationUsages(AnnotationDescriptor<A> type) Get all usages of the specifiedannotationTypein this scope.- API Note:
- For repeatable annotation types (e.g.
@NamedQuery), the returned list will contain the union of- the singular
@NamedQueryusage - the nested
@NamedQueryusages from the@NamedQueriesusage
- the singular
-
getRepeatedAnnotationUsages
Form of getRepeatedAnnotationUsages(AnnotationDescriptor) accepting the annotation Class -
forEachAnnotationUsage
default <X extends Annotation> void forEachAnnotationUsage(AnnotationDescriptor<X> type, Consumer<AnnotationUsage<X>> consumer) - API Note:
- For repeatable annotation types, the consumer will also be called for those defined on the container.
-
forEachAnnotationUsage
<X extends Annotation> void forEachAnnotationUsage(Class<X> type, Consumer<AnnotationUsage<X>> consumer) Form offorEachAnnotationUsage(AnnotationDescriptor, Consumer)accepting the annotation Class -
getMetaAnnotated
<A extends Annotation> List<AnnotationUsage<? extends Annotation>> getMetaAnnotated(Class<A> metaAnnotationType) Returns all AnnotationUsage references from this target where the usage's annotation class is annotated with the givenmetaAnnotationType. E.g., given the following class and annotationsa call to this method passing@interface TheMeta{ ... }@TheMeta(...)@interface TheAnnotation{ ... }@TheAnnotationclass TheClass{ ... }TheMetaonClassDetails(TheClass)will return the usage of@TheAnnotationonTheClass.- API Note:
- This method does not check across repeatable containers. Although the return is a List, we are functionally wanting just the unique ones.
-
getNamedAnnotationUsage
default <X extends Annotation> AnnotationUsage<X> getNamedAnnotationUsage(AnnotationDescriptor<X> type, String matchName) Get a usage of the given annotationtypewhoseattributeToMatchattribute value matches the givenmatchName.- Parameters:
matchName- The name to match.
-
getNamedAnnotationUsage
default <X extends Annotation> AnnotationUsage<X> getNamedAnnotationUsage(Class<X> type, String matchName) Helper form of getNamedAnnotationUsage(AnnotationDescriptor, String) -
getNamedAnnotationUsage
<X extends Annotation> AnnotationUsage<X> getNamedAnnotationUsage(AnnotationDescriptor<X> type, String matchName, String attributeToMatch) Get a usage of the given annotationtypewhoseattributeToMatchattribute value matches the givenmatchName.- Parameters:
matchName- The name to match.attributeToMatch- Name of the attribute to match on.
-
getNamedAnnotationUsage
<X extends Annotation> AnnotationUsage<X> getNamedAnnotationUsage(Class<X> type, String matchName, String attributeToMatch) -
fromAnnotations
default <T,A extends Annotation> T fromAnnotations(Class<A> annotationType, AnnotationTarget.AnnotationUsageProcessor<T> processor) Returns a "matching value" using the passedprocessorfrom the annotations, of the passedannotationType, used on the target.- Type Parameters:
T- The type of the value being returned.A- The type of annotations to check- Returns:
- The matching value or
null - API Note:
- In the case of repeatable annotations, the first usage for which
the passed
processordoes not returnnullwill be returned.
-