diff --git a/framework-docs/modules/ROOT/pages/core/expressions/language-ref/functions.adoc b/framework-docs/modules/ROOT/pages/core/expressions/language-ref/functions.adoc index 332db2af96..79a39bb038 100644 --- a/framework-docs/modules/ROOT/pages/core/expressions/language-ref/functions.adoc +++ b/framework-docs/modules/ROOT/pages/core/expressions/language-ref/functions.adoc @@ -55,7 +55,7 @@ Kotlin:: ---- ====== -You can then register and use the preceding method, as the following example shows: +You can register and use the preceding method, as the following example shows: [tabs] ====== @@ -67,8 +67,9 @@ Java:: EvaluationContext context = SimpleEvaluationContext.forReadOnlyDataBinding().build(); context.setVariable("reverseString", - StringUtils.class.getDeclaredMethod("reverseString", String.class)); + StringUtils.class.getMethod("reverseString", String.class)); + // evaluates to "olleh" String helloWorldReversed = parser.parseExpression( "#reverseString('hello')").getValue(context, String.class); ---- @@ -80,16 +81,18 @@ Kotlin:: val parser = SpelExpressionParser() val context = SimpleEvaluationContext.forReadOnlyDataBinding().build() - context.setVariable("reverseString", ::reverseString::javaMethod) + context.setVariable("reverseString", ::reverseString.javaMethod) + // evaluates to "olleh" val helloWorldReversed = parser.parseExpression( "#reverseString('hello')").getValue(context, String::class.java) ---- ====== -The use of `MethodHandle` is also supported. This enables potentially more efficient use -cases if the `MethodHandle` target and parameters have been fully bound prior to -registration, but partially bound handles are also supported. +A function can also be registered as a `java.lang.invoke.MethodHandle`. This enables +potentially more efficient use cases if the `MethodHandle` target and parameters have +been fully bound prior to registration; however, partially bound handles are also +supported. Consider the `String#formatted(String, Object...)` instance method, which produces a message according to a template and a variable number of arguments. @@ -110,9 +113,9 @@ Java:: MethodType.methodType(String.class, Object[].class)); context.setVariable("message", mh); + // evaluates to "Simple message: " String message = parser.parseExpression("#message('Simple message: <%s>', 'Hello World', 'ignored')") .getValue(context, String.class); - //returns "Simple message: " ---- Kotlin:: @@ -126,6 +129,7 @@ Kotlin:: MethodType.methodType(String::class.java, Array::class.java)) context.setVariable("message", mh) + // evaluates to "Simple message: " val message = parser.parseExpression("#message('Simple message: <%s>', 'Hello World', 'ignored')") .getValue(context, String::class.java) ---- diff --git a/framework-docs/modules/ROOT/pages/web/webflux-functional.adoc b/framework-docs/modules/ROOT/pages/web/webflux-functional.adoc index b56f90d37a..90a2e33547 100644 --- a/framework-docs/modules/ROOT/pages/web/webflux-functional.adoc +++ b/framework-docs/modules/ROOT/pages/web/webflux-functional.adoc @@ -787,7 +787,7 @@ Kotlin:: WebFlux.fn provides built-in support for serving resources. -NOTE: In addition to the capabilities described below, it is possible to implement an even more flexible resource handling thanks to +NOTE: In addition to the capabilities described below, it is possible to implement even more flexible resource handling thanks to {spring-framework-api}++/web/reactive/function/server/RouterFunctions.html#resources(java.util.function.Function)++[`RouterFunctions#resource(java.util.function.Function)`]. [[webflux-fn-resource]] diff --git a/framework-docs/modules/ROOT/pages/web/webmvc-functional.adoc b/framework-docs/modules/ROOT/pages/web/webmvc-functional.adoc index c68a41e6d1..bac604d4d6 100644 --- a/framework-docs/modules/ROOT/pages/web/webmvc-functional.adoc +++ b/framework-docs/modules/ROOT/pages/web/webmvc-functional.adoc @@ -765,7 +765,7 @@ Kotlin:: WebMvc.fn provides built-in support for serving resources. -NOTE: In addition to the capabilities described below, it is possible to implement an even more flexible resource handling thanks to +NOTE: In addition to the capabilities described below, it is possible to implement even more flexible resource handling thanks to {spring-framework-api}++/web/servlet/function/RouterFunctions.html#resources(java.util.function.Function)++[`RouterFunctions#resource(java.util.function.Function)`]. [[webmvc-fn-resource]] diff --git a/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java b/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java index 4a27351b4c..d4951f1514 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java @@ -40,7 +40,7 @@ import org.springframework.util.ReflectionUtils; /** * Register the necessary reflection hints so that the specified type can be - * bound at runtime. Fields, constructors, properties and record components + * bound at runtime. Fields, constructors, properties, and record components * are registered, except for a set of types like those in the {@code java.} * package where just the type is registered. Types are discovered transitively * on properties and record components, and generic types are registered as well. @@ -200,9 +200,9 @@ public class BindingReflectionHintsRegistrar { } private void registerHintsForClassAttributes(ReflectionHints hints, MergedAnnotation annotation) { - annotation.getRoot().asMap().forEach((key,value) -> { + annotation.getRoot().asMap().forEach((attributeName, value) -> { if (value instanceof Class classValue && value != Void.class) { - if (key.equals("builder")) { + if (attributeName.equals("builder")) { hints.registerType(classValue, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS); } diff --git a/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java b/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java index 0c393a86db..e79859c4a6 100644 --- a/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java +++ b/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java @@ -121,6 +121,7 @@ public interface EvaluationContext { * configuration for the context. * @param name the name of the variable to set * @param value the value to be placed in the variable + * @see #lookupVariable(String) */ void setVariable(String name, @Nullable Object value); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/SimpleEvaluationContext.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/SimpleEvaluationContext.java index 1cbc6d56e3..91f12190ef 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/SimpleEvaluationContext.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/SimpleEvaluationContext.java @@ -87,6 +87,7 @@ import org.springframework.lang.Nullable; * @see StandardEvaluationContext * @see StandardTypeConverter * @see DataBindingPropertyAccessor + * @see DataBindingMethodResolver */ public final class SimpleEvaluationContext implements EvaluationContext { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java index 012487f0c2..7fa3e515c3 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java @@ -269,7 +269,7 @@ public class StandardEvaluationContext implements EvaluationContext { } /** - * Set multiple named variables in this evaluation context to given values. + * Set multiple named variables in this evaluation context to the specified values. *

This is a convenience variant of {@link #setVariable(String, Object)}. * @param variables the names and values of the variables to set * @see #setVariable(String, Object) @@ -284,7 +284,7 @@ public class StandardEvaluationContext implements EvaluationContext { * evaluation context, as populated by {@link #setVariable(String, Object)}. * Make sure that specified function names and variable names do not overlap. * @param name the name of the function - * @param method the Method to register + * @param method the {@code Method} to register * @see #registerFunction(String, MethodHandle) */ public void registerFunction(String name, Method method) { @@ -297,7 +297,7 @@ public class StandardEvaluationContext implements EvaluationContext { * evaluation context, as populated by {@link #setVariable(String, Object)}. * Make sure that specified function names and variable names do not overlap. * @param name the name of the function - * @param methodHandle the MethodHandle to register + * @param methodHandle the {@link MethodHandle} to register * @since 6.1 * @see #registerFunction(String, Method) */