MCPcopy Create free account
hub / github.com/beanshell/beanshell / generateReturnCode

Method generateReturnCode

src/bsh/ClassGeneratorUtil.java:711–756  ·  view source on GitHub ↗

Generates the code to unreify the result of the given method. For a method "int m (int i, String s)", this code is the bytecode corresponding to the "((Integer)...).intValue()" expression. @param cv the code visitor to be used to generate the bytecode. @author Eric Bruneton @author Pat Niemeyer

(String returnType, CodeVisitor cv)

Source from the content-addressed store, hash-verified

709 * @author Pat Niemeyer
710 */
711 private static void generateReturnCode(String returnType, CodeVisitor cv) {
712 if (returnType.equals("V")) {
713 cv.visitInsn(POP);
714 cv.visitInsn(RETURN);
715 } else if (isPrimitive(returnType)) {
716 int opcode = IRETURN;
717 String type;
718 String meth;
719 if (returnType.equals("B")) {
720 type = "java/lang/Byte";
721 meth = "byteValue";
722 } else if (returnType.equals("I")) {
723 type = "java/lang/Integer";
724 meth = "intValue";
725 } else if (returnType.equals("Z")) {
726 type = "java/lang/Boolean";
727 meth = "booleanValue";
728 } else if (returnType.equals("D")) {
729 opcode = DRETURN;
730 type = "java/lang/Double";
731 meth = "doubleValue";
732 } else if (returnType.equals("F")) {
733 opcode = FRETURN;
734 type = "java/lang/Float";
735 meth = "floatValue";
736 } else if (returnType.equals("J")) {
737 opcode = LRETURN;
738 type = "java/lang/Long";
739 meth = "longValue";
740 } else if (returnType.equals("C")) {
741 type = "java/lang/Character";
742 meth = "charValue";
743 } else /*if (returnType.equals("S") )*/ {
744 type = "java/lang/Short";
745 meth = "shortValue";
746 }
747
748 String desc = returnType;
749 cv.visitTypeInsn(CHECKCAST, type); // type is correct here
750 cv.visitMethodInsn(INVOKEVIRTUAL, type, meth, "()" + desc);
751 cv.visitInsn(opcode);
752 } else {
753 cv.visitTypeInsn(CHECKCAST, descriptorToClassName(returnType));
754 cv.visitInsn(ARETURN);
755 }
756 }
757
758
759 /**

Callers 1

generateMethodMethod · 0.95

Calls 6

isPrimitiveMethod · 0.95
descriptorToClassNameMethod · 0.95
visitInsnMethod · 0.65
visitTypeInsnMethod · 0.65
visitMethodInsnMethod · 0.65
equalsMethod · 0.45

Tested by

no test coverage detected