public class AnnotationHelper
extends java.lang.Object
Parsed
Modifier and Type | Field and Description |
---|---|
private static java.util.Set<java.lang.Class> |
customAnnotationTypes |
private static java.util.Set<java.lang.Class> |
javaLangAnnotationTypes |
private static java.lang.annotation.Annotation |
lastAnnotationFound |
private static java.lang.Class<? extends java.lang.annotation.Annotation> |
lastProcessedAnnotationType |
private static java.lang.reflect.AnnotatedElement |
lastProcessedElement |
Modifier | Constructor and Description |
---|---|
private |
AnnotationHelper() |
Modifier and Type | Method and Description |
---|---|
static boolean |
allFieldsIndexBasedForParsing(java.lang.Class<?> beanClass)
Runs through all annotations of a given class to identify whether all annotated fields and methods
(with the
Parsed annotation) are mapped to a column by index. |
static boolean |
allFieldsIndexBasedForWriting(java.lang.Class<?> beanClass)
Runs through all annotations of a given class to identify whether all annotated fields and methods
(with the
Parsed annotation) are mapped to a column by index. |
private static boolean |
allFieldsIndexOrNameBased(boolean searchName,
java.lang.Class<?> beanClass,
MethodFilter filter) |
static boolean |
allFieldsNameBasedForParsing(java.lang.Class<?> beanClass)
Runs through all annotations of a given class to identify whether all annotated fields and methods
(with the
Parsed annotation) are mapped to a column by name. |
static boolean |
allFieldsNameBasedForWriting(java.lang.Class<?> beanClass)
Runs through all annotations of a given class to identify whether all annotated fields and methods
(with the
Parsed annotation) are mapped to a column by name. |
static void |
applyFormatSettings(java.lang.Object formatter,
java.lang.String[] propertiesAndValues)
Applied the configuration of a formatter object (
SimpleDateFormat , NumberFormat and others). |
static java.lang.String[] |
deriveHeaderNamesFromFields(java.lang.Class<?> beanClass,
MethodFilter filter)
Runs through all
Parsed annotations of a given class to identify all header names associated with its fields |
(package private) static java.lang.String |
describeElement(java.lang.reflect.AnnotatedElement element) |
static java.util.List<java.lang.annotation.Annotation> |
findAllAnnotationsInPackage(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Package aPackage)
Returns all annotations applied to an element, excluding the ones not in a given package.
|
private static void |
findAllAnnotationsInPackage(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Package aPackage,
java.util.ArrayList<? super java.lang.annotation.Annotation> found,
java.util.Set<java.lang.annotation.Annotation> visited) |
static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<A> annotationType)
Searches for an annotation of a given type that's been applied to an element either directly (as a regular annotation)
or indirectly (as a meta-annotations, i.e.
|
private static <A> A |
findAnnotation(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class<A> annotationType,
java.util.Set<java.lang.annotation.Annotation> visited,
java.util.Stack<java.lang.annotation.Annotation> path) |
static Headers |
findHeadersAnnotation(java.lang.Class<?> beanClass)
Searches for the
Headers annotation in the hierarchy of a class |
static java.util.Map<java.lang.reflect.Field,PropertyWrapper> |
getAllFields(java.lang.Class<?> beanClass)
Returns all fields available from a given class.
|
static java.util.List<java.lang.reflect.Method> |
getAnnotatedMethods(java.lang.Class<?> beanClass,
MethodFilter filter)
Returns all methods available from a given class that have an annotation.
|
static Conversion |
getConversion(java.lang.reflect.AnnotatedElement target,
java.lang.annotation.Annotation annotation)
Identifies the proper conversion for a given Field and an annotation from the package
com.univocity.parsers.annotations |
private static Conversion |
getConversion(java.lang.Class fieldType,
java.lang.reflect.AnnotatedElement target,
java.lang.annotation.Annotation annotation) |
static Conversion |
getConversion(java.lang.Class classType,
java.lang.annotation.Annotation annotation)
Identifies the proper conversion for a given type and an annotation from the package
com.univocity.parsers.annotations |
static java.lang.Class<?> |
getDeclaringClass(java.lang.reflect.AnnotatedElement element) |
static Conversion |
getDefaultConversion(java.lang.reflect.AnnotatedElement target)
Returns the default
Conversion that should be applied to the field based on its type. |
static Conversion |
getDefaultConversion(java.lang.Class fieldType,
Parsed parsed)
Identifies the proper conversion for a given type
|
static java.lang.Object |
getDefaultPrimitiveValue(java.lang.Class type)
Returns Java's default value for a given type, in a primitive type wrapper.
|
static java.util.List<TransformedHeader> |
getFieldSequence(java.lang.Class beanClass,
boolean processNested,
HeaderTransformer transformer,
MethodFilter filter)
Returns a list of fields with
Parsed annotations in the sequence they should be processed for parsing
or writing. |
private static java.util.List<TransformedHeader> |
getFieldSequence(java.lang.Class beanClass,
boolean processNested,
java.util.List<java.lang.Integer> indexes,
HeaderTransformer transformer,
MethodFilter filter) |
static java.lang.String |
getName(java.lang.reflect.AnnotatedElement element) |
private static java.lang.String |
getNullReadValue(Parsed parsed) |
private static java.lang.String |
getNullValue(java.lang.String defaultValue)
Converts the special "null" strings that might be provided by
and Parsed#defaultNullWrite() |
private static java.lang.String |
getNullWriteValue(Parsed parsed) |
static java.lang.Integer[] |
getSelectedIndexes(java.lang.Class<?> beanClass,
MethodFilter filter)
Runs through all
Parsed annotations of a given class to identify all indexes associated with its fields |
private static java.lang.annotation.Annotation |
getTargetAnnotation(java.lang.reflect.AnnotatedElement annotatedElement,
java.lang.Class targetClass,
java.lang.annotation.Annotation current) |
static java.lang.Class<?> |
getType(java.lang.reflect.AnnotatedElement element) |
private static java.lang.Object |
invoke(java.lang.annotation.Annotation annotation,
java.lang.reflect.Method method) |
private static void |
invokeSetter(java.lang.Object formatter,
PropertyWrapper property,
java.lang.String value) |
private static boolean |
isCustomAnnotation(java.lang.annotation.Annotation annotation) |
static <T> T |
newInstance(java.lang.Class parent,
java.lang.Class<T> type,
java.lang.String[] args) |
private static void |
processAnnotations(java.lang.reflect.AnnotatedElement element,
boolean processNested,
java.util.List<java.lang.Integer> indexes,
java.util.List<TransformedHeader> tmp,
java.util.Map<java.lang.reflect.AnnotatedElement,java.util.List<TransformedHeader>> nestedReplacements,
HeaderTransformer transformer,
MethodFilter filter) |
private static void |
setAnnotationValue(java.lang.annotation.Annotation annotation,
java.lang.String attribute,
java.lang.Object newValue) |
private static java.lang.reflect.AnnotatedElement lastProcessedElement
private static java.lang.Class<? extends java.lang.annotation.Annotation> lastProcessedAnnotationType
private static java.lang.annotation.Annotation lastAnnotationFound
private static final java.util.Set<java.lang.Class> javaLangAnnotationTypes
private static final java.util.Set<java.lang.Class> customAnnotationTypes
private static java.lang.String getNullValue(java.lang.String defaultValue)
and Parsed#defaultNullWrite()
defaultValue
- The string returned by and Parsed#defaultNullWrite()
If "null" was provided, then null will be returned.
If "'null'" was provided, then "null" will be returned.
private static java.lang.String getNullWriteValue(Parsed parsed)
private static java.lang.String getNullReadValue(Parsed parsed)
public static Conversion getConversion(java.lang.reflect.AnnotatedElement target, java.lang.annotation.Annotation annotation)
com.univocity.parsers.annotations
target
- The field or method to have conversions applied toannotation
- the annotation from com.univocity.parsers.annotations
that identifies a Conversion
instance.Conversion
that should be applied to the fieldpublic static Conversion getConversion(java.lang.Class classType, java.lang.annotation.Annotation annotation)
com.univocity.parsers.annotations
classType
- the type to have conversions applied toannotation
- the annotation from com.univocity.parsers.annotations
that identifies a Conversion
instance.Conversion
that should be applied to the typeprivate static Conversion getConversion(java.lang.Class fieldType, java.lang.reflect.AnnotatedElement target, java.lang.annotation.Annotation annotation)
public static <T> T newInstance(java.lang.Class parent, java.lang.Class<T> type, java.lang.String[] args)
public static Conversion getDefaultConversion(java.lang.Class fieldType, Parsed parsed)
fieldType
- The type of field to have conversions applied to.parsed
- the Parsed
annotation from com.univocity.parsers.annotations
.Conversion
that should be applied to the field typepublic static Conversion getDefaultConversion(java.lang.reflect.AnnotatedElement target)
Conversion
that should be applied to the field based on its type.target
- The field or method whose values must be converted from a given parsed String.Conversion
applied to the given field.public static void applyFormatSettings(java.lang.Object formatter, java.lang.String[] propertiesAndValues)
SimpleDateFormat
, NumberFormat
and others).formatter
- the formatter instancepropertiesAndValues
- a sequence of key-value pairs, where the key is a property of the formatter
object to be set to the following value via reflectionprivate static void invokeSetter(java.lang.Object formatter, PropertyWrapper property, java.lang.String value)
private static boolean allFieldsIndexOrNameBased(boolean searchName, java.lang.Class<?> beanClass, MethodFilter filter)
public static boolean allFieldsIndexBasedForParsing(java.lang.Class<?> beanClass)
Parsed
annotation) are mapped to a column by index.public static boolean allFieldsNameBasedForParsing(java.lang.Class<?> beanClass)
Parsed
annotation) are mapped to a column by name.public static boolean allFieldsIndexBasedForWriting(java.lang.Class<?> beanClass)
Parsed
annotation) are mapped to a column by index.public static boolean allFieldsNameBasedForWriting(java.lang.Class<?> beanClass)
Parsed
annotation) are mapped to a column by name.public static java.lang.Integer[] getSelectedIndexes(java.lang.Class<?> beanClass, MethodFilter filter)
Parsed
annotations of a given class to identify all indexes associated with its fieldsbeanClass
- a class whose Parsed
annotations will be processed.filter
- filter to apply over annotated methods when the class is being used for reading data from beans (to write values to an output)
or when writing values into beans (while parsing). It is used to choose either a "get" or a "set"
method annotated with Parsed
, when both methods target the same field.public static java.lang.String[] deriveHeaderNamesFromFields(java.lang.Class<?> beanClass, MethodFilter filter)
Parsed
annotations of a given class to identify all header names associated with its fieldsbeanClass
- a class whose Parsed
annotations will be processed.filter
- a filter to exclude annotated methods that won't be used for parsing or writingpublic static Headers findHeadersAnnotation(java.lang.Class<?> beanClass)
Headers
annotation in the hierarchy of a classbeanClass
- the class whose hierarchy will be searchedHeaders
annotation of the given class or its most immediate parent, or null
if not found.public static java.lang.Class<?> getType(java.lang.reflect.AnnotatedElement element)
public static java.lang.Class<?> getDeclaringClass(java.lang.reflect.AnnotatedElement element)
public static java.lang.String getName(java.lang.reflect.AnnotatedElement element)
static java.lang.String describeElement(java.lang.reflect.AnnotatedElement element)
private static void processAnnotations(java.lang.reflect.AnnotatedElement element, boolean processNested, java.util.List<java.lang.Integer> indexes, java.util.List<TransformedHeader> tmp, java.util.Map<java.lang.reflect.AnnotatedElement,java.util.List<TransformedHeader>> nestedReplacements, HeaderTransformer transformer, MethodFilter filter)
public static java.util.List<TransformedHeader> getFieldSequence(java.lang.Class beanClass, boolean processNested, HeaderTransformer transformer, MethodFilter filter)
Parsed
annotations in the sequence they should be processed for parsing
or writing. The sequence is ordered taking into account their original order in the annotated class, unless
Parsed.index()
is set to a non-negative number.beanClass
- the class whose field sequence will be returned.processNested
- flag indicating whether Nested
annotations should be processedtransformer
- a HeaderTransformer
instance to be used for transforming headers of a given Nested
attribute.filter
- filter to apply over annotated methods when the class is being used for reading data from beans (to write values to an output)
or when writing values into beans (while parsing). It is used to choose either a "get" or a "set"
method annotated with Parsed
, when both methods target the same field.private static java.util.List<TransformedHeader> getFieldSequence(java.lang.Class beanClass, boolean processNested, java.util.List<java.lang.Integer> indexes, HeaderTransformer transformer, MethodFilter filter)
public static java.util.Map<java.lang.reflect.Field,PropertyWrapper> getAllFields(java.lang.Class<?> beanClass)
beanClass
- a class whose fields will be returned.Field
and the corresponding PropertyWrapper
public static java.util.List<java.lang.reflect.Method> getAnnotatedMethods(java.lang.Class<?> beanClass, MethodFilter filter)
beanClass
- a class whose methods will be returned.filter
- filter to apply over annotated methods when the class is being used for reading data from beans (to write values to an output)
or when writing values into beans (while parsing). It is used to choose either a "get" or a "set"
method annotated with Parsed
, when both methods target the same field.Method
and the corresponding PropertyWrapper
public static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType)
A
- the type of the annotation being searched forannotatedElement
- the element whose annotations will be searchedannotationType
- the type of annotation to search fornull
if not found.private static java.lang.annotation.Annotation getTargetAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class targetClass, java.lang.annotation.Annotation current)
private static void setAnnotationValue(java.lang.annotation.Annotation annotation, java.lang.String attribute, java.lang.Object newValue)
private static java.lang.Object invoke(java.lang.annotation.Annotation annotation, java.lang.reflect.Method method)
private static <A> A findAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<A> annotationType, java.util.Set<java.lang.annotation.Annotation> visited, java.util.Stack<java.lang.annotation.Annotation> path)
private static boolean isCustomAnnotation(java.lang.annotation.Annotation annotation)
public static java.util.List<java.lang.annotation.Annotation> findAllAnnotationsInPackage(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Package aPackage)
annotatedElement
- the element (method, field, etc) whose annotations will be extractedaPackage
- the package of the annotations that should be returnedprivate static void findAllAnnotationsInPackage(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Package aPackage, java.util.ArrayList<? super java.lang.annotation.Annotation> found, java.util.Set<java.lang.annotation.Annotation> visited)
public static final java.lang.Object getDefaultPrimitiveValue(java.lang.Class type)
type
- the primitive type whose default value will be returned.null
if the type is not primitive.