Polishing
This commit is contained in:
parent
ea534b6820
commit
214fa9c2a0
|
@ -348,72 +348,72 @@ public class CodeFlow implements Opcodes {
|
||||||
public static void insertAnyNecessaryTypeConversionBytecodes(MethodVisitor mv, char targetDescriptor, String stackDescriptor) {
|
public static void insertAnyNecessaryTypeConversionBytecodes(MethodVisitor mv, char targetDescriptor, String stackDescriptor) {
|
||||||
if (CodeFlow.isPrimitive(stackDescriptor)) {
|
if (CodeFlow.isPrimitive(stackDescriptor)) {
|
||||||
char stackTop = stackDescriptor.charAt(0);
|
char stackTop = stackDescriptor.charAt(0);
|
||||||
if (stackTop=='I' || stackTop=='B' || stackTop=='S' || stackTop=='C') {
|
if (stackTop == 'I' || stackTop == 'B' || stackTop == 'S' || stackTop == 'C') {
|
||||||
if (targetDescriptor=='D') {
|
if (targetDescriptor == 'D') {
|
||||||
mv.visitInsn(I2D);
|
mv.visitInsn(I2D);
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='F') {
|
else if (targetDescriptor == 'F') {
|
||||||
mv.visitInsn(I2F);
|
mv.visitInsn(I2F);
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='J') {
|
else if (targetDescriptor == 'J') {
|
||||||
mv.visitInsn(I2L);
|
mv.visitInsn(I2L);
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='I') {
|
else if (targetDescriptor == 'I') {
|
||||||
// nop
|
// nop
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalStateException("cannot get from "+stackTop+" to "+targetDescriptor);
|
throw new IllegalStateException("Cannot get from " + stackTop + " to " + targetDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (stackTop=='J') {
|
else if (stackTop == 'J') {
|
||||||
if (targetDescriptor=='D') {
|
if (targetDescriptor == 'D') {
|
||||||
mv.visitInsn(L2D);
|
mv.visitInsn(L2D);
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='F') {
|
else if (targetDescriptor == 'F') {
|
||||||
mv.visitInsn(L2F);
|
mv.visitInsn(L2F);
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='J') {
|
else if (targetDescriptor == 'J') {
|
||||||
// nop
|
// nop
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='I') {
|
else if (targetDescriptor == 'I') {
|
||||||
mv.visitInsn(L2I);
|
mv.visitInsn(L2I);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalStateException("cannot get from "+stackTop+" to "+targetDescriptor);
|
throw new IllegalStateException("Cannot get from " + stackTop + " to " + targetDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (stackTop=='F') {
|
else if (stackTop == 'F') {
|
||||||
if (targetDescriptor=='D') {
|
if (targetDescriptor == 'D') {
|
||||||
mv.visitInsn(F2D);
|
mv.visitInsn(F2D);
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='F') {
|
else if (targetDescriptor == 'F') {
|
||||||
// nop
|
// nop
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='J') {
|
else if (targetDescriptor == 'J') {
|
||||||
mv.visitInsn(F2L);
|
mv.visitInsn(F2L);
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='I') {
|
else if (targetDescriptor == 'I') {
|
||||||
mv.visitInsn(F2I);
|
mv.visitInsn(F2I);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalStateException("cannot get from "+stackTop+" to "+targetDescriptor);
|
throw new IllegalStateException("Cannot get from " + stackTop + " to " + targetDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (stackTop=='D') {
|
else if (stackTop == 'D') {
|
||||||
if (targetDescriptor=='D') {
|
if (targetDescriptor == 'D') {
|
||||||
// nop
|
// nop
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='F') {
|
else if (targetDescriptor == 'F') {
|
||||||
mv.visitInsn(D2F);
|
mv.visitInsn(D2F);
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='J') {
|
else if (targetDescriptor == 'J') {
|
||||||
mv.visitInsn(D2L);
|
mv.visitInsn(D2L);
|
||||||
}
|
}
|
||||||
else if (targetDescriptor=='I') {
|
else if (targetDescriptor == 'I') {
|
||||||
mv.visitInsn(D2I);
|
mv.visitInsn(D2I);
|
||||||
}
|
}
|
||||||
else {
|
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
|
* @param descriptor type descriptor
|
||||||
* @return {@code true} if the descriptor is boolean compatible
|
* @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
|
* @param descriptor type descriptor
|
||||||
* @return {@code true} if a primitive type
|
* @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
|
* @param descriptor the descriptor for a possible primitive array
|
||||||
* @return {@code true} if the descriptor a 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
|
* Determine whether boxing/unboxing can get from one type to the other.
|
||||||
* one of the types is in boxed form (i.e. single char descriptor).
|
* 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
|
* @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) {
|
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
|
* Deduce the descriptor for a type. Descriptors are like JVM type names but missing the
|
||||||
* the trailing ';' so for Object the descriptor is "Ljava/lang/Object" for int it is
|
* trailing ';' so for Object the descriptor is "Ljava/lang/Object" for int it is "I".
|
||||||
* "I".
|
|
||||||
* @param type the type (may be primitive) for which to determine the descriptor
|
* @param type the type (may be primitive) for which to determine the descriptor
|
||||||
* @return the descriptor
|
* @return the descriptor
|
||||||
*/
|
*/
|
||||||
|
@ -957,7 +956,7 @@ public class CodeFlow implements Opcodes {
|
||||||
case 'S': return T_SHORT;
|
case 'S': return T_SHORT;
|
||||||
case 'Z': return T_BOOLEAN;
|
case 'Z': return T_BOOLEAN;
|
||||||
default:
|
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 == '[') {
|
if (ch == '[') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return ch=='L';
|
return (ch == 'L');
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -991,10 +990,10 @@ public class CodeFlow implements Opcodes {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (arraytype.charAt(0) == '[') {
|
if (arraytype.charAt(0) == '[') {
|
||||||
// Handling the nested array case here. If vararg
|
// Handling the nested array case here.
|
||||||
// is [[I then we want [I and not [I;
|
// If vararg is [[I then we want [I and not [I;
|
||||||
if (CodeFlow.isReferenceTypeArray(arraytype)) {
|
if (CodeFlow.isReferenceTypeArray(arraytype)) {
|
||||||
mv.visitTypeInsn(ANEWARRAY, arraytype+";");
|
mv.visitTypeInsn(ANEWARRAY, arraytype + ";");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mv.visitTypeInsn(ANEWARRAY, arraytype);
|
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)) {
|
switch (primitiveDescriptor.charAt(0)) {
|
||||||
case 'I': return "Ljava/lang/Integer";
|
case 'I': return "Ljava/lang/Integer";
|
||||||
case 'J': return "Ljava/lang/Long";
|
case 'J': return "Ljava/lang/Long";
|
||||||
|
@ -1037,7 +1036,7 @@ public class CodeFlow implements Opcodes {
|
||||||
case 'S': return "Ljava/lang/Short";
|
case 'S': return "Ljava/lang/Short";
|
||||||
case 'Z': return "Ljava/lang/Boolean";
|
case 'Z': return "Ljava/lang/Boolean";
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unexpected non primitive descriptor "+primitiveDescriptor);
|
throw new IllegalArgumentException("Unexpected non primitive descriptor " + primitiveDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue