Browse Source

Apply "instanceof pattern matching" in remainder of spring-expression module

See gh-30067
pull/30074/head
Sam Brannen 3 years ago
parent
commit
cb4f93561e
  1. 10
      spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java
  2. 4
      spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java
  3. 8
      spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java

10
spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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 { @@ -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) {

4
spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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

8
spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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) {

Loading…
Cancel
Save