Search in sources :

Example 36 with AstNode

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

the class RhinoJavaScriptBuilder method variableDeclaration.

/**
 * {@inheritDoc}
 */
@Override
public AstNode variableDeclaration(boolean statement, Iterable<NameValue<AstNode>> vars) {
    VariableDeclaration varDecl = new VariableDeclaration();
    varDecl.setIsStatement(statement);
    for (NameValue<AstNode> v : vars) {
        VariableInitializer var = new VariableInitializer();
        var.setTarget(name(v.getName()));
        var.setInitializer(v.getValue());
        varDecl.addVariable(var);
    }
    return varDecl;
}
Also used : VariableDeclaration(org.mozilla.javascript.ast.VariableDeclaration) VariableInitializer(org.mozilla.javascript.ast.VariableInitializer) AstNode(org.mozilla.javascript.ast.AstNode)

Example 37 with AstNode

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

the class RhinoJavaScriptBuilder method binary.

/**
 * {@inheritDoc}
 */
@Override
public AstNode binary(BinaryOperator operator, Iterable<AstNode> operands) {
    // this is to deal with the COMMA operator who can have less than two operands
    if (Iterables.isEmpty(operands)) {
        return new EmptyExpression();
    }
    if (Iterables.size(operands) == 1) {
        return operands.iterator().next();
    }
    InfixExpression list = new InfixExpression();
    list.setOperator(operator.getJavaScript());
    Iterator<AstNode> it = operands.iterator();
    list.setLeft(it.next());
    list.setRight(it.next());
    while (it.hasNext()) {
        InfixExpression tmpIncrements = new InfixExpression();
        tmpIncrements.setOperator(operator.getJavaScript());
        tmpIncrements.setLeft(list);
        tmpIncrements.setRight(it.next());
        list = tmpIncrements;
    }
    return list;
}
Also used : InfixExpression(org.mozilla.javascript.ast.InfixExpression) AstNode(org.mozilla.javascript.ast.AstNode) EmptyExpression(org.mozilla.javascript.ast.EmptyExpression)

Example 38 with AstNode

use of org.mozilla.javascript.ast.AstNode in project pmd by pmd.

the class EcmascriptTreeBuilder method buildInternal.

private <T extends AstNode> EcmascriptNode<T> buildInternal(T astNode) {
    // Create a Node
    EcmascriptNode<T> node = createNodeAdapter(astNode);
    // Append to parent
    Node parent = nodes.isEmpty() ? null : nodes.peek();
    if (parent != null) {
        parent.jjtAddChild(node, parent.jjtGetNumChildren());
        node.jjtSetParent(parent);
    }
    handleParseProblems(node);
    // Build the children...
    nodes.push(node);
    parents.push(astNode);
    astNode.visit(this);
    nodes.pop();
    parents.pop();
    return node;
}
Also used : AstNode(org.mozilla.javascript.ast.AstNode) LetNode(org.mozilla.javascript.ast.LetNode) Node(net.sourceforge.pmd.lang.ast.Node) FunctionNode(org.mozilla.javascript.ast.FunctionNode)

Example 39 with AstNode

use of org.mozilla.javascript.ast.AstNode in project MtgDesktopCompanion by nicho92.

the class MTGSalvationDeckSniffer method parseColor.

private String parseColor(String string) {
    AstNode node = new Parser().parse(string, "", 1);
    node.visit(n -> {
        manajson = n.toSource();
        return false;
    });
    manajson = manajson.substring(manajson.indexOf("series") + "series: ".length(), manajson.length() - 8);
    JsonArray arr = new JsonParser().parse(manajson).getAsJsonArray();
    manajson = "";
    boolean hascolor = false;
    for (int i = 0; i < arr.size(); i++) {
        JsonObject obj = arr.get(i).getAsJsonObject();
        String c = ColorParser.parse(obj.get("name").getAsString());
        JsonArray tab = obj.get("data").getAsJsonArray();
        hascolor = false;
        for (int j = 0; j < tab.size(); j++) {
            if (tab.get(j).getAsInt() > 0)
                hascolor = true;
        }
        if (hascolor && !c.equals("{C}")) {
            manajson += c;
        }
    }
    return manajson;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) AstNode(org.mozilla.javascript.ast.AstNode) JsonParser(com.google.gson.JsonParser) ColorParser(org.magic.tools.ColorParser) Parser(org.mozilla.javascript.Parser) JsonParser(com.google.gson.JsonParser)

Example 40 with AstNode

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

the class IRFactory method transformParenExpr.

private Node transformParenExpr(ParenthesizedExpression node) {
    AstNode expr = node.getExpression();
    decompiler.addToken(Token.LP);
    int count = 1;
    while (expr instanceof ParenthesizedExpression) {
        decompiler.addToken(Token.LP);
        count++;
        expr = ((ParenthesizedExpression) expr).getExpression();
    }
    Node result = transform(expr);
    for (int i = 0; i < count; i++) {
        decompiler.addToken(Token.RP);
    }
    result.putProp(Node.PARENTHESIZED_PROP, Boolean.TRUE);
    return result;
}
Also used : ParenthesizedExpression(org.mozilla.javascript.ast.ParenthesizedExpression) ScriptNode(org.mozilla.javascript.ast.ScriptNode) AstNode(org.mozilla.javascript.ast.AstNode) LetNode(org.mozilla.javascript.ast.LetNode) FunctionNode(org.mozilla.javascript.ast.FunctionNode) AstNode(org.mozilla.javascript.ast.AstNode)

Aggregations

AstNode (org.mozilla.javascript.ast.AstNode)80 FunctionNode (org.mozilla.javascript.ast.FunctionNode)22 LetNode (org.mozilla.javascript.ast.LetNode)22 ScriptNode (org.mozilla.javascript.ast.ScriptNode)19 XmlString (org.mozilla.javascript.ast.XmlString)15 InfixExpression (org.mozilla.javascript.ast.InfixExpression)13 EmptyExpression (org.mozilla.javascript.ast.EmptyExpression)9 Comment (org.mozilla.javascript.ast.Comment)8 Name (org.mozilla.javascript.ast.Name)8 ArrayList (java.util.ArrayList)6 Block (org.mozilla.javascript.ast.Block)5 ExpressionStatement (org.mozilla.javascript.ast.ExpressionStatement)5 VariableDeclaration (org.mozilla.javascript.ast.VariableDeclaration)5 ArrayComprehensionLoop (org.mozilla.javascript.ast.ArrayComprehensionLoop)4 ErrorNode (org.mozilla.javascript.ast.ErrorNode)4 GeneratorExpressionLoop (org.mozilla.javascript.ast.GeneratorExpressionLoop)4 DoLoop (org.mozilla.javascript.ast.DoLoop)3 Scope (org.mozilla.javascript.ast.Scope)3 VariableInitializer (org.mozilla.javascript.ast.VariableInitializer)3 IOException (java.io.IOException)2