From cb4f93561e52928a56d3e0e83b7670275ae9952e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 6 Mar 2023 14:44:31 +0100 Subject: [PATCH] Apply "instanceof pattern matching" in remainder of spring-expression module See gh-30067 --- .../expression/spel/ast/PropertyOrFieldReference.java | 10 +++++----- .../spel/support/ReflectiveMethodResolver.java | 4 ++-- .../spel/support/StandardTypeComparator.java | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java index 34c125de3e..04e4336a7e 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java @@ -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) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java index b4c634d348..7eedb3bf16 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java @@ -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 filtered = filter.filter(methods); - methods = (filtered instanceof ArrayList ? (ArrayList) filtered : new ArrayList<>(filtered)); + methods = (filtered instanceof ArrayList arrayList ? arrayList : new ArrayList<>(filtered)); } // Sort methods into a sensible order diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java index cdbc46e1c4..6e18cce83e 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java @@ -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) left).compareTo(right); + if (left instanceof Comparable comparable) { + return comparable.compareTo(right); } } catch (ClassCastException ex) {