Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2008 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.

Used by GenericCollectionTypeResolver, org.springframework.beans.BeanWrapperImpl and org.springframework.beans.factory.support.AbstractBeanFactory.

Note that this class does not depend on JDK 1.5 API artifacts, in order to remain compatible with JDK 1.4. Concrete generic type resolution via JDK 1.5 API happens in GenericCollectionTypeResolver only.

Author(s):
Juergen Hoeller
Rob Harrop
Since:
2.0
See also:
GenericCollectionTypeResolver
 
 public class MethodParameter {
 
 	private static final Method methodParameterAnnotationsMethod =
 			ClassUtils.getMethodIfAvailable(Method.class"getParameterAnnotations"new Class[0]);
 
 	private static final Method constructorParameterAnnotationsMethod =
 			ClassUtils.getMethodIfAvailable(Constructor.class"getParameterAnnotations"new Class[0]);
 
 
 	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 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) {
			this. = (this. != null ?
		}
		return this.;
	}

Return the annotations associated with the method/constructor parameter.

Returns:
the parameter annotations, or null if there is no annotation support (on JDK < 1.5). The return value is an Object array instead of an Annotation array simply for compatibility with older JDKs; feel free to cast it to Annotation[] on JDK 1.5 or higher.
		if (this. != null) {
		}
			return null;
		}
		Object[][] annotationArray = (this. != null ?
				((Object[][]) ReflectionUtils.invokeMethod(this.)) :
		this. = annotationArray[this.];
	}

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) {
		getTypeIndexesPerLevel().put(new Integer(this.), new Integer(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 (IntegergetTypeIndexesPerLevel().get(new Integer(nestingLevel));
	}

Obtain the (lazily constructed) type-indexes-per-level Map.
		if (this. == null) {
			this. = new HashMap(4);
		}
		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