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

Method doSwitchBranch

src/bsh/ClassGeneratorUtil.java:498–546  ·  view source on GitHub ↗
(int index, String targetClassName, String[] paramTypes, Label endLabel, Label[] labels, int consArgsVar, CodeVisitor cv)

Source from the content-addressed store, hash-verified

496
497
498 private static void doSwitchBranch(int index, String targetClassName, String[] paramTypes, Label endLabel, Label[] labels, int consArgsVar, CodeVisitor cv) {
499 cv.visitLabel(labels[index]);
500 //cv.visitLineNumber( index, labels[index] );
501 cv.visitVarInsn(ALOAD, 0); // push this before args
502
503 // Unload the arguments from the ConstructorArgs object
504 for (String type : paramTypes) {
505 final String method;
506 if (type.equals("Z")) {
507 method = "getBoolean";
508 } else if (type.equals("B")) {
509 method = "getByte";
510 } else if (type.equals("C")) {
511 method = "getChar";
512 } else if (type.equals("S")) {
513 method = "getShort";
514 } else if (type.equals("I")) {
515 method = "getInt";
516 } else if (type.equals("J")) {
517 method = "getLong";
518 } else if (type.equals("D")) {
519 method = "getDouble";
520 } else if (type.equals("F")) {
521 method = "getFloat";
522 } else {
523 method = "getObject";
524 }
525
526 // invoke the iterator method on the ConstructorArgs
527 cv.visitVarInsn(ALOAD, consArgsVar); // push the ConstructorArgs
528 String className = "bsh/ClassGeneratorUtil$ConstructorArgs";
529 String retType;
530 if (method.equals("getObject")) {
531 retType = OBJECT;
532 } else {
533 retType = type;
534 }
535 cv.visitMethodInsn(INVOKEVIRTUAL, className, method, "()" + retType);
536 // if it's an object type we must do a check cast
537 if (method.equals("getObject")) {
538 cv.visitTypeInsn(CHECKCAST, descriptorToClassName(type));
539 }
540 }
541
542 // invoke the constructor for this branch
543 String descriptor = getMethodDescriptor("V", paramTypes);
544 cv.visitMethodInsn(INVOKESPECIAL, targetClassName, "<init>", descriptor);
545 cv.visitJumpInsn(GOTO, endLabel);
546 }
547
548
549 private static String getMethodDescriptor(String returnType, String[] paramTypes) {

Callers 1

Calls 8

descriptorToClassNameMethod · 0.95
getMethodDescriptorMethod · 0.95
visitLabelMethod · 0.65
visitVarInsnMethod · 0.65
visitMethodInsnMethod · 0.65
visitTypeInsnMethod · 0.65
visitJumpInsnMethod · 0.65
equalsMethod · 0.45

Tested by

no test coverage detected