private boolean tryJavaInvocation(FunctionCall node) throws IOException { if (!(node.getTarget() instanceof PropertyGet)) { return false; } PropertyGet propertyGet = (PropertyGet) node.getTarget(); String callMethod = getJavaMethod(propertyGet.getTarget()); if (callMethod == null || !propertyGet.getProperty().getIdentifier().equals("invoke")) { return false; } MethodReference method = MethodReference.parseIfPossible(callMethod); if (method == null) { return false; } writer.appendMethodBody(method).append('('); printList(node.getArguments()); writer.append(')'); return true; }
private void print(FunctionCall node, int precedence) throws IOException { if (tryJavaInvocation(node)) { return; } if (precedence < PRECEDENCE_FUNCTION) { writer.append('('); } int innerPrecedence = node instanceof NewExpression ? PRECEDENCE_FUNCTION - 1 : PRECEDENCE_FUNCTION; if (node instanceof NewExpression) { writer.append("new "); } print(node.getTarget(), innerPrecedence); writer.append('('); printList(node.getArguments()); writer.append(')'); if (node instanceof NewExpression) { NewExpression newExpr = (NewExpression) node; if (newExpr.getInitializer() != null) { writer.ws(); print(newExpr.getInitializer()); } } if (precedence < PRECEDENCE_FUNCTION) { writer.append(')'); } }
private static Node getCallTarget(FunctionCall n) { return n.getTarget(); } /**
public boolean visit(AstNode node) { if (node instanceof FunctionCall) { FunctionCall call = (FunctionCall) node; node = call.getTarget(); if (node instanceof Name) { Name name = (Name) node; if (funcName.equals(name.toSource())) { target.set(call); return false; } } } return true; } });
private String createLookupString(FunctionCall fn) { StringBuilder sb = new StringBuilder(); String name = ""; switch(fn.getTarget().getType()) { case Token.NAME : name = ((Name) fn.getTarget()).getIdentifier(); break; } sb.append(name); sb.append("("); Iterator<AstNode> i = fn.getArguments().iterator(); while (i.hasNext()) { i.next(); sb.append("p"); if(i.hasNext()) sb.append(","); } sb.append(")"); return sb.toString(); }
@Override public String getFunctionNameLookup(FunctionCall call, SourceCompletionProvider provider) { if (call != null) { StringBuilder sb = new StringBuilder(); if (call.getTarget() instanceof PropertyGet) { PropertyGet get = (PropertyGet) call.getTarget(); sb.append(get.getProperty().getIdentifier()); } sb.append("("); int count = call.getArguments().size(); for (int i = 0; i < count; i++) { sb.append("p"); if (i < count - 1) { sb.append(","); } } sb.append(")"); return sb.toString(); } return null; }
private MethodReference getJavaMethodSelector(AstNode node) { if (!(node instanceof FunctionCall)) { return null; } FunctionCall call = (FunctionCall) node; if (!isJavaMethodRepository(call.getTarget())) { return null; } if (call.getArguments().size() != 1) { diagnostics.error(location, "javaMethods.get method should take exactly one argument"); return null; } StringBuilder nameBuilder = new StringBuilder(); if (!extractMethodName(call.getArguments().get(0), nameBuilder)) { diagnostics.error(location, "javaMethods.get method should take string constant"); return null; } MethodReference method = MethodReference.parseIfPossible(nameBuilder.toString()); if (method == null) { diagnostics.error(location, "Wrong method reference: " + nameBuilder); } return method; }
private Node transformFunctionCall(FunctionCall node) { Node call = createCallOrNew(Token.CALL, transform(node.getTarget())); call.setLineno(node.getLineno()); decompiler.addToken(Token.LP); List<AstNode> args = node.getArguments(); for (int i = 0; i < args.size(); i++) { AstNode arg = args.get(i); call.addChildToBack(transform(arg)); if (i < args.size() - 1) { decompiler.addToken(Token.COMMA); } } decompiler.addToken(Token.RP); return call; }
private Node transformFunctionCall(FunctionCall node) { Node call = createCallOrNew(Token.CALL, transform(node.getTarget())); call.setLineno(node.getLineno()); decompiler.addToken(Token.LP); List<AstNode> args = node.getArguments(); for (int i = 0; i < args.size(); i++) { AstNode arg = args.get(i); call.addChildToBack(transform(arg)); if (i < args.size() - 1) { decompiler.addToken(Token.COMMA); } } decompiler.addToken(Token.RP); return call; }
private Node transformFunctionCall(FunctionCall node) { Node call = createCallOrNew(Token.CALL, transform(node.getTarget())); call.setLineno(node.getLineno()); decompiler.addToken(Token.LP); List<AstNode> args = node.getArguments(); for (int i = 0; i < args.size(); i++) { AstNode arg = args.get(i); call.addChildToBack(transform(arg)); if (i < args.size() - 1) { decompiler.addToken(Token.COMMA); } } decompiler.addToken(Token.RP); return call; }
private Node transformFunctionCall(FunctionCall node) { Node call = createCallOrNew(Token.CALL, transform(node.getTarget())); call.setLineno(node.getLineno()); decompiler.addToken(Token.LP); List<AstNode> args = node.getArguments(); for (int i = 0; i < args.size(); i++) { AstNode arg = args.get(i); call.addChildToBack(transform(arg)); if (i < args.size() - 1) { decompiler.addToken(Token.COMMA); } } decompiler.addToken(Token.RP); return call; }
private boolean tryJavaInvocation(FunctionCall node) throws IOException { if (!(node.getTarget() instanceof PropertyGet)) { return false; } PropertyGet propertyGet = (PropertyGet) node.getTarget(); String callMethod = getJavaMethod(propertyGet.getTarget()); if (callMethod == null || !propertyGet.getProperty().getIdentifier().equals("invoke")) { return false; } MethodReference method = MethodReference.parseIfPossible(callMethod); if (method == null) { return false; } writer.appendMethodBody(method).append('('); printList(node.getArguments()); writer.append(')'); return true; }
case CALL: { FunctionCall call = (FunctionCall) node; String name = nameOf(call.getTarget());
private boolean visit(FunctionCall call) { if (!(call.getTarget() instanceof PropertyGet)) { return true; PropertyGet propertyGet = (PropertyGet) call.getTarget(); MethodReference methodRef = getJavaMethodSelector(propertyGet.getTarget()); if (methodRef == null || !propertyGet.getProperty().getIdentifier().equals("invoke")) {
private void print(FunctionCall node, int precedence) throws IOException { if (tryJavaInvocation(node)) { return; } if (precedence < PRECEDENCE_FUNCTION) { writer.append('('); } int innerPrecedence = node instanceof NewExpression ? PRECEDENCE_FUNCTION - 1 : PRECEDENCE_FUNCTION; if (node instanceof NewExpression) { writer.append("new "); } print(node.getTarget(), innerPrecedence); writer.append('('); printList(node.getArguments()); writer.append(')'); if (node instanceof NewExpression) { writer.ws(); NewExpression newExpr = (NewExpression) node; if (newExpr.getInitializer() != null) { print(newExpr.getInitializer()); } } if (precedence < PRECEDENCE_FUNCTION) { writer.append(')'); } }
@Override public CAstNode visitFunctionCall(FunctionCall n, WalkContext context) { if (!isPrimitiveCall(context, n)) { AstNode callee = n.getTarget(); int thisBaseVarNum = ++tempVarNum; WalkContext child = new MemberDestructuringContext(context, callee, thisBaseVarNum);
@Override public CAstNode visitUnaryExpression(UnaryExpression node, WalkContext arg) { if (node.getType() == Token.INC || node.getType() == Token.DEC) { CAstNode op = (node.getType() == Token.DEC) ? CAstOperator.OP_SUB : CAstOperator.OP_ADD; AstNode l = node.getOperand(); CAstNode last = visit(l, arg); return Ast.makeNode((node.isPostfix() ? CAstNode.ASSIGN_POST_OP : CAstNode.ASSIGN_PRE_OP), last, Ast.makeConstant(1), op); } else if (node.getType() == Token.TYPEOFNAME) { return Ast.makeNode(CAstNode.TYPE_OF, Ast.makeNode(CAstNode.VAR, Ast.makeConstant(node.getString()))); } else if (node.getType() == Token.TYPEOF) { return Ast.makeNode(CAstNode.TYPE_OF, visit(node.getOperand(), arg)); } else if (node.getType() == Token.DELPROP) { AstNode expr = node.getOperand(); if (expr instanceof FunctionCall) { expr = ((FunctionCall) expr).getTarget(); assert expr instanceof PropertyGet; } return Ast.makeNode(CAstNode.ASSIGN, visit(expr, arg), Ast.makeConstant(null)); } else if (node.getType() == Token.VOID) { return Ast.makeConstant(null); } else { return Ast.makeNode(CAstNode.UNARY_EXPR, translateOpcode(node.getOperator()), visit(node.getOperand(), arg)); } }