Skip to content

Commit 5fd9fab

Browse files
committed
Polishing (backported from main)
1 parent 95a8646 commit 5fd9fab

File tree

6 files changed

+44
-31
lines changed

6 files changed

+44
-31
lines changed

framework-docs/modules/ROOT/pages/core/expressions/language-ref/collection-projection.adoc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Projection lets a collection drive the evaluation of a sub-expression, and the result is
55
a new collection. The syntax for projection is `.![projectionExpression]`. For example,
66
suppose we have a list of inventors but want the list of cities where they were born.
7-
Effectively, we want to evaluate 'placeOfBirth.city' for every entry in the inventor
7+
Effectively, we want to evaluate `placeOfBirth.city` for every entry in the inventor
88
list. The following example uses projection to do so:
99

1010
[tabs]
@@ -13,16 +13,18 @@ Java::
1313
+
1414
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
1515
----
16-
// returns ['Smiljan', 'Idvor' ]
17-
List placesOfBirth = (List)parser.parseExpression("members.![placeOfBirth.city]");
16+
// evaluates to ["SmilJan", "Idvor"]
17+
List placesOfBirth = parser.parseExpression("members.![placeOfBirth.city]")
18+
.getValue(societyContext, List.class);
1819
----
1920
2021
Kotlin::
2122
+
2223
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
2324
----
24-
// returns ['Smiljan', 'Idvor' ]
25-
val placesOfBirth = parser.parseExpression("members.![placeOfBirth.city]") as List<*>
25+
// evaluates to ["SmilJan", "Idvor"]
26+
val placesOfBirth = parser.parseExpression("members.![placeOfBirth.city]")
27+
.getValue(societyContext) as List<*>
2628
----
2729
======
2830

framework-docs/modules/ROOT/pages/core/expressions/language-ref/collection-selection.adoc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,36 @@ Kotlin::
2828
======
2929

3030
Selection is supported for arrays and anything that implements `java.lang.Iterable` or
31-
`java.util.Map`. For a list or array, the selection criteria is evaluated against each
32-
individual element. Against a map, the selection criteria is evaluated against each map
33-
entry (objects of the Java type `Map.Entry`). Each map entry has its `key` and `value`
34-
accessible as properties for use in the selection.
31+
`java.util.Map`. For an array or `Iterable`, the selection expression is evaluated
32+
against each individual element. Against a map, the selection expression is evaluated
33+
against each map entry (objects of the Java type `Map.Entry`). Each map entry has its
34+
`key` and `value` accessible as properties for use in the selection.
3535

36-
The following expression returns a new map that consists of those elements of the
37-
original map where the entry's value is less than 27:
36+
Given a `Map` stored in a variable named `#map`, the following expression returns a new
37+
map that consists of those elements of the original map where the entry's value is less
38+
than 27:
3839

3940
[tabs]
4041
======
4142
Java::
4243
+
4344
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
4445
----
45-
Map newMap = parser.parseExpression("map.?[value<27]").getValue();
46+
Map newMap = parser.parseExpression("#map.?[value < 27]").getValue(Map.class);
4647
----
4748
4849
Kotlin::
4950
+
5051
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
5152
----
52-
val newMap = parser.parseExpression("map.?[value<27]").getValue()
53+
val newMap = parser.parseExpression("#map.?[value < 27]").getValue() as Map
5354
----
5455
======
5556

5657
In addition to returning all the selected elements, you can retrieve only the first or
57-
the last element. To obtain the first element matching the selection, the syntax is
58-
`.^[selectionExpression]`. To obtain the last matching selection, the syntax is
59-
`.$[selectionExpression]`.
58+
the last element. To obtain the first element matching the selection expression, the
59+
syntax is `.^[selectionExpression]`. To obtain the last element matching the selection
60+
expression, the syntax is `.$[selectionExpression]`.
6061

6162

6263

framework-docs/modules/ROOT/pages/testing/spring-mvc-test-framework/server-setup-options.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Kotlin::
152152
@Autowired
153153
lateinit var accountService: AccountService
154154
155-
lateinit mockMvc: MockMvc
155+
lateinit var mockMvc: MockMvc
156156
157157
@BeforeEach
158158
fun setup(wac: WebApplicationContext) {

spring-expression/src/main/java/org/springframework/expression/TypedValue.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,8 @@
2222

2323
/**
2424
* Encapsulates an object and a {@link TypeDescriptor} that describes it.
25-
* The type descriptor can contain generic declarations that would not
25+
*
26+
* <p>The type descriptor can contain generic declarations that would not
2627
* be accessible through a simple {@code getClass()} call on the object.
2728
*
2829
* @author Andy Clement

spring-expression/src/main/java/org/springframework/expression/spel/ast/Selection.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,9 @@
3636

3737
/**
3838
* Represents selection over a map or collection.
39-
* For example: {1,2,3,4,5,6,7,8,9,10}.?{#isEven(#this) == 'y'} returns [2, 4, 6, 8, 10]
39+
*
40+
* <p>For example, <code>{1,2,3,4,5,6,7,8,9,10}.?{#isEven(#this)}</code> evaluates
41+
* to {@code [2, 4, 6, 8, 10]}.
4042
*
4143
* <p>Basically a subset of the input data is returned based on the
4244
* evaluation of the expression supplied as selection criteria.
@@ -100,11 +102,10 @@ protected ValueRef getValueRef(ExpressionState state) throws EvaluationException
100102
Object val = selectionCriteria.getValueInternal(state).getValue();
101103
if (val instanceof Boolean b) {
102104
if (b) {
105+
result.put(entry.getKey(), entry.getValue());
103106
if (this.variant == FIRST) {
104-
result.put(entry.getKey(), entry.getValue());
105107
return new ValueRef.TypedValueHolderValueRef(new TypedValue(result), this);
106108
}
107-
result.put(entry.getKey(), entry.getValue());
108109
lastKey = entry.getKey();
109110
}
110111
}
@@ -120,22 +121,22 @@ protected ValueRef getValueRef(ExpressionState state) throws EvaluationException
120121
}
121122

122123
if ((this.variant == FIRST || this.variant == LAST) && result.isEmpty()) {
123-
return new ValueRef.TypedValueHolderValueRef(new TypedValue(null), this);
124+
return new ValueRef.TypedValueHolderValueRef(TypedValue.NULL, this);
124125
}
125126

126127
if (this.variant == LAST) {
127128
Map<Object, Object> resultMap = new HashMap<>();
128129
Object lastValue = result.get(lastKey);
129-
resultMap.put(lastKey,lastValue);
130-
return new ValueRef.TypedValueHolderValueRef(new TypedValue(resultMap),this);
130+
resultMap.put(lastKey, lastValue);
131+
return new ValueRef.TypedValueHolderValueRef(new TypedValue(resultMap), this);
131132
}
132133

133-
return new ValueRef.TypedValueHolderValueRef(new TypedValue(result),this);
134+
return new ValueRef.TypedValueHolderValueRef(new TypedValue(result), this);
134135
}
135136

136137
if (operand instanceof Iterable || ObjectUtils.isArray(operand)) {
137-
Iterable<?> data = (operand instanceof Iterable<?> iterable ?
138-
iterable : Arrays.asList(ObjectUtils.toObjectArray(operand)));
138+
Iterable<?> data = (operand instanceof Iterable<?> iterable ? iterable :
139+
Arrays.asList(ObjectUtils.toObjectArray(operand)));
139140

140141
List<Object> result = new ArrayList<>();
141142
int index = 0;

spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -106,6 +106,7 @@ public static RequestPredicate methods(HttpMethod... httpMethods) {
106106
* against the given path pattern.
107107
* @param pattern the pattern to match to
108108
* @return a predicate that tests against the given path pattern
109+
* @see org.springframework.web.util.pattern.PathPattern
109110
*/
110111
public static RequestPredicate path(String pattern) {
111112
Assert.notNull(pattern, "'pattern' must not be null");
@@ -168,6 +169,7 @@ public static RequestPredicate accept(MediaType... mediaTypes) {
168169
* @param pattern the path pattern to match against
169170
* @return a predicate that matches if the request method is GET and if the given pattern
170171
* matches against the request path
172+
* @see org.springframework.web.util.pattern.PathPattern
171173
*/
172174
public static RequestPredicate GET(String pattern) {
173175
return method(HttpMethod.GET).and(path(pattern));
@@ -179,6 +181,7 @@ public static RequestPredicate GET(String pattern) {
179181
* @param pattern the path pattern to match against
180182
* @return a predicate that matches if the request method is HEAD and if the given pattern
181183
* matches against the request path
184+
* @see org.springframework.web.util.pattern.PathPattern
182185
*/
183186
public static RequestPredicate HEAD(String pattern) {
184187
return method(HttpMethod.HEAD).and(path(pattern));
@@ -190,6 +193,7 @@ public static RequestPredicate HEAD(String pattern) {
190193
* @param pattern the path pattern to match against
191194
* @return a predicate that matches if the request method is POST and if the given pattern
192195
* matches against the request path
196+
* @see org.springframework.web.util.pattern.PathPattern
193197
*/
194198
public static RequestPredicate POST(String pattern) {
195199
return method(HttpMethod.POST).and(path(pattern));
@@ -201,6 +205,7 @@ public static RequestPredicate POST(String pattern) {
201205
* @param pattern the path pattern to match against
202206
* @return a predicate that matches if the request method is PUT and if the given pattern
203207
* matches against the request path
208+
* @see org.springframework.web.util.pattern.PathPattern
204209
*/
205210
public static RequestPredicate PUT(String pattern) {
206211
return method(HttpMethod.PUT).and(path(pattern));
@@ -212,6 +217,7 @@ public static RequestPredicate PUT(String pattern) {
212217
* @param pattern the path pattern to match against
213218
* @return a predicate that matches if the request method is PATCH and if the given pattern
214219
* matches against the request path
220+
* @see org.springframework.web.util.pattern.PathPattern
215221
*/
216222
public static RequestPredicate PATCH(String pattern) {
217223
return method(HttpMethod.PATCH).and(path(pattern));
@@ -223,6 +229,7 @@ public static RequestPredicate PATCH(String pattern) {
223229
* @param pattern the path pattern to match against
224230
* @return a predicate that matches if the request method is DELETE and if the given pattern
225231
* matches against the request path
232+
* @see org.springframework.web.util.pattern.PathPattern
226233
*/
227234
public static RequestPredicate DELETE(String pattern) {
228235
return method(HttpMethod.DELETE).and(path(pattern));
@@ -234,6 +241,7 @@ public static RequestPredicate DELETE(String pattern) {
234241
* @param pattern the path pattern to match against
235242
* @return a predicate that matches if the request method is OPTIONS and if the given pattern
236243
* matches against the request path
244+
* @see org.springframework.web.util.pattern.PathPattern
237245
*/
238246
public static RequestPredicate OPTIONS(String pattern) {
239247
return method(HttpMethod.OPTIONS).and(path(pattern));
@@ -317,7 +325,6 @@ private static PathPattern mergePatterns(@Nullable PathPattern oldPattern, PathP
317325
else {
318326
return newPattern;
319327
}
320-
321328
}
322329

323330

@@ -337,6 +344,7 @@ public interface Visitor {
337344
* Receive notification of a path predicate.
338345
* @param pattern the path pattern that makes up the predicate
339346
* @see RequestPredicates#path(String)
347+
* @see org.springframework.web.util.pattern.PathPattern
340348
*/
341349
void path(String pattern);
342350

0 commit comments

Comments
 (0)