MCPcopy Index your code
hub / github.com/beanshell/beanshell / getConstructorArgs

Method getConstructorArgs

src/bsh/ClassGeneratorUtil.java:770–872  ·  view source on GitHub ↗

Evaluate the arguments (if any) for the constructor specified by the constructor index. Return the ConstructorArgs object which contains the actual arguments to the alternate constructor and also the index of that constructor for the constructor switch. @param consArgs the arguments to the constru

(String superClassName, This classStaticThis, Object[] consArgs, int index)

Source from the content-addressed store, hash-verified

768 * and evaluated arguments for the alternate constructor
769 */
770 public static ConstructorArgs getConstructorArgs(String superClassName, This classStaticThis, Object[] consArgs, int index) {
771 DelayedEvalBshMethod[] constructors;
772 try {
773 constructors = (DelayedEvalBshMethod[]) classStaticThis.getNameSpace().getVariable(BSHCONSTRUCTORS);
774 } catch (Exception e) {
775 throw new InterpreterError("unable to get instance initializer: " + e);
776 }
777
778 if (index == DEFAULTCONSTRUCTOR) // auto-gen default constructor
779 {
780 return ConstructorArgs.DEFAULT;
781 } // use default super constructor
782
783 DelayedEvalBshMethod constructor = constructors[index];
784
785 if (constructor.methodBody.jjtGetNumChildren() == 0) {
786 return ConstructorArgs.DEFAULT;
787 } // use default super constructor
788
789 // Determine if the constructor calls this() or super()
790 String altConstructor = null;
791 BSHArguments argsNode = null;
792 SimpleNode firstStatement = (SimpleNode) constructor.methodBody.jjtGetChild(0);
793 if (firstStatement instanceof BSHPrimaryExpression) {
794 firstStatement = (SimpleNode) firstStatement.jjtGetChild(0);
795 }
796 if (firstStatement instanceof BSHMethodInvocation) {
797 BSHMethodInvocation methodNode = (BSHMethodInvocation) firstStatement;
798 BSHAmbiguousName methodName = methodNode.getNameNode();
799 if (methodName.text.equals("super") || methodName.text.equals("this")) {
800 altConstructor = methodName.text;
801 argsNode = methodNode.getArgsNode();
802 }
803 }
804
805 if (altConstructor == null) {
806 return ConstructorArgs.DEFAULT;
807 } // use default super constructor
808
809 // Make a tmp namespace to hold the original constructor args for
810 // use in eval of the parameters node
811 NameSpace consArgsNameSpace = new NameSpace(classStaticThis.getNameSpace(), "consArgs");
812 String[] consArgNames = constructor.getParameterNames();
813 Class[] consArgTypes = constructor.getParameterTypes();
814 for (int i = 0; i < consArgs.length; i++) {
815 try {
816 consArgsNameSpace.setTypedVariable(consArgNames[i], consArgTypes[i], consArgs[i], null/*modifiers*/);
817 } catch (UtilEvalError e) {
818 throw new InterpreterError("err setting local cons arg:" + e);
819 }
820 }
821
822 // evaluate the args
823
824 CallStack callstack = new CallStack();
825 callstack.push(consArgsNameSpace);
826 Object[] args;
827 Interpreter interpreter = classStaticThis.declaringInterpreter;

Callers

nothing calls this directly

Calls 15

jjtGetChildMethod · 0.95
getNameNodeMethod · 0.95
getArgsNodeMethod · 0.95
getParameterTypesMethod · 0.95
setTypedVariableMethod · 0.95
pushMethod · 0.95
getArgumentsMethod · 0.95
getTypesMethod · 0.95
unwrapMethod · 0.95
getClassManagerMethod · 0.95

Tested by

no test coverage detected