I need to create FunctionCall statement like Utiliy.initialize("value") and add this in first line of every function of js file.
Below is the code using which I am trying to create FunctionCall
private FunctionCall getFunctionCall() {
FunctionCall functionCall = new FunctionCall();
Name name = new Name();
name.setIdentifier("initialize");
functionCall.setTarget(name);
}
below is the code I am using to add in every functionNode
class FunctionVisitor implements NodeVisitor {
@Override
public boolean visit(AstNode node) {
if (node.getClass() == FunctionNode.class) {
FunctionNode fun = (FunctionNode) node;
fun.addChildrenToFront(getFunctionCall());
}
return true;
}
}
Please suggest how I can create FunctionCall with arguments and how I can print created FunctionCall statement to test. Is there any tool available to view javascript nodes like java ASTVIEW viewer?
You have to create StringLiteral as a argument and add it to functionCall, in othere case it could be NumberLiteral, ArrrayLiteral etc. (see: http://javadox.com/org.mozilla/rhino/1.7R4/org/mozilla/javascript/ast/AstNode.html)
You can print every corect AstNode by toSource() method. I hope this will help.