Search in sources :

Example 1 with AstNode

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

the class RhinoJavaScriptBuilder method tryStatement.

/**
 * {@inheritDoc}
 */
@Override
public AstNode tryStatement(AstNode tryBlock, Iterable<AstNode> catchClauses, AstNode finallyBlock) {
    TryStatement t = new TryStatement();
    t.setTryBlock(tryBlock);
    for (AstNode c : catchClauses) {
        t.addCatchClause((CatchClause) c);
    }
    t.setFinallyBlock(finallyBlock);
    return t;
}
Also used : TryStatement(org.mozilla.javascript.ast.TryStatement) AstNode(org.mozilla.javascript.ast.AstNode)

Example 2 with AstNode

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

the class RhinoJavaScriptBuilder method caseStatement.

/**
 * {@inheritDoc}
 */
@Override
public AstNode caseStatement(AstNode expression, Iterable<AstNode> statements) {
    SwitchCase s = new SwitchCase();
    s.setExpression(expression);
    for (AstNode stmt : statements) {
        if (stmt != null) {
            s.addStatement(stmt);
        }
    }
    return s;
}
Also used : SwitchCase(org.mozilla.javascript.ast.SwitchCase) AstNode(org.mozilla.javascript.ast.AstNode)

Example 3 with AstNode

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

the class RhinoJavaScriptWriter method visitSwitchCase.

/**
 * {@inheritDoc}
 */
@Override
public void visitSwitchCase(SwitchCase s, Boolean param) {
    if (s.getExpression() == null) {
        println("default:");
    } else {
        print("case ");
        visitorSupport.accept(s.getExpression(), this, param);
        println(":");
    }
    if (s.getStatements() != null) {
        indent();
        for (AstNode stmt : s.getStatements()) {
            visitorSupport.accept(stmt, this, param);
        }
        unindent();
    }
}
Also used : AstNode(org.mozilla.javascript.ast.AstNode)

Example 4 with AstNode

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

the class RhinoJavaScriptWriter method printList.

/**
 * <p>printList.</p>
 *
 * @param items a {@link java.util.List} object.
 * @param param a {@link java.lang.Boolean} object.
 */
protected <T extends AstNode> void printList(List<T> items, Boolean param) {
    int max = items.size();
    int count = 0;
    for (AstNode item : items) {
        visitorSupport.accept(item, this, param);
        if (count < max - 1) {
            count++;
            print(", ");
        } else if (item instanceof EmptyExpression) {
            print(",");
        }
    }
}
Also used : AstNode(org.mozilla.javascript.ast.AstNode) EmptyExpression(org.mozilla.javascript.ast.EmptyExpression)

Example 5 with AstNode

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

the class MTGoldFishDashBoard method getPriceVariation.

public Map<Date, Double> getPriceVariation(MagicCard mc, MagicEdition me) throws IOException {
    stop = false;
    String url = "";
    Map<Date, Double> historyPrice = new TreeMap<>();
    int index = 0;
    if (me == null)
        me = mc.getEditions().get(0);
    if (mc == null) {
        url = getString("URL_EDITIONS") + replace(me.getId(), false) + "#" + getString("FORMAT");
        index = 6;
    } else {
        String cardName = StringUtils.replaceAll(mc.getName(), " ", "+");
        cardName = StringUtils.replaceAll(cardName, "'", "");
        cardName = StringUtils.replaceAll(cardName, ",", "");
        if (cardName.indexOf('/') > -1)
            cardName = cardName.substring(0, cardName.indexOf('/')).trim();
        String editionName = StringUtils.replaceAll(me.toString(), " ", "+");
        editionName = StringUtils.replaceAll(editionName, "'", "");
        editionName = StringUtils.replaceAll(editionName, ",", "");
        editionName = StringUtils.replaceAll(editionName, ":", "");
        url = getString("WEBSITE") + "/price/" + convert(editionName) + "/" + cardName + "#" + getString("FORMAT");
        index = 8;
    }
    try {
        logger.debug("get shakes from " + url);
        Document d = read(url);
        Element js = d.getElementsByTag("script").get(index);
        AstNode root = new Parser().parse(js.html(), "", 1);
        root.visit(visitedNode -> {
            if (!stop && visitedNode.toSource().startsWith("d")) {
                String val = visitedNode.toSource();
                val = StringUtils.replaceAll(val, "d \\+\\= ", "");
                val = StringUtils.replaceAll(val, "\\\\n", "");
                val = StringUtils.replaceAll(val, ";", "");
                val = StringUtils.replaceAll(val, "\"", "");
                String[] res = val.split(",");
                try {
                    Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm").parse(res[0] + " 00:00");
                    if (historyPrice.get(date) == null)
                        historyPrice.put(date, Double.parseDouble(res[1]));
                } catch (Exception e) {
                    MTGLogger.printStackTrace(e);
                }
            }
            if (visitedNode.toSource().startsWith("g =")) {
                stop = true;
            }
            return true;
        });
        return historyPrice;
    } catch (Exception e) {
        logger.error(e);
        return historyPrice;
    }
}
Also used : Element(org.jsoup.nodes.Element) TreeMap(java.util.TreeMap) Document(org.jsoup.nodes.Document) Date(java.util.Date) ParseException(java.text.ParseException) IOException(java.io.IOException) Parser(org.mozilla.javascript.Parser) SimpleDateFormat(java.text.SimpleDateFormat) 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