Implement optional get<list>() methods in EvaluationContext as default methods

This commit is contained in:
Sam Brannen 2024-04-24 15:54:05 +03:00
parent 33fbd7141d
commit 1e4275a0f9
2 changed files with 14 additions and 15 deletions

View File

@ -47,15 +47,18 @@ public interface EvaluationContext {
/** /**
* Return the default root context object against which unqualified * Return the default root context object against which unqualified
* properties/methods/etc should be resolved. This can be overridden * properties, methods, etc. should be resolved.
* when evaluating an expression. * <p>This can be overridden when evaluating an expression.
*/ */
TypedValue getRootObject(); TypedValue getRootObject();
/** /**
* Return a list of accessors that will be asked in turn to read/write a property. * Return a list of accessors that will be asked in turn to read/write a property.
* <p>The default implementation returns an empty list.
*/ */
List<PropertyAccessor> getPropertyAccessors(); default List<PropertyAccessor> getPropertyAccessors() {
return Collections.emptyList();
}
/** /**
* Return a list of index accessors that will be asked in turn to access or * Return a list of index accessors that will be asked in turn to access or
@ -69,13 +72,19 @@ public interface EvaluationContext {
/** /**
* Return a list of resolvers that will be asked in turn to locate a constructor. * Return a list of resolvers that will be asked in turn to locate a constructor.
* <p>The default implementation returns an empty list.
*/ */
List<ConstructorResolver> getConstructorResolvers(); default List<ConstructorResolver> getConstructorResolvers() {
return Collections.emptyList();
}
/** /**
* Return a list of resolvers that will be asked in turn to locate a method. * Return a list of resolvers that will be asked in turn to locate a method.
* <p>The default implementation returns an empty list.
*/ */
List<MethodResolver> getMethodResolvers(); default List<MethodResolver> getMethodResolvers() {
return Collections.emptyList();
}
/** /**
* Return a bean resolver that can look up beans by name. * Return a bean resolver that can look up beans by name.

View File

@ -26,7 +26,6 @@ import java.util.function.Supplier;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.BeanResolver; import org.springframework.expression.BeanResolver;
import org.springframework.expression.ConstructorResolver;
import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationContext;
import org.springframework.expression.MethodResolver; import org.springframework.expression.MethodResolver;
import org.springframework.expression.OperatorOverloader; import org.springframework.expression.OperatorOverloader;
@ -146,15 +145,6 @@ public final class SimpleEvaluationContext implements EvaluationContext {
return this.propertyAccessors; return this.propertyAccessors;
} }
/**
* Return an empty list, always, since this context does not support the
* use of type references.
*/
@Override
public List<ConstructorResolver> getConstructorResolvers() {
return Collections.emptyList();
}
/** /**
* Return the specified {@link MethodResolver} delegates, if any. * Return the specified {@link MethodResolver} delegates, if any.
* @see Builder#withMethodResolvers * @see Builder#withMethodResolvers