Use Class#componentType() for consistency with arrayType()

Java 12 introduced java.lang.Class#componentType() as a shortcut for
getComponentType().

Since we started using arrayType() in fe5560400c, this commit switches
to componentType() for consistent API usage style.
This commit is contained in:
Sam Brannen
2023-08-07 12:43:40 +03:00
parent 96fd3c10fb
commit 526fc391ee
40 changed files with 88 additions and 88 deletions

View File

@@ -450,7 +450,7 @@ public class CodeFlow implements Opcodes {
if (clazz.isArray()) {
while (clazz.isArray()) {
sb.append('[');
clazz = clazz.getComponentType();
clazz = clazz.componentType();
}
}
if (clazz.isPrimitive()) {

View File

@@ -384,7 +384,7 @@ public class Indexer extends SpelNodeImpl {
}
private Object accessArrayElement(Object ctx, int idx) throws SpelEvaluationException {
Class<?> arrayComponentType = ctx.getClass().getComponentType();
Class<?> arrayComponentType = ctx.getClass().componentType();
if (arrayComponentType == Boolean.TYPE) {
boolean[] array = (boolean[]) ctx;
checkAccess(array.length, idx);

View File

@@ -373,7 +373,7 @@ public abstract class ReflectionHelper {
conversionOccurred |= (argument != arguments[i]);
}
final Class<?> varArgClass = methodHandleArgumentTypes.lastParameterType().getComponentType();
final Class<?> varArgClass = methodHandleArgumentTypes.lastParameterType().componentType();
ResolvableType varArgResolvableType = ResolvableType.forClass(varArgClass);
TypeDescriptor varArgContentType = new TypeDescriptor(varArgResolvableType, varArgClass, null);
@@ -431,11 +431,11 @@ public abstract class ReflectionHelper {
}
Class<?> type = possibleArray.getClass();
if (!type.isArray() || Array.getLength(possibleArray) == 0 ||
!ClassUtils.isAssignableValue(type.getComponentType(), value)) {
!ClassUtils.isAssignableValue(type.componentType(), value)) {
return false;
}
Object arrayValue = Array.get(possibleArray, 0);
return (type.getComponentType().isPrimitive() ? arrayValue.equals(value) : arrayValue == value);
return (type.componentType().isPrimitive() ? arrayValue.equals(value) : arrayValue == value);
}
/**
@@ -468,7 +468,7 @@ public abstract class ReflectionHelper {
if (argumentCount >= parameterCount) {
varargsArraySize = argumentCount - (parameterCount - 1);
}
Class<?> componentType = requiredParameterTypes[parameterCount - 1].getComponentType();
Class<?> componentType = requiredParameterTypes[parameterCount - 1].componentType();
Object varargsArray = Array.newInstance(componentType, varargsArraySize);
for (int i = 0; i < varargsArraySize; i++) {
Array.set(varargsArray, i, args[parameterCount - 1 + i]);

View File

@@ -258,8 +258,8 @@ public abstract class AbstractExpressionTests {
}
if (value.getClass().isArray()) {
StringBuilder sb = new StringBuilder();
if (value.getClass().getComponentType().isPrimitive()) {
Class<?> primitiveType = value.getClass().getComponentType();
if (value.getClass().componentType().isPrimitive()) {
Class<?> primitiveType = value.getClass().componentType();
if (primitiveType == Integer.TYPE) {
int[] l = (int[]) value;
sb.append("int[").append(l.length).append("]{");
@@ -287,10 +287,10 @@ public abstract class AbstractExpressionTests {
" in ExpressionTestCase.stringValueOf()");
}
}
else if (value.getClass().getComponentType().isArray()) {
else if (value.getClass().componentType().isArray()) {
List<Object> l = Arrays.asList((Object[]) value);
if (!isNested) {
sb.append(value.getClass().getComponentType().getName());
sb.append(value.getClass().componentType().getName());
}
sb.append('[').append(l.size()).append("]{");
int i = 0;
@@ -306,7 +306,7 @@ public abstract class AbstractExpressionTests {
else {
List<Object> l = Arrays.asList((Object[]) value);
if (!isNested) {
sb.append(value.getClass().getComponentType().getName());
sb.append(value.getClass().componentType().getName());
}
sb.append('[').append(l.size()).append("]{");
int i = 0;

View File

@@ -260,7 +260,7 @@ class ReflectionHelperTests extends AbstractExpressionTests {
assertThat(newArray).hasSize(1);
Object firstParam = newArray[0];
assertThat(firstParam.getClass().getComponentType()).isEqualTo(String.class);
assertThat(firstParam.getClass().componentType()).isEqualTo(String.class);
Object[] firstParamArray = (Object[]) firstParam;
assertThat(firstParamArray).containsExactly("a", "b", "c");
}