Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.core
Class MethodParameter

    java.lang.Object
      org.springframework.core.MethodParameter

    public class MethodParameter

extends java.lang.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.

Since:
  2.0
Author:
  Juergen Hoeller, Rob Harrop, Andy Clement, Nikita Tovstoles, Chris Beams
See Also:
  `GenericCollectionTypeResolver`

Constructor Summary
`MethodParameter(java.lang.reflect.Constructor constructor, int parameterIndex)` Create a new MethodParameter for the given constructor, with nesting level 1.
`MethodParameter(java.lang.reflect.Constructor constructor, int parameterIndex, int nestingLevel)` Create a new MethodParameter for the given constructor.
`MethodParameter(java.lang.reflect.Method method, int parameterIndex)` Create a new MethodParameter for the given method, with nesting level 1.
`MethodParameter(java.lang.reflect.Method method, int parameterIndex, int nestingLevel)` Create a new MethodParameter for the given method.
`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.

Method Summary
`void` | `decreaseNestingLevel()` Decrease this parameter's nesting level.
`boolean` | `equals(java.lang.Object obj)`
`static MethodParameter` | `forMethodOrConstructor(java.lang.Object methodOrConstructor, int parameterIndex)` Create a new MethodParameter for the given method or constructor.
`java.lang.reflect.Constructor` | `getConstructor()` Return the wrapped Constructor, if any.
`java.lang.Class` | `getDeclaringClass()` Return the class that declares the underlying Method or Constructor.
`java.lang.reflect.Type` | `getGenericParameterType()` Return the generic type of the method/constructor parameter.
`java.lang.reflect.Method` | `getMethod()` Return the wrapped Method, if any.
`
`<T extends java.lang.annotation.Annotation> T`
` | `getMethodAnnotation(java.lang.Class<T> annotationType)` Return the method/constructor annotation of the given type, if available.
`java.lang.annotation.Annotation[]` | `getMethodAnnotations()` Return the annotations associated with the target method/constructor itself.
`java.lang.Class<?>` | `getNestedParameterType()`
`int` | `getNestingLevel()` Return the nesting level of the target type (typically 1; e.g.
`
`<T extends java.lang.annotation.Annotation> T`
` | `getParameterAnnotation(java.lang.Class<T> annotationType)` Return the parameter annotation of the given type, if available.
`java.lang.annotation.Annotation[]` | `getParameterAnnotations()` Return the annotations associated with the specific method/constructor parameter.
`int` | `getParameterIndex()` Return the index of the method/constructor parameter.
`java.lang.String` | `getParameterName()` Return the name of the method/constructor parameter.
`java.lang.Class<?>` | `getParameterType()` Return the type of the method/constructor parameter.
`java.lang.Integer` | `getTypeIndexForCurrentLevel()` Return the type index for the current nesting level.
`java.lang.Integer` | `getTypeIndexForLevel(int nestingLevel)` Return the type index for the specified nesting level.
`int` | `hashCode()`
`
`<T extends java.lang.annotation.Annotation> boolean`
` | `hasParameterAnnotation(java.lang.Class<T> annotationType)` Return true if the parameter has the given annotation type, and false if it doesn't.
`boolean` | `hasParameterAnnotations()` Return true if the parameter has at least one annotation, false if it has none.
`void` | `increaseNestingLevel()` Increase this parameter's nesting level.
`void` | `initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer)` Initialize parameter name discovery for this method parameter.
`void` | `setTypeIndexForCurrentLevel(int typeIndex)` Set the type index for the current nesting level.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MethodParameter

    public MethodParameter(java.lang.reflect.Method method,
                           int parameterIndex)

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

  Parameters:
    `method` - the Method to specify a parameter for
    `parameterIndex` - the index of the parameter

### MethodParameter

    public MethodParameter(java.lang.reflect.Method method,
                           int parameterIndex,
                           int nestingLevel)

  Create a new MethodParameter for the given method.

  Parameters:
    `method` - the Method to specify a parameter for
    `parameterIndex` - 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

    public MethodParameter(java.lang.reflect.Constructor constructor,
                           int parameterIndex)

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

  Parameters:
    `constructor` - the Constructor to specify a parameter for
    `parameterIndex` - the index of the parameter

### MethodParameter

    public MethodParameter(java.lang.reflect.Constructor constructor,
                           int parameterIndex,
                           int nestingLevel)

  Create a new MethodParameter for the given constructor.

  Parameters:
    `constructor` - the Constructor to specify a parameter for
    `parameterIndex` - the index of the parameter
    `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

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

  Parameters:
    `original` - the original MethodParameter object to copy from

Method Detail

### getMethod

    public java.lang.reflect.Method getMethod()

  Return the wrapped Method, if any.

  Note: Either Method or Constructor is available.

  Returns:
    the Method, or `null` if none

### getConstructor

    public java.lang.reflect.Constructor getConstructor()

  Return the wrapped Constructor, if any.

  Note: Either Method or Constructor is available.

  Returns:
    the Constructor, or `null` if none

### getDeclaringClass

    public java.lang.Class 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 (never negative)

### getParameterType

    public java.lang.Class<?> getParameterType()

  Return the type of the method/constructor parameter.

  Returns:
    the parameter type (never `null`)

### getGenericParameterType

    public java.lang.reflect.Type getGenericParameterType()

  Return the generic type of the method/constructor parameter.

  Returns:
    the parameter type (never `null`)

### getNestedParameterType

    public java.lang.Class<?> getNestedParameterType()

### getMethodAnnotations

    public java.lang.annotation.Annotation[] getMethodAnnotations()

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

### getMethodAnnotation

    public <T extends java.lang.annotation.Annotation> T getMethodAnnotation(java.lang.Class<T> annotationType)

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

  Parameters:
    `annotationType` - the annotation type to look for
  Returns:
    the annotation object, or `null` if not found

### getParameterAnnotations

    public java.lang.annotation.Annotation[] getParameterAnnotations()

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

### getParameterAnnotation

    public <T extends java.lang.annotation.Annotation> T getParameterAnnotation(java.lang.Class<T> annotationType)

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

  Parameters:
    `annotationType` - the annotation type to look for
  Returns:
    the annotation object, or `null` if not found

### hasParameterAnnotations

    public boolean hasParameterAnnotations()

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

### hasParameterAnnotation

    public <T extends java.lang.annotation.Annotation> boolean hasParameterAnnotation(java.lang.Class<T> annotationType)

  Return true if the parameter has the given annotation type, and false if it doesn't.

### initParameterNameDiscovery

    public void initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer)

  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

    public java.lang.String getParameterName()

  Return the name of the method/constructor parameter.

  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)

### 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 (or `null` for the default type index)
  See Also:
    `getNestingLevel()`

### getTypeIndexForCurrentLevel

    public java.lang.Integer getTypeIndexForCurrentLevel()

  Return the type index for the current nesting level.

  Returns:
    the corresponding type index, or `null` if none specified (indicating the default type index)
  See Also:
    `getNestingLevel()`

### getTypeIndexForLevel

    public java.lang.Integer getTypeIndexForLevel(int nestingLevel)

  Return the type index for the specified nesting level.

  Parameters:
    `nestingLevel` - the nesting level to check
  Returns:
    the corresponding type index, or `null` if none specified (indicating the default type index)

### forMethodOrConstructor

    public static MethodParameter forMethodOrConstructor(java.lang.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 for
    `parameterIndex` - the index of the parameter
  Returns:
    the corresponding MethodParameter instance

### equals

    public boolean equals(java.lang.Object obj)

  Overrides:
    `equals` in class `java.lang.Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `java.lang.Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD