Add missing constructors to SynthesizingMethodParameter
This commit primarily allows for a `SynthesizingMethodParameter` to be created for a `Constructor` parameter but also introduces an additional overloaded constructor from `MethodParameter`. Issue: SPR-14054
This commit is contained in:
@@ -48,15 +48,18 @@ import org.springframework.util.ClassUtils;
|
|||||||
*/
|
*/
|
||||||
public class MethodParameter {
|
public class MethodParameter {
|
||||||
|
|
||||||
private static Class<?> javaUtilOptionalClass = null;
|
private static final Class<?> javaUtilOptionalClass;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
Class<?> clazz;
|
||||||
try {
|
try {
|
||||||
javaUtilOptionalClass = ClassUtils.forName("java.util.Optional", MethodParameter.class.getClassLoader());
|
clazz = ClassUtils.forName("java.util.Optional", MethodParameter.class.getClassLoader());
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
// Java 8 not available - Optional references simply not supported then.
|
// Java 8 not available - Optional references simply not supported then.
|
||||||
|
clazz = null;
|
||||||
}
|
}
|
||||||
|
javaUtilOptionalClass = clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -312,7 +315,7 @@ public class MethodParameter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether this method parameter is declared as optiona
|
* Return whether this method parameter is declared as optional
|
||||||
* in the form of Java 8's {@link java.util.Optional}.
|
* in the form of Java 8's {@link java.util.Optional}.
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.springframework.core.annotation;
|
package org.springframework.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
@@ -34,7 +35,8 @@ import org.springframework.core.MethodParameter;
|
|||||||
public class SynthesizingMethodParameter extends MethodParameter {
|
public class SynthesizingMethodParameter extends MethodParameter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@code SynthesizingMethodParameter} for the given method.
|
* Create a new {@code SynthesizingMethodParameter} for the given method,
|
||||||
|
* with nesting level 1.
|
||||||
* @param method the Method to specify a parameter for
|
* @param method the Method to specify a parameter for
|
||||||
* @param parameterIndex the index of the parameter: -1 for the method
|
* @param parameterIndex the index of the parameter: -1 for the method
|
||||||
* return type; 0 for the first method parameter; 1 for the second method
|
* return type; 0 for the first method parameter; 1 for the second method
|
||||||
@@ -44,6 +46,47 @@ public class SynthesizingMethodParameter extends MethodParameter {
|
|||||||
super(method, parameterIndex);
|
super(method, parameterIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@code SynthesizingMethodParameter} for the given method.
|
||||||
|
* @param method the Method to specify a parameter for
|
||||||
|
* @param 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.
|
||||||
|
* @param 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 SynthesizingMethodParameter(Method method, int parameterIndex, int nestingLevel) {
|
||||||
|
super(method, parameterIndex, nestingLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@code SynthesizingMethodParameter} for the given constructor,
|
||||||
|
* with nesting level 1.
|
||||||
|
* @param constructor the Constructor to specify a parameter for
|
||||||
|
* @param parameterIndex the index of the parameter
|
||||||
|
*/
|
||||||
|
public SynthesizingMethodParameter(Constructor<?> constructor, int parameterIndex) {
|
||||||
|
super(constructor, parameterIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@code SynthesizingMethodParameter} for the given constructor.
|
||||||
|
* @param constructor the Constructor to specify a parameter for
|
||||||
|
* @param parameterIndex the index of the parameter
|
||||||
|
* @param 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 SynthesizingMethodParameter(Constructor<?> constructor, int parameterIndex, int nestingLevel) {
|
||||||
|
super(constructor, parameterIndex, nestingLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy constructor, resulting in an independent {@code SynthesizingMethodParameter}
|
||||||
|
* based on the same metadata and cache state that the original object was in.
|
||||||
|
* @param original the original SynthesizingMethodParameter object to copy from
|
||||||
|
*/
|
||||||
protected SynthesizingMethodParameter(SynthesizingMethodParameter original) {
|
protected SynthesizingMethodParameter(SynthesizingMethodParameter original) {
|
||||||
super(original);
|
super(original);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user