27
27
import org .springframework .core .convert .TypeDescriptor ;
28
28
import org .springframework .expression .BeanResolver ;
29
29
import org .springframework .expression .EvaluationContext ;
30
+ import org .springframework .expression .IndexAccessor ;
30
31
import org .springframework .expression .MethodResolver ;
31
32
import org .springframework .expression .OperatorOverloader ;
32
33
import org .springframework .expression .PropertyAccessor ;
@@ -107,6 +108,8 @@ public final class SimpleEvaluationContext implements EvaluationContext {
107
108
108
109
private final List <PropertyAccessor > propertyAccessors ;
109
110
111
+ private final List <IndexAccessor > indexAccessors ;
112
+
110
113
private final List <MethodResolver > methodResolvers ;
111
114
112
115
private final TypeConverter typeConverter ;
@@ -118,10 +121,11 @@ public final class SimpleEvaluationContext implements EvaluationContext {
118
121
private final Map <String , Object > variables = new HashMap <>();
119
122
120
123
121
- private SimpleEvaluationContext (List <PropertyAccessor > accessors , List <MethodResolver > resolvers ,
122
- @ Nullable TypeConverter converter , @ Nullable TypedValue rootObject ) {
124
+ private SimpleEvaluationContext (List <PropertyAccessor > propertyAccessors , List <IndexAccessor > indexAccessors ,
125
+ List < MethodResolver > resolvers , @ Nullable TypeConverter converter , @ Nullable TypedValue rootObject ) {
123
126
124
- this .propertyAccessors = accessors ;
127
+ this .propertyAccessors = propertyAccessors ;
128
+ this .indexAccessors = indexAccessors ;
125
129
this .methodResolvers = resolvers ;
126
130
this .typeConverter = (converter != null ? converter : new StandardTypeConverter ());
127
131
this .rootObject = (rootObject != null ? rootObject : TypedValue .NULL );
@@ -145,6 +149,16 @@ public List<PropertyAccessor> getPropertyAccessors() {
145
149
return this .propertyAccessors ;
146
150
}
147
151
152
+ /**
153
+ * Return the specified {@link IndexAccessor} delegates, if any.
154
+ * @since 6.2
155
+ * @see Builder#withIndexAccessors(IndexAccessor...)
156
+ */
157
+ @ Override
158
+ public List <IndexAccessor > getIndexAccessors () {
159
+ return this .indexAccessors ;
160
+ }
161
+
148
162
/**
149
163
* Return the specified {@link MethodResolver} delegates, if any.
150
164
* @see Builder#withMethodResolvers
@@ -289,7 +303,9 @@ public static Builder forReadWriteDataBinding() {
289
303
*/
290
304
public static final class Builder {
291
305
292
- private final List <PropertyAccessor > accessors ;
306
+ private final List <PropertyAccessor > propertyAccessors ;
307
+
308
+ private List <IndexAccessor > indexAccessors = Collections .emptyList ();
293
309
294
310
private List <MethodResolver > resolvers = Collections .emptyList ();
295
311
@@ -299,8 +315,20 @@ public static final class Builder {
299
315
@ Nullable
300
316
private TypedValue rootObject ;
301
317
318
+
302
319
private Builder (PropertyAccessor ... accessors ) {
303
- this .accessors = Arrays .asList (accessors );
320
+ this .propertyAccessors = Arrays .asList (accessors );
321
+ }
322
+
323
+
324
+ /**
325
+ * Register the specified {@link IndexAccessor} delegates.
326
+ * @param indexAccessors the index accessors to use
327
+ * @since 6.2
328
+ */
329
+ public Builder withIndexAccessors (IndexAccessor ... indexAccessors ) {
330
+ this .indexAccessors = Arrays .asList (indexAccessors );
331
+ return this ;
304
332
}
305
333
306
334
/**
@@ -381,7 +409,8 @@ public Builder withTypedRootObject(Object rootObject, TypeDescriptor typeDescrip
381
409
}
382
410
383
411
public SimpleEvaluationContext build () {
384
- return new SimpleEvaluationContext (this .accessors , this .resolvers , this .typeConverter , this .rootObject );
412
+ return new SimpleEvaluationContext (this .propertyAccessors , this .indexAccessors ,
413
+ this .resolvers , this .typeConverter , this .rootObject );
385
414
}
386
415
}
387
416
0 commit comments