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

@@ -165,7 +165,7 @@ public class QSort extends Sort implements Serializable {
*/
private static String preparePropertyPath(Path<?> path) {
var root = path.getRoot();
Path<?> root = path.getRoot();
return root == null || path.equals(root) ? path.toString()
: path.toString().substring(root.toString().length() + 1);

View File

@@ -19,6 +19,7 @@ import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.PathMetadata;
import com.querydsl.core.types.PathType;
/**
@@ -57,8 +58,8 @@ public abstract class QuerydslUtils {
return tail;
}
var metadata = path.getMetadata();
var parent = metadata.getParent();
PathMetadata metadata = path.getMetadata();
Path<?> parent = metadata.getParent();
if (parent == null) {
return tail;
@@ -68,7 +69,7 @@ public abstract class QuerydslUtils {
return toDotPath(parent, tail);
}
var element = metadata.getElement();
Object element = metadata.getElement();
if (element == null || !StringUtils.hasText(element.toString())) {
return toDotPath(parent, tail);

View File

@@ -64,11 +64,11 @@ public class SimpleEntityPathResolver implements EntityPathResolver {
@SuppressWarnings("unchecked")
public <T> EntityPath<T> createPath(Class<T> domainClass) {
var pathClassName = getQueryClassName(domainClass);
String pathClassName = getQueryClassName(domainClass);
try {
var pathClass = ClassUtils.forName(pathClassName, domainClass.getClassLoader());
Class<?> pathClass = ClassUtils.forName(pathClassName, domainClass.getClassLoader());
return getStaticFieldOfType(pathClass)//
.map(it -> (EntityPath<T>) ReflectionUtils.getField(it, null))//
@@ -88,17 +88,17 @@ public class SimpleEntityPathResolver implements EntityPathResolver {
*/
private Optional<Field> getStaticFieldOfType(Class<?> type) {
for (var field : type.getDeclaredFields()) {
for (Field field : type.getDeclaredFields()) {
var isStatic = Modifier.isStatic(field.getModifiers());
var hasSameType = type.equals(field.getType());
boolean isStatic = Modifier.isStatic(field.getModifiers());
boolean hasSameType = type.equals(field.getType());
if (isStatic && hasSameType) {
return Optional.of(field);
}
}
var superclass = type.getSuperclass();
Class<?> superclass = type.getSuperclass();
return Object.class.equals(superclass) ? Optional.empty() : getStaticFieldOfType(superclass);
}
@@ -110,8 +110,8 @@ public class SimpleEntityPathResolver implements EntityPathResolver {
*/
private String getQueryClassName(Class<?> domainClass) {
var simpleClassName = ClassUtils.getShortName(domainClass);
var packageName = domainClass.getPackage().getName();
String simpleClassName = ClassUtils.getShortName(domainClass);
String packageName = domainClass.getPackage().getName();
return String.format("%s%s.Q%s%s", packageName, querySuffix, getClassBase(simpleClassName),
domainClass.getSimpleName());
@@ -125,7 +125,7 @@ public class SimpleEntityPathResolver implements EntityPathResolver {
*/
private String getClassBase(String shortName) {
var parts = shortName.split("\\.");
String[] parts = shortName.split("\\.");
return parts.length < 2 ? "" : parts[0] + "_";
}

View File

@@ -16,6 +16,7 @@
package org.springframework.data.querydsl.binding;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import org.springframework.beans.BeanUtils;
import org.springframework.data.mapping.PropertyPath;
@@ -107,10 +108,10 @@ record PropertyPathInformation(PropertyPath path) implements PathInformation {
return reifyPath(resolver, path, (Path<?>) ((CollectionPathBase<?, ?, ?>) base).any());
}
var entityPath = base != null ? base : resolver.createPath(path.getOwningType().getType());
Path<?> entityPath = base != null ? base : resolver.createPath(path.getOwningType().getType());
var field = ReflectionUtils.findField(entityPath.getClass(), path.getSegment());
var value = ReflectionUtils.getField(field, entityPath);
Field field = ReflectionUtils.findField(entityPath.getClass(), path.getSegment());
Object value = ReflectionUtils.getField(field, entityPath);
if (path.hasNext()) {
return reifyPath(resolver, path.next(), (Path<?>) value);
@@ -136,7 +137,7 @@ record PropertyPathInformation(PropertyPath path) implements PathInformation {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(getRootParentType());
int result = ObjectUtils.nullSafeHashCode(getRootParentType());
result = 31 * result + ObjectUtils.nullSafeHashCode(toDotPath());
return result;
}

View File

@@ -128,7 +128,7 @@ public class QuerydslBindings {
Assert.notEmpty(paths, "At least one path has to be provided!");
for (var path : paths) {
for (Path<?> path : paths) {
this.denyList.add(toDotPath(Optional.of(path)));
}
}
@@ -142,7 +142,7 @@ public class QuerydslBindings {
Assert.notEmpty(paths, "At least one path has to be provided!");
for (var path : paths) {
for (Path<?> path : paths) {
this.allowList.add(toDotPath(Optional.of(path)));
}
}
@@ -204,11 +204,11 @@ public class QuerydslBindings {
Assert.notNull(path, "PropertyPath must not be null!");
var pathAndBinding = (PathAndBinding<S, T>) pathSpecs.get(createKey(path));
PathAndBinding<S, T> pathAndBinding = (PathAndBinding<S, T>) pathSpecs.get(createKey(path));
if (pathAndBinding != null) {
var binding = pathAndBinding.getBinding();
Optional<MultiValueBinding<S, T>> binding = pathAndBinding.getBinding();
if (binding.isPresent()) {
return binding;
@@ -251,7 +251,7 @@ public class QuerydslBindings {
}
// fully-qualified path lookup
var key = createKey(type, path);
String key = createKey(type, path);
if (pathSpecs.containsKey(key)) {
return pathSpecs.get(key).getPath()//
.map(QuerydslPathInformation::of)//
@@ -303,9 +303,9 @@ public class QuerydslBindings {
*/
private boolean isPathVisible(PathInformation path) {
var segments = Arrays.asList(path.toDotPath().split("\\."));
List<String> segments = Arrays.asList(path.toDotPath().split("\\."));
for (var i = 1; i <= segments.size(); i++) {
for (int i = 1; i <= segments.size(); i++) {
if (!isPathVisible(StringUtils.collectionToDelimitedString(segments.subList(0, i), "."))) {
@@ -354,7 +354,7 @@ public class QuerydslBindings {
private static String fromRootPath(Path<?> path) {
var rootPath = path.getMetadata().getRootPath();
Path<?> rootPath = path.getMetadata().getRootPath();
if (rootPath == null) {
throw new IllegalStateException(String.format("Couldn't find root path on path %s!", path));
@@ -481,7 +481,7 @@ public class QuerydslBindings {
super.registerBinding(binding);
var dotPath = toDotPath(binding.getPath());
String dotPath = toDotPath(binding.getPath());
if (alias != null) {
QuerydslBindings.this.pathSpecs.put(alias, binding);
@@ -587,7 +587,7 @@ public class QuerydslBindings {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(path);
int result = ObjectUtils.nullSafeHashCode(path);
result = 31 * result + ObjectUtils.nullSafeHashCode(binding);
return result;
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.querydsl.binding;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -124,9 +125,9 @@ public class QuerydslBindingsFactory implements ApplicationContextAware {
Assert.notNull(customizer, "Customizer must not be null!");
Assert.notNull(domainType, "Domain type must not be null!");
var path = verifyEntityPathPresent(domainType);
EntityPath<?> path = verifyEntityPathPresent(domainType);
var bindings = new QuerydslBindings();
QuerydslBindings bindings = new QuerydslBindings();
defaultCustomizer.customize(bindings, path);
findCustomizerForDomainType(customizer, domainType.getType()).customize(bindings, path);
@@ -166,11 +167,11 @@ public class QuerydslBindingsFactory implements ApplicationContextAware {
private QuerydslBinderCustomizer<EntityPath<?>> getDefaultQuerydslBinderCustomizer(
AutowireCapableBeanFactory beanFactory) {
var customizers = beanFactory
List<QuerydslBinderCustomizerDefaults> customizers = beanFactory
.getBeanProvider(QuerydslBinderCustomizerDefaults.class).stream().collect(Collectors.toList());
return (bindings, root) -> {
for (var querydslBinderCustomizerDefaults : customizers) {
for (QuerydslBinderCustomizerDefaults querydslBinderCustomizerDefaults : customizers) {
querydslBinderCustomizerDefaults.customize(bindings, root);
}
};

View File

@@ -55,7 +55,7 @@ class QuerydslDefaultBinding implements MultiValueBinding<Path<? extends Object>
if (path instanceof CollectionPathBase) {
var builder = new BooleanBuilder();
BooleanBuilder builder = new BooleanBuilder();
for (Object element : value) {
builder.and(((CollectionPathBase) path).contains(element));
@@ -70,7 +70,7 @@ class QuerydslDefaultBinding implements MultiValueBinding<Path<? extends Object>
return Optional.of(expression.in(value));
}
var object = value.iterator().next();
Object object = value.iterator().next();
return Optional.of(object == null //
? expression.isNull() //

View File

@@ -57,7 +57,7 @@ class QuerydslPathInformation implements PathInformation {
@Override
public Class<?> getLeafParentType() {
var parent = path.getMetadata().getParent();
Path<?> parent = path.getMetadata().getParent();
if (parent == null) {
throw new IllegalStateException(String.format("Could not obtain metadata for parent node of %s!", path));
@@ -103,7 +103,7 @@ class QuerydslPathInformation implements PathInformation {
@Override
public int hashCode() {
var result = ObjectUtils.nullSafeHashCode(getRootParentType());
int result = ObjectUtils.nullSafeHashCode(getRootParentType());
result = 31 * result + ObjectUtils.nullSafeHashCode(toDotPath());
return result;
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.querydsl.binding;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -85,7 +86,7 @@ public class QuerydslPredicateBuilder {
Assert.notNull(bindings, "Context must not be null!");
var builder = new BooleanBuilder();
BooleanBuilder builder = new BooleanBuilder();
if (values.isEmpty()) {
return getPredicate(builder);
@@ -97,20 +98,20 @@ public class QuerydslPredicateBuilder {
continue;
}
var path = entry.getKey();
String path = entry.getKey();
if (!bindings.isPathAvailable(path, type)) {
continue;
}
var propertyPath = bindings.getPropertyPath(path, type);
PathInformation propertyPath = bindings.getPropertyPath(path, type);
if (propertyPath == null) {
continue;
}
var value = convertToPropertyPathSpecificType(entry.getValue(), propertyPath);
var predicate = invokeBinding(propertyPath, bindings, value);
Collection<Object> value = convertToPropertyPathSpecificType(entry.getValue(), propertyPath);
Optional<Predicate> predicate = invokeBinding(propertyPath, bindings, value);
predicate.ifPresent(builder::and);
}
@@ -141,7 +142,7 @@ public class QuerydslPredicateBuilder {
private Optional<Predicate> invokeBinding(PathInformation dotPath, QuerydslBindings bindings,
Collection<Object> values) {
var path = getPath(dotPath, bindings);
Path<?> path = getPath(dotPath, bindings);
return bindings.getBindingForPath(dotPath).orElse(defaultBinding).bind(path, values);
}
@@ -157,7 +158,7 @@ public class QuerydslPredicateBuilder {
*/
private Path<?> getPath(PathInformation path, QuerydslBindings bindings) {
var resolvedPath = bindings.getExistingPath(path);
Optional<Path<?>> resolvedPath = bindings.getExistingPath(path);
return resolvedPath.orElseGet(() -> paths.computeIfAbsent(path, it -> it.reifyPath(resolver)));
}
@@ -173,7 +174,7 @@ public class QuerydslPredicateBuilder {
*/
private Collection<Object> convertToPropertyPathSpecificType(List<?> source, PathInformation path) {
var targetType = path.getLeafType();
Class<?> targetType = path.getLeafType();
if (source.isEmpty() || isSingleElementCollectionWithEmptyItem(source)) {
return Collections.emptyList();
@@ -181,7 +182,7 @@ public class QuerydslPredicateBuilder {
Collection<Object> target = new ArrayList<>(source.size());
for (var value : source) {
for (Object value : source) {
target.add(getValue(path, targetType, value));
}
@@ -211,12 +212,12 @@ public class QuerydslPredicateBuilder {
*/
private static TypeDescriptor getTargetTypeDescriptor(PathInformation path) {
var descriptor = path.getLeafPropertyDescriptor();
PropertyDescriptor descriptor = path.getLeafPropertyDescriptor();
var owningType = path.getLeafParentType();
var leafProperty = path.getLeafProperty();
Class<?> owningType = path.getLeafParentType();
String leafProperty = path.getLeafProperty();
var result = descriptor == null //
TypeDescriptor result = descriptor == null //
? TypeDescriptor
.nested(org.springframework.data.util.ReflectionUtils.findRequiredField(owningType, leafProperty), 0)
: TypeDescriptor
@@ -248,7 +249,7 @@ public class QuerydslPredicateBuilder {
*/
private static Predicate getPredicate(BooleanBuilder builder) {
var predicate = builder.getValue();
Predicate predicate = builder.getValue();
return predicate == null ? new BooleanBuilder() : predicate;
}
}