mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-09 04:34:49 +00:00
HHH-6202 Adding new helper method for getting a single annotation instance from a map
This commit is contained in:
parent
ac0cf3afd8
commit
5d766b237b
@ -93,11 +93,24 @@ else if ( methodName.startsWith( "get" ) ) {
|
|||||||
*
|
*
|
||||||
* @return the single annotation defined on the class or {@code null} in case the annotation is not specified at all
|
* @return the single annotation defined on the class or {@code null} in case the annotation is not specified at all
|
||||||
*
|
*
|
||||||
* @throws org.hibernate.AssertionFailure in case there is
|
* @throws org.hibernate.AssertionFailure in case there is there is more than one annotation of this type.
|
||||||
*/
|
*/
|
||||||
public static AnnotationInstance getSingleAnnotation(ClassInfo classInfo, DotName annotationName)
|
public static AnnotationInstance getSingleAnnotation(ClassInfo classInfo, DotName annotationName)
|
||||||
throws AssertionFailure {
|
throws AssertionFailure {
|
||||||
List<AnnotationInstance> annotationList = classInfo.annotations().get( annotationName );
|
return getSingleAnnotation( classInfo.annotations(), annotationName );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param annotations List of annotation instances keyed against their dot name.
|
||||||
|
* @param annotationName the annotation to retrieve from map
|
||||||
|
*
|
||||||
|
* @return the single annotation of the specified dot name or {@code null} in case the annotation is not specified at all
|
||||||
|
*
|
||||||
|
* @throws org.hibernate.AssertionFailure in case there is there is more than one annotation of this type.
|
||||||
|
*/
|
||||||
|
public static AnnotationInstance getSingleAnnotation(Map<DotName, List<AnnotationInstance>> annotations, DotName annotationName)
|
||||||
|
throws AssertionFailure {
|
||||||
|
List<AnnotationInstance> annotationList = annotations.get( annotationName );
|
||||||
if ( annotationList == null ) {
|
if ( annotationList == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -113,6 +126,20 @@ else if ( annotationList.size() == 1 ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param annotations List of annotation instances keyed against their dot name.
|
||||||
|
* @param annotationNames the annotation names to filter
|
||||||
|
*
|
||||||
|
* @return a new map of annotation instances only containing annotations of the specified dot names.
|
||||||
|
*/
|
||||||
|
public static Map<DotName, List<AnnotationInstance>> filterAnnotations(Map<DotName, List<AnnotationInstance>> annotations, DotName... annotationNames) {
|
||||||
|
Map<DotName, List<AnnotationInstance>> filteredAnnotations = new HashMap<DotName, List<AnnotationInstance>>();
|
||||||
|
for ( DotName name : annotationNames ) {
|
||||||
|
filteredAnnotations.put( name, annotations.get( name ) );
|
||||||
|
}
|
||||||
|
return filteredAnnotations;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a jandex index for the specified classes
|
* Creates a jandex index for the specified classes
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user