org.hibernate.metamodel.source.annotations
Class JandexHelper

java.lang.Object
  extended by org.hibernate.metamodel.source.annotations.JandexHelper

public class JandexHelper
extends Object

Utility methods for working with the jandex annotation index.


Method Summary
static boolean containsSingleAnnotations(Map<org.jboss.jandex.DotName,List<org.jboss.jandex.AnnotationInstance>> annotations, org.jboss.jandex.DotName annotationName)
           
static
<T extends Enum<T>>
T
getEnumValue(org.jboss.jandex.AnnotationInstance annotation, String element, Class<T> type)
          Retrieves a jandex annotation element value, converting it to the supplied enumerated type.
static Map<org.jboss.jandex.DotName,List<org.jboss.jandex.AnnotationInstance>> getMemberAnnotations(org.jboss.jandex.ClassInfo classInfo, String name)
           
static String getPropertyName(org.jboss.jandex.AnnotationTarget target)
          Expects a method or field annotation target and returns the property name for this target
static org.jboss.jandex.AnnotationInstance getSingleAnnotation(org.jboss.jandex.ClassInfo classInfo, org.jboss.jandex.DotName annotationName)
           
static org.jboss.jandex.AnnotationInstance getSingleAnnotation(Map<org.jboss.jandex.DotName,List<org.jboss.jandex.AnnotationInstance>> annotations, org.jboss.jandex.DotName annotationName)
           
static
<T> T
getValue(org.jboss.jandex.AnnotationInstance annotation, String element, Class<T> type)
          Retrieves a jandex annotation element value.
static org.jboss.jandex.Index indexForClass(ClassLoaderService classLoaderService, Class<?>... classes)
          Creates a jandex index for the specified classes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getValue

public static <T> T getValue(org.jboss.jandex.AnnotationInstance annotation,
                             String element,
                             Class<T> type)
                  throws AssertionFailure
Retrieves a jandex annotation element value. If the value is null, the default value specified in the annotation class is retrieved instead.

There are two special cases. Class parameters should be retrieved as strings (and then can later be loaded) and enumerated values should be retrieved via getEnumValue(AnnotationInstance, String, Class).

Parameters:
annotation - the annotation containing the element with the supplied name
element - the name of the element value to be retrieve
type - the type of element to retrieve. The following types are supported:
  • Byte
  • Short
  • Integer
  • Character
  • Float
  • Double
  • Long
  • Boolean
  • String
  • AnnotationInstance
  • Returns:
    the value if not null, else the default value if not null, else null.
    Throws:
    AssertionFailure - in case the specified type is a class instance or the specified type causes a ClassCastException when retrieving the value.

getEnumValue

public static <T extends Enum<T>> T getEnumValue(org.jboss.jandex.AnnotationInstance annotation,
                                                 String element,
                                                 Class<T> type)
Retrieves a jandex annotation element value, converting it to the supplied enumerated type. If the value is null, the default value specified in the annotation class is retrieved instead.

Type Parameters:
T - an enumerated type
Parameters:
annotation - the annotation containing the enumerated element with the supplied name
element - the name of the enumerated element value to be retrieve
type - the type to which to convert the value before being returned
Returns:
the value converted to the supplied enumerated type if the value is not null, else the default value if not null, else null.
See Also:
getValue(AnnotationInstance, String, Class)

getPropertyName

public static String getPropertyName(org.jboss.jandex.AnnotationTarget target)
Expects a method or field annotation target and returns the property name for this target

Parameters:
target - the annotation target
Returns:
the property name of the target. For a field it is the field name and for a method name it is the method name stripped of 'is', 'has' or 'get'

getSingleAnnotation

public static org.jboss.jandex.AnnotationInstance getSingleAnnotation(org.jboss.jandex.ClassInfo classInfo,
                                                                      org.jboss.jandex.DotName annotationName)
                                                               throws AssertionFailure
Parameters:
classInfo - the class info from which to retrieve the annotation instance
annotationName - the annotation to retrieve from the class info
Returns:
the single annotation defined on the class or null in case the annotation is not specified at all
Throws:
AssertionFailure - in case there is there is more than one annotation of this type.

getSingleAnnotation

public static org.jboss.jandex.AnnotationInstance getSingleAnnotation(Map<org.jboss.jandex.DotName,List<org.jboss.jandex.AnnotationInstance>> annotations,
                                                                      org.jboss.jandex.DotName annotationName)
                                                               throws AssertionFailure
Parameters:
annotations - List of annotation instances keyed against their dot name.
annotationName - the annotation to retrieve from map
Returns:
the single annotation of the specified dot name or null in case the annotation is not specified at all
Throws:
AssertionFailure - in case there is there is more than one annotation of this type.

containsSingleAnnotations

public static boolean containsSingleAnnotations(Map<org.jboss.jandex.DotName,List<org.jboss.jandex.AnnotationInstance>> annotations,
                                                org.jboss.jandex.DotName annotationName)
                                         throws AssertionFailure
Parameters:
annotations - List of annotation instances keyed against their dot name.
annotationName - the annotation to check
Returns:
returns true if the map contains only a single instance of specified annotation or false otherwise.
Throws:
AssertionFailure - in case there is there is more than one annotation of this type.

indexForClass

public static org.jboss.jandex.Index indexForClass(ClassLoaderService classLoaderService,
                                                   Class<?>... classes)
Creates a jandex index for the specified classes

Parameters:
classLoaderService - class loader service
classes - the classes to index
Returns:
an annotation repository w/ all the annotation discovered in the specified classes

getMemberAnnotations

public static Map<org.jboss.jandex.DotName,List<org.jboss.jandex.AnnotationInstance>> getMemberAnnotations(org.jboss.jandex.ClassInfo classInfo,
                                                                                                           String name)


Copyright © 2001-2012 Red Hat, Inc. All Rights Reserved.