Search in sources :

Example 1 with Parameter

use of net.jangaroo.jooc.ast.Parameter in project jangaroo-tools by CoreMedia.

the class JsCodeGenerator method getParameterInitializerCodeGenerator.

public CodeGenerator getParameterInitializerCodeGenerator(final Parameters params) {
    return new CodeGenerator() {

        @Override
        public void generate(JsWriter out, boolean first) throws IOException {
            // collect the ... (rest) parameter and all optional parameters with their position index:
            int restParamIndex = -1;
            Parameter restParam = null;
            Map<Integer, Parameter> paramByIndex = new HashMap<Integer, Parameter>();
            Parameters parameters = params;
            for (int paramIndex = 0; parameters != null; parameters = parameters.getTail()) {
                Parameter param = parameters.getHead();
                if (param.isRest()) {
                    restParamIndex = paramIndex;
                    restParam = param;
                    break;
                }
                if (param.hasInitializer()) {
                    paramByIndex.put(paramIndex, param);
                }
                ++paramIndex;
            }
            generateParameterInitializers(out, paramByIndex);
            if (restParam != null) {
                generateRestParamCode(restParam, restParamIndex);
            }
        }
    };
}
Also used : Parameters(net.jangaroo.jooc.ast.Parameters) HashMap(java.util.HashMap) AnnotationParameter(net.jangaroo.jooc.ast.AnnotationParameter) Parameter(net.jangaroo.jooc.ast.Parameter) CodeGenerator(net.jangaroo.jooc.CodeGenerator) JsWriter(net.jangaroo.jooc.JsWriter)

Aggregations

HashMap (java.util.HashMap)1 CodeGenerator (net.jangaroo.jooc.CodeGenerator)1 JsWriter (net.jangaroo.jooc.JsWriter)1 AnnotationParameter (net.jangaroo.jooc.ast.AnnotationParameter)1 Parameter (net.jangaroo.jooc.ast.Parameter)1 Parameters (net.jangaroo.jooc.ast.Parameters)1