diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 593687efa8..03374f757f 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 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. @@ -54,12 +54,12 @@ public class TypeDescriptor implements Serializable { private static final boolean streamAvailable = ClassUtils.isPresent( "java.util.stream.Stream", TypeDescriptor.class.getClassLoader()); - private static final Map, TypeDescriptor> commonTypesCache = new HashMap, TypeDescriptor>(18); + private static final Map, TypeDescriptor> commonTypesCache = new HashMap, TypeDescriptor>(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) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java b/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java index c52f28d717..7f860b49cf 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java @@ -469,33 +469,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"); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java index 526dc26712..68a1f44340 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -292,29 +292,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()); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java index 7507a0f26e..243111b555 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java @@ -319,30 +319,10 @@ public class Indexer extends SpelNodeImpl { private void setArrayElement(TypeConverter converter, Object ctx, int idx, 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; @@ -354,10 +334,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; @@ -368,34 +368,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) { @@ -410,10 +386,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 { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeCode.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeCode.java index fe785b1a39..2595365508 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeCode.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeCode.java @@ -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) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java index ad25bc4223..0ba17de87c 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java @@ -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. @@ -98,33 +98,30 @@ public class TypeReference extends SpelNodeImpl { public void generateCode(MethodVisitor mv, CodeFlow cf) { // TODO Future optimization - if followed by a static method call, skip generating code here 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));