/** * @param obj * @param text * @param addChildren * @return */ public ArrayList<String> getChildrenList( String obj, String text, boolean addChildren, boolean firstLine) { Node[] c = getChildren(obj, text); this.suggestions.clear(); if (c != null) { for (int idx = 0; idx < c.length; idx++) { if (addChildren) { this.addChildToList(c[idx], c[idx].getToken(), this.suggestions); } else { this.suggestions.add(c[idx].getToken()); } } } if (text.trim().length() == 0 || this.suggestions.isEmpty()) { // in the event the list is empty, we also add // the top level nodes for (Node t : rootCond.getChildren()) { if ((!firstLine || t.getToken() != null) && !this.suggestions.contains(t.getToken())) { if (addChildren) { this.addChildToList(t, t.getToken(), this.suggestions); } else { this.suggestions.add(t.getToken()); } } } } return this.suggestions; }
/** * method will print the node and then iterate over the children * * @param n */ protected void printNode(Node n) { printTabs(n.getDepth()); System.out.println("- \"" + n.getToken() + "\""); for (Node c : n.getChildren()) { printNode(c); } }
/** * method will prepend the parent text to the child and generate the possible combinations in text * format. * * @param n * @param prefix * @param list */ public void addChildToList(Node n, String prefix, ArrayList<String> list) { if (n.getChildren().size() > 0) { for (Node child : n.getChildren()) { if (prefix != null && "-".equals(child.getToken())) { if (!list.contains(prefix)) { list.add(prefix); } return; } String text = (prefix == null ? "" : prefix + " ") + child.getToken(); // list.add(text); addChildToList(child, text, list); } } else { if (!list.contains(prefix)) { list.add(prefix); } } }
/** * the method expects the caller to pass the object * * @param obj * @param text * @return */ public Node[] getChildren(String obj, String text) { Node thenode = this.rootCond.getChild(obj); if (thenode == null) { for (Node child : this.rootCond.getChildren()) { String tokenText = child.getToken(); if (tokenText != null) { int index = tokenText.indexOf("{"); if (index != -1) { String substring = tokenText.substring(0, index); if (obj != null && obj.startsWith(substring)) { thenode = child; } } } } } if (thenode != null && text.length() > 0) { StringTokenizer tokenz = new StringTokenizer(text); this.last = this.current; while (tokenz.hasMoreTokens()) { String strtk = tokenz.nextToken(); Node ch = thenode.getChild(strtk); // if a child is found, we set thenode to the child Node if (ch != null) { thenode = ch; } else { break; } } if (thenode != this.rootCond) { this.current = thenode; } } if (thenode == null) { return null; // thenode = this.rootCond; } Collection<Node> children = thenode.getChildren(); Node[] nchild = new Node[children.size()]; return children.toArray(nchild); }
/** * Create a new lexer token literal based on a parent node (source, token, finish) * * @param parent parent node * @param value lexer token * @return the new literal node */ public static LiteralNode<?> newInstance(final Node parent, final LexerToken value) { return new LexerTokenLiteralNode(parent.getToken(), parent.getFinish(), value); }
/** * Create a new String literal based on a parent node (source, token, finish) * * @param parent parent node * @param value string value * @return the new literal node */ public static LiteralNode<?> newInstance(final Node parent, final String value) { return new StringLiteralNode(parent.getToken(), parent.getFinish(), value); }
/** * Create a new null literal based on a parent node (source, token, finish) * * @param parent parent node * @param value undefined value * @return the new literal node */ public static LiteralNode<?> newInstance(final Node parent, final Undefined value) { return new UndefinedLiteralNode(parent.getToken(), parent.getFinish()); }
/** * Create a new number literal based on a parent node (source, token, finish) * * @param parent parent node * @param value literal value * @return the new literal node */ public static LiteralNode<?> newInstance(final Node parent, final Number value) { return new NumberLiteralNode(parent.getToken(), parent.getFinish(), value); }
/** * Create a new null literal based on a parent node (source, token, finish) * * @param parent parent node * @return the new literal node */ public static LiteralNode<Object> newInstance(final Node parent) { return new NullLiteralNode(parent.getToken(), parent.getFinish()); }
/** * Create a new array literal based on a parent node (source, token, finish) * * @param parent parent node * @param value literal value list * @return the new literal node */ public static LiteralNode<?> newInstance(final Node parent, final List<Expression> value) { return new ArrayLiteralNode(parent.getToken(), parent.getFinish(), valueToArray(value)); }