Package org.hibernate.models.spi
Interface AnnotationTarget
- All Known Subinterfaces:
AnnotationDescriptor<A>,AnnotationTargetSupport,ClassDetails,ClassDetailsSupport,FieldDetails,MemberDetails,MethodDetails,MutableAnnotationDescriptor<A,,C> MutableAnnotationTarget,MutableClassDetails,MutableMemberDetails,RecordComponentDetails
- All Known Implementing Classes:
AbstractAnnotationDescriptor,AbstractAnnotationTarget,AbstractAnnotationTarget,AbstractJdkAnnotationTarget,DynamicClassDetails,DynamicFieldDetails,JdkClassDetails,JdkFieldDetails,JdkMethodDetails,JdkRecordComponentDetails,MissingPackageInfoDetails,OrmAnnotationDescriptor,SimpleClassDetails,StandardAnnotationDescriptor
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 TypeMethodDescription<A extends Annotation>
AnnotationDescriptor<A> Safe cast method for cases when the target is an annotation.Safe cast method for cases when the target is a record component.default <X extends Annotation>
voidforEachAnnotationUsage(Class<X> type, ModelsContext modelContext, Consumer<X> consumer) Form offorEachAnnotationUsage(AnnotationDescriptor, ModelsContext, Consumer)accepting the annotation Classdefault <X extends Annotation>
voidforEachAnnotationUsage(AnnotationDescriptor<X> type, ModelsContext modelContext, Consumer<X> consumer) Call theconsumerfor each usage of the giventype.default voidforEachDirectAnnotationUsage(Consumer<? extends Annotation> consumer) Allows to visit every annotation on the target.<A extends Annotation,C extends Annotation>
voidforEachRepeatedAnnotationUsages(Class<A> repeatable, Class<C> container, ModelsContext modelContext, Consumer<A> consumer) default <A extends Annotation,C extends Annotation>
voidforEachRepeatedAnnotationUsages(AnnotationDescriptor<A> repeatable, ModelsContext modelContext, Consumer<A> consumer) default <T,A extends Annotation>
TfromAnnotations(Class<A> annotationType, AnnotationTarget.AnnotationUsageProcessor<T, A> processor, ModelsContext modelContext) Returns a "matching value" using the passedprocessorfrom the annotations, of the passedannotationType, used on the target.default <T> TfromContainers(boolean crossPackageBoundaries, ModelsContext modelContext, Function<ClassDetails, T> matchingExtractor) Walk "up" containers from this target.default <T> TfromSelfAndContainers(boolean crossPackageBoundaries, ModelsContext modelContext, Function<AnnotationTarget, T> matchingExtractor) Walk "up" containers from this target.default <A extends Annotation>
AgetAnnotationUsage(Class<A> type, ModelsContext modelContext) Form ofgetAnnotationUsage(AnnotationDescriptor, ModelsContext)accepting the annotation Class<A extends Annotation>
AgetAnnotationUsage(AnnotationDescriptor<A> descriptor, ModelsContext modelContext) Get the usage of the given annotation on this target.getContainer(ModelsContext modelsContext) Get the ClassDetails for the class which is the "container" for this target. For a member (org.hib.Thing#id), this will be the declaring type (org.hib.Thing).<A extends Annotation>
AgetDirectAnnotationUsage(Class<A> type) Form ofgetDirectAnnotationUsage(AnnotationDescriptor)accepting the annotation Class<A extends Annotation>
AgetDirectAnnotationUsage(AnnotationDescriptor<A> descriptor) Form of getAnnotationUsage(AnnotationDescriptor, ModelsContext) which returnsnullinstead of throwing AnnotationAccessException when more than one usage of the requested annotation exists.Collection<? extends Annotation> Access to all the annotations used on this target.getKind()The kind of target<A extends Annotation>
List<? extends Annotation> getMetaAnnotated(Class<A> metaAnnotationType, ModelsContext modelContext) Returns all Annotation usages from this target where the usage's annotation class is annotated with the givenmetaAnnotationType.getName()A descriptive name for the target used mostly for logging<X extends Annotation>
XgetNamedAnnotationUsage(Class<X> type, String matchName, String attributeToMatch, ModelsContext modelContext) default <X extends Annotation>
XgetNamedAnnotationUsage(Class<X> type, String matchName, ModelsContext modelContext) <X extends Annotation>
XgetNamedAnnotationUsage(AnnotationDescriptor<X> type, String matchName, String attributeToMatch, ModelsContext modelContext) Get a usage of the given annotationtypewhoseattributeToMatchattribute value matches the givenmatchName.default <X extends Annotation>
XgetNamedAnnotationUsage(AnnotationDescriptor<X> type, String matchName, ModelsContext modelContext) Get a usage of the given annotationtypewhoseattributeToMatchattribute value matches the givenmatchName.default <A extends Annotation>
A[]getRepeatedAnnotationUsages(Class<A> type, ModelsContext modelContext) Form of getRepeatedAnnotationUsages(AnnotationDescriptor, ModelsContext) accepting the annotation Class<A extends Annotation>
A[]getRepeatedAnnotationUsages(AnnotationDescriptor<A> type, ModelsContext modelContext) Get all usages of the specifiedannotationTypein this scope.<A extends Annotation>
booleanhasAnnotationUsage(Class<A> type, ModelsContext modelContext) Whether the given annotation is used on this target.<A extends Annotation>
booleanhasDirectAnnotationUsage(Class<A> type) Whether the given annotation is used on this target.<A extends Annotation>
AlocateAnnotationUsage(Class<A> type, ModelsContext modelContext) Form of getAnnotationUsage(org.hibernate.models.spi.AnnotationDescriptor<A>, org.hibernate.models.spi.ModelsContext) which also considers meta-annotations - annotations on the classes of each local annotation.default voidwalkContainers(boolean crossPackageBoundaries, ModelsContext modelContext, Consumer<ClassDetails> consumer) Walk "up" containers from this target.default voidwalkSelfAndContainers(boolean crossPackageBoundaries, ModelsContext modelContext, Consumer<AnnotationTarget> consumer) Walk "up" containers from this target.
-
Method Details
-
getKind
AnnotationTarget.Kind getKind()The kind of target -
getName
String getName()A descriptive name for the target used mostly for logging -
getContainer
Get the ClassDetails for the class which is the "container" for this target.- For a member (
org.hib.Thing#id), this will be the declaring type (org.hib.Thing). - For a class (
org.hib.Thing), this will be the ClassDetails for its package (org.hib.package-info) - For a package (
org.hib.package-info), this will be the ClassDetails for the containing package (org.package-info)
- API Note:
- If not already, this resolution should be registered into the context's class registry
- For a member (
-
walkContainers
default void walkContainers(boolean crossPackageBoundaries, ModelsContext modelContext, Consumer<ClassDetails> consumer) Walk "up" containers from this target.- Parameters:
crossPackageBoundaries- If this target is a package, should we walk to its container?modelContext- Access to useful stuff.consumer- Consumer of the containers
-
walkSelfAndContainers
default void walkSelfAndContainers(boolean crossPackageBoundaries, ModelsContext modelContext, Consumer<AnnotationTarget> consumer) Walk "up" containers from this target.- Parameters:
crossPackageBoundaries- If this target is a package, should we walk to its container?modelContext- Access to useful stuff.consumer- Consumer of the containers
-
fromContainers
default <T> T fromContainers(boolean crossPackageBoundaries, ModelsContext modelContext, Function<ClassDetails, T> matchingExtractor) Walk "up" containers from this target.- Parameters:
crossPackageBoundaries- If this target is a package, should we walk to its container?modelContext- Access to useful stuff.matchingExtractor- A function that acts as an extractor against a container. A non-null return indicates a match, which will be the return from this method.
-
fromSelfAndContainers
default <T> T fromSelfAndContainers(boolean crossPackageBoundaries, ModelsContext modelContext, Function<AnnotationTarget, T> matchingExtractor) Walk "up" containers from this target.- Parameters:
crossPackageBoundaries- If this target is a package, should we walk to its container?modelContext- Access to useful stuff.matchingExtractor- A function that acts as an extractor against a container. A non-null return indicates a match, which will be the return from this method.
-
getDirectAnnotationUsages
Collection<? extends Annotation> getDirectAnnotationUsages()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).
-
forEachDirectAnnotationUsage
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).
-
hasDirectAnnotationUsage
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.
-
getDirectAnnotationUsage
Form of getAnnotationUsage(AnnotationDescriptor, ModelsContext) which returnsnullinstead of throwing AnnotationAccessException when more than one usage of the requested annotation exists. -
getDirectAnnotationUsage
Form ofgetDirectAnnotationUsage(AnnotationDescriptor)accepting the annotation Class -
hasAnnotationUsage
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
<A extends Annotation> A getAnnotationUsage(AnnotationDescriptor<A> descriptor, ModelsContext modelContext) 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, ModelsContext)accepting the annotation Class -
locateAnnotationUsage
Form of getAnnotationUsage(org.hibernate.models.spi.AnnotationDescriptor<A>, org.hibernate.models.spi.ModelsContext) which also considers meta-annotations - annotations on the classes of each local annotation. -
getRepeatedAnnotationUsages
<A extends Annotation> A[] getRepeatedAnnotationUsages(AnnotationDescriptor<A> type, ModelsContext modelContext) 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
default <A extends Annotation> A[] getRepeatedAnnotationUsages(Class<A> type, ModelsContext modelContext) Form of getRepeatedAnnotationUsages(AnnotationDescriptor, ModelsContext) accepting the annotation Class -
forEachRepeatedAnnotationUsages
<A extends Annotation,C extends Annotation> void forEachRepeatedAnnotationUsages(Class<A> repeatable, Class<C> container, ModelsContext modelContext, Consumer<A> consumer) -
forEachRepeatedAnnotationUsages
default <A extends Annotation,C extends Annotation> void forEachRepeatedAnnotationUsages(AnnotationDescriptor<A> repeatable, ModelsContext modelContext, Consumer<A> consumer) -
forEachAnnotationUsage
default <X extends Annotation> void forEachAnnotationUsage(AnnotationDescriptor<X> type, ModelsContext modelContext, Consumer<X> consumer) Call theconsumerfor each usage of the giventype.- API Note:
- For repeatable annotation types, the consumer will also be called for those defined on the container.
-
forEachAnnotationUsage
default <X extends Annotation> void forEachAnnotationUsage(Class<X> type, ModelsContext modelContext, Consumer<X> consumer) Form offorEachAnnotationUsage(AnnotationDescriptor, ModelsContext, Consumer)accepting the annotation Class -
getMetaAnnotated
<A extends Annotation> List<? extends Annotation> getMetaAnnotated(Class<A> metaAnnotationType, ModelsContext modelContext) Returns all Annotation usages 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> X getNamedAnnotationUsage(AnnotationDescriptor<X> type, String matchName, ModelsContext modelContext) Get a usage of the given annotationtypewhoseattributeToMatchattribute value matches the givenmatchName.- Parameters:
matchName- The name to match.
-
getNamedAnnotationUsage
default <X extends Annotation> X getNamedAnnotationUsage(Class<X> type, String matchName, ModelsContext modelContext) -
getNamedAnnotationUsage
<X extends Annotation> X getNamedAnnotationUsage(AnnotationDescriptor<X> type, String matchName, String attributeToMatch, ModelsContext modelContext) 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> X getNamedAnnotationUsage(Class<X> type, String matchName, String attributeToMatch, ModelsContext modelContext) -
fromAnnotations
default <T,A extends Annotation> T fromAnnotations(Class<A> annotationType, AnnotationTarget.AnnotationUsageProcessor<T, A> processor, ModelsContext modelContext) 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.
-
asAnnotationDescriptor
Safe cast method for cases when the target is an annotation.- Throws:
IllegalCastException- If the target is not an annotation
-
asClassDetails
ClassDetails asClassDetails()- Throws:
IllegalCastException- If the target is not a class
-
asMemberDetails
MemberDetails asMemberDetails()- Throws:
IllegalCastException- If the target is not a member
-
asFieldDetails
FieldDetails asFieldDetails()- Throws:
IllegalCastException- If the target is not a field
-
asMethodDetails
MethodDetails asMethodDetails()- Throws:
IllegalCastException- If the target is not a method
-
asRecordComponentDetails
RecordComponentDetails asRecordComponentDetails()Safe cast method for cases when the target is a record component.- Throws:
IllegalCastException- If the target is not a record component
-