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

@@ -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.
@@ -291,7 +291,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
private void appendType(StringBuilder sb, Class<?> type, boolean useLongTypeName) {
if (type.isArray()) {
appendType(sb, type.getComponentType(), useLongTypeName);
appendType(sb, type.componentType(), useLongTypeName);
sb.append("[]");
}
else {

View File

@@ -266,7 +266,7 @@ public abstract class AopProxyUtils {
if (varargArray instanceof Object[] && !varargType.isInstance(varargArray)) {
Object[] newArguments = new Object[arguments.length];
System.arraycopy(arguments, 0, newArguments, 0, varargIndex);
Class<?> targetElementType = varargType.getComponentType();
Class<?> targetElementType = varargType.componentType();
int varargLength = Array.getLength(varargArray);
Object newVarargArray = Array.newInstance(targetElementType, varargLength);
System.arraycopy(varargArray, 0, newVarargArray, 0, varargLength);

View File

@@ -291,7 +291,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
String lastKey = tokens.keys[tokens.keys.length - 1];
if (propValue.getClass().isArray()) {
Class<?> requiredType = propValue.getClass().getComponentType();
Class<?> requiredType = propValue.getClass().componentType();
int arrayIndex = Integer.parseInt(lastKey);
Object oldValue = null;
try {
@@ -302,7 +302,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
requiredType, ph.nested(tokens.keys.length));
int length = Array.getLength(propValue);
if (arrayIndex >= length && arrayIndex < this.autoGrowCollectionLimit) {
Class<?> componentType = propValue.getClass().getComponentType();
Class<?> componentType = propValue.getClass().componentType();
Object newArray = Array.newInstance(componentType, arrayIndex + 1);
System.arraycopy(propValue, 0, newArray, 0, length);
int lastKeyIndex = tokens.canonicalName.lastIndexOf('[');
@@ -769,7 +769,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
int length = Array.getLength(array);
if (index >= length && index < this.autoGrowCollectionLimit) {
Class<?> componentType = array.getClass().getComponentType();
Class<?> componentType = array.getClass().componentType();
Object newArray = Array.newInstance(componentType, index + 1);
System.arraycopy(array, 0, newArray, 0, length);
for (int i = length; i < Array.getLength(newArray); i++) {
@@ -900,11 +900,11 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
private Object newValue(Class<?> type, @Nullable TypeDescriptor desc, String name) {
try {
if (type.isArray()) {
Class<?> componentType = type.getComponentType();
Class<?> componentType = type.componentType();
// TODO - only handles 2-dimensional arrays
if (componentType.isArray()) {
Object array = Array.newInstance(componentType, 1);
Array.set(array, 0, Array.newInstance(componentType.getComponentType(), 0));
Array.set(array, 0, Array.newInstance(componentType.componentType(), 0));
return array;
}
else {

View File

@@ -654,7 +654,7 @@ public abstract class BeanUtils {
*/
public static boolean isSimpleProperty(Class<?> type) {
Assert.notNull(type, "'type' must not be null");
return isSimpleValueType(type) || (type.isArray() && isSimpleValueType(type.getComponentType()));
return isSimpleValueType(type) || (type.isArray() && isSimpleValueType(type.componentType()));
}
/**

View File

@@ -192,14 +192,14 @@ class ExtendedBeanInfo implements BeanInfo {
if (pd instanceof IndexedPropertyDescriptor indexedPd) {
candidateType = indexedPd.getIndexedPropertyType();
if (candidateName.equals(propertyName) &&
(candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) {
(candidateType.equals(propertyType) || candidateType.equals(propertyType.componentType()))) {
return pd;
}
}
else {
candidateType = pd.getPropertyType();
if (candidateName.equals(propertyName) &&
(candidateType.equals(propertyType) || propertyType.equals(candidateType.getComponentType()))) {
(candidateType.equals(propertyType) || propertyType.equals(candidateType.componentType()))) {
return pd;
}
}

View File

@@ -233,7 +233,7 @@ abstract class PropertyDescriptorUtils {
}
if (propertyType != null && (!propertyType.isArray() ||
propertyType.getComponentType() != indexedPropertyType)) {
propertyType.componentType() != indexedPropertyType)) {
throw new IntrospectionException("Type mismatch between indexed and non-indexed methods: " +
indexedReadMethod + " - " + indexedWriteMethod);
}

View File

@@ -172,10 +172,10 @@ class TypeConverterDelegate {
else if (requiredType.isArray()) {
// Array required -> apply appropriate conversion of elements.
if (convertedValue instanceof String text &&
Enum.class.isAssignableFrom(requiredType.getComponentType())) {
Enum.class.isAssignableFrom(requiredType.componentType())) {
convertedValue = StringUtils.commaDelimitedListToStringArray(text);
}
return (T) convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType());
return (T) convertToTypedArray(convertedValue, propertyName, requiredType.componentType());
}
else if (convertedValue.getClass().isArray()) {
if (Array.getLength(convertedValue) == 1) {
@@ -453,7 +453,7 @@ class TypeConverterDelegate {
}
else if (input.getClass().isArray()) {
// Convert array elements, if necessary.
if (componentType.equals(input.getClass().getComponentType()) &&
if (componentType.equals(input.getClass().componentType()) &&
!this.propertyEditorRegistry.hasCustomEditorForElement(componentType, propertyName)) {
return input;
}

View File

@@ -917,7 +917,7 @@ class ConstructorResolver {
// Single constructor or factory method -> let's return an empty array/collection
// for e.g. a vararg or a non-null List/Set/Map parameter.
if (paramType.isArray()) {
return Array.newInstance(paramType.getComponentType(), 0);
return Array.newInstance(paramType.componentType(), 0);
}
else if (CollectionFactory.isApproximableCollectionType(paramType)) {
return CollectionFactory.createCollection(paramType, 0);

View File

@@ -1464,7 +1464,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
return stream;
}
else if (type.isArray()) {
Class<?> componentType = type.getComponentType();
Class<?> componentType = type.componentType();
ResolvableType resolvableType = descriptor.getResolvableType();
Class<?> resolvedArrayType = resolvableType.resolve(type);
if (resolvedArrayType != type) {

View File

@@ -145,7 +145,7 @@ class BeanUtilsTests {
for (PropertyDescriptor descriptor : descriptors) {
if ("containedBeans".equals(descriptor.getName())) {
assertThat(descriptor.getPropertyType().isArray()).as("Property should be an array").isTrue();
assertThat(ContainedBean.class).isEqualTo(descriptor.getPropertyType().getComponentType());
assertThat(ContainedBean.class).isEqualTo(descriptor.getPropertyType().componentType());
}
}
}

View File

@@ -605,8 +605,8 @@ public class MBeanClientInterceptor
}
private Object convertDataArrayToTargetArray(Object[] array, Class<?> targetClass) throws NoSuchMethodException {
Class<?> targetType = targetClass.getComponentType();
Method fromMethod = targetType.getMethod("from", array.getClass().getComponentType());
Class<?> targetType = targetClass.componentType();
Method fromMethod = targetType.getMethod("from", array.getClass().componentType());
Object resultArray = Array.newInstance(targetType, array.length);
for (int i = 0; i < array.length; i++) {
Array.set(resultArray, i, ReflectionUtils.invokeMethod(fromMethod, null, array[i]));
@@ -617,7 +617,7 @@ public class MBeanClientInterceptor
private Collection<?> convertDataArrayToTargetCollection(Object[] array, Class<?> collectionType, Class<?> elementType)
throws NoSuchMethodException {
Method fromMethod = elementType.getMethod("from", array.getClass().getComponentType());
Method fromMethod = elementType.getMethod("from", array.getClass().componentType());
Collection<Object> resultColl = CollectionFactory.createCollection(collectionType, Array.getLength(array));
for (Object element : array) {
resultColl.add(ReflectionUtils.invokeMethod(fromMethod, null, element));

View File

@@ -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.
@@ -215,7 +215,7 @@ public final class AccessControl {
clazz = ClassUtils.getUserClass(clazz);
Visibility visibility = forModifiers(clazz.getModifiers());
if (clazz.isArray()) {
visibility = lowest(visibility, forClass(clazz.getComponentType()));
visibility = lowest(visibility, forClass(clazz.componentType()));
}
Class<?> enclosingClass = clazz.getEnclosingClass();
if (enclosingClass != null) {

View File

@@ -37,7 +37,7 @@ final class ReflectionTypeReference extends AbstractTypeReference {
@Nullable
private static TypeReference getEnclosingClass(Class<?> type) {
Class<?> candidate = (type.isArray() ? type.getComponentType().getEnclosingClass() :
Class<?> candidate = (type.isArray() ? type.componentType().getEnclosingClass() :
type.getEnclosingClass());
return (candidate != null ? new ReflectionTypeReference(candidate) : null);
}
@@ -56,7 +56,7 @@ final class ReflectionTypeReference extends AbstractTypeReference {
@Override
protected boolean isPrimitive() {
return this.type.isPrimitive() ||
(this.type.isArray() && this.type.getComponentType().isPrimitive());
(this.type.isArray() && this.type.componentType().isPrimitive());
}
}

View File

@@ -614,7 +614,7 @@ public final class Type {
Class<?> currentClass = clazz;
while (currentClass.isArray()) {
stringBuilder.append('[');
currentClass = currentClass.getComponentType();
currentClass = currentClass.componentType();
}
if (currentClass.isPrimitive()) {
char descriptor;

View File

@@ -347,7 +347,7 @@ public class EmitUtils {
public static void push_array(CodeEmitter e, Object[] array) {
e.push(array.length);
e.newarray(Type.getType(remapComponentType(array.getClass().getComponentType())));
e.newarray(Type.getType(remapComponentType(array.getClass().componentType())));
for (int i = 0; i < array.length; i++) {
e.dup();
e.push(i);

View File

@@ -154,7 +154,7 @@ abstract public class ParallelSorter extends SorterTemplate {
private void chooseComparer(int index, Comparator cmp) {
Object array = a[index];
Class type = array.getClass().getComponentType();
Class type = array.getClass().componentType();
if (type.equals(Integer.TYPE)) {
comparer = new IntComparer((int[])array);
} else if (type.equals(Long.TYPE)) {

View File

@@ -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.
@@ -158,7 +158,7 @@ public final class BridgeMethodResolver {
Class<?> candidateParameter = candidateParameters[i];
if (candidateParameter.isArray()) {
// An array type: compare the component type.
if (!candidateParameter.getComponentType().equals(genericParameter.getComponentType().toClass())) {
if (!candidateParameter.componentType().equals(genericParameter.getComponentType().toClass())) {
return false;
}
}

View File

@@ -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.
@@ -67,7 +67,7 @@ public final class Conventions {
boolean pluralize = false;
if (value.getClass().isArray()) {
valueClass = value.getClass().getComponentType();
valueClass = value.getClass().componentType();
pluralize = true;
}
else if (value instanceof Collection<?> collection) {
@@ -104,7 +104,7 @@ public final class Conventions {
String reactiveSuffix = "";
if (parameter.getParameterType().isArray()) {
valueClass = parameter.getParameterType().getComponentType();
valueClass = parameter.getParameterType().componentType();
pluralize = true;
}
else if (Collection.class.isAssignableFrom(parameter.getParameterType())) {
@@ -178,7 +178,7 @@ public final class Conventions {
String reactiveSuffix = "";
if (resolvedType.isArray()) {
valueClass = resolvedType.getComponentType();
valueClass = resolvedType.componentType();
pluralize = true;
}
else if (Collection.class.isAssignableFrom(resolvedType)) {

View File

@@ -396,7 +396,7 @@ public class ResolvableType implements Serializable {
return this.componentType;
}
if (this.type instanceof Class<?> clazz) {
Class<?> componentType = clazz.getComponentType();
Class<?> componentType = clazz.componentType();
return forType(componentType, this.variableResolver);
}
if (this.type instanceof GenericArrayType genericArrayType) {

View File

@@ -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.

View File

@@ -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,8 +352,8 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
assertAttributePresence(attributeName, value);
assertNotException(attributeName, value);
if (!expectedType.isInstance(value) && expectedType.isArray() &&
expectedType.getComponentType().isInstance(value)) {
Object array = Array.newInstance(expectedType.getComponentType(), 1);
expectedType.componentType().isInstance(value)) {
Object array = Array.newInstance(expectedType.componentType(), 1);
Array.set(array, 0, value);
value = array;
}

View File

@@ -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.
@@ -217,7 +217,7 @@ final class AnnotationTypeMapping {
}
private boolean isCompatibleReturnType(Class<?> attributeType, Class<?> targetType) {
return (attributeType == targetType || attributeType == targetType.getComponentType());
return (attributeType == targetType || attributeType == targetType.componentType());
}
private void processAliases() {
@@ -399,9 +399,9 @@ final class AnnotationTypeMapping {
for (int i = 0; i < attributeMethods.size(); i++) {
Method method = attributeMethods.get(i);
Class<?> type = method.getReturnType();
if (type.isAnnotation() || (type.isArray() && type.getComponentType().isAnnotation())) {
if (type.isAnnotation() || (type.isArray() && type.componentType().isAnnotation())) {
Class<? extends Annotation> annotationType =
(Class<? extends Annotation>) (type.isAnnotation() ? type : type.getComponentType());
(Class<? extends Annotation>) (type.isAnnotation() ? type : type.componentType());
AnnotationTypeMapping mapping = AnnotationTypeMappings.forAnnotationType(annotationType).get(0);
if (mapping.isSynthesizable()) {
return true;

View File

@@ -1011,7 +1011,7 @@ public abstract class AnnotationUtils {
}
if (value instanceof Annotation[] annotations) {
Annotation[] synthesized = (Annotation[]) Array.newInstance(
annotations.getClass().getComponentType(), annotations.length);
annotations.getClass().componentType(), annotations.length);
for (int i = 0; i < annotations.length; i++) {
synthesized[i] = MergedAnnotation.from(annotatedElement, annotations[i]).synthesize();
}
@@ -1292,7 +1292,7 @@ public abstract class AnnotationUtils {
return annotations;
}
Annotation[] synthesized = (Annotation[]) Array.newInstance(
annotations.getClass().getComponentType(), annotations.length);
annotations.getClass().componentType(), annotations.length);
for (int i = 0; i < annotations.length; i++) {
synthesized[i] = synthesizeAnnotation(annotations[i], annotatedElement);
}

View File

@@ -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.
@@ -75,7 +75,7 @@ final class AttributeMethods {
if (!foundDefaultValueMethod && (method.getDefaultValue() != null)) {
foundDefaultValueMethod = true;
}
if (!foundNestedAnnotation && (type.isAnnotation() || (type.isArray() && type.getComponentType().isAnnotation()))) {
if (!foundNestedAnnotation && (type.isAnnotation() || (type.isArray() && type.componentType().isAnnotation()))) {
foundNestedAnnotation = true;
}
ReflectionUtils.makeAccessible(method);

View File

@@ -174,7 +174,7 @@ public abstract class RepeatableContainers {
if (method != null) {
Class<?> returnType = method.getReturnType();
if (returnType.isArray()) {
Class<?> componentType = returnType.getComponentType();
Class<?> componentType = returnType.componentType();
if (Annotation.class.isAssignableFrom(componentType) &&
componentType.isAnnotationPresent(Repeatable.class)) {
return method;
@@ -211,7 +211,7 @@ public abstract class RepeatableContainers {
throw new NoSuchMethodException("No value method found");
}
Class<?> returnType = valueMethod.getReturnType();
if (!returnType.isArray() || returnType.getComponentType() != repeatable) {
if (!returnType.isArray() || returnType.componentType() != repeatable) {
throw new AnnotationConfigurationException(
"Container type [%s] must declare a 'value' attribute for an array of type [%s]"
.formatted(container.getName(), repeatable.getName()));

View File

@@ -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.
@@ -228,7 +228,7 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
int attributeIndex = getAttributeIndex(attributeName, true);
Method attribute = this.mapping.getAttributes().get(attributeIndex);
Class<?> componentType = attribute.getReturnType().getComponentType();
Class<?> componentType = attribute.getReturnType().componentType();
Assert.notNull(type, "Type must not be null");
Assert.notNull(componentType, () -> "Attribute " + attributeName + " is not an array");
Assert.isAssignable(type, componentType, () -> "Attribute " + attributeName + " component type mismatch:");
@@ -286,7 +286,7 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
private Class<?> getTypeForMapOptions(Method attribute, Adapt[] adaptations) {
Class<?> attributeType = attribute.getReturnType();
Class<?> componentType = (attributeType.isArray() ? attributeType.getComponentType() : attributeType);
Class<?> componentType = (attributeType.isArray() ? attributeType.componentType() : attributeType);
if (Adapt.CLASS_TO_STRING.isIn(adaptations) && componentType == Class.class) {
return (attributeType.isArray() ? String[].class : String.class);
}
@@ -309,7 +309,7 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
return result;
}
Object result = Array.newInstance(
attribute.getReturnType().getComponentType(), annotations.length);
attribute.getReturnType().componentType(), annotations.length);
for (int i = 0; i < annotations.length; i++) {
Array.set(result, i, annotations[i].synthesize());
}
@@ -470,8 +470,8 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
value = annotation.synthesize();
}
else if (value instanceof MergedAnnotation<?>[] annotations &&
type.isArray() && type.getComponentType().isAnnotation()) {
Object array = Array.newInstance(type.getComponentType(), annotations.length);
type.isArray() && type.componentType().isAnnotation()) {
Object array = Array.newInstance(type.componentType(), annotations.length);
for (int i = 0; i < annotations.length; i++) {
Array.set(array, i, annotations[i].synthesize());
}
@@ -495,11 +495,11 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
if (attributeType.isAnnotation()) {
return adaptToMergedAnnotation(value, (Class<? extends Annotation>) attributeType);
}
if (attributeType.isArray() && attributeType.getComponentType().isAnnotation()) {
if (attributeType.isArray() && attributeType.componentType().isAnnotation()) {
MergedAnnotation<?>[] result = new MergedAnnotation<?>[Array.getLength(value)];
for (int i = 0; i < result.length; i++) {
result[i] = adaptToMergedAnnotation(Array.get(value, i),
(Class<? extends Annotation>) attributeType.getComponentType());
(Class<? extends Annotation>) attributeType.componentType());
}
return result;
}
@@ -510,7 +510,7 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
return value;
}
if (attributeType.isArray() && isEmptyObjectArray(value)) {
return emptyArray(attributeType.getComponentType());
return emptyArray(attributeType.componentType());
}
if (!attributeType.isInstance(value)) {
throw new IllegalStateException("Attribute '" + attribute.getName() +
@@ -561,7 +561,7 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
if (attributeType.isAnnotation()) {
return (Class<T>) MergedAnnotation.class;
}
if (attributeType.isArray() && attributeType.getComponentType().isAnnotation()) {
if (attributeType.isArray() && attributeType.componentType().isAnnotation()) {
return (Class<T>) MergedAnnotation[].class;
}
return (Class<T>) ClassUtils.resolvePrimitiveIfNecessary(attributeType);

View File

@@ -551,7 +551,7 @@ public class GenericConversionService implements ConfigurableConversionService {
int i = 0;
while (i < hierarchy.size()) {
Class<?> candidate = hierarchy.get(i);
candidate = (array ? candidate.getComponentType() : ClassUtils.resolvePrimitiveIfNecessary(candidate));
candidate = (array ? candidate.componentType() : ClassUtils.resolvePrimitiveIfNecessary(candidate));
Class<?> superclass = candidate.getSuperclass();
if (superclass != null && superclass != Object.class && superclass != Enum.class) {
addToClassHierarchy(i + 1, candidate.getSuperclass(), array, hierarchy, visited);

View File

@@ -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.
@@ -178,14 +178,14 @@ public class DefaultValueStyler implements ValueStyler {
*/
protected String styleArray(Object[] array) {
if (array.length == 0) {
return ARRAY + '<' + ClassUtils.getShortName(array.getClass().getComponentType()) + '>' + EMPTY;
return ARRAY + '<' + ClassUtils.getShortName(array.getClass().componentType()) + '>' + EMPTY;
}
StringJoiner result = new StringJoiner(", ", "[", "]");
for (Object element : array) {
result.add(style(element));
}
return ARRAY + '<' + ClassUtils.getShortName(array.getClass().getComponentType()) + '>' + result;
return ARRAY + '<' + ClassUtils.getShortName(array.getClass().componentType()) + '>' + result;
}
/**

View File

@@ -516,7 +516,7 @@ public abstract class ClassUtils {
*/
public static boolean isPrimitiveArray(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
return (clazz.isArray() && clazz.getComponentType().isPrimitive());
return (clazz.isArray() && clazz.componentType().isPrimitive());
}
/**
@@ -527,7 +527,7 @@ public abstract class ClassUtils {
*/
public static boolean isPrimitiveWrapperArray(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
return (clazz.isArray() && isPrimitiveWrapper(clazz.getComponentType()));
return (clazz.isArray() && isPrimitiveWrapper(clazz.componentType()));
}
/**

View File

@@ -244,7 +244,7 @@ public abstract class ObjectUtils {
}
}
throw new IllegalArgumentException("Constant [" + constant + "] does not exist in enum type " +
enumValues.getClass().getComponentType().getName());
enumValues.getClass().componentType().getName());
}
/**
@@ -270,7 +270,7 @@ public abstract class ObjectUtils {
public static <A, O extends A> A[] addObjectToArray(@Nullable A[] array, @Nullable O obj, int position) {
Class<?> componentType = Object.class;
if (array != null) {
componentType = array.getClass().getComponentType();
componentType = array.getClass().componentType();
}
else if (obj != null) {
componentType = obj.getClass();

View File

@@ -75,7 +75,7 @@ public abstract class TypeUtils {
else if (lhsClass.isArray() && rhsType instanceof GenericArrayType rhsGenericArrayType) {
Type rhsComponent = rhsGenericArrayType.getGenericComponentType();
return isAssignable(lhsClass.getComponentType(), rhsComponent);
return isAssignable(lhsClass.componentType(), rhsComponent);
}
}
@@ -97,7 +97,7 @@ public abstract class TypeUtils {
Type lhsComponent = lhsGenericArrayType.getGenericComponentType();
if (rhsType instanceof Class<?> rhsClass && rhsClass.isArray()) {
return isAssignable(lhsComponent, rhsClass.getComponentType());
return isAssignable(lhsComponent, rhsClass.componentType());
}
else if (rhsType instanceof GenericArrayType rhsGenericArrayType) {
Type rhsComponent = rhsGenericArrayType.getGenericComponentType();

View File

@@ -360,7 +360,7 @@ class ResolvableTypeTests {
ResolvableType type = ResolvableType.forField(field);
assertThat(type.isArray()).isTrue();
assertThat(type.getComponentType().getType())
.isEqualTo(((Class) field.getGenericType()).getComponentType());
.isEqualTo(((Class) field.getGenericType()).componentType());
}
@Test

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");
}

View File

@@ -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.
@@ -619,7 +619,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
parameterizedType.getActualTypeArguments().length == 1) {
Type typeArgument = parameterizedType.getActualTypeArguments()[0];
if (typeArgument instanceof Class<?> classArgument) {
return ((classArgument.isArray() && Byte.TYPE == classArgument.getComponentType()) ||
return ((classArgument.isArray() && Byte.TYPE == classArgument.componentType()) ||
isPrimitiveWrapper(classArgument) || isStandardClass(classArgument) ||
supportsInternal(classArgument, false));
}

View File

@@ -344,7 +344,7 @@ public class WebDataBinder extends DataBinder {
}
else if (fieldType.isArray()) {
// Special handling of array property.
return Array.newInstance(fieldType.getComponentType(), 0);
return Array.newInstance(fieldType.componentType(), 0);
}
else if (Collection.class.isAssignableFrom(fieldType)) {
return CollectionFactory.createCollection(fieldType, 0);

View File

@@ -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.
@@ -157,7 +157,7 @@ public final class MultipartResolutionDelegate {
}
private static boolean isMultipartFileArray(MethodParameter methodParam) {
return (MultipartFile.class == methodParam.getNestedParameterType().getComponentType());
return (MultipartFile.class == methodParam.getNestedParameterType().componentType());
}
private static boolean isPartCollection(MethodParameter methodParam) {
@@ -165,7 +165,7 @@ public final class MultipartResolutionDelegate {
}
private static boolean isPartArray(MethodParameter methodParam) {
return (Part.class == methodParam.getNestedParameterType().getComponentType());
return (Part.class == methodParam.getNestedParameterType().componentType());
}
@Nullable