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