Skip to content

Commit dfd4aae

Browse files
committed
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
1 parent 2a9b2ca commit dfd4aae

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

spring-core/src/main/java/org/springframework/core/MethodParameter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@
4848
*/
4949
public class MethodParameter {
5050

51-
private static Class<?> javaUtilOptionalClass = null;
51+
private static final Class<?> javaUtilOptionalClass;
5252

5353
static {
54+
Class<?> clazz;
5455
try {
55-
javaUtilOptionalClass = ClassUtils.forName("java.util.Optional", MethodParameter.class.getClassLoader());
56+
clazz = ClassUtils.forName("java.util.Optional", MethodParameter.class.getClassLoader());
5657
}
5758
catch (ClassNotFoundException ex) {
5859
// Java 8 not available - Optional references simply not supported then.
60+
clazz = null;
5961
}
62+
javaUtilOptionalClass = clazz;
6063
}
6164

6265

@@ -312,7 +315,7 @@ public MethodParameter nested() {
312315
}
313316

314317
/**
315-
* Return whether this method parameter is declared as optiona
318+
* Return whether this method parameter is declared as optional
316319
* in the form of Java 8's {@link java.util.Optional}.
317320
* @since 4.3
318321
*/

spring-core/src/main/java/org/springframework/core/annotation/SynthesizingMethodParameter.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.core.annotation;
1818

1919
import java.lang.annotation.Annotation;
20+
import java.lang.reflect.Constructor;
2021
import java.lang.reflect.Method;
2122

2223
import org.springframework.core.MethodParameter;
@@ -34,7 +35,8 @@
3435
public class SynthesizingMethodParameter extends MethodParameter {
3536

3637
/**
37-
* Create a new {@code SynthesizingMethodParameter} for the given method.
38+
* Create a new {@code SynthesizingMethodParameter} for the given method,
39+
* with nesting level 1.
3840
* @param method the Method to specify a parameter for
3941
* @param parameterIndex the index of the parameter: -1 for the method
4042
* return type; 0 for the first method parameter; 1 for the second method
@@ -44,6 +46,47 @@ public SynthesizingMethodParameter(Method method, int parameterIndex) {
4446
super(method, parameterIndex);
4547
}
4648

49+
/**
50+
* Create a new {@code SynthesizingMethodParameter} for the given method.
51+
* @param method the Method to specify a parameter for
52+
* @param parameterIndex the index of the parameter: -1 for the method
53+
* return type; 0 for the first method parameter; 1 for the second method
54+
* parameter, etc.
55+
* @param nestingLevel the nesting level of the target type
56+
* (typically 1; e.g. in case of a List of Lists, 1 would indicate the
57+
* nested List, whereas 2 would indicate the element of the nested List)
58+
*/
59+
public SynthesizingMethodParameter(Method method, int parameterIndex, int nestingLevel) {
60+
super(method, parameterIndex, nestingLevel);
61+
}
62+
63+
/**
64+
* Create a new {@code SynthesizingMethodParameter} for the given constructor,
65+
* with nesting level 1.
66+
* @param constructor the Constructor to specify a parameter for
67+
* @param parameterIndex the index of the parameter
68+
*/
69+
public SynthesizingMethodParameter(Constructor<?> constructor, int parameterIndex) {
70+
super(constructor, parameterIndex);
71+
}
72+
73+
/**
74+
* Create a new {@code SynthesizingMethodParameter} for the given constructor.
75+
* @param constructor the Constructor to specify a parameter for
76+
* @param parameterIndex the index of the parameter
77+
* @param nestingLevel the nesting level of the target type
78+
* (typically 1; e.g. in case of a List of Lists, 1 would indicate the
79+
* nested List, whereas 2 would indicate the element of the nested List)
80+
*/
81+
public SynthesizingMethodParameter(Constructor<?> constructor, int parameterIndex, int nestingLevel) {
82+
super(constructor, parameterIndex, nestingLevel);
83+
}
84+
85+
/**
86+
* Copy constructor, resulting in an independent {@code SynthesizingMethodParameter}
87+
* based on the same metadata and cache state that the original object was in.
88+
* @param original the original SynthesizingMethodParameter object to copy from
89+
*/
4790
protected SynthesizingMethodParameter(SynthesizingMethodParameter original) {
4891
super(original);
4992
}

0 commit comments

Comments
 (0)