private IBoundNode validateNode(ISyntaxNode node, IBindingContext bindingContext) { if (node.getNumberOfChildren() < 1) { return makeErrorNode("New node should have at least one subnode", node, bindingContext); } return null; } }
private IBoundNode validateNode(ISyntaxNode node, IBindingContext bindingContext) { if (node.getNumberOfChildren() < 1) { return makeErrorNode("New node should have at least one subnode", node, bindingContext); } return null; } }
private String concatChildren(ISyntaxNode node) { StringBuilder builder = new StringBuilder(100); for (int i = 0; i < node.getNumberOfChildren(); i++) { builder.append(((IdentifierNode) node.getChild(i)).getIdentifier()); } return builder.toString(); }
private String concatChildren(ISyntaxNode node) { StringBuilder builder = new StringBuilder(100); for (int i = 0; i < node.getNumberOfChildren(); i++) { builder.append(((IdentifierNode) node.getChild(i)).getIdentifier()); } return builder.toString(); }
private static ISyntaxNode getIdentifierSyntaxNode(ISyntaxNode syntaxNode) { if (!(syntaxNode instanceof IdentifierNode)) { if ("function".equals(syntaxNode.getType())) { syntaxNode = syntaxNode.getChild(syntaxNode.getNumberOfChildren() - 1); } } return syntaxNode; }
private static IBoundNode[] makeLocalVarsFromWhere(ISyntaxNode whereNode, IBindingContext bindingContext) throws Exception { int n = whereNode.getNumberOfChildren(); IBoundNode[] boundNodes = new IBoundNode[n + 1]; for (int i = 0; i < n; i++) { boundNodes[i] = makeLocalVar(whereNode.getChild(i), bindingContext); } return boundNodes; }
private static IBoundNode[] makeLocalVarsFromWhere(ISyntaxNode whereNode, IBindingContext bindingContext) throws Exception { int n = whereNode.getNumberOfChildren(); IBoundNode[] boundNodes = new IBoundNode[n + 1]; for (int i = 0; i < n; i++) { boundNodes[i] = makeLocalVar(whereNode.getChild(i), bindingContext); } return boundNodes; }
public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { if (node.getNumberOfChildren() != 2) { throw SyntaxNodeExceptionUtils.createError("Binary node must have 2 subnodes", node); } int index = node.getType().lastIndexOf('.'); String methodName = node.getType().substring(index + 1); IBoundNode[] children = bindChildren(node, bindingContext); return bindOperator(node, methodName, children[0], children[1], bindingContext); }
public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { if (node.getNumberOfChildren() != 2) { throw SyntaxNodeExceptionUtils.createError("Binary node must have 2 subnodes", node); } int index = node.getType().lastIndexOf('.'); String methodName = node.getType().substring(index + 1); IBoundNode[] children = bindChildren(node, bindingContext); return bindOperator(node, methodName, children[0], children[1], bindingContext); }
public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { if ("list".equals(node.getType())) { IBoundNode[] children = bindChildren(node, bindingContext); String[] res = new String[children.length]; for (int i = 0; i < res.length; i++) { res[i] = (String) ((LiteralBoundNode) children[i]).getValue(); } return new LiteralBoundNode(node, res, JavaOpenClass.getOpenClass(String[].class)); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < node.getNumberOfChildren(); i++) { ISyntaxNode child = node.getChild(i); if (i > 0) { sb.append(' '); } sb.append(((IdentifierNode) child).getIdentifier()); } return new LiteralBoundNode(node, sb.toString(), JavaOpenClass.STRING); }
public ILocation getParamTypeLocation(int paramNum) { // 0-th child is param type, 1-st child is param name. See ParameterDeclarationNodeBinder ISyntaxNode typeNode = children[paramNum].getSyntaxNode().getChild(0); while (typeNode.getNumberOfChildren() == 1 && !(typeNode instanceof IdentifierNode)) { // Get type node for array typeNode = typeNode.getChild(0); } return typeNode.getSourceLocation(); }
public ILocation getParamTypeLocation(int paramNum) { // 0-th child is param type, 1-st child is param name. See ParameterDeclarationNodeBinder ISyntaxNode typeNode = children[paramNum].getSyntaxNode().getChild(0); while (typeNode.getNumberOfChildren() == 1 && !(typeNode instanceof IdentifierNode)) { // Get type node for array typeNode = typeNode.getChild(0); } return typeNode.getSourceLocation(); }
public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { if (node.getNumberOfChildren() != 1) { return makeErrorNode("Unary node should have 1 subnode", node, bindingContext); } int index = node.getType().lastIndexOf('.'); String methodName = node.getType().substring(index + 1); IBoundNode[] children = bindChildren(node, bindingContext); IOpenClass[] types = getTypes(children); IMethodCaller methodCaller = findUnaryOperatorMethodCaller(methodName, types, bindingContext); if (methodCaller == null) { String message = errorMsg(methodName, types[0]); return makeErrorNode(message, node, bindingContext); } return new UnaryOpNode(node, children, methodCaller); }
public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { if (node.getNumberOfChildren() != 1) { return makeErrorNode("Unary node should have 1 subnode", node, bindingContext); } int index = node.getType().lastIndexOf('.'); String methodName = node.getType().substring(index + 1); IBoundNode[] children = bindChildren(node, bindingContext); IOpenClass[] types = getTypes(children); IMethodCaller methodCaller = findUnaryOperatorMethodCaller(methodName, types, bindingContext); if (methodCaller == null) { String message = errorMsg(methodName, types[0]); return makeErrorNode(message, node, bindingContext); } return new UnaryOpNode(node, children, methodCaller); }
@Override public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { ISyntaxNode nameSyntaxNode; ISyntaxNode typeSyntaxNode; IBoundNode typeBoundNode = null; if (node.getNumberOfChildren() == 1) { nameSyntaxNode = node.getChild(0); } else { typeSyntaxNode = node.getChild(0); typeBoundNode = bindChildNode(typeSyntaxNode, bindingContext); nameSyntaxNode = node.getChild(1); } String name = ((IdentifierNode)nameSyntaxNode).getIdentifier(); return new IndexParameterNode(node, typeBoundNode, name); }
@Override public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { if (node.getNumberOfChildren() != 2) { return makeErrorNode("Binary node must have 2 subnodes", node, bindingContext); } IBoundNode[] children = bindChildren(node, bindingContext); IOpenClass[] types = getTypes(children); if ((types[0].getInstanceClass() == boolean.class || types[0].getInstanceClass() == Boolean.class) && (types[1].getInstanceClass() == boolean.class || types[1].getInstanceClass() == Boolean.class)) { return new BinaryOpNodeAnd(node, children); } int index = node.getType().lastIndexOf('.'); String methodName = node.getType().substring(index + 1); IMethodCaller methodCaller = findBinaryOperatorMethodCaller(methodName, types, bindingContext); if (methodCaller == null) { String message = errorMsg(methodName, types[0], types[1]); return makeErrorNode(message, node, bindingContext); } return new BinaryOpNode(node, children, methodCaller); }
public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { IOpenClass returnType; IBoundNode exprNode = null; if (node.getNumberOfChildren() == 1) { returnType = bindingContext.getReturnType(); if (returnType == NullOpenClass.the) { IBoundNode chNode = bindChildNode(node.getChild(0), bindingContext); bindingContext.setReturnType(returnType = chNode.getType()); } exprNode = bindTypeNode(node.getChild(0), bindingContext, returnType); } else if (bindingContext.getReturnType() != JavaOpenClass.VOID) { return makeErrorNode("The method must return a value", node, bindingContext); } IBoundNode[] children = {}; if (exprNode != null) { children = new IBoundNode[] { exprNode }; } return new ReturnNode(node, children); }
public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { IOpenClass returnType; IBoundNode exprNode = null; if (node.getNumberOfChildren() == 1) { returnType = bindingContext.getReturnType(); if (returnType == NullOpenClass.the) { IBoundNode chNode = bindChildNode(node.getChild(0), bindingContext); bindingContext.setReturnType(returnType = chNode.getType()); } exprNode = bindTypeNode(node.getChild(0), bindingContext, returnType); } else if (bindingContext.getReturnType() != JavaOpenClass.VOID) { return makeErrorNode("The method must return a value", node, bindingContext); } IBoundNode[] children = {}; if (exprNode != null) { children = new IBoundNode[] { exprNode }; } return new ReturnNode(node, children); }
public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { IBoundNode conditionNode = bindChildNode(node.getChild(0), bindingContext); IBoundNode checkConditionNode = BindHelper.checkConditionBoundNode(conditionNode, bindingContext); if (checkConditionNode != conditionNode) return checkConditionNode; IBoundNode thenNode = bindChildNode(node.getChild(1), bindingContext); IOpenClass type = thenNode.getType(); if (node.getNumberOfChildren() == 3) { // else branch IBoundNode elseNode = bindChildNode(node.getChild(2), bindingContext); IOpenClass elseType = elseNode.getType(); return buildIfElseNode(node, bindingContext, conditionNode, thenNode, type, elseNode, elseType); } else { return new IfNode(node, conditionNode, thenNode, type); } }
public IBoundNode bind(ISyntaxNode node, IBindingContext bindingContext) throws Exception { IBoundNode conditionNode = bindChildNode(node.getChild(0), bindingContext); IBoundNode checkConditionNode = BindHelper.checkConditionBoundNode(conditionNode, bindingContext); if (checkConditionNode != conditionNode) return checkConditionNode; IBoundNode thenNode = bindChildNode(node.getChild(1), bindingContext); IOpenClass type = thenNode.getType(); if (node.getNumberOfChildren() == 3) { // else branch IBoundNode elseNode = bindChildNode(node.getChild(2), bindingContext); IOpenClass elseType = elseNode.getType(); return buildIfElseNode(node, bindingContext, conditionNode, thenNode, type, elseNode, elseType); } else { return new IfNode(node, conditionNode, thenNode, type); } }