raven-compiler/src/main/java/org/raven/compiler/Method.java
/**
     * Place super calls in the constructor. Since the variables are dynamic the super constructor
     * is chosen at runtime based on the how coercible the arguments are
     *
     * @param clazz      The
     * @param candidates The list of parameter types for each class constructor candidate
     * @param params     The parameters to pass
     * @throws NoSuchMethodException
     */
Place super calls in the constructor. Since the variables are dynamic the super constructor
is chosen at runtime based on the how coercible the arguments are

@param clazz      The
@param candidates The list of parameter types for each class constructor candidate
@param params     The parameters to pass
@throws NoSuchMethodException
Place super calls in the constructor . Since the variables are dynamic the super constructor is chosen at runtime based on the how coercible the arguments are @param clazz The @param candidates The list of parameter types for each class constructor candidate @param params The parameters to pass @throws NoSuchMethodException
private void putSuperCalls(final Class clazz, final LinkedList<Class[]> candidates, final Expression[] params) throws NoSuchMethodException {
        final Class[] candidate = candidates.getFirst();
        final String getParamDesc = getDesc(Intrinsics.class, "getParams", TObject.class, Class[].class);
        visitVarInsn(ALOAD, getLocal(" TL_PARAMS "));
        visitLdcInsn(params.length);
        visitTypeInsn(ANEWARRAY, getName(Class.class));
        int i = 0;
        for (final Class cl : candidate) {
            visitInsn(DUP);
            visitLdcInsn(i++);
            putType(cl);
            visitInsn(AASTORE);
        }
        visitMethodInsn(INVOKESTATIC, getName(Intrinsics.class), "getParams", getParamDesc, false);
        visitVarInsn(ASTORE, getLocal(" SUPER_PARAMS "));
        final Label coercionFailedLabel = new Label();
        visitVarInsn(ALOAD, getLocal(" SUPER_PARAMS "));
        visitJumpInsn(IFNULL, coercionFailedLabel);
        final String superDesc = Type.getConstructorDescriptor(clazz.getConstructor(candidate));
        for (int n = 0; n < params.length; n++) {
            visitVarInsn(ALOAD, getLocal(" SUPER_PARAMS "));
            visitLdcInsn(n);
            visitInsn(AALOAD);
            if (!candidate[n].isPrimitive() || (candidate[n].isArray() && candidate[n].getComponentType().isPrimitive())) {
                visitTypeInsn(CHECKCAST, Type.getType(candidate[n]).getInternalName());
            } else {
                toPrimitive(candidate[n]);
            }
        }
        visitMethodInsn(INVOKESPECIAL, ctx.getClassDef().getSuper().toString().replace(".", "/"),
                "<init>", superDesc, false);
        final Label after = new Label();
        visitJumpInsn(GOTO, after);
        visitLabel(coercionFailedLabel);
        candidates.removeFirst();
        if (candidates.size() > 0) {
            putSuperCalls(clazz, candidates, params);
        } else {
            throwException(IllegalArgumentException.class, "Illegal parameters in super() call");
        }
        visitLabel(after);
    }
private void putSuperCalls ( final Class clazz , final LinkedList < Class [ ] > candidates , final Expression [ ] params ) throws NoSuchMethodException { final Class [ ] candidate = candidates . getFirst ( ) ; final String getParamDesc = getDesc ( Intrinsics . class , "getParams" , TObject . class , Class [ ] . class ) ; visitVarInsn ( ALOAD , getLocal ( " TL_PARAMS " ) ) ; visitLdcInsn ( params . length ) ; visitTypeInsn ( ANEWARRAY , getName ( Class . class ) ) ; int i = 0 ; for ( final Class cl : candidate ) { visitInsn ( DUP ) ; visitLdcInsn ( i ++ ) ; putType ( cl ) ; visitInsn ( AASTORE ) ; } visitMethodInsn ( INVOKESTATIC , getName ( Intrinsics . class ) , "getParams" , getParamDesc , false ) ; visitVarInsn ( ASTORE , getLocal ( " SUPER_PARAMS " ) ) ; final Label coercionFailedLabel = new Label ( ) ; visitVarInsn ( ALOAD , getLocal ( " SUPER_PARAMS " ) ) ; visitJumpInsn ( IFNULL , coercionFailedLabel ) ; final String superDesc = Type . getConstructorDescriptor ( clazz . getConstructor ( candidate ) ) ; for ( int n = 0 ; n < params . length ; n ++ ) { visitVarInsn ( ALOAD , getLocal ( " SUPER_PARAMS " ) ) ; visitLdcInsn ( n ) ; visitInsn ( AALOAD ) ; if ( ! candidate [ n ] . isPrimitive ( ) || ( candidate [ n ] . isArray ( ) && candidate [ n ] . getComponentType ( ) . isPrimitive ( ) ) ) { visitTypeInsn ( CHECKCAST , Type . getType ( candidate [ n ] ) . getInternalName ( ) ) ; } else { toPrimitive ( candidate [ n ] ) ; } } visitMethodInsn ( INVOKESPECIAL , ctx . getClassDef ( ) . getSuper ( ) . toString ( ) . replace ( "." , "/" ) , "<init>" , superDesc , false ) ; final Label after = new Label ( ) ; visitJumpInsn ( GOTO , after ) ; visitLabel ( coercionFailedLabel ) ; candidates . removeFirst ( ) ; if ( candidates . size ( ) > 0 ) { putSuperCalls ( clazz , candidates , params ) ; } else { throwException ( IllegalArgumentException . class , "Illegal parameters in super() call" ) ; } visitLabel ( after ) ; }
Place super calls in the constructor.
Place super calls in the constructor .
// put the types on the stack that we wish to coerce to // perform coercion // if coercion is impossible for this super constructor is not possible // skip the super() call and try the next candidate // label to jump to the end