Reintroduce explicit local variable types.

We now reinstate local variable types instead of var as general var usage removes contextual detail that cannot be omitted generally.

See #2465
This commit is contained in:
Mark Paluch
2022-03-28 08:55:29 +02:00
parent c85c4ef2ed
commit 0e5e869cbf
249 changed files with 1662 additions and 1507 deletions

View File

@@ -17,6 +17,7 @@ package org.springframework.data.spel;
import static org.springframework.data.util.StreamUtils.*;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -73,7 +74,7 @@ class EvaluationContextExtensionInformation {
Assert.notNull(type, "Extension type must not be null!");
var rootObjectType = org.springframework.data.util.ReflectionUtils.findRequiredMethod(type, "getRootObject")
Class<?> rootObjectType = org.springframework.data.util.ReflectionUtils.findRequiredMethod(type, "getRootObject")
.getReturnType();
this.rootObjectInformation = Optional
@@ -216,8 +217,8 @@ class EvaluationContextExtensionInformation {
return false;
}
var methodStatic = Modifier.isStatic(method.getModifiers());
var staticMatch = staticOnly ? methodStatic : !methodStatic;
boolean methodStatic = Modifier.isStatic(method.getModifiers());
boolean staticMatch = staticOnly ? methodStatic : !methodStatic;
return Modifier.isPublic(method.getModifiers()) && staticMatch;
}
@@ -225,8 +226,8 @@ class EvaluationContextExtensionInformation {
@Override
public boolean matches(Field field) {
var fieldStatic = Modifier.isStatic(field.getModifiers());
var staticMatch = staticOnly ? fieldStatic : !fieldStatic;
boolean fieldStatic = Modifier.isStatic(field.getModifiers());
boolean staticMatch = staticOnly ? fieldStatic : !fieldStatic;
return Modifier.isPublic(field.getModifiers()) && staticMatch;
}
@@ -265,7 +266,7 @@ class EvaluationContextExtensionInformation {
return;
}
var descriptors = Streamable.of(BeanUtils.getPropertyDescriptors(type));
Streamable<PropertyDescriptor> descriptors = Streamable.of(BeanUtils.getPropertyDescriptors(type));
ReflectionUtils.doWithMethods(type, method -> {
@@ -334,7 +335,7 @@ class EvaluationContextExtensionInformation {
return true;
}
for (var field : fields) {
for (Field field : fields) {
if (field.getName().equals(dependency.getSymbol())) {
return true;
}

View File

@@ -138,7 +138,7 @@ public class ExpressionDependencies implements Streamable<ExpressionDependencies
ExpressionDependency.forPropertyOrField(((PropertyOrFieldReference) node).getName()).nest(compoundPosition));
}
for (var i = 0; i < node.getChildCount(); i++) {
for (int i = 0; i < node.getChildCount(); i++) {
collectDependencies(node.getChild(i), node instanceof CompoundExpression ? i : 0, dependencies);
}
}
@@ -270,7 +270,7 @@ public class ExpressionDependencies implements Streamable<ExpressionDependencies
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(type);
int result = ObjectUtils.nullSafeHashCode(type);
result = 31 * result + ObjectUtils.nullSafeHashCode(symbol);
result = 31 * result + nestLevel;
return result;

View File

@@ -112,13 +112,13 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
StandardEvaluationContext doGetEvaluationContext(Object rootObject,
Collection<? extends EvaluationContextExtension> extensions) {
var context = new StandardEvaluationContext();
StandardEvaluationContext context = new StandardEvaluationContext();
if (beanFactory != null) {
context.setBeanResolver(new BeanFactoryResolver(beanFactory));
}
var accessor = new ExtensionAwarePropertyAccessor(extensions);
ExtensionAwarePropertyAccessor accessor = new ExtensionAwarePropertyAccessor(extensions);
context.addPropertyAccessor(accessor);
context.addPropertyAccessor(new ReflectivePropertyAccessor());
@@ -302,7 +302,7 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
*/
private TypedValue lookupPropertyFrom(EvaluationContextExtensionAdapter extension, String name) {
var value = extension.getProperties().get(name);
Object value = extension.getProperties().get(name);
if (!(value instanceof Function function)) {
return new TypedValue(value);
@@ -371,9 +371,11 @@ public class ExtensionAwareEvaluationContextProvider implements EvaluationContex
Assert.notNull(extension, "Extension must not be null!");
Assert.notNull(information, "Extension information must not be null!");
var target = Optional.ofNullable(extension.getRootObject());
var extensionTypeInformation = information.getExtensionTypeInformation();
var rootObjectInformation = information.getRootObjectInformation(target);
Optional<Object> target = Optional.ofNullable(extension.getRootObject());
EvaluationContextExtensionInformation.ExtensionTypeInformation extensionTypeInformation = information
.getExtensionTypeInformation();
EvaluationContextExtensionInformation.RootObjectInformation rootObjectInformation = information
.getRootObjectInformation(target);
functions.addAll(extension.getFunctions());
functions.addAll(rootObjectInformation.getFunctions(target));

View File

@@ -20,6 +20,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.data.spel.spi.Function;
@@ -46,7 +47,7 @@ class Functions {
newFunctions.forEach((n, f) -> {
var currentElements = get(n);
List<Function> currentElements = get(n);
if (!contains(currentElements, f)) {
functions.add(n, f);
@@ -58,7 +59,7 @@ class Functions {
newFunctions.forEach((k, list) -> {
var currentElements = get(k);
List<Function> currentElements = get(k);
list.stream() //
.filter(f -> !contains(currentElements, f)) //
@@ -82,10 +83,10 @@ class Functions {
*/
Optional<Function> get(String name, List<TypeDescriptor> argumentTypes) {
var candidates = get(name).stream() //
Stream<Function> candidates = get(name).stream() //
.filter(f -> f.supports(argumentTypes));
var collect = candidates.collect(Collectors.toList());
List<Function> collect = candidates.collect(Collectors.toList());
return bestMatch(collect, argumentTypes);
}
@@ -104,7 +105,7 @@ class Functions {
return Optional.of(candidates.get(0));
}
var exactMatch = candidates.stream().filter(f -> f.supportsExact(argumentTypes)).findFirst();
Optional<Function> exactMatch = candidates.stream().filter(f -> f.supportsExact(argumentTypes)).findFirst();
if (!exactMatch.isPresent()) {
throw new IllegalStateException(createErrorMessage(candidates, argumentTypes));
@@ -115,7 +116,7 @@ class Functions {
private static String createErrorMessage(List<Function> candidates, List<TypeDescriptor> argumentTypes) {
var argumentTypeString = argumentTypes.stream()//
String argumentTypeString = argumentTypes.stream()//
.map(TypeDescriptor::getName)//
.collect(Collectors.joining(","));

View File

@@ -98,13 +98,13 @@ public class ReactiveExtensionAwareEvaluationContextProvider implements Reactive
private Mono<List<EvaluationContextExtension>> getExtensions(
Predicate<EvaluationContextExtensionInformation> extensionFilter) {
var extensions = evaluationContextProvider.getExtensions();
Collection<? extends ExtensionIdAware> extensions = evaluationContextProvider.getExtensions();
return Flux.fromIterable(extensions).concatMap(it -> {
if (it instanceof EvaluationContextExtension extension) {
var information = evaluationContextProvider.getOrCreateInformation(extension);
EvaluationContextExtensionInformation information = evaluationContextProvider.getOrCreateInformation(extension);
if (extensionFilter.test(information)) {
return Mono.just(extension);
@@ -115,13 +115,13 @@ public class ReactiveExtensionAwareEvaluationContextProvider implements Reactive
if (it instanceof ReactiveEvaluationContextExtension extension) {
var actualType = getExtensionType(it);
ResolvableType actualType = getExtensionType(it);
if (actualType.equals(ResolvableType.NONE) || actualType.isAssignableFrom(GENERIC_EXTENSION_TYPE)) {
return extension.getExtension();
}
var information = evaluationContextProvider
EvaluationContextExtensionInformation information = evaluationContextProvider
.getOrCreateInformation((Class) actualType.getRawClass());
if (extensionFilter.test(information)) {

View File

@@ -82,23 +82,23 @@ public class Function {
return method.invoke(target, arguments);
}
var types = method.getParameterTypes();
var tailType = types[types.length - 1];
Class<?>[] types = method.getParameterTypes();
Class<?> tailType = types[types.length - 1];
if (tailType.isArray()) {
List<Object> argumentsToUse = new ArrayList<>(types.length);
// Add all arguments up until the last one
for (var i = 0; i < types.length - 1; i++) {
for (int i = 0; i < types.length - 1; i++) {
argumentsToUse.add(arguments[i]);
}
// Gather all other arguments into an array of the tail type
var varargs = (Object[]) Array.newInstance(tailType.getComponentType(), arguments.length - types.length + 1);
var count = 0;
Object[] varargs = (Object[]) Array.newInstance(tailType.getComponentType(), arguments.length - types.length + 1);
int count = 0;
for (var i = types.length - 1; i < arguments.length; i++) {
for (int i = types.length - 1; i < arguments.length; i++) {
varargs[count++] = arguments[i];
}