Skip to content

Commit 64f304c

Browse files
committed
Consistent references to primitive types (in alphabetical order)
(cherry picked from commit 08dad4e)
1 parent 5f6b042 commit 64f304c

File tree

6 files changed

+89
-92
lines changed

6 files changed

+89
-92
lines changed

spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,12 +54,12 @@ public class TypeDescriptor implements Serializable {
5454
private static final boolean streamAvailable = ClassUtils.isPresent(
5555
"java.util.stream.Stream", TypeDescriptor.class.getClassLoader());
5656

57-
private static final Map<Class<?>, TypeDescriptor> commonTypesCache = new HashMap<Class<?>, TypeDescriptor>(18);
57+
private static final Map<Class<?>, TypeDescriptor> commonTypesCache = new HashMap<Class<?>, TypeDescriptor>(32);
5858

5959
private static final Class<?>[] CACHED_COMMON_TYPES = {
6060
boolean.class, Boolean.class, byte.class, Byte.class, char.class, Character.class,
61-
double.class, Double.class, int.class, Integer.class, long.class, Long.class,
62-
float.class, Float.class, short.class, Short.class, String.class, Object.class};
61+
double.class, Double.class, float.class, Float.class, int.class, Integer.class,
62+
long.class, Long.class, short.class, Short.class, String.class, Object.class};
6363

6464
static {
6565
for (Class<?> preCachedClass : CACHED_COMMON_TYPES) {

spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -469,33 +469,33 @@ public static String toJvmDescriptor(Class<?> clazz) {
469469
}
470470
}
471471
if (clazz.isPrimitive()) {
472-
if (clazz == Void.TYPE) {
473-
sb.append('V');
474-
}
475-
else if (clazz == Integer.TYPE) {
476-
sb.append('I');
477-
}
478-
else if (clazz == Boolean.TYPE) {
472+
if (clazz == Boolean.TYPE) {
479473
sb.append('Z');
480474
}
475+
else if (clazz == Byte.TYPE) {
476+
sb.append('B');
477+
}
481478
else if (clazz == Character.TYPE) {
482479
sb.append('C');
483480
}
484-
else if (clazz == Long.TYPE) {
485-
sb.append('J');
486-
}
487481
else if (clazz == Double.TYPE) {
488482
sb.append('D');
489483
}
490484
else if (clazz == Float.TYPE) {
491485
sb.append('F');
492486
}
493-
else if (clazz == Byte.TYPE) {
494-
sb.append('B');
487+
else if (clazz == Integer.TYPE) {
488+
sb.append('I');
489+
}
490+
else if (clazz == Long.TYPE) {
491+
sb.append('J');
495492
}
496493
else if (clazz == Short.TYPE) {
497494
sb.append('S');
498495
}
496+
else if (clazz == Void.TYPE) {
497+
sb.append('V');
498+
}
499499
}
500500
else {
501501
sb.append("L");

spring-expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -292,29 +292,29 @@ private TypedValue createArray(ExpressionState state) throws EvaluationException
292292
if (arrayTypeCode == TypeCode.OBJECT) {
293293
populateReferenceTypeArray(state, newArray, typeConverter, initializer, componentType);
294294
}
295-
else if (arrayTypeCode == TypeCode.INT) {
296-
populateIntArray(state, newArray, typeConverter, initializer);
297-
}
298295
else if (arrayTypeCode == TypeCode.BOOLEAN) {
299296
populateBooleanArray(state, newArray, typeConverter, initializer);
300297
}
298+
else if (arrayTypeCode == TypeCode.BYTE) {
299+
populateByteArray(state, newArray, typeConverter, initializer);
300+
}
301301
else if (arrayTypeCode == TypeCode.CHAR) {
302302
populateCharArray(state, newArray, typeConverter, initializer);
303303
}
304-
else if (arrayTypeCode == TypeCode.LONG) {
305-
populateLongArray(state, newArray, typeConverter, initializer);
306-
}
307-
else if (arrayTypeCode == TypeCode.SHORT) {
308-
populateShortArray(state, newArray, typeConverter, initializer);
309-
}
310304
else if (arrayTypeCode == TypeCode.DOUBLE) {
311305
populateDoubleArray(state, newArray, typeConverter, initializer);
312306
}
313307
else if (arrayTypeCode == TypeCode.FLOAT) {
314308
populateFloatArray(state, newArray, typeConverter, initializer);
315309
}
316-
else if (arrayTypeCode == TypeCode.BYTE) {
317-
populateByteArray(state, newArray, typeConverter, initializer);
310+
else if (arrayTypeCode == TypeCode.INT) {
311+
populateIntArray(state, newArray, typeConverter, initializer);
312+
}
313+
else if (arrayTypeCode == TypeCode.LONG) {
314+
populateLongArray(state, newArray, typeConverter, initializer);
315+
}
316+
else if (arrayTypeCode == TypeCode.SHORT) {
317+
populateShortArray(state, newArray, typeConverter, initializer);
318318
}
319319
else {
320320
throw new IllegalStateException(arrayTypeCode.name());

spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,22 @@ public String toStringAST() {
319319
private void setArrayElement(TypeConverter converter, Object ctx, int idx, Object newValue,
320320
Class<?> arrayComponentType) throws EvaluationException {
321321

322-
if (arrayComponentType == Double.TYPE) {
322+
if (arrayComponentType == Boolean.TYPE) {
323+
boolean[] array = (boolean[]) ctx;
324+
checkAccess(array.length, idx);
325+
array[idx] = convertValue(converter, newValue, Boolean.class);
326+
}
327+
else if (arrayComponentType == Byte.TYPE) {
328+
byte[] array = (byte[]) ctx;
329+
checkAccess(array.length, idx);
330+
array[idx] = convertValue(converter, newValue, Byte.class);
331+
}
332+
else if (arrayComponentType == Character.TYPE) {
333+
char[] array = (char[]) ctx;
334+
checkAccess(array.length, idx);
335+
array[idx] = convertValue(converter, newValue, Character.class);
336+
}
337+
else if (arrayComponentType == Double.TYPE) {
323338
double[] array = (double[]) ctx;
324339
checkAccess(array.length, idx);
325340
array[idx] = convertValue(converter, newValue, Double.class);
@@ -329,36 +344,21 @@ else if (arrayComponentType == Float.TYPE) {
329344
checkAccess(array.length, idx);
330345
array[idx] = convertValue(converter, newValue, Float.class);
331346
}
332-
else if (arrayComponentType == Long.TYPE) {
333-
long[] array = (long[]) ctx;
334-
checkAccess(array.length, idx);
335-
array[idx] = convertValue(converter, newValue, Long.class);
336-
}
337347
else if (arrayComponentType == Integer.TYPE) {
338348
int[] array = (int[]) ctx;
339349
checkAccess(array.length, idx);
340350
array[idx] = convertValue(converter, newValue, Integer.class);
341351
}
352+
else if (arrayComponentType == Long.TYPE) {
353+
long[] array = (long[]) ctx;
354+
checkAccess(array.length, idx);
355+
array[idx] = convertValue(converter, newValue, Long.class);
356+
}
342357
else if (arrayComponentType == Short.TYPE) {
343358
short[] array = (short[]) ctx;
344359
checkAccess(array.length, idx);
345360
array[idx] = convertValue(converter, newValue, Short.class);
346361
}
347-
else if (arrayComponentType == Byte.TYPE) {
348-
byte[] array = (byte[]) ctx;
349-
checkAccess(array.length, idx);
350-
array[idx] = convertValue(converter, newValue, Byte.class);
351-
}
352-
else if (arrayComponentType == Character.TYPE) {
353-
char[] array = (char[]) ctx;
354-
checkAccess(array.length, idx);
355-
array[idx] = convertValue(converter, newValue, Character.class);
356-
}
357-
else if (arrayComponentType == Boolean.TYPE) {
358-
boolean[] array = (boolean[]) ctx;
359-
checkAccess(array.length, idx);
360-
array[idx] = convertValue(converter, newValue, Boolean.class);
361-
}
362362
else {
363363
Object[] array = (Object[]) ctx;
364364
checkAccess(array.length, idx);
@@ -368,52 +368,52 @@ else if (arrayComponentType == Boolean.TYPE) {
368368

369369
private Object accessArrayElement(Object ctx, int idx) throws SpelEvaluationException {
370370
Class<?> arrayComponentType = ctx.getClass().getComponentType();
371-
if (arrayComponentType == Double.TYPE) {
372-
double[] array = (double[]) ctx;
371+
if (arrayComponentType == Boolean.TYPE) {
372+
boolean[] array = (boolean[]) ctx;
373373
checkAccess(array.length, idx);
374-
this.exitTypeDescriptor = "D";
374+
this.exitTypeDescriptor = "Z";
375375
return array[idx];
376376
}
377-
else if (arrayComponentType == Float.TYPE) {
378-
float[] array = (float[]) ctx;
377+
else if (arrayComponentType == Byte.TYPE) {
378+
byte[] array = (byte[]) ctx;
379379
checkAccess(array.length, idx);
380-
this.exitTypeDescriptor = "F";
380+
this.exitTypeDescriptor = "B";
381381
return array[idx];
382382
}
383-
else if (arrayComponentType == Long.TYPE) {
384-
long[] array = (long[]) ctx;
383+
else if (arrayComponentType == Character.TYPE) {
384+
char[] array = (char[]) ctx;
385385
checkAccess(array.length, idx);
386-
this.exitTypeDescriptor = "J";
386+
this.exitTypeDescriptor = "C";
387387
return array[idx];
388388
}
389-
else if (arrayComponentType == Integer.TYPE) {
390-
int[] array = (int[]) ctx;
389+
else if (arrayComponentType == Double.TYPE) {
390+
double[] array = (double[]) ctx;
391391
checkAccess(array.length, idx);
392-
this.exitTypeDescriptor = "I";
392+
this.exitTypeDescriptor = "D";
393393
return array[idx];
394394
}
395-
else if (arrayComponentType == Short.TYPE) {
396-
short[] array = (short[]) ctx;
395+
else if (arrayComponentType == Float.TYPE) {
396+
float[] array = (float[]) ctx;
397397
checkAccess(array.length, idx);
398-
this.exitTypeDescriptor = "S";
398+
this.exitTypeDescriptor = "F";
399399
return array[idx];
400400
}
401-
else if (arrayComponentType == Byte.TYPE) {
402-
byte[] array = (byte[]) ctx;
401+
else if (arrayComponentType == Integer.TYPE) {
402+
int[] array = (int[]) ctx;
403403
checkAccess(array.length, idx);
404-
this.exitTypeDescriptor = "B";
404+
this.exitTypeDescriptor = "I";
405405
return array[idx];
406406
}
407-
else if (arrayComponentType == Character.TYPE) {
408-
char[] array = (char[]) ctx;
407+
else if (arrayComponentType == Long.TYPE) {
408+
long[] array = (long[]) ctx;
409409
checkAccess(array.length, idx);
410-
this.exitTypeDescriptor = "C";
410+
this.exitTypeDescriptor = "J";
411411
return array[idx];
412412
}
413-
else if (arrayComponentType == Boolean.TYPE) {
414-
boolean[] array = (boolean[]) ctx;
413+
else if (arrayComponentType == Short.TYPE) {
414+
short[] array = (short[]) ctx;
415415
checkAccess(array.length, idx);
416-
this.exitTypeDescriptor = "Z";
416+
this.exitTypeDescriptor = "S";
417417
return array[idx];
418418
}
419419
else {

spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeCode.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,15 +32,15 @@ public enum TypeCode {
3232

3333
CHAR(Character.TYPE),
3434

35-
SHORT(Short.TYPE),
35+
DOUBLE(Double.TYPE),
36+
37+
FLOAT(Float.TYPE),
3638

3739
INT(Integer.TYPE),
3840

3941
LONG(Long.TYPE),
4042

41-
FLOAT(Float.TYPE),
42-
43-
DOUBLE(Double.TYPE);
43+
SHORT(Short.TYPE);
4444

4545

4646
private Class<?> type;
@@ -64,7 +64,7 @@ public static TypeCode forName(String name) {
6464
return tcs[i];
6565
}
6666
}
67-
return TypeCode.OBJECT;
67+
return OBJECT;
6868
}
6969

7070
public static TypeCode forClass(Class<?> clazz) {

spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -98,33 +98,30 @@ public boolean isCompilable() {
9898
public void generateCode(MethodVisitor mv, CodeFlow cf) {
9999
// TODO Future optimization - if followed by a static method call, skip generating code here
100100
if (this.type.isPrimitive()) {
101-
if (this.type == Integer.TYPE) {
102-
mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;");
103-
}
104-
else if (this.type == Boolean.TYPE) {
101+
if (this.type == Boolean.TYPE) {
105102
mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
106103
}
107104
else if (this.type == Byte.TYPE) {
108105
mv.visitFieldInsn(GETSTATIC, "java/lang/Byte", "TYPE", "Ljava/lang/Class;");
109106
}
110-
else if (this.type == Short.TYPE) {
111-
mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
107+
else if (this.type == Character.TYPE) {
108+
mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;");
112109
}
113110
else if (this.type == Double.TYPE) {
114111
mv.visitFieldInsn(GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;");
115112
}
116-
else if (this.type == Character.TYPE) {
117-
mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;");
118-
}
119113
else if (this.type == Float.TYPE) {
120114
mv.visitFieldInsn(GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;");
121115
}
116+
else if (this.type == Integer.TYPE) {
117+
mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;");
118+
}
122119
else if (this.type == Long.TYPE) {
123120
mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
124121
}
125-
else if (this.type == Boolean.TYPE) {
126-
mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
127-
}
122+
else if (this.type == Short.TYPE) {
123+
mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
124+
}
128125
}
129126
else {
130127
mv.visitLdcInsn(Type.getType(this.type));

0 commit comments

Comments
 (0)