Apply "instanceof pattern matching" in remainder of spring-core module
See gh-30067
This commit is contained in:
@@ -139,7 +139,7 @@ public class BeanGenerator extends AbstractClassGenerator
|
||||
|
||||
@Override
|
||||
protected Object nextInstance(Object instance) {
|
||||
Class protoclass = (instance instanceof Class) ? (Class)instance : instance.getClass();
|
||||
Class protoclass = (instance instanceof Class<?> clazz) ? clazz : instance.getClass();
|
||||
if (classOnly) {
|
||||
return protoclass;
|
||||
} else {
|
||||
|
||||
@@ -367,15 +367,14 @@ public class EmitUtils {
|
||||
if (obj == null) {
|
||||
e.aconst_null();
|
||||
} else {
|
||||
Class type = obj.getClass();
|
||||
if (type.isArray()) {
|
||||
push_array(e, (Object[])obj);
|
||||
} else if (obj instanceof String) {
|
||||
e.push((String)obj);
|
||||
} else if (obj instanceof Type) {
|
||||
load_class(e, (Type)obj);
|
||||
} else if (obj instanceof Class) {
|
||||
load_class(e, Type.getType((Class)obj));
|
||||
if (obj.getClass().isArray()) {
|
||||
push_array(e, (Object[]) obj);
|
||||
} else if (obj instanceof String text) {
|
||||
e.push(text);
|
||||
} else if (obj instanceof Type type) {
|
||||
load_class(e, type);
|
||||
} else if (obj instanceof Class<?> clazz) {
|
||||
load_class(e, Type.getType(clazz));
|
||||
} else if (obj instanceof BigInteger) {
|
||||
e.new_instance(Constants.TYPE_BIG_INTEGER);
|
||||
e.dup();
|
||||
|
||||
@@ -69,8 +69,8 @@ public class LoadingCache<K, KK, V> {
|
||||
throw new IllegalStateException("Interrupted while loading cache item", e);
|
||||
} catch (ExecutionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw ((RuntimeException) cause);
|
||||
if (cause instanceof RuntimeException runtimeException) {
|
||||
throw runtimeException;
|
||||
}
|
||||
throw new IllegalStateException("Unable to load cache item", cause);
|
||||
}
|
||||
|
||||
@@ -154,10 +154,10 @@ abstract public class FastClass
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || !(o instanceof FastClass)) {
|
||||
if (o == null || !(o instanceof FastClass that)) {
|
||||
return false;
|
||||
}
|
||||
return type.equals(((FastClass)o).type);
|
||||
return type.equals(that.type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -105,9 +105,9 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (other instanceof AttributeAccessorSupport &&
|
||||
this.attributes.equals(((AttributeAccessorSupport) other).attributes)));
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return (this == obj || (obj instanceof AttributeAccessorSupport that &&
|
||||
this.attributes.equals(that.attributes)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -111,10 +111,10 @@ public class Constants {
|
||||
*/
|
||||
public Number asNumber(String code) throws ConstantException {
|
||||
Object obj = asObject(code);
|
||||
if (!(obj instanceof Number)) {
|
||||
if (!(obj instanceof Number number)) {
|
||||
throw new ConstantException(this.className, code, "not a Number");
|
||||
}
|
||||
return (Number) obj;
|
||||
return number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -172,9 +172,8 @@ public final class GenericTypeResolver {
|
||||
ResolvableType contextType = ResolvableType.forClass(contextClass);
|
||||
for (int i = 0; i < typeArguments.length; i++) {
|
||||
Type typeArgument = typeArguments[i];
|
||||
if (typeArgument instanceof TypeVariable) {
|
||||
ResolvableType resolvedTypeArgument = resolveVariable(
|
||||
(TypeVariable<?>) typeArgument, contextType);
|
||||
if (typeArgument instanceof TypeVariable<?> typeVariable) {
|
||||
ResolvableType resolvedTypeArgument = resolveVariable(typeVariable, contextType);
|
||||
if (resolvedTypeArgument != ResolvableType.NONE) {
|
||||
generics[i] = resolvedTypeArgument.resolve();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -195,7 +195,7 @@ public class MethodParameter {
|
||||
*/
|
||||
@Nullable
|
||||
public Method getMethod() {
|
||||
return (this.executable instanceof Method ? (Method) this.executable : null);
|
||||
return (this.executable instanceof Method method ? method : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,7 +205,7 @@ public class MethodParameter {
|
||||
*/
|
||||
@Nullable
|
||||
public Constructor<?> getConstructor() {
|
||||
return (this.executable instanceof Constructor ? (Constructor<?>) this.executable : null);
|
||||
return (this.executable instanceof Constructor<?> constructor ? constructor : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -142,7 +142,7 @@ public class OrderComparator implements Comparator<Object> {
|
||||
*/
|
||||
@Nullable
|
||||
protected Integer findOrder(Object obj) {
|
||||
return (obj instanceof Ordered ? ((Ordered) obj).getOrder() : null);
|
||||
return (obj instanceof Ordered ordered ? ordered.getOrder() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -67,9 +67,8 @@ public abstract class ParameterizedTypeReference<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (other instanceof ParameterizedTypeReference &&
|
||||
this.type.equals(((ParameterizedTypeReference<?>) other).type)));
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return (this == obj || (obj instanceof ParameterizedTypeReference<?> that && this.type.equals(that.type)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -149,7 +149,7 @@ public class ReactiveAdapterRegistry {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object sourceToUse = (source instanceof Optional ? ((Optional<?>) source).orElse(null) : source);
|
||||
Object sourceToUse = (source instanceof Optional<?> optional ? optional.orElse(null) : source);
|
||||
Class<?> clazz = (sourceToUse != null ? sourceToUse.getClass() : reactiveType);
|
||||
if (clazz == null) {
|
||||
return null;
|
||||
|
||||
@@ -215,7 +215,7 @@ public class ResolvableType implements Serializable {
|
||||
if (rawType instanceof ParameterizedType parameterizedType) {
|
||||
rawType = parameterizedType.getRawType();
|
||||
}
|
||||
return (rawType instanceof Class ? (Class<?>) rawType : null);
|
||||
return (rawType instanceof Class<?> rawClass ? rawClass : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -376,7 +376,7 @@ public class ResolvableType implements Serializable {
|
||||
if (this == NONE) {
|
||||
return false;
|
||||
}
|
||||
return ((this.type instanceof Class && ((Class<?>) this.type).isArray()) ||
|
||||
return ((this.type instanceof Class<?> clazz && clazz.isArray()) ||
|
||||
this.type instanceof GenericArrayType || resolveType().isArray());
|
||||
}
|
||||
|
||||
@@ -1647,13 +1647,12 @@ public class ResolvableType implements Serializable {
|
||||
@Nullable
|
||||
public static WildcardBounds get(ResolvableType type) {
|
||||
ResolvableType resolveToWildcard = type;
|
||||
while (!(resolveToWildcard.getType() instanceof WildcardType)) {
|
||||
while (!(resolveToWildcard.getType() instanceof WildcardType wildcardType)) {
|
||||
if (resolveToWildcard == NONE) {
|
||||
return null;
|
||||
}
|
||||
resolveToWildcard = resolveToWildcard.resolveType();
|
||||
}
|
||||
WildcardType wildcardType = (WildcardType) resolveToWildcard.type;
|
||||
Kind boundsType = (wildcardType.getLowerBounds().length > 0 ? Kind.LOWER : Kind.UPPER);
|
||||
Type[] bounds = (boundsType == Kind.UPPER ? wildcardType.getUpperBounds() : wildcardType.getLowerBounds());
|
||||
ResolvableType[] resolvableBounds = new ResolvableType[bounds.length];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -352,7 +352,7 @@ final class SerializableTypeWrapper {
|
||||
// Cache the result for further calls to getType()
|
||||
this.result = result;
|
||||
}
|
||||
return (result instanceof Type[] ? ((Type[]) result)[this.index] : (Type) result);
|
||||
return (result instanceof Type[] results ? results[this.index] : (Type) result);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -70,7 +70,7 @@ public class AnnotationAwareOrderComparator extends OrderComparator {
|
||||
|
||||
@Nullable
|
||||
private Integer findOrderFromAnnotation(Object obj) {
|
||||
AnnotatedElement element = (obj instanceof AnnotatedElement ? (AnnotatedElement) obj : obj.getClass());
|
||||
AnnotatedElement element = (obj instanceof AnnotatedElement ae ? ae : obj.getClass());
|
||||
MergedAnnotations annotations = MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY);
|
||||
Integer order = OrderUtils.getOrderFromAnnotations(element, annotations);
|
||||
if (order == null && obj instanceof DecoratingProxy decoratingProxy) {
|
||||
|
||||
@@ -107,7 +107,7 @@ public interface Decoder<T> {
|
||||
catch (InterruptedException ex) {
|
||||
failure = ex;
|
||||
}
|
||||
throw (failure instanceof CodecException ? (CodecException) failure :
|
||||
throw (failure instanceof CodecException codecException ? codecException :
|
||||
new DecodingException("Failed to decode: " + failure.getMessage(), failure));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -779,9 +779,9 @@ public class TypeDescriptor implements Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (other instanceof AnnotatedElementAdapter &&
|
||||
Arrays.equals(this.annotations, ((AnnotatedElementAdapter) other).annotations)));
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return (this == obj || (obj instanceof AnnotatedElementAdapter that &&
|
||||
Arrays.equals(this.annotations, that.annotations)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -76,7 +76,7 @@ final class ObjectToOptionalConverter implements ConditionalGenericConverter {
|
||||
else if (targetType.getResolvableType().hasGenerics()) {
|
||||
Object target = this.conversionService.convert(source, sourceType, new GenericTypeDescriptor(targetType));
|
||||
if (target == null || (target.getClass().isArray() && Array.getLength(target) == 0) ||
|
||||
(target instanceof Collection && ((Collection<?>) target).isEmpty())) {
|
||||
(target instanceof Collection<?> collection && collection.isEmpty())) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(target);
|
||||
|
||||
@@ -337,9 +337,8 @@ public final class Netty5DataBuffer implements CloseableDataBuffer, TouchableDat
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (other instanceof Netty5DataBuffer dataBuffer &&
|
||||
this.buffer.equals(dataBuffer.buffer)));
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return (this == obj || (obj instanceof Netty5DataBuffer that && this.buffer.equals(that.buffer)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -363,9 +363,8 @@ public class NettyDataBuffer implements PooledDataBuffer {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (other instanceof NettyDataBuffer &&
|
||||
this.byteBuf.equals(((NettyDataBuffer) other).byteBuf)));
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return (this == obj || (obj instanceof NettyDataBuffer that && this.byteBuf.equals(that.byteBuf)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -122,8 +122,8 @@ public class StandardClassMetadata implements ClassMetadata {
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return ((this == obj) || ((obj instanceof StandardClassMetadata) &&
|
||||
getIntrospectedClass().equals(((StandardClassMetadata) obj).getIntrospectedClass())));
|
||||
return (this == obj || (obj instanceof StandardClassMetadata that &&
|
||||
getIntrospectedClass().equals(that.getIntrospectedClass())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -151,8 +151,8 @@ public class StandardMethodMetadata implements MethodMetadata {
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return ((this == obj) || ((obj instanceof StandardMethodMetadata) &&
|
||||
this.introspectedMethod.equals(((StandardMethodMetadata) obj).introspectedMethod)));
|
||||
return (this == obj || (obj instanceof StandardMethodMetadata that &&
|
||||
this.introspectedMethod.equals(that.introspectedMethod)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -164,8 +164,7 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata {
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return ((this == obj) || ((obj instanceof SimpleAnnotationMetadata) &&
|
||||
this.className.equals(((SimpleAnnotationMetadata) obj).className)));
|
||||
return (this == obj || (obj instanceof SimpleAnnotationMetadata that && this.className.equals(that.className)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -102,8 +102,7 @@ final class SimpleMethodMetadata implements MethodMetadata {
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return ((this == obj) || ((obj instanceof SimpleMethodMetadata) &&
|
||||
this.source.equals(((SimpleMethodMetadata) obj).source)));
|
||||
return (this == obj || (obj instanceof SimpleMethodMetadata that && this.source.equals(that.source)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -361,8 +361,8 @@ public abstract class CollectionUtils {
|
||||
if (isEmpty(set)) {
|
||||
return null;
|
||||
}
|
||||
if (set instanceof SortedSet) {
|
||||
return ((SortedSet<T>) set).first();
|
||||
if (set instanceof SortedSet<T> sortedSet) {
|
||||
return sortedSet.first();
|
||||
}
|
||||
|
||||
Iterator<T> it = set.iterator();
|
||||
@@ -402,8 +402,8 @@ public abstract class CollectionUtils {
|
||||
if (isEmpty(set)) {
|
||||
return null;
|
||||
}
|
||||
if (set instanceof SortedSet) {
|
||||
return ((SortedSet<T>) set).last();
|
||||
if (set instanceof SortedSet<T> sortedSet) {
|
||||
return sortedSet.last();
|
||||
}
|
||||
|
||||
// Full iteration necessary...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -154,7 +154,7 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
return (key instanceof String && this.caseInsensitiveKeys.containsKey(convertKey((String) key)));
|
||||
return (key instanceof String string && this.caseInsensitiveKeys.containsKey(convertKey(string)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -246,8 +246,8 @@ public abstract class NumberUtils {
|
||||
Assert.notNull(targetClass, "Target class must not be null");
|
||||
DecimalFormat decimalFormat = null;
|
||||
boolean resetBigDecimal = false;
|
||||
if (numberFormat instanceof DecimalFormat) {
|
||||
decimalFormat = (DecimalFormat) numberFormat;
|
||||
if (numberFormat instanceof DecimalFormat dc) {
|
||||
decimalFormat = dc;
|
||||
if (BigDecimal.class == targetClass && !decimalFormat.isParseBigDecimal()) {
|
||||
decimalFormat.setParseBigDecimal(true);
|
||||
resetBigDecimal = true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -510,7 +510,7 @@ public abstract class StringUtils {
|
||||
*/
|
||||
@Nullable
|
||||
public static Object quoteIfString(@Nullable Object obj) {
|
||||
return (obj instanceof String ? quote((String) obj) : obj);
|
||||
return (obj instanceof String text ? quote(text) : obj);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -69,9 +69,8 @@ public class BooleanComparator implements Comparator<Boolean>, Serializable {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (other instanceof BooleanComparator &&
|
||||
this.trueLow == ((BooleanComparator) other).trueLow));
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return (this == obj || (obj instanceof BooleanComparator that && this.trueLow == that.trueLow));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user