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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations