spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
55.28k stars 37.62k forks source link

Introduce `ReflectiveIndexAccessor` convenience class in SpEL #32714

Closed sbrannen closed 2 weeks ago

sbrannen commented 2 weeks ago

Overview

Somewhat analogous to the ReflectivePropertyAccessor implementation of PropertyAccessor, we should introduce a general purpose ReflectiveIndexAccessor implementation as a convenience for users.

However, ReflectiveIndexAccessor should implement CompilableIndexAccessor (instead of just IndexAccessor) in order to provide built-in compilation support.

A proof of concept has already been implemented in the tests for CompilableIndexAccessor:

https://github.com/spring-projects/spring-framework/blob/27d2200058bffb022b43a8bba4399e2fe837ee97/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java#L7238-L7333

Related Issues

sbrannen commented 2 weeks ago

Current work on this can be viewed in the following feature branch.

https://github.com/spring-projects/spring-framework/compare/main...sbrannen:spring-framework:issues/gh-32714-ReflectiveIndexAccessor

sbrannen commented 2 weeks ago

@artembilan, @pilak, @jackmiking, @jdomigon, @martin-jamszolik: you may also be interested in the new ReflectiveIndexAccessor that I just pushed to main for inclusion in Spring Framework 6.2 M2.

It greatly simplifies custom index access with zero code (plus built-in compilation support) for the most common use cases.

See commit 35c183d6346d68f443b6d06757f749a3d415bd88 for details.