Skip to content

Commit

Permalink
Consistently use class literals for primitive types
Browse files Browse the repository at this point in the history
To improve consistency and avoid confusion regarding primitive types
and their wrapper types, this commit ensures that we always use class
literals for primitive types.

For example, instead of using the `Void.TYPE` constant, we now
consistently use `void.class`.
  • Loading branch information
sbrannen committed Jan 30, 2024
1 parent 95a3f3b commit db53586
Show file tree
Hide file tree
Showing 33 changed files with 231 additions and 231 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -94,7 +94,7 @@ public boolean canConvert(TypeDescriptor sourceTypeDescriptor, TypeDescriptor ta

@Override
public Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (targetType.getType() == Void.class || targetType.getType() == Void.TYPE) {
if (targetType.getType() == Void.class || targetType.getType() == void.class) {
return null;
}
if (conversionService.canConvert(sourceType, targetType)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -417,7 +417,7 @@ private static Object processReturnType(
returnValue = proxy;
}
Class<?> returnType = method.getReturnType();
if (returnValue == null && returnType != Void.TYPE && returnType.isPrimitive()) {
if (returnValue == null && returnType != void.class && returnType.isPrimitive()) {
throw new AopInvocationException(
"Null return value from advice does not match primitive return type for: " + method);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -230,7 +230,7 @@ else if (!this.advised.opaque && method.getDeclaringClass().isInterface() &&
// a reference to itself in another returned object.
retVal = proxy;
}
else if (retVal == null && returnType != Void.TYPE && returnType.isPrimitive()) {
else if (retVal == null && returnType != void.class && returnType.isPrimitive()) {
throw new AopInvocationException(
"Null return value from advice does not match primitive return type for: " + method);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -101,7 +101,7 @@ private static class SetterPointcut extends StaticMethodMatcherPointcut implemen
public boolean matches(Method method, Class<?> targetClass) {
return (method.getName().startsWith("set") &&
method.getParameterCount() == 1 &&
method.getReturnType() == Void.TYPE);
method.getReturnType() == void.class);
}

private Object readResolve() {
Expand All @@ -127,7 +127,7 @@ private static class GetterPointcut extends StaticMethodMatcherPointcut implemen
public boolean matches(Method method, Class<?> targetClass) {
return (method.getName().startsWith("get") &&
method.getParameterCount() == 0 &&
method.getReturnType() != Void.TYPE);
method.getReturnType() != void.class);
}

private Object readResolve() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -68,7 +68,7 @@ public static Collection<? extends PropertyDescriptor> determineBasicProperties(
setter = true;
nameIndex = 3;
}
else if (methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != Void.TYPE) {
else if (methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != void.class) {
setter = false;
nameIndex = 3;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public static Class<?> findPropertyType(@Nullable Method readMethod, @Nullable M
throw new IntrospectionException("Bad read method arg count: " + readMethod);
}
propertyType = readMethod.getReturnType();
if (propertyType == Void.TYPE) {
if (propertyType == void.class) {
throw new IntrospectionException("Read method returns void: " + readMethod);
}
}
Expand Down Expand Up @@ -197,11 +197,11 @@ public static Class<?> findIndexedPropertyType(String name, @Nullable Class<?> p
if (params.length != 1) {
throw new IntrospectionException("Bad indexed read method arg count: " + indexedReadMethod);
}
if (params[0] != Integer.TYPE) {
if (params[0] != int.class) {
throw new IntrospectionException("Non int index to indexed read method: " + indexedReadMethod);
}
indexedPropertyType = indexedReadMethod.getReturnType();
if (indexedPropertyType == Void.TYPE) {
if (indexedPropertyType == void.class) {
throw new IntrospectionException("Indexed read method returns void: " + indexedReadMethod);
}
}
Expand All @@ -211,7 +211,7 @@ public static Class<?> findIndexedPropertyType(String name, @Nullable Class<?> p
if (params.length != 2) {
throw new IntrospectionException("Bad indexed write method arg count: " + indexedWriteMethod);
}
if (params[0] != Integer.TYPE) {
if (params[0] != int.class) {
throw new IntrospectionException("Non int index to indexed write method: " + indexedWriteMethod);
}
if (indexedPropertyType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ public PointcutForVoid() {
setPointcut(new DynamicMethodMatcherPointcut() {
@Override
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
return m.getReturnType() == Void.TYPE;
return m.getReturnType() == void.class;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -107,7 +107,7 @@ private void registerReflectionHints(ReflectionHints hints, Set<Type> seen, Type
if (methodName.startsWith("set") && method.getParameterCount() == 1) {
registerPropertyHints(hints, seen, method, 0);
}
else if ((methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != Void.TYPE) ||
else if ((methodName.startsWith("get") && method.getParameterCount() == 0 && method.getReturnType() != void.class) ||
(methodName.startsWith("is") && method.getParameterCount() == 0 && method.getReturnType() == boolean.class)) {
registerPropertyHints(hints, seen, method, -1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public MethodParameter getReturnValueType(@Nullable Object returnValue) {
* Return {@code true} if the method's return type is void, {@code false} otherwise.
*/
public boolean isVoid() {
return Void.TYPE.equals(getReturnType().getParameterType());
return (getReturnType().getParameterType() == void.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -52,7 +52,7 @@ class MethodParameterTests {

@BeforeEach
void setup() throws NoSuchMethodException {
method = getClass().getMethod("method", String.class, Long.TYPE);
method = getClass().getMethod("method", String.class, long.class);
stringParameter = new MethodParameter(method, 0);
longParameter = new MethodParameter(method, 1);
intReturnType = new MethodParameter(method, -1);
Expand All @@ -72,7 +72,7 @@ void equals() throws NoSuchMethodException {
assertThat(intReturnType).isNotEqualTo(stringParameter);
assertThat(intReturnType).isNotEqualTo(longParameter);

Method method = getClass().getMethod("method", String.class, Long.TYPE);
Method method = getClass().getMethod("method", String.class, long.class);
MethodParameter methodParameter = new MethodParameter(method, 0);
assertThat(methodParameter).isEqualTo(stringParameter);
assertThat(stringParameter).isEqualTo(methodParameter);
Expand All @@ -86,7 +86,7 @@ void testHashCode() throws NoSuchMethodException {
assertThat(longParameter.hashCode()).isEqualTo(longParameter.hashCode());
assertThat(intReturnType.hashCode()).isEqualTo(intReturnType.hashCode());

Method method = getClass().getMethod("method", String.class, Long.TYPE);
Method method = getClass().getMethod("method", String.class, long.class);
MethodParameter methodParameter = new MethodParameter(method, 0);
assertThat(methodParameter.hashCode()).isEqualTo(stringParameter.hashCode());
assertThat(methodParameter.hashCode()).isNotEqualTo(longParameter.hashCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -43,7 +43,7 @@ class SynthesizingMethodParameterTests {

@BeforeEach
void setUp() throws NoSuchMethodException {
method = getClass().getMethod("method", String.class, Long.TYPE);
method = getClass().getMethod("method", String.class, long.class);
stringParameter = new SynthesizingMethodParameter(method, 0);
longParameter = new SynthesizingMethodParameter(method, 1);
intReturnType = new SynthesizingMethodParameter(method, -1);
Expand All @@ -63,7 +63,7 @@ void equals() throws NoSuchMethodException {
assertThat(intReturnType).isNotEqualTo(stringParameter);
assertThat(intReturnType).isNotEqualTo(longParameter);

Method method = getClass().getMethod("method", String.class, Long.TYPE);
Method method = getClass().getMethod("method", String.class, long.class);
MethodParameter methodParameter = new SynthesizingMethodParameter(method, 0);
assertThat(methodParameter).isEqualTo(stringParameter);
assertThat(stringParameter).isEqualTo(methodParameter);
Expand All @@ -83,7 +83,7 @@ void testHashCode() throws NoSuchMethodException {
assertThat(longParameter.hashCode()).isEqualTo(longParameter.hashCode());
assertThat(intReturnType.hashCode()).isEqualTo(intReturnType.hashCode());

Method method = getClass().getMethod("method", String.class, Long.TYPE);
Method method = getClass().getMethod("method", String.class, long.class);
SynthesizingMethodParameter methodParameter = new SynthesizingMethodParameter(method, 0);
assertThat(methodParameter.hashCode()).isEqualTo(stringParameter.hashCode());
assertThat(methodParameter.hashCode()).isNotEqualTo(longParameter.hashCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -303,7 +303,7 @@ void fieldListOfListUnknown() throws Exception {
void fieldArray() throws Exception {
TypeDescriptor typeDescriptor = new TypeDescriptor(TypeDescriptorTests.class.getDeclaredField("intArray"));
assertThat(typeDescriptor.isArray()).isTrue();
assertThat(typeDescriptor.getElementTypeDescriptor().getType()).isEqualTo(Integer.TYPE);
assertThat(typeDescriptor.getElementTypeDescriptor().getType()).isEqualTo(int.class);
assertThat(typeDescriptor.toString()).isEqualTo("int[]");
}

Expand Down Expand Up @@ -359,7 +359,7 @@ void valueOfPrimitive() {
assertThat(typeDescriptor.isArray()).isFalse();
assertThat(typeDescriptor.isCollection()).isFalse();
assertThat(typeDescriptor.isMap()).isFalse();
assertThat(typeDescriptor.getType()).isEqualTo(Integer.TYPE);
assertThat(typeDescriptor.getType()).isEqualTo(int.class);
assertThat(typeDescriptor.getObjectType()).isEqualTo(Integer.class);
}

Expand All @@ -369,7 +369,7 @@ void valueOfArray() {
assertThat(typeDescriptor.isArray()).isTrue();
assertThat(typeDescriptor.isCollection()).isFalse();
assertThat(typeDescriptor.isMap()).isFalse();
assertThat(typeDescriptor.getElementTypeDescriptor().getType()).isEqualTo(Integer.TYPE);
assertThat(typeDescriptor.getElementTypeDescriptor().getType()).isEqualTo(int.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -454,31 +454,31 @@ public static String toJvmDescriptor(Class<?> clazz) {
}
}
if (clazz.isPrimitive()) {
if (clazz == Boolean.TYPE) {
if (clazz == boolean.class) {
sb.append('Z');
}
else if (clazz == Byte.TYPE) {
else if (clazz == byte.class) {
sb.append('B');
}
else if (clazz == Character.TYPE) {
else if (clazz == char.class) {
sb.append('C');
}
else if (clazz == Double.TYPE) {
else if (clazz == double.class) {
sb.append('D');
}
else if (clazz == Float.TYPE) {
else if (clazz == float.class) {
sb.append('F');
}
else if (clazz == Integer.TYPE) {
else if (clazz == int.class) {
sb.append('I');
}
else if (clazz == Long.TYPE) {
else if (clazz == long.class) {
sb.append('J');
}
else if (clazz == Short.TYPE) {
else if (clazz == short.class) {
sb.append('S');
}
else if (clazz == Void.TYPE) {
else if (clazz == void.class) {
sb.append('V');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,49 +385,49 @@ else if (arrayComponentType == short.class) {

private Object accessArrayElement(Object ctx, int idx) throws SpelEvaluationException {
Class<?> arrayComponentType = ctx.getClass().componentType();
if (arrayComponentType == Boolean.TYPE) {
if (arrayComponentType == boolean.class) {
boolean[] array = (boolean[]) ctx;
checkAccess(array.length, idx);
this.exitTypeDescriptor = "Z";
return array[idx];
}
else if (arrayComponentType == Byte.TYPE) {
else if (arrayComponentType == byte.class) {
byte[] array = (byte[]) ctx;
checkAccess(array.length, idx);
this.exitTypeDescriptor = "B";
return array[idx];
}
else if (arrayComponentType == Character.TYPE) {
else if (arrayComponentType == char.class) {
char[] array = (char[]) ctx;
checkAccess(array.length, idx);
this.exitTypeDescriptor = "C";
return array[idx];
}
else if (arrayComponentType == Double.TYPE) {
else if (arrayComponentType == double.class) {
double[] array = (double[]) ctx;
checkAccess(array.length, idx);
this.exitTypeDescriptor = "D";
return array[idx];
}
else if (arrayComponentType == Float.TYPE) {
else if (arrayComponentType == float.class) {
float[] array = (float[]) ctx;
checkAccess(array.length, idx);
this.exitTypeDescriptor = "F";
return array[idx];
}
else if (arrayComponentType == Integer.TYPE) {
else if (arrayComponentType == int.class) {
int[] array = (int[]) ctx;
checkAccess(array.length, idx);
this.exitTypeDescriptor = "I";
return array[idx];
}
else if (arrayComponentType == Long.TYPE) {
else if (arrayComponentType == long.class) {
long[] array = (long[]) ctx;
checkAccess(array.length, idx);
this.exitTypeDescriptor = "J";
return array[idx];
}
else if (arrayComponentType == Short.TYPE) {
else if (arrayComponentType == short.class) {
short[] array = (short[]) ctx;
checkAccess(array.length, idx);
this.exitTypeDescriptor = "S";
Expand Down
Loading

0 comments on commit db53586

Please sign in to comment.