From 214fa9c2a0aeb368a02faec1d4ac7f73fc9fba91 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 29 Jun 2018 22:43:13 +0200 Subject: [PATCH] Polishing --- .../expression/spel/CodeFlow.java | 77 +++++++++---------- 1 file changed, 38 insertions(+), 39 deletions(-) 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 8a4abc9559..5a82908d90 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 @@ -348,72 +348,72 @@ public class CodeFlow implements Opcodes { public static void insertAnyNecessaryTypeConversionBytecodes(MethodVisitor mv, char targetDescriptor, String stackDescriptor) { if (CodeFlow.isPrimitive(stackDescriptor)) { char stackTop = stackDescriptor.charAt(0); - if (stackTop=='I' || stackTop=='B' || stackTop=='S' || stackTop=='C') { - if (targetDescriptor=='D') { + if (stackTop == 'I' || stackTop == 'B' || stackTop == 'S' || stackTop == 'C') { + if (targetDescriptor == 'D') { mv.visitInsn(I2D); } - else if (targetDescriptor=='F') { + else if (targetDescriptor == 'F') { mv.visitInsn(I2F); } - else if (targetDescriptor=='J') { + else if (targetDescriptor == 'J') { mv.visitInsn(I2L); } - else if (targetDescriptor=='I') { + else if (targetDescriptor == 'I') { // nop } else { - throw new IllegalStateException("cannot get from "+stackTop+" to "+targetDescriptor); + throw new IllegalStateException("Cannot get from " + stackTop + " to " + targetDescriptor); } } - else if (stackTop=='J') { - if (targetDescriptor=='D') { + else if (stackTop == 'J') { + if (targetDescriptor == 'D') { mv.visitInsn(L2D); } - else if (targetDescriptor=='F') { + else if (targetDescriptor == 'F') { mv.visitInsn(L2F); } - else if (targetDescriptor=='J') { + else if (targetDescriptor == 'J') { // nop } - else if (targetDescriptor=='I') { + else if (targetDescriptor == 'I') { mv.visitInsn(L2I); } else { - throw new IllegalStateException("cannot get from "+stackTop+" to "+targetDescriptor); + throw new IllegalStateException("Cannot get from " + stackTop + " to " + targetDescriptor); } } - else if (stackTop=='F') { - if (targetDescriptor=='D') { + else if (stackTop == 'F') { + if (targetDescriptor == 'D') { mv.visitInsn(F2D); } - else if (targetDescriptor=='F') { + else if (targetDescriptor == 'F') { // nop } - else if (targetDescriptor=='J') { + else if (targetDescriptor == 'J') { mv.visitInsn(F2L); } - else if (targetDescriptor=='I') { + else if (targetDescriptor == 'I') { mv.visitInsn(F2I); } else { - throw new IllegalStateException("cannot get from "+stackTop+" to "+targetDescriptor); + throw new IllegalStateException("Cannot get from " + stackTop + " to " + targetDescriptor); } } - else if (stackTop=='D') { - if (targetDescriptor=='D') { + else if (stackTop == 'D') { + if (targetDescriptor == 'D') { // nop } - else if (targetDescriptor=='F') { + else if (targetDescriptor == 'F') { mv.visitInsn(D2F); } - else if (targetDescriptor=='J') { + else if (targetDescriptor == 'J') { mv.visitInsn(D2L); } - else if (targetDescriptor=='I') { + else if (targetDescriptor == 'I') { mv.visitInsn(D2I); } else { - throw new IllegalStateException("cannot get from "+stackDescriptor+" to "+targetDescriptor); + throw new IllegalStateException("Cannot get from " + stackDescriptor + " to " + targetDescriptor); } } } @@ -530,7 +530,7 @@ public class CodeFlow implements Opcodes { } /** - * Returns if the descriptor is for a boolean primitive or boolean reference type. + * Determine whether the descriptor is for a boolean primitive or boolean reference type. * @param descriptor type descriptor * @return {@code true} if the descriptor is boolean compatible */ @@ -539,7 +539,7 @@ public class CodeFlow implements Opcodes { } /** - * Returns if the descriptor is for a primitive type. + * Determine whether the descriptor is for a primitive type. * @param descriptor type descriptor * @return {@code true} if a primitive type */ @@ -548,7 +548,7 @@ public class CodeFlow implements Opcodes { } /** - * Returns if the descriptor is for a primitive array (e.g. "[[I"). + * Determine whether the descriptor is for a primitive array (e.g. "[[I"). * @param descriptor the descriptor for a possible primitive array * @return {@code true} if the descriptor a primitive array */ @@ -569,8 +569,8 @@ public class CodeFlow implements Opcodes { } /** - * Determine if boxing/unboxing can get from one type to the other. Assumes at least - * one of the types is in boxed form (i.e. single char descriptor). + * Determine whether boxing/unboxing can get from one type to the other. + * Assumes at least one of the types is in boxed form (i.e. single char descriptor). * @return {@code true} if it is possible to get (via boxing) from one descriptor to the other */ public static boolean areBoxingCompatible(String desc1, String desc2) { @@ -781,9 +781,8 @@ public class CodeFlow implements Opcodes { } /** - * Deduce the descriptor for a type. Descriptors are like JVM type names but missing - * the trailing ';' so for Object the descriptor is "Ljava/lang/Object" for int it is - * "I". + * Deduce the descriptor for a type. Descriptors are like JVM type names but missing the + * trailing ';' so for Object the descriptor is "Ljava/lang/Object" for int it is "I". * @param type the type (may be primitive) for which to determine the descriptor * @return the descriptor */ @@ -957,7 +956,7 @@ public class CodeFlow implements Opcodes { case 'S': return T_SHORT; case 'Z': return T_BOOLEAN; default: - throw new IllegalArgumentException("Unexpected arraytype "+arraytype.charAt(0)); + throw new IllegalArgumentException("Unexpected arraytype " + arraytype.charAt(0)); } } @@ -971,7 +970,7 @@ public class CodeFlow implements Opcodes { if (ch == '[') { continue; } - return ch=='L'; + return (ch == 'L'); } return false; } @@ -991,10 +990,10 @@ public class CodeFlow implements Opcodes { } else { if (arraytype.charAt(0) == '[') { - // Handling the nested array case here. If vararg - // is [[I then we want [I and not [I; + // Handling the nested array case here. + // If vararg is [[I then we want [I and not [I; if (CodeFlow.isReferenceTypeArray(arraytype)) { - mv.visitTypeInsn(ANEWARRAY, arraytype+";"); + mv.visitTypeInsn(ANEWARRAY, arraytype + ";"); } else { mv.visitTypeInsn(ANEWARRAY, arraytype); @@ -1026,7 +1025,7 @@ public class CodeFlow implements Opcodes { } } - public static final String toBoxedDescriptor(String primitiveDescriptor) { + public static String toBoxedDescriptor(String primitiveDescriptor) { switch (primitiveDescriptor.charAt(0)) { case 'I': return "Ljava/lang/Integer"; case 'J': return "Ljava/lang/Long"; @@ -1037,7 +1036,7 @@ public class CodeFlow implements Opcodes { case 'S': return "Ljava/lang/Short"; case 'Z': return "Ljava/lang/Boolean"; default: - throw new IllegalArgumentException("Unexpected non primitive descriptor "+primitiveDescriptor); + throw new IllegalArgumentException("Unexpected non primitive descriptor " + primitiveDescriptor); } }