Browse Source

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.
pull/31012/head
Sam Brannen 1 year ago
parent
commit
526fc391ee
  1. 4
      spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java
  2. 2
      spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java
  3. 10
      spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java
  4. 2
      spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
  5. 4
      spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java
  6. 2
      spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java
  7. 6
      spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java
  8. 2
      spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java
  9. 2
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  10. 2
      spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java
  11. 6
      spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java
  12. 4
      spring-core/src/main/java/org/springframework/aot/generate/AccessControl.java
  13. 4
      spring-core/src/main/java/org/springframework/aot/hint/ReflectionTypeReference.java
  14. 2
      spring-core/src/main/java/org/springframework/asm/Type.java
  15. 2
      spring-core/src/main/java/org/springframework/cglib/core/EmitUtils.java
  16. 2
      spring-core/src/main/java/org/springframework/cglib/util/ParallelSorter.java
  17. 4
      spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java
  18. 8
      spring-core/src/main/java/org/springframework/core/Conventions.java
  19. 2
      spring-core/src/main/java/org/springframework/core/ResolvableType.java
  20. 2
      spring-core/src/main/java/org/springframework/core/annotation/AbstractMergedAnnotation.java
  21. 6
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java
  22. 8
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMapping.java
  23. 4
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java
  24. 4
      spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.java
  25. 4
      spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java
  26. 20
      spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java
  27. 2
      spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
  28. 6
      spring-core/src/main/java/org/springframework/core/style/DefaultValueStyler.java
  29. 4
      spring-core/src/main/java/org/springframework/util/ClassUtils.java
  30. 4
      spring-core/src/main/java/org/springframework/util/ObjectUtils.java
  31. 4
      spring-core/src/main/java/org/springframework/util/TypeUtils.java
  32. 2
      spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java
  33. 2
      spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java
  34. 2
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java
  35. 8
      spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java
  36. 10
      spring-expression/src/test/java/org/springframework/expression/spel/AbstractExpressionTests.java
  37. 2
      spring-expression/src/test/java/org/springframework/expression/spel/support/ReflectionHelperTests.java
  38. 4
      spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java
  39. 2
      spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java
  40. 6
      spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java

4
spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.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.
@ -291,7 +291,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, @@ -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 {

2
spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java

@ -266,7 +266,7 @@ public abstract class AopProxyUtils { @@ -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);

10
spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java

@ -291,7 +291,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA @@ -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 @@ -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 @@ -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 @@ -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 {

2
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

@ -654,7 +654,7 @@ public abstract class BeanUtils { @@ -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()));
}
/**

4
spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

@ -192,14 +192,14 @@ class ExtendedBeanInfo implements BeanInfo { @@ -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;
}
}

2
spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java

@ -233,7 +233,7 @@ abstract class PropertyDescriptorUtils { @@ -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);
}

6
spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java

@ -172,10 +172,10 @@ class TypeConverterDelegate { @@ -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 { @@ -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;
}

2
spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java

@ -917,7 +917,7 @@ class ConstructorResolver { @@ -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);

2
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

@ -1464,7 +1464,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @@ -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) {

2
spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java

@ -145,7 +145,7 @@ class BeanUtilsTests { @@ -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());
}
}
}

6
spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java

@ -605,8 +605,8 @@ public class MBeanClientInterceptor @@ -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 @@ -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));

4
spring-core/src/main/java/org/springframework/aot/generate/AccessControl.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.
@ -215,7 +215,7 @@ public final class AccessControl { @@ -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) {

4
spring-core/src/main/java/org/springframework/aot/hint/ReflectionTypeReference.java

@ -37,7 +37,7 @@ final class ReflectionTypeReference extends AbstractTypeReference { @@ -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 { @@ -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());
}
}

2
spring-core/src/main/java/org/springframework/asm/Type.java

@ -614,7 +614,7 @@ public final class Type { @@ -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;

2
spring-core/src/main/java/org/springframework/cglib/core/EmitUtils.java

@ -347,7 +347,7 @@ public class EmitUtils { @@ -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);

2
spring-core/src/main/java/org/springframework/cglib/util/ParallelSorter.java

@ -154,7 +154,7 @@ abstract public class ParallelSorter extends SorterTemplate { @@ -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)) {

4
spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.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.
@ -158,7 +158,7 @@ public final class BridgeMethodResolver { @@ -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;
}
}

8
spring-core/src/main/java/org/springframework/core/Conventions.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.
@ -67,7 +67,7 @@ public final class Conventions { @@ -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 { @@ -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 { @@ -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)) {

2
spring-core/src/main/java/org/springframework/core/ResolvableType.java

@ -396,7 +396,7 @@ public class ResolvableType implements Serializable { @@ -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) {

2
spring-core/src/main/java/org/springframework/core/annotation/AbstractMergedAnnotation.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.

6
spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.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.
@ -352,8 +352,8 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> { @@ -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;
}

8
spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMapping.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.
@ -217,7 +217,7 @@ final class AnnotationTypeMapping { @@ -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 { @@ -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;

4
spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

@ -1011,7 +1011,7 @@ public abstract class AnnotationUtils { @@ -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 { @@ -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);
}

4
spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.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.
@ -75,7 +75,7 @@ final class AttributeMethods { @@ -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);

4
spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java

@ -174,7 +174,7 @@ public abstract class RepeatableContainers { @@ -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 { @@ -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()));

20
spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.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.
@ -228,7 +228,7 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);

2
spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java

@ -551,7 +551,7 @@ public class GenericConversionService implements ConfigurableConversionService { @@ -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);

6
spring-core/src/main/java/org/springframework/core/style/DefaultValueStyler.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.
@ -178,14 +178,14 @@ public class DefaultValueStyler implements ValueStyler { @@ -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;
}
/**

4
spring-core/src/main/java/org/springframework/util/ClassUtils.java

@ -516,7 +516,7 @@ public abstract class ClassUtils { @@ -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 { @@ -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()));
}
/**

4
spring-core/src/main/java/org/springframework/util/ObjectUtils.java

@ -244,7 +244,7 @@ public abstract class ObjectUtils { @@ -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 { @@ -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();

4
spring-core/src/main/java/org/springframework/util/TypeUtils.java

@ -75,7 +75,7 @@ public abstract class TypeUtils { @@ -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 { @@ -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();

2
spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java

@ -360,7 +360,7 @@ class ResolvableTypeTests { @@ -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

2
spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java

@ -450,7 +450,7 @@ public class CodeFlow implements Opcodes { @@ -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()) {

2
spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java

@ -384,7 +384,7 @@ public class Indexer extends SpelNodeImpl { @@ -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);

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

@ -373,7 +373,7 @@ public abstract class ReflectionHelper { @@ -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 { @@ -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 { @@ -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]);

10
spring-expression/src/test/java/org/springframework/expression/spel/AbstractExpressionTests.java

@ -258,8 +258,8 @@ public abstract class AbstractExpressionTests { @@ -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 { @@ -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 { @@ -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;

2
spring-expression/src/test/java/org/springframework/expression/spel/support/ReflectionHelperTests.java

@ -260,7 +260,7 @@ class ReflectionHelperTests extends AbstractExpressionTests { @@ -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");
}

4
spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.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.
@ -619,7 +619,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi @@ -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));
}

2
spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java

@ -344,7 +344,7 @@ public class WebDataBinder extends DataBinder { @@ -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);

6
spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java

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

Loading…
Cancel
Save