Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2009 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.springframework.core;
 
 import java.util.Map;
 
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.

Author(s):
Juergen Hoeller
Rob Harrop
Andy Clement
Since:
2.0
See also:
GenericCollectionTypeResolver
 
 public class MethodParameter {
 
 	private Method method;
 
 
 	private final int parameterIndex;
 
 	private Class<?> parameterType;
 
 
 
 
 	private String parameterName;
 
 	private int nestingLevel = 1;

Map from Integer level to Integer type index
 
 
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
 
 	public MethodParameter(Method methodint parameterIndex) {
 		this(methodparameterIndex, 1);
 	}

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)
 
 	public MethodParameter(Method methodint parameterIndexint nestingLevel) {
 		Assert.notNull(method"Method must not be null");
 		this. = method;
 		this. = parameterIndex;
 		this. = nestingLevel;
 	}

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
 
 	public MethodParameter(Constructor constructorint parameterIndex) {
 		this(constructorparameterIndex, 1);
 	}

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)
	public MethodParameter(Constructor constructorint parameterIndexint nestingLevel) {
		Assert.notNull(constructor"Constructor must not be null");
		this. = constructor;
		this. = parameterIndex;
		this. = nestingLevel;
	}

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
	public MethodParameter(MethodParameter original) {
		Assert.notNull(original"Original must not be null");
		this. = original.method;
		this. = original.constructor;
		this. = original.parameterIndex;
		this. = original.parameterType;
		this. = original.parameterAnnotations;
		this. = original.typeVariableMap;
	}


Return the wrapped Method, if any.

Note: Either Method or Constructor is available.

Returns:
the Method, or null if none
	public Method getMethod() {
		return this.;
	}

Return the wrapped Constructor, if any.

Note: Either Method or Constructor is available.

Returns:
the Constructor, or null if none
		return this.;
	}

Return the class that declares the underlying Method or Constructor.
		return (this. != null ? this..getDeclaringClass() : this..getDeclaringClass());
	}

Return the index of the method/constructor parameter.

Returns:
the parameter index (never negative)
	public int getParameterIndex() {
		return this.;
	}

Set a resolved (generic) parameter type.
	void setParameterType(Class<?> parameterType) {
		this. = parameterType;
	}

Return the type of the method/constructor parameter.

Returns:
the parameter type (never null)
	public Class<?> getParameterType() {
		if (this. == null) {
			if (this. < 0) {
				this. = (this. != null ? this..getReturnType() : null);
			}
			else {
				this. = (this. != null ?
			}
		}
		return this.;
	}

Return the generic type of the method/constructor parameter.

Returns:
the parameter type (never null)
		if (this. == null) {
			if (this. < 0) {
				this. = (this. != null ? this..getGenericReturnType() : null);
			}
			else {
				this. = (this. != null ?
			}
		}
	}

Return the annotations associated with the target method/constructor itself.
		return (this. != null ? this..getAnnotations() : this..getAnnotations());
	}

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
	@SuppressWarnings("unchecked")
	public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
		return (this. != null ? this..getAnnotation(annotationType) :
				(T) this..getAnnotation(annotationType));
	}

Return the annotations associated with the specific method/constructor parameter.
		if (this. == null) {
			Annotation[][] annotationArray = (this. != null ?
			this. = annotationArray[this.];
		}
	}

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
	@SuppressWarnings("unchecked")
	public <T extends Annotation> T getParameterAnnotation(Class<T> annotationType) {
		for (Annotation ann : anns) {
			if (annotationType.isInstance(ann)) {
				return (T) ann;
			}
		}
		return null;
	}

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

	public void initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer) {
		this. = parameterNameDiscoverer;
	}

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)
		if (this. != null) {
			String[] parameterNames = (this. != null ?
			if (parameterNames != null) {
				this. = parameterNames[this.];
			}
		}
		return this.;
	}

Increase this parameter's nesting level.

	public void increaseNestingLevel() {
	}

Decrease this parameter's nesting level.

	public void decreaseNestingLevel() {
	}

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 int getNestingLevel() {
		return this.;
	}

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()
	public void setTypeIndexForCurrentLevel(int typeIndex) {
	}

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()
	}

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)
	public Integer getTypeIndexForLevel(int nestingLevel) {
		return getTypeIndexesPerLevel().get(nestingLevel);
	}

Obtain the (lazily constructed) type-indexes-per-level Map.
		if (this. == null) {
		}
		return this.;
	}


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
	public static MethodParameter forMethodOrConstructor(Object methodOrConstructorint parameterIndex) {
		if (methodOrConstructor instanceof Method) {
			return new MethodParameter((MethodmethodOrConstructorparameterIndex);
		}
		else if (methodOrConstructor instanceof Constructor) {
			return new MethodParameter((ConstructormethodOrConstructorparameterIndex);
		}
		else {
					"Given object [" + methodOrConstructor + "] is neither a Method nor a Constructor");
		}
	}
New to GrepCode? Check out our FAQ X