Apply "instanceof pattern matching" in remainder of spring-expression module
See gh-30067
This commit is contained in:
@@ -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.
|
||||
@@ -92,8 +92,8 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
|
||||
TypedValue tv = getValueInternal(state.getActiveContextObject(), state.getEvaluationContext(),
|
||||
state.getConfiguration().isAutoGrowNullReferences());
|
||||
PropertyAccessor accessorToUse = this.cachedReadAccessor;
|
||||
if (accessorToUse instanceof CompilablePropertyAccessor accessor) {
|
||||
setExitTypeDescriptor(CodeFlow.toDescriptor(accessor.getPropertyType()));
|
||||
if (accessorToUse instanceof CompilablePropertyAccessor compilablePropertyAccessor) {
|
||||
setExitTypeDescriptor(CodeFlow.toDescriptor(compilablePropertyAccessor.getPropertyType()));
|
||||
}
|
||||
return tv;
|
||||
}
|
||||
@@ -337,7 +337,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
|
||||
@Override
|
||||
public void generateCode(MethodVisitor mv, CodeFlow cf) {
|
||||
PropertyAccessor accessorToUse = this.cachedReadAccessor;
|
||||
if (!(accessorToUse instanceof CompilablePropertyAccessor)) {
|
||||
if (!(accessorToUse instanceof CompilablePropertyAccessor compilablePropertyAccessor)) {
|
||||
throw new IllegalStateException("Property accessor is not compilable: " + accessorToUse);
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
|
||||
mv.visitLabel(continueLabel);
|
||||
}
|
||||
|
||||
((CompilablePropertyAccessor) accessorToUse).generateCode(this.name, mv, cf);
|
||||
compilablePropertyAccessor.generateCode(this.name, mv, cf);
|
||||
cf.pushDescriptor(this.exitTypeDescriptor);
|
||||
|
||||
if (this.originalPrimitiveExitTypeDescriptor != 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.
|
||||
@@ -121,7 +121,7 @@ public class ReflectiveMethodResolver implements MethodResolver {
|
||||
MethodFilter filter = (this.filters != null ? this.filters.get(type) : null);
|
||||
if (filter != null) {
|
||||
List<Method> filtered = filter.filter(methods);
|
||||
methods = (filtered instanceof ArrayList ? (ArrayList<Method>) filtered : new ArrayList<>(filtered));
|
||||
methods = (filtered instanceof ArrayList<Method> arrayList ? arrayList : new ArrayList<>(filtered));
|
||||
}
|
||||
|
||||
// Sort methods into a sensible order
|
||||
|
||||
@@ -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.
|
||||
@@ -53,7 +53,7 @@ public class StandardTypeComparator implements TypeComparator {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public int compare(@Nullable Object left, @Nullable Object right) throws SpelEvaluationException {
|
||||
// If one is null, check if the other is
|
||||
if (left == null) {
|
||||
@@ -100,8 +100,8 @@ public class StandardTypeComparator implements TypeComparator {
|
||||
}
|
||||
|
||||
try {
|
||||
if (left instanceof Comparable) {
|
||||
return ((Comparable<Object>) left).compareTo(right);
|
||||
if (left instanceof Comparable comparable) {
|
||||
return comparable.compareTo(right);
|
||||
}
|
||||
}
|
||||
catch (ClassCastException ex) {
|
||||
|
||||
Reference in New Issue
Block a user