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:
@@ -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 {
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user