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;
}
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;
}
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();
}
}
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(",");
}
}
}
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;
}
}
Aggregations