当前位置: 首页>>代码示例>>Java>>正文


Java FunctionNode.addParam方法代码示例

本文整理汇总了Java中org.mozilla.javascript.ast.FunctionNode.addParam方法的典型用法代码示例。如果您正苦于以下问题:Java FunctionNode.addParam方法的具体用法?Java FunctionNode.addParam怎么用?Java FunctionNode.addParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mozilla.javascript.ast.FunctionNode的用法示例。


在下文中一共展示了FunctionNode.addParam方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: arrowFunctionParams

import org.mozilla.javascript.ast.FunctionNode; //导入方法依赖的package包/类
private void arrowFunctionParams(FunctionNode fnNode, AstNode params, Map<String, Node> destructuring, Set<String> paramNames) {
    if (params instanceof ArrayLiteral || params instanceof ObjectLiteral) {
        markDestructuring(params);
        fnNode.addParam(params);
        String pname = currentScriptOrFn.getNextTempName();
        defineSymbol(Token.LP, pname, false);
        destructuring.put(pname, params);
    } else if (params instanceof InfixExpression && params.getType() == Token.COMMA) {
        arrowFunctionParams(fnNode, ((InfixExpression)params).getLeft(), destructuring, paramNames);
        arrowFunctionParams(fnNode, ((InfixExpression)params).getRight(), destructuring, paramNames);
    } else if (params instanceof Name) {
        fnNode.addParam(params);
        String paramName = ((Name)params).getIdentifier();
        defineSymbol(Token.LP, paramName);

        if (this.inUseStrictDirective) {
            if ("eval".equals(paramName) ||
                "arguments".equals(paramName))
                {
                    reportError("msg.bad.id.strict", paramName);
                }
            if (paramNames.contains(paramName))
                addError("msg.dup.param.strict", paramName);
            paramNames.add(paramName);
        }
    } else {
        reportError("msg.no.parm", params.getPosition(), params.getLength());
        fnNode.addParam(makeErrorNode());
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:31,代码来源:Parser.java

示例2: parseFunctionParams

import org.mozilla.javascript.ast.FunctionNode; //导入方法依赖的package包/类
private void  parseFunctionParams(FunctionNode fnNode)
    throws IOException
{
    if (matchToken(Token.RP)) {
        fnNode.setRp(ts.tokenBeg - fnNode.getPosition());
        return;
    }
    // Would prefer not to call createDestructuringAssignment until codegen,
    // but the symbol definitions have to happen now, before body is parsed.
    Map<String, Node> destructuring = null;
    Set<String> paramNames = new HashSet<String>();
    do {
        int tt = peekToken();
        if (tt == Token.LB || tt == Token.LC) {
            AstNode expr = destructuringPrimaryExpr();
            markDestructuring(expr);
            fnNode.addParam(expr);
            // Destructuring assignment for parameters: add a dummy
            // parameter name, and add a statement to the body to initialize
            // variables from the destructuring assignment
            if (destructuring == null) {
                destructuring = new HashMap<String, Node>();
            }
            String pname = currentScriptOrFn.getNextTempName();
            defineSymbol(Token.LP, pname, false);
            destructuring.put(pname, expr);
        } else {
            if (mustMatchToken(Token.NAME, "msg.no.parm")) {
                Name paramNameNode = createNameNode();
                Comment jsdocNodeForName = getAndResetJsDoc();
                if (jsdocNodeForName != null) {
                  paramNameNode.setJsDocNode(jsdocNodeForName);
                }
                fnNode.addParam(paramNameNode);
                String paramName = ts.getString();
                defineSymbol(Token.LP, paramName);
                if (this.inUseStrictDirective) {
                    if ("eval".equals(paramName) ||
                        "arguments".equals(paramName))
                    {
                        reportError("msg.bad.id.strict", paramName);
                    }
                    if (paramNames.contains(paramName))
                        addError("msg.dup.param.strict", paramName);
                    paramNames.add(paramName);
                }
            } else {
                fnNode.addParam(makeErrorNode());
            }
        }
    } while (matchToken(Token.COMMA));

    if (destructuring != null) {
        Node destructuringNode = new Node(Token.COMMA);
        // Add assignment helper for each destructuring parameter
        for (Map.Entry<String, Node> param: destructuring.entrySet()) {
            Node assign = createDestructuringAssignment(Token.VAR,
                    param.getValue(), createName(param.getKey()));
            destructuringNode.addChildToBack(assign);

        }
        fnNode.putProp(Node.DESTRUCTURING_PARAMS, destructuringNode);
    }

    if (mustMatchToken(Token.RP, "msg.no.paren.after.parms")) {
        fnNode.setRp(ts.tokenBeg - fnNode.getPosition());
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:69,代码来源:Parser.java


注:本文中的org.mozilla.javascript.ast.FunctionNode.addParam方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。