Package com.gengoai.reflection
Class RParameter
- java.lang.Object
-
- com.gengoai.reflection.RParameter
-
- All Implemented Interfaces:
Serializable
public class RParameter extends Object
Wraps a Parameter giving easy access to its type information.- Author:
- David B. Bracewell
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <A extends Annotation>
AgetAnnotation(@NonNull Class<A> annotationClass, boolean onlyDirect)
Gets the annotation of the given class on this object.<A extends Annotation>
AgetAnnotation(Class<A> annotationClass)
Gets the annotation of the given class present on this object.Annotation[]
getAnnotations()
Gets all annotations present on this object.Annotation[]
getAnnotations(boolean onlyDirect)
Gets all annotations on this object.<A extends Annotation>
A[]getAnnotations(@NonNull Class<A> annotationClass)
Gets all associated annotations of given type on this object.<A extends Annotation>
A[]getAnnotations(@NonNull Class<A> annotationClass, boolean onlyDirect)
Gets all annotations on this object.Parameter
getElement()
Gets the AnnotatedElementint
getModifiers()
Gets the modifiers on this field.String
getName()
Gets the name of the elementType
getType()
Gets the type of the elementboolean
isAnnotationDeclared(@NonNull Class<? extends Annotation>... annotationClasses)
Determines if any of the given annotations are declared on this objectboolean
isAnnotationPresent(@NonNull Class<? extends Annotation>... annotationClasses)
Determines if any of the given annotations are present on this objectboolean
isTypeCompatible(@NonNull Type type)
Determines if the given type is compatible with the type of this parameter<T extends RExecutable<?,T>>
Towner()
Gets the executable that this parameter belongs to<A extends Annotation,O>
OprocessAnnotation(@NonNull Class<A> annotationClass, @NonNull CheckedFunction<? super A,? extends O> function)
Applies the givenCheckedBiFunction
to this object with the given annotation if it is present on the object.<A extends Annotation,O>
List<O>processAnnotations(@NonNull Class<A> annotationClass, @NonNull CheckedFunction<? super A,? extends O> function)
Applies the givenCheckedBiFunction
to this object and all instances of the given annotation present on the object.String
toString()
<A extends Annotation>
VwithAnnotation(@NonNull Class<A> annotationClass, @NonNull CheckedConsumer<? super A> consumer)
Applies the givenCheckedBiConsumer
to this object with the given annotation if it is present on the object.<A extends Annotation>
VwithAnnotations(@NonNull Class<A> annotationClass, @NonNull CheckedConsumer<? super A> consumer)
Applies the givenCheckedBiConsumer
to this object and all instances of the given annotation present on this object.
-
-
-
Method Detail
-
getElement
public Parameter getElement()
Gets the AnnotatedElement- Returns:
- the AnnotatedElement object
-
getModifiers
public int getModifiers()
Gets the modifiers on this field.- Returns:
- the modifiers
-
getName
public String getName()
Gets the name of the element- Returns:
- the name of the element
-
getType
public Type getType()
Gets the type of the element- Returns:
- the type of the element
-
isTypeCompatible
public boolean isTypeCompatible(@NonNull @NonNull Type type)
Determines if the given type is compatible with the type of this parameter- Parameters:
type
- the type to check- Returns:
- True if the given type is assignable to this parameter
-
owner
public <T extends RExecutable<?,T>> T owner()
Gets the executable that this parameter belongs to- Type Parameters:
T
- the executable type parameter- Returns:
- the Executable that this parameter belongs to
-
toString
public String toString()
-
getAnnotation
public final <A extends Annotation> A getAnnotation(Class<A> annotationClass)
Gets the annotation of the given class present on this object.- Type Parameters:
A
- the annotation type parameter- Parameters:
annotationClass
- the annotation class- Returns:
- the annotation (null if does not exist)
-
getAnnotation
public final <A extends Annotation> A getAnnotation(@NonNull @NonNull Class<A> annotationClass, boolean onlyDirect)
Gets the annotation of the given class on this object. WhenonlyDirect
is true it will only return annotations directly present viagetDeclaredAnnotation
otherwise will return any instance present viagetAnnotation
.- Type Parameters:
A
- the annotation type parameter- Parameters:
annotationClass
- the annotation classonlyDirect
- True - only declared annotations, False present annotations- Returns:
- the annotation (null if does not exist)
-
getAnnotations
public final Annotation[] getAnnotations(boolean onlyDirect)
Gets all annotations on this object. WhenonlyDirect
is true it will only return annotations directly present viagetDeclaredAnnotations
otherwise will return any instance present viagetAnnotations
.- Parameters:
onlyDirect
- True - only declared annotations, False present annotations- Returns:
- the array of Annotation
-
getAnnotations
public final Annotation[] getAnnotations()
Gets all annotations present on this object.- Returns:
- the array of Annotation
-
getAnnotations
public final <A extends Annotation> A[] getAnnotations(@NonNull @NonNull Class<A> annotationClass, boolean onlyDirect)
Gets all annotations on this object. WhenonlyDirect
is true it will only return annotations directly present viagetDeclaredAnnotationsByType
otherwise will return any instance present viagetAnnotationsByType
.- Type Parameters:
A
- the annotation type parameter- Parameters:
annotationClass
- the annotation classonlyDirect
- True - only declared annotations, False present annotations- Returns:
- the array of Annotation
-
getAnnotations
public final <A extends Annotation> A[] getAnnotations(@NonNull @NonNull Class<A> annotationClass)
Gets all associated annotations of given type on this object.- Type Parameters:
A
- the annotation type parameter- Parameters:
annotationClass
- the annotation class- Returns:
- the array of Annotation
-
isAnnotationDeclared
@SafeVarargs public final boolean isAnnotationDeclared(@NonNull @NonNull Class<? extends Annotation>... annotationClasses)
Determines if any of the given annotations are declared on this object- Parameters:
annotationClasses
- the annotation classes- Returns:
- True - if any of the given annotations are declared on this object
-
isAnnotationPresent
@SafeVarargs public final boolean isAnnotationPresent(@NonNull @NonNull Class<? extends Annotation>... annotationClasses)
Determines if any of the given annotations are present on this object- Parameters:
annotationClasses
- the annotation classes- Returns:
- True - if any of the given annotations are present on this object
-
processAnnotation
public final <A extends Annotation,O> O processAnnotation(@NonNull @NonNull Class<A> annotationClass, @NonNull @NonNull CheckedFunction<? super A,? extends O> function) throws ReflectionException
Applies the givenCheckedBiFunction
to this object with the given annotation if it is present on the object.- Type Parameters:
A
- the annotation type parameterO
- the return type parameter- Parameters:
annotationClass
- the annotation classfunction
- the function to apply- Returns:
- the return value of the function or null if no annotation was present
- Throws:
ReflectionException
- Something went wrong during reflection
-
processAnnotations
public final <A extends Annotation,O> List<O> processAnnotations(@NonNull @NonNull Class<A> annotationClass, @NonNull @NonNull CheckedFunction<? super A,? extends O> function) throws ReflectionException
Applies the givenCheckedBiFunction
to this object and all instances of the given annotation present on the object.- Type Parameters:
A
- the annotation type parameterO
- the return type parameter- Parameters:
annotationClass
- the annotation classfunction
- the function to apply- Returns:
- A list of the return values of the function or null if no annotation was present
- Throws:
ReflectionException
- Something went wrong during reflection
-
withAnnotation
public final <A extends Annotation> V withAnnotation(@NonNull @NonNull Class<A> annotationClass, @NonNull @NonNull CheckedConsumer<? super A> consumer) throws ReflectionException
Applies the givenCheckedBiConsumer
to this object with the given annotation if it is present on the object.- Type Parameters:
A
- the annotation type parameter- Parameters:
annotationClass
- the annotation classconsumer
- the consumer to apply- Returns:
- This object
- Throws:
ReflectionException
- Something went wrong during reflection
-
withAnnotations
public final <A extends Annotation> V withAnnotations(@NonNull @NonNull Class<A> annotationClass, @NonNull @NonNull CheckedConsumer<? super A> consumer) throws ReflectionException
Applies the givenCheckedBiConsumer
to this object and all instances of the given annotation present on this object.- Type Parameters:
A
- the annotation type parameter- Parameters:
annotationClass
- the annotation classconsumer
- the consumer to apply- Returns:
- This object
- Throws:
ReflectionException
- Something went wrong during reflection
-
-