Consistent references to primitive types (in alphabetical order)
This commit is contained in:
parent
695bf2961f
commit
08dad4e3ac
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
|
@ -49,14 +49,14 @@ import org.springframework.util.ObjectUtils;
|
|||
@SuppressWarnings("serial")
|
||||
public class TypeDescriptor implements Serializable {
|
||||
|
||||
static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
|
||||
private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
|
||||
|
||||
private static final Map<Class<?>, TypeDescriptor> commonTypesCache = new HashMap<>(18);
|
||||
private static final Map<Class<?>, TypeDescriptor> commonTypesCache = new HashMap<>(32);
|
||||
|
||||
private static final Class<?>[] CACHED_COMMON_TYPES = {
|
||||
boolean.class, Boolean.class, byte.class, Byte.class, char.class, Character.class,
|
||||
double.class, Double.class, int.class, Integer.class, long.class, Long.class,
|
||||
float.class, Float.class, short.class, Short.class, String.class, Object.class};
|
||||
double.class, Double.class, float.class, Float.class, int.class, Integer.class,
|
||||
long.class, Long.class, short.class, Short.class, String.class, Object.class};
|
||||
|
||||
static {
|
||||
for (Class<?> preCachedClass : CACHED_COMMON_TYPES) {
|
||||
|
|
|
|||
|
|
@ -478,33 +478,33 @@ public class CodeFlow implements Opcodes {
|
|||
}
|
||||
}
|
||||
if (clazz.isPrimitive()) {
|
||||
if (clazz == Void.TYPE) {
|
||||
sb.append('V');
|
||||
}
|
||||
else if (clazz == Integer.TYPE) {
|
||||
sb.append('I');
|
||||
}
|
||||
else if (clazz == Boolean.TYPE) {
|
||||
if (clazz == Boolean.TYPE) {
|
||||
sb.append('Z');
|
||||
}
|
||||
else if (clazz == Byte.TYPE) {
|
||||
sb.append('B');
|
||||
}
|
||||
else if (clazz == Character.TYPE) {
|
||||
sb.append('C');
|
||||
}
|
||||
else if (clazz == Long.TYPE) {
|
||||
sb.append('J');
|
||||
}
|
||||
else if (clazz == Double.TYPE) {
|
||||
sb.append('D');
|
||||
}
|
||||
else if (clazz == Float.TYPE) {
|
||||
sb.append('F');
|
||||
}
|
||||
else if (clazz == Byte.TYPE) {
|
||||
sb.append('B');
|
||||
else if (clazz == Integer.TYPE) {
|
||||
sb.append('I');
|
||||
}
|
||||
else if (clazz == Long.TYPE) {
|
||||
sb.append('J');
|
||||
}
|
||||
else if (clazz == Short.TYPE) {
|
||||
sb.append('S');
|
||||
}
|
||||
else if (clazz == Void.TYPE) {
|
||||
sb.append('V');
|
||||
}
|
||||
}
|
||||
else {
|
||||
sb.append("L");
|
||||
|
|
|
|||
|
|
@ -295,29 +295,29 @@ public class ConstructorReference extends SpelNodeImpl {
|
|||
if (arrayTypeCode == TypeCode.OBJECT) {
|
||||
populateReferenceTypeArray(state, newArray, typeConverter, initializer, componentType);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.INT) {
|
||||
populateIntArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.BOOLEAN) {
|
||||
populateBooleanArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.BYTE) {
|
||||
populateByteArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.CHAR) {
|
||||
populateCharArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.LONG) {
|
||||
populateLongArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.SHORT) {
|
||||
populateShortArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.DOUBLE) {
|
||||
populateDoubleArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.FLOAT) {
|
||||
populateFloatArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.BYTE) {
|
||||
populateByteArray(state, newArray, typeConverter, initializer);
|
||||
else if (arrayTypeCode == TypeCode.INT) {
|
||||
populateIntArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.LONG) {
|
||||
populateLongArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else if (arrayTypeCode == TypeCode.SHORT) {
|
||||
populateShortArray(state, newArray, typeConverter, initializer);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(arrayTypeCode.name());
|
||||
|
|
|
|||
|
|
@ -335,30 +335,10 @@ public class Indexer extends SpelNodeImpl {
|
|||
private void setArrayElement(TypeConverter converter, Object ctx, int idx, @Nullable Object newValue,
|
||||
Class<?> arrayComponentType) throws EvaluationException {
|
||||
|
||||
if (arrayComponentType == Double.TYPE) {
|
||||
double[] array = (double[]) ctx;
|
||||
if (arrayComponentType == Boolean.TYPE) {
|
||||
boolean[] array = (boolean[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Double.class);
|
||||
}
|
||||
else if (arrayComponentType == Float.TYPE) {
|
||||
float[] array = (float[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Float.class);
|
||||
}
|
||||
else if (arrayComponentType == Long.TYPE) {
|
||||
long[] array = (long[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Long.class);
|
||||
}
|
||||
else if (arrayComponentType == Integer.TYPE) {
|
||||
int[] array = (int[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Integer.class);
|
||||
}
|
||||
else if (arrayComponentType == Short.TYPE) {
|
||||
short[] array = (short[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Short.class);
|
||||
array[idx] = convertValue(converter, newValue, Boolean.class);
|
||||
}
|
||||
else if (arrayComponentType == Byte.TYPE) {
|
||||
byte[] array = (byte[]) ctx;
|
||||
|
|
@ -370,10 +350,30 @@ public class Indexer extends SpelNodeImpl {
|
|||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Character.class);
|
||||
}
|
||||
else if (arrayComponentType == Boolean.TYPE) {
|
||||
boolean[] array = (boolean[]) ctx;
|
||||
else if (arrayComponentType == Double.TYPE) {
|
||||
double[] array = (double[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Boolean.class);
|
||||
array[idx] = convertValue(converter, newValue, Double.class);
|
||||
}
|
||||
else if (arrayComponentType == Float.TYPE) {
|
||||
float[] array = (float[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Float.class);
|
||||
}
|
||||
else if (arrayComponentType == Integer.TYPE) {
|
||||
int[] array = (int[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Integer.class);
|
||||
}
|
||||
else if (arrayComponentType == Long.TYPE) {
|
||||
long[] array = (long[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Long.class);
|
||||
}
|
||||
else if (arrayComponentType == Short.TYPE) {
|
||||
short[] array = (short[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = convertValue(converter, newValue, Short.class);
|
||||
}
|
||||
else {
|
||||
Object[] array = (Object[]) ctx;
|
||||
|
|
@ -384,34 +384,10 @@ public class Indexer extends SpelNodeImpl {
|
|||
|
||||
private Object accessArrayElement(Object ctx, int idx) throws SpelEvaluationException {
|
||||
Class<?> arrayComponentType = ctx.getClass().getComponentType();
|
||||
if (arrayComponentType == Double.TYPE) {
|
||||
double[] array = (double[]) ctx;
|
||||
if (arrayComponentType == Boolean.TYPE) {
|
||||
boolean[] array = (boolean[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
this.exitTypeDescriptor = "D";
|
||||
return array[idx];
|
||||
}
|
||||
else if (arrayComponentType == Float.TYPE) {
|
||||
float[] array = (float[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
this.exitTypeDescriptor = "F";
|
||||
return array[idx];
|
||||
}
|
||||
else if (arrayComponentType == Long.TYPE) {
|
||||
long[] array = (long[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
this.exitTypeDescriptor = "J";
|
||||
return array[idx];
|
||||
}
|
||||
else if (arrayComponentType == Integer.TYPE) {
|
||||
int[] array = (int[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
this.exitTypeDescriptor = "I";
|
||||
return array[idx];
|
||||
}
|
||||
else if (arrayComponentType == Short.TYPE) {
|
||||
short[] array = (short[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
this.exitTypeDescriptor = "S";
|
||||
this.exitTypeDescriptor = "Z";
|
||||
return array[idx];
|
||||
}
|
||||
else if (arrayComponentType == Byte.TYPE) {
|
||||
|
|
@ -426,10 +402,34 @@ public class Indexer extends SpelNodeImpl {
|
|||
this.exitTypeDescriptor = "C";
|
||||
return array[idx];
|
||||
}
|
||||
else if (arrayComponentType == Boolean.TYPE) {
|
||||
boolean[] array = (boolean[]) ctx;
|
||||
else if (arrayComponentType == Double.TYPE) {
|
||||
double[] array = (double[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
this.exitTypeDescriptor = "Z";
|
||||
this.exitTypeDescriptor = "D";
|
||||
return array[idx];
|
||||
}
|
||||
else if (arrayComponentType == Float.TYPE) {
|
||||
float[] array = (float[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
this.exitTypeDescriptor = "F";
|
||||
return array[idx];
|
||||
}
|
||||
else if (arrayComponentType == Integer.TYPE) {
|
||||
int[] array = (int[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
this.exitTypeDescriptor = "I";
|
||||
return array[idx];
|
||||
}
|
||||
else if (arrayComponentType == Long.TYPE) {
|
||||
long[] array = (long[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
this.exitTypeDescriptor = "J";
|
||||
return array[idx];
|
||||
}
|
||||
else if (arrayComponentType == Short.TYPE) {
|
||||
short[] array = (short[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
this.exitTypeDescriptor = "S";
|
||||
return array[idx];
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
|
@ -32,15 +32,15 @@ public enum TypeCode {
|
|||
|
||||
CHAR(Character.TYPE),
|
||||
|
||||
SHORT(Short.TYPE),
|
||||
DOUBLE(Double.TYPE),
|
||||
|
||||
FLOAT(Float.TYPE),
|
||||
|
||||
INT(Integer.TYPE),
|
||||
|
||||
LONG(Long.TYPE),
|
||||
|
||||
FLOAT(Float.TYPE),
|
||||
|
||||
DOUBLE(Double.TYPE);
|
||||
SHORT(Short.TYPE);
|
||||
|
||||
|
||||
private Class<?> type;
|
||||
|
|
@ -64,7 +64,7 @@ public enum TypeCode {
|
|||
return tcs[i];
|
||||
}
|
||||
}
|
||||
return TypeCode.OBJECT;
|
||||
return OBJECT;
|
||||
}
|
||||
|
||||
public static TypeCode forClass(Class<?> clazz) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
|
@ -103,33 +103,30 @@ public class TypeReference extends SpelNodeImpl {
|
|||
// TODO Future optimization - if followed by a static method call, skip generating code here
|
||||
Assert.state(this.type != null, "No type available");
|
||||
if (this.type.isPrimitive()) {
|
||||
if (this.type == Integer.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else if (this.type == Boolean.TYPE) {
|
||||
if (this.type == Boolean.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else if (this.type == Byte.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Byte", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else if (this.type == Short.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
|
||||
else if (this.type == Character.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else if (this.type == Double.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else if (this.type == Character.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else if (this.type == Float.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else if (this.type == Integer.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else if (this.type == Long.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else if (this.type == Boolean.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else if (this.type == Short.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
}
|
||||
else {
|
||||
mv.visitLdcInsn(Type.getType(this.type));
|
||||
|
|
|
|||
Loading…
Reference in New Issue