Top Description Inners Fields Constructors Methods
org.springframework.core

public Class MethodParameter

extends Object
Class Inheritance
Known Direct Subclasses
org.springframework.core.MethodParameter.FieldAwareConstructorParameter, org.springframework.core.annotation.SynthesizingMethodParameter
Imports
java.lang.annotation.Annotation, java.lang.reflect.AnnotatedElement, .Constructor, .Executable, .Field, .Member, .Method, .Parameter, .ParameterizedType, .Type, java.util.ArrayList, .Arrays, .HashMap, .List, .Map, .Optional, java.util.function.Predicate, kotlin.Unit, kotlin.reflect.KFunction, kotlin.reflect.KParameter, kotlin.reflect.jvm.ReflectJvmMapping, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ObjectUtils

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.

As of 4.2, there is a org.springframework.core.annotation.SynthesizingMethodParameter subclass available which synthesizes annotations with attribute aliases. That subclass is used for web and message endpoint processing, in particular.

Authors
Juergen Hoeller, Rob Harrop, Andy Clement, Sam Brannen, Sebastien Deleuze, Phillip Webb
Since
2.0
See Also
org.springframework.core.annotation.SynthesizingMethodParameter

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MethodParameter.FieldAwareConstructorParameter

MethodParameter subclass which detects field annotations as well.

private static class
MethodParameter.KotlinDelegate

Inner class to avoid a hard dependency on Kotlin at runtime.

Field Summary

Modifier and TypeField and Description
private volatile Class<?>
containingClass

The containing class.

private static final Annotation[]
private final Executable
private volatile Type
private volatile MethodParameter
private int
private volatile Parameter
private volatile Annotation[]
private final int
pack-priv volatile String
private volatile ParameterNameDiscoverer
private volatile Class<?>
pack-priv Map<Integer, Integer>
typeIndexesPerLevel

Map from Integer level to Integer type index.

Constructor Summary

AccessConstructor and Description
public
MethodParameter(Method
the Method to specify a parameter for
method
,
int
the index of the parameter: -1 for the method return type; 0 for the first method parameter; 1 for the second method parameter, etc.
parameterIndex
)

Create a new MethodParameter for the given method, with nesting level 1.

public
MethodParameter(Method
the Method to specify a parameter for
method
,
int
the index of the parameter: -1 for the method return type; 0 for the first method parameter; 1 for the second method parameter, etc.
parameterIndex
,
int
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)
nestingLevel
)

Create a new MethodParameter for the given method.

public
MethodParameter(Constructor<?>
the Constructor to specify a parameter for
constructor
,
int
the index of the parameter
parameterIndex
)

Create a new MethodParameter for the given constructor, with nesting level 1.

public
MethodParameter(Constructor<?>
the Constructor to specify a parameter for
constructor
,
int
the index of the parameter
parameterIndex
,
int
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)
nestingLevel
)

Create a new MethodParameter for the given constructor.

pack-priv
MethodParameter(Executable
the Executable to specify a parameter for
executable
,
int
the index of the parameter
parameterIndex
,
Class<?>
the containing class
containingClass
)

Internal constructor used to create a MethodParameter with a containing class already set.

public
MethodParameter(MethodParameter
the original MethodParameter object to copy from
original
)

Copy constructor, resulting in an independent MethodParameter object based on the same metadata and cache state that the original object was in.

Method Summary

Modifier and TypeMethod and Description
protected <A extends Annotation> A

Returns:

the post-processed annotation (or simply the original one)
adaptAnnotation
(A
the annotation about to be returned
annotation
)

A template method to post-process a given annotation instance before returning it to the caller.

protected Annotation[]

Returns:

the post-processed annotation array (or simply the original one)
adaptAnnotationArray
(Annotation[]
the annotation array about to be returned
annotations
)

A template method to post-process a given annotation array before returning it to the caller.

public MethodParameter
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
private Class<?>
public void
decreaseNestingLevel()

Deprecated since 5.2 in favor of retaining the original MethodParameter and using nested(Integer) if nesting is required
Decrease this parameter's nesting level.
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
protected static int
public static MethodParameter

Returns:

the corresponding MethodParameter instance
forExecutable
(Executable
the Method or Constructor to specify a parameter for
executable
,
int
the index of the parameter
parameterIndex
)

Create a new MethodParameter for the given method or constructor.

public static MethodParameter

Returns:

the corresponding MethodParameter instance
forFieldAwareConstructor
(Constructor<?>
the Constructor to specify a parameter for
ctor
,
int
the index of the parameter
parameterIndex
,
String
the name of the underlying field, matching the constructor's parameter name
fieldName
)

Create a new MethodParameter for the given field-aware constructor, e.g. on a data class or record type.

public static MethodParameter

Returns:

the corresponding MethodParameter instance
forMethodOrConstructor
(Object
the Method or Constructor to specify a parameter for
methodOrConstructor
,
int
the index of the parameter
parameterIndex
)

Deprecated as of 5.0, in favor of forExecutable
Create a new MethodParameter for the given method or constructor.
public static MethodParameter

Returns:

the corresponding MethodParameter instance
forParameter
(Parameter
the parameter descriptor
parameter
)

Create a new MethodParameter for the given parameter descriptor.

public AnnotatedElement

Returns:

the Method or Constructor as AnnotatedElement
getAnnotatedElement
()

Return the wrapped annotated element.

public Constructor<?>

Returns:

the Constructor, or null if none
getConstructor
()

Return the wrapped Constructor, if any.

public Class<?>

Returns:

a specific containing class (potentially a subclass of the declaring class), or otherwise simply the declaring class itself
getContainingClass
()

Return the containing class for this method parameter.

public Class<?>
getDeclaringClass()

Return the class that declares the underlying Method or Constructor.

public Executable

Returns:

the Method or Constructor as Executable
getExecutable
()

Return the wrapped executable.

public Type

Returns:

the parameter type (never null)
getGenericParameterType
()

Return the generic type of the method/constructor parameter.

public Member

Returns:

the Method or Constructor as Member
getMember
()

Return the wrapped member.

public Method

Returns:

the Method, or null if none
getMethod
()

Return the wrapped Method, if any.

public <A extends Annotation> A

Returns:

the annotation object, or null if not found
getMethodAnnotation
(Class<A>
the annotation type to look for
annotationType
)

Return the method/constructor annotation of the given type, if available.

public Annotation[]
getMethodAnnotations()

Return the annotations associated with the target method/constructor itself.

public Type

Returns:

the parameter type (never null)
getNestedGenericParameterType
()

Return the nested generic type of the method/constructor parameter.

public Class<?>

Returns:

the parameter type (never null)
getNestedParameterType
()

Return the nested type of the method/constructor parameter.

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).

public Parameter
getParameter()

Return the Parameter descriptor for method/constructor parameter.

public <A extends Annotation> A

Returns:

the annotation object, or null if not found
getParameterAnnotation
(Class<A>
the annotation type to look for
annotationType
)

Return the parameter annotation of the given type, if available.

public Annotation[]
getParameterAnnotations()

Return the annotations associated with the specific method/constructor parameter.

public int

Returns:

the parameter index (-1 in case of the return type)
getParameterIndex
()

Return the index of the method/constructor parameter.

public String

Returns:

the parameter name (may be null if no parameter name metadata is contained in the class file or no ParameterNameDiscoverer has been set to begin with)
getParameterName
()

Return the name of the method/constructor parameter.

public Class<?>

Returns:

the parameter type (never null)
getParameterType
()

Return the type of the method/constructor parameter.

private Map<Integer, Integer>
getTypeIndexesPerLevel()

Obtain the (lazily constructed) type-indexes-per-level Map.

public Integer

Returns:

the corresponding type index, or null if none specified (indicating the default type index)
getTypeIndexForCurrentLevel
()

Return the type index for the current nesting level.

public Integer

Returns:

the corresponding type index, or null if none specified (indicating the default type index)
getTypeIndexForLevel
(int
the nesting level to check
nestingLevel
)

Return the type index for the specified nesting level.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public <A extends Annotation> boolean
hasMethodAnnotation(Class<A>
the annotation type to look for
annotationType
)

Return whether the method/constructor is annotated with the given type.

private boolean
hasNullableAnnotation()

Check whether this method parameter is annotated with any variant of a Nullable annotation, e.g. jakarta.annotation.Nullable or edu.umd.cs.findbugs.annotations.Nullable.

public <A extends Annotation> boolean
hasParameterAnnotation(Class<A>
the annotation type to look for
annotationType
)

Return whether the parameter is declared with the given annotation type.

public boolean
hasParameterAnnotations()

Return true if the parameter has at least one annotation, false if it has none.

public void
increaseNestingLevel()

Deprecated since 5.2 in favor of nested(Integer)
Increase this parameter's nesting level.
public void
initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer)

Initialize parameter name discovery for this method parameter.

public boolean
isOptional()

Return whether this method indicates a parameter which is not required: either in the form of Java 8's java.util.Optional, any variant of a parameter-level Nullable annotation (such as from JSR-305 or the FindBugs set of annotations), or a language-level nullable type declaration or Continuation parameter in Kotlin.

public MethodParameter
nested()

Return a variant of this MethodParameter which points to the same parameter but one nesting level deeper.

public MethodParameter
nested(Integer
the type index for the new nesting level
typeIndex
)

Return a variant of this MethodParameter which points to the same parameter but one nesting level deeper.

private MethodParameter
nested(int nestingLevel, Integer typeIndex)

public MethodParameter
nestedIfOptional()

Return a variant of this MethodParameter which points to the same parameter but one nesting level deeper in case of a java.util.Optional declaration.

pack-priv void
setContainingClass(Class<?> containingClass)

Deprecated
Set a containing class to resolve the parameter type against.
pack-priv void
setParameterType(Class<?> parameterType)

Deprecated
Set a resolved (generic) parameter type.
public void
setTypeIndexForCurrentLevel(int
the corresponding type index (or null for the default type index)
typeIndex
)

Deprecated since 5.2 in favor of withTypeIndex
Set the type index for the current nesting level.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private static int
validateIndex(Executable executable, int parameterIndex)

public MethodParameter
withContainingClass(Class<?>
a specific containing class (potentially a subclass of the declaring class, e.g. substituting a type variable)
containingClass
)

Return a variant of this MethodParameter which refers to the given containing class.

public MethodParameter
withTypeIndex(int
the new type index
typeIndex
)

Return a variant of this MethodParameter with the type for the current level set to the specified value.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait