Consistent references to primitive types (in alphabetical order)
This commit is contained in:
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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")
|
@SuppressWarnings("serial")
|
||||||
public class TypeDescriptor implements Serializable {
|
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 = {
|
private static final Class<?>[] CACHED_COMMON_TYPES = {
|
||||||
boolean.class, Boolean.class, byte.class, Byte.class, char.class, Character.class,
|
boolean.class, Boolean.class, byte.class, Byte.class, char.class, Character.class,
|
||||||
double.class, Double.class, int.class, Integer.class, long.class, Long.class,
|
double.class, Double.class, float.class, Float.class, int.class, Integer.class,
|
||||||
float.class, Float.class, short.class, Short.class, String.class, Object.class};
|
long.class, Long.class, short.class, Short.class, String.class, Object.class};
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (Class<?> preCachedClass : CACHED_COMMON_TYPES) {
|
for (Class<?> preCachedClass : CACHED_COMMON_TYPES) {
|
||||||
|
|||||||
@@ -478,33 +478,33 @@ public class CodeFlow implements Opcodes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (clazz.isPrimitive()) {
|
if (clazz.isPrimitive()) {
|
||||||
if (clazz == Void.TYPE) {
|
if (clazz == Boolean.TYPE) {
|
||||||
sb.append('V');
|
|
||||||
}
|
|
||||||
else if (clazz == Integer.TYPE) {
|
|
||||||
sb.append('I');
|
|
||||||
}
|
|
||||||
else if (clazz == Boolean.TYPE) {
|
|
||||||
sb.append('Z');
|
sb.append('Z');
|
||||||
}
|
}
|
||||||
|
else if (clazz == Byte.TYPE) {
|
||||||
|
sb.append('B');
|
||||||
|
}
|
||||||
else if (clazz == Character.TYPE) {
|
else if (clazz == Character.TYPE) {
|
||||||
sb.append('C');
|
sb.append('C');
|
||||||
}
|
}
|
||||||
else if (clazz == Long.TYPE) {
|
|
||||||
sb.append('J');
|
|
||||||
}
|
|
||||||
else if (clazz == Double.TYPE) {
|
else if (clazz == Double.TYPE) {
|
||||||
sb.append('D');
|
sb.append('D');
|
||||||
}
|
}
|
||||||
else if (clazz == Float.TYPE) {
|
else if (clazz == Float.TYPE) {
|
||||||
sb.append('F');
|
sb.append('F');
|
||||||
}
|
}
|
||||||
else if (clazz == Byte.TYPE) {
|
else if (clazz == Integer.TYPE) {
|
||||||
sb.append('B');
|
sb.append('I');
|
||||||
|
}
|
||||||
|
else if (clazz == Long.TYPE) {
|
||||||
|
sb.append('J');
|
||||||
}
|
}
|
||||||
else if (clazz == Short.TYPE) {
|
else if (clazz == Short.TYPE) {
|
||||||
sb.append('S');
|
sb.append('S');
|
||||||
}
|
}
|
||||||
|
else if (clazz == Void.TYPE) {
|
||||||
|
sb.append('V');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sb.append("L");
|
sb.append("L");
|
||||||
|
|||||||
@@ -295,29 +295,29 @@ public class ConstructorReference extends SpelNodeImpl {
|
|||||||
if (arrayTypeCode == TypeCode.OBJECT) {
|
if (arrayTypeCode == TypeCode.OBJECT) {
|
||||||
populateReferenceTypeArray(state, newArray, typeConverter, initializer, componentType);
|
populateReferenceTypeArray(state, newArray, typeConverter, initializer, componentType);
|
||||||
}
|
}
|
||||||
else if (arrayTypeCode == TypeCode.INT) {
|
|
||||||
populateIntArray(state, newArray, typeConverter, initializer);
|
|
||||||
}
|
|
||||||
else if (arrayTypeCode == TypeCode.BOOLEAN) {
|
else if (arrayTypeCode == TypeCode.BOOLEAN) {
|
||||||
populateBooleanArray(state, newArray, typeConverter, initializer);
|
populateBooleanArray(state, newArray, typeConverter, initializer);
|
||||||
}
|
}
|
||||||
|
else if (arrayTypeCode == TypeCode.BYTE) {
|
||||||
|
populateByteArray(state, newArray, typeConverter, initializer);
|
||||||
|
}
|
||||||
else if (arrayTypeCode == TypeCode.CHAR) {
|
else if (arrayTypeCode == TypeCode.CHAR) {
|
||||||
populateCharArray(state, newArray, typeConverter, initializer);
|
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) {
|
else if (arrayTypeCode == TypeCode.DOUBLE) {
|
||||||
populateDoubleArray(state, newArray, typeConverter, initializer);
|
populateDoubleArray(state, newArray, typeConverter, initializer);
|
||||||
}
|
}
|
||||||
else if (arrayTypeCode == TypeCode.FLOAT) {
|
else if (arrayTypeCode == TypeCode.FLOAT) {
|
||||||
populateFloatArray(state, newArray, typeConverter, initializer);
|
populateFloatArray(state, newArray, typeConverter, initializer);
|
||||||
}
|
}
|
||||||
else if (arrayTypeCode == TypeCode.BYTE) {
|
else if (arrayTypeCode == TypeCode.INT) {
|
||||||
populateByteArray(state, newArray, typeConverter, initializer);
|
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 {
|
else {
|
||||||
throw new IllegalStateException(arrayTypeCode.name());
|
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,
|
private void setArrayElement(TypeConverter converter, Object ctx, int idx, @Nullable Object newValue,
|
||||||
Class<?> arrayComponentType) throws EvaluationException {
|
Class<?> arrayComponentType) throws EvaluationException {
|
||||||
|
|
||||||
if (arrayComponentType == Double.TYPE) {
|
if (arrayComponentType == Boolean.TYPE) {
|
||||||
double[] array = (double[]) ctx;
|
boolean[] array = (boolean[]) ctx;
|
||||||
checkAccess(array.length, idx);
|
checkAccess(array.length, idx);
|
||||||
array[idx] = convertValue(converter, newValue, Double.class);
|
array[idx] = convertValue(converter, newValue, Boolean.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);
|
|
||||||
}
|
}
|
||||||
else if (arrayComponentType == Byte.TYPE) {
|
else if (arrayComponentType == Byte.TYPE) {
|
||||||
byte[] array = (byte[]) ctx;
|
byte[] array = (byte[]) ctx;
|
||||||
@@ -370,10 +350,30 @@ public class Indexer extends SpelNodeImpl {
|
|||||||
checkAccess(array.length, idx);
|
checkAccess(array.length, idx);
|
||||||
array[idx] = convertValue(converter, newValue, Character.class);
|
array[idx] = convertValue(converter, newValue, Character.class);
|
||||||
}
|
}
|
||||||
else if (arrayComponentType == Boolean.TYPE) {
|
else if (arrayComponentType == Double.TYPE) {
|
||||||
boolean[] array = (boolean[]) ctx;
|
double[] array = (double[]) ctx;
|
||||||
checkAccess(array.length, idx);
|
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 {
|
else {
|
||||||
Object[] array = (Object[]) ctx;
|
Object[] array = (Object[]) ctx;
|
||||||
@@ -384,34 +384,10 @@ public class Indexer extends SpelNodeImpl {
|
|||||||
|
|
||||||
private Object accessArrayElement(Object ctx, int idx) throws SpelEvaluationException {
|
private Object accessArrayElement(Object ctx, int idx) throws SpelEvaluationException {
|
||||||
Class<?> arrayComponentType = ctx.getClass().getComponentType();
|
Class<?> arrayComponentType = ctx.getClass().getComponentType();
|
||||||
if (arrayComponentType == Double.TYPE) {
|
if (arrayComponentType == Boolean.TYPE) {
|
||||||
double[] array = (double[]) ctx;
|
boolean[] array = (boolean[]) ctx;
|
||||||
checkAccess(array.length, idx);
|
checkAccess(array.length, idx);
|
||||||
this.exitTypeDescriptor = "D";
|
this.exitTypeDescriptor = "Z";
|
||||||
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";
|
|
||||||
return array[idx];
|
return array[idx];
|
||||||
}
|
}
|
||||||
else if (arrayComponentType == Byte.TYPE) {
|
else if (arrayComponentType == Byte.TYPE) {
|
||||||
@@ -426,10 +402,34 @@ public class Indexer extends SpelNodeImpl {
|
|||||||
this.exitTypeDescriptor = "C";
|
this.exitTypeDescriptor = "C";
|
||||||
return array[idx];
|
return array[idx];
|
||||||
}
|
}
|
||||||
else if (arrayComponentType == Boolean.TYPE) {
|
else if (arrayComponentType == Double.TYPE) {
|
||||||
boolean[] array = (boolean[]) ctx;
|
double[] array = (double[]) ctx;
|
||||||
checkAccess(array.length, idx);
|
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];
|
return array[idx];
|
||||||
}
|
}
|
||||||
else {
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,15 +32,15 @@ public enum TypeCode {
|
|||||||
|
|
||||||
CHAR(Character.TYPE),
|
CHAR(Character.TYPE),
|
||||||
|
|
||||||
SHORT(Short.TYPE),
|
DOUBLE(Double.TYPE),
|
||||||
|
|
||||||
|
FLOAT(Float.TYPE),
|
||||||
|
|
||||||
INT(Integer.TYPE),
|
INT(Integer.TYPE),
|
||||||
|
|
||||||
LONG(Long.TYPE),
|
LONG(Long.TYPE),
|
||||||
|
|
||||||
FLOAT(Float.TYPE),
|
SHORT(Short.TYPE);
|
||||||
|
|
||||||
DOUBLE(Double.TYPE);
|
|
||||||
|
|
||||||
|
|
||||||
private Class<?> type;
|
private Class<?> type;
|
||||||
@@ -64,7 +64,7 @@ public enum TypeCode {
|
|||||||
return tcs[i];
|
return tcs[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TypeCode.OBJECT;
|
return OBJECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TypeCode forClass(Class<?> clazz) {
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
// TODO Future optimization - if followed by a static method call, skip generating code here
|
||||||
Assert.state(this.type != null, "No type available");
|
Assert.state(this.type != null, "No type available");
|
||||||
if (this.type.isPrimitive()) {
|
if (this.type.isPrimitive()) {
|
||||||
if (this.type == Integer.TYPE) {
|
if (this.type == Boolean.TYPE) {
|
||||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;");
|
|
||||||
}
|
|
||||||
else if (this.type == Boolean.TYPE) {
|
|
||||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
|
mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
|
||||||
}
|
}
|
||||||
else if (this.type == Byte.TYPE) {
|
else if (this.type == Byte.TYPE) {
|
||||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Byte", "TYPE", "Ljava/lang/Class;");
|
mv.visitFieldInsn(GETSTATIC, "java/lang/Byte", "TYPE", "Ljava/lang/Class;");
|
||||||
}
|
}
|
||||||
else if (this.type == Short.TYPE) {
|
else if (this.type == Character.TYPE) {
|
||||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
|
mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;");
|
||||||
}
|
}
|
||||||
else if (this.type == Double.TYPE) {
|
else if (this.type == Double.TYPE) {
|
||||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;");
|
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) {
|
else if (this.type == Float.TYPE) {
|
||||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;");
|
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) {
|
else if (this.type == Long.TYPE) {
|
||||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
|
mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
|
||||||
}
|
}
|
||||||
else if (this.type == Boolean.TYPE) {
|
else if (this.type == Short.TYPE) {
|
||||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
|
mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mv.visitLdcInsn(Type.getType(this.type));
|
mv.visitLdcInsn(Type.getType(this.type));
|
||||||
|
|||||||
Reference in New Issue
Block a user