Search in sources :

Example 1 with IfStatement

use of org.mozilla.javascript.ast.IfStatement in project HL4A by HL4A.

the class Parser method ifStatement.

private IfStatement ifStatement() throws IOException {
    if (currentToken != Token.IF)
        codeBug();
    consumeToken();
    int pos = ts.tokenBeg, lineno = ts.lineno, elsePos = -1;
    ConditionData data = condition();
    AstNode ifTrue = statement(), ifFalse = null;
    if (matchToken(Token.ELSE)) {
        elsePos = ts.tokenBeg - pos;
        ifFalse = statement();
    }
    int end = getNodeEnd(ifFalse != null ? ifFalse : ifTrue);
    IfStatement pn = new IfStatement(pos, end - pos);
    pn.setCondition(data.condition);
    pn.setParens(data.lp - pos, data.rp - pos);
    pn.setThenPart(ifTrue);
    pn.setElsePart(ifFalse);
    pn.setElsePosition(elsePos);
    pn.setLineno(lineno);
    return pn;
}
Also used : IfStatement(org.mozilla.javascript.ast.IfStatement) AstNode(org.mozilla.javascript.ast.AstNode)

Example 2 with IfStatement

use of org.mozilla.javascript.ast.IfStatement in project st-js by st-js.

the class RhinoJavaScriptBuilder method ifStatement.

/**
 * {@inheritDoc}
 */
@Override
public AstNode ifStatement(AstNode condition, AstNode thenPart, AstNode elsePart) {
    IfStatement ifs = new IfStatement();
    ifs.setCondition(condition);
    ifs.setThenPart(thenPart);
    ifs.setElsePart(elsePart);
    return ifs;
}
Also used : IfStatement(org.mozilla.javascript.ast.IfStatement)

Aggregations

IfStatement (org.mozilla.javascript.ast.IfStatement)2 AstNode (org.mozilla.javascript.ast.AstNode)1