java.lang.Object
io.lettuce.core.dynamic.support.MethodParameter
public class MethodParameter extends Object
Helper class that encapsulates the specification of a method parameter, i.e. a
Method or Constructor plus a
parameter index and a nested type index for a declared generic type. Useful as a specification object to pass along.-
Constructor Summary
Constructors Constructor Description MethodParameter(MethodParameter original)Copy constructor, resulting in an independent MethodParameter object based on the same metadata and cache state that the original object was in.MethodParameter(Constructor<?> constructor, int parameterIndex)Create a new MethodParameter for the given constructor, with nesting level 1.MethodParameter(Constructor<?> constructor, int parameterIndex, int nestingLevel)Create a new MethodParameter for the given constructor.MethodParameter(Method method, int parameterIndex)Create a newMethodParameterfor the given method, with nesting level 1.MethodParameter(Method method, int parameterIndex, int nestingLevel)Create a newMethodParameterfor the given method. -
Method Summary
Modifier and Type Method Description protected <A extends Annotation>
AadaptAnnotation(A annotation)A template method to post-process a given annotation instance before returning it to the caller.protected Annotation[]adaptAnnotationArray(Annotation[] annotations)A template method to post-process a given annotation array before returning it to the caller.voiddecreaseNestingLevel()Decrease this parameter's nesting level.booleanequals(Object other)static MethodParameterforMethodOrConstructor(Object methodOrConstructor, int parameterIndex)Create a new MethodParameter for the given method or constructor.AnnotatedElementgetAnnotatedElement()Returns the wrapped annotated element.Constructor<?>getConstructor()Return the wrapped Constructor, if any.Class<?>getContainingClass()Class<?>getDeclaringClass()Return the class that declares the underlying Method or Constructor.TypegetGenericParameterType()Return the generic type of the method/constructor parameter.MembergetMember()Returns the wrapped member.MethodgetMethod()Return the wrapped Method, if any.<A extends Annotation>
AgetMethodAnnotation(Class<A> annotationType)Return the method/constructor annotation of the given type, if available.Annotation[]getMethodAnnotations()Return the annotations associated with the target method/constructor itself.TypegetNestedGenericParameterType()Return the nested generic type of the method/constructor parameter.Class<?>getNestedParameterType()Return the nested type of the method/constructor parameter.intgetNestingLevel()Return the nesting level of the target type (typically 1; e.g.<T extends Annotation>
TgetParameterAnnotation(Class<T> annotationType)Return the parameter annotation of the given type, if available.Annotation[]getParameterAnnotations()Return the annotations associated with the specific method/constructor parameter.intgetParameterIndex()Return the index of the method/constructor parameter.StringgetParameterName()Return the name of the method/constructor parameter.Class<?>getParameterType()Return the type of the method/constructor parameter.IntegergetTypeIndexForCurrentLevel()Return the type index for the current nesting level.IntegergetTypeIndexForLevel(int nestingLevel)Return the type index for the specified nesting level.inthashCode()<T extends Annotation>
booleanhasParameterAnnotation(Class<T> annotationType)Return true if the parameter has the given annotation type, and false if it doesn't.booleanhasParameterAnnotations()Return true if the parameter has at least one annotation, false if it has none.voidincreaseNestingLevel()Increase this parameter's nesting level.voidinitParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer)Initialize parameter name discovery for this method parameter.voidsetTypeIndexForCurrentLevel(int typeIndex)Set the type index for the current nesting level.
-
Constructor Details
-
MethodParameter
Create a newMethodParameterfor the given method, with nesting level 1.- Parameters:
method- the Method to specify a parameter forparameterIndex- the index of the parameter: -1 for the method return type; 0 for the first method parameter; 1 for the second method parameter, etc.
-
MethodParameter
Create a newMethodParameterfor the given method.- Parameters:
method- the Method to specify a parameter forparameterIndex- the index of the parameter: -1 for the method return type; 0 for the first method parameter; 1 for the second method parameter, etc.nestingLevel- the nesting level of the target type (typically 1; e.g. in case of a List of Lists, 1 would indicate the nested List, whereas 2 would indicate the element of the nested List)
-
MethodParameter
Create a new MethodParameter for the given constructor, with nesting level 1.- Parameters:
constructor- the Constructor to specify a parameter forparameterIndex- the index of the parameter
-
MethodParameter
Create a new MethodParameter for the given constructor.- Parameters:
constructor- the Constructor to specify a parameter forparameterIndex- the index of the parameternestingLevel- the nesting level of the target type (typically 1; e.g. in case of a List of Lists, 1 would indicate the nested List, whereas 2 would indicate the element of the nested List)
-
MethodParameter
Copy constructor, resulting in an independent MethodParameter object based on the same metadata and cache state that the original object was in.- Parameters:
original- the original MethodParameter object to copy from
-
-
Method Details
-
getMethod
Return the wrapped Method, if any.Note: Either Method or Constructor is available.
- Returns:
- the Method, or
nullif none
-
getConstructor
Return the wrapped Constructor, if any.Note: Either Method or Constructor is available.
- Returns:
- the Constructor, or
nullif none
-
getMember
Returns the wrapped member.- Returns:
- the Method or Constructor as Member
-
getAnnotatedElement
Returns the wrapped annotated element.- Returns:
- the Method or Constructor as AnnotatedElement
-
getDeclaringClass
Return the class that declares the underlying Method or Constructor. -
getParameterIndex
public int getParameterIndex()Return the index of the method/constructor parameter.- Returns:
- the parameter index (-1 in case of the return type)
-
increaseNestingLevel
public void increaseNestingLevel()Increase this parameter's nesting level.- See Also:
getNestingLevel()
-
decreaseNestingLevel
public void decreaseNestingLevel()Decrease this parameter's nesting level.- See Also:
getNestingLevel()
-
getNestingLevel
public int getNestingLevel()Return the nesting level of the target type (typically 1; e.g. in case of a List of Lists, 1 would indicate the nested List, whereas 2 would indicate the element of the nested List). -
setTypeIndexForCurrentLevel
public void setTypeIndexForCurrentLevel(int typeIndex)Set the type index for the current nesting level.- Parameters:
typeIndex- the corresponding type index (ornullfor the default type index)- See Also:
getNestingLevel()
-
getTypeIndexForCurrentLevel
Return the type index for the current nesting level.- Returns:
- the corresponding type index, or
nullif none specified (indicating the default type index) - See Also:
getNestingLevel()
-
getTypeIndexForLevel
Return the type index for the specified nesting level.- Parameters:
nestingLevel- the nesting level to check- Returns:
- the corresponding type index, or
nullif none specified (indicating the default type index)
-
getContainingClass
-
getParameterType
Return the type of the method/constructor parameter.- Returns:
- the parameter type (never
null)
-
getGenericParameterType
Return the generic type of the method/constructor parameter.- Returns:
- the parameter type (never
null)
-
getNestedParameterType
Return the nested type of the method/constructor parameter.- Returns:
- the parameter type (never
null) - See Also:
getNestingLevel()
-
getNestedGenericParameterType
Return the nested generic type of the method/constructor parameter.- Returns:
- the parameter type (never
null) - See Also:
getNestingLevel()
-
getMethodAnnotations
Return the annotations associated with the target method/constructor itself. -
getMethodAnnotation
Return the method/constructor annotation of the given type, if available.- Parameters:
annotationType- the annotation type to look for- Returns:
- the annotation object, or
nullif not found
-
getParameterAnnotations
Return the annotations associated with the specific method/constructor parameter. -
getParameterAnnotation
Return the parameter annotation of the given type, if available.- Parameters:
annotationType- the annotation type to look for- Returns:
- the annotation object, or
nullif not found
-
hasParameterAnnotations
public boolean hasParameterAnnotations()Return true if the parameter has at least one annotation, false if it has none. -
hasParameterAnnotation
Return true if the parameter has the given annotation type, and false if it doesn't. -
initParameterNameDiscovery
Initialize parameter name discovery for this method parameter.This method does not actually try to retrieve the parameter name at this point; it just allows discovery to happen when the application calls
getParameterName()(if ever). -
getParameterName
Return the name of the method/constructor parameter.- Returns:
- the parameter name (may be
nullif no parameter name metadata is contained in the class file or noParameterNameDiscovererhas been set to begin with)
-
adaptAnnotation
A template method to post-process a given annotation instance before returning it to the caller.The default implementation simply returns the given annotation as-is.
- Parameters:
annotation- the annotation about to be returned- Returns:
- the post-processed annotation (or simply the original one)
-
adaptAnnotationArray
A template method to post-process a given annotation array before returning it to the caller.The default implementation simply returns the given annotation array as-is.
- Parameters:
annotations- the annotation array about to be returned- Returns:
- the post-processed annotation array (or simply the original one)
-
equals
-
hashCode
public int hashCode() -
forMethodOrConstructor
public static MethodParameter forMethodOrConstructor(Object methodOrConstructor, int parameterIndex)Create a new MethodParameter for the given method or constructor.This is a convenience constructor for scenarios where a Method or Constructor reference is treated in a generic fashion.
- Parameters:
methodOrConstructor- the Method or Constructor to specify a parameter forparameterIndex- the index of the parameter- Returns:
- the corresponding MethodParameter instance
-