From dfd4aae4f6994b967d59a346d4556ba07d66fc89 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 15 Mar 2016 16:28:36 +0100 Subject: [PATCH] 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 --- .../springframework/core/MethodParameter.java | 9 ++-- .../SynthesizingMethodParameter.java | 45 ++++++++++++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 2338866dc2c..8d37976279a 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -48,15 +48,18 @@ import org.springframework.util.ClassUtils; */ public class MethodParameter { - private static Class javaUtilOptionalClass = null; + private static final Class javaUtilOptionalClass; static { + Class clazz; try { - javaUtilOptionalClass = ClassUtils.forName("java.util.Optional", MethodParameter.class.getClassLoader()); + clazz = ClassUtils.forName("java.util.Optional", MethodParameter.class.getClassLoader()); } catch (ClassNotFoundException ex) { // 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}. * @since 4.3 */ diff --git a/spring-core/src/main/java/org/springframework/core/annotation/SynthesizingMethodParameter.java b/spring-core/src/main/java/org/springframework/core/annotation/SynthesizingMethodParameter.java index ea5bb83189a..eb287c478de 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/SynthesizingMethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/SynthesizingMethodParameter.java @@ -17,6 +17,7 @@ package org.springframework.core.annotation; import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; import java.lang.reflect.Method; import org.springframework.core.MethodParameter; @@ -34,7 +35,8 @@ import org.springframework.core.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 parameterIndex the index of the parameter: -1 for the 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); } + /** + * 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) { super(original); }