Java Code Examples for org.antlr.runtime.tree.Tree#getParent()

The following examples show how to use org.antlr.runtime.tree.Tree#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryParserUtils.java    From spork with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
static void replaceNodeWithNodeList(Tree oldNode, CommonTree newTree,
        String fileName) {
    int idx = oldNode.getChildIndex();

    CommonTree parent = (CommonTree) oldNode.getParent();
    int count = parent.getChildCount();

    List childList = new ArrayList(parent.getChildren());
    List macroList = newTree.getChildren();

    while (parent.getChildCount() > 0) {
        parent.deleteChild(0);
    }

    for (int i = 0; i < count; i++) {
        if (i == idx) {
            // add only there is something to add
            if (macroList != null) {
                parent.addChildren(macroList);
            }
        } else {
            parent.addChild((Tree) childList.get(i));
        }
    }
}
 
Example 2
Source File: PathNodeFinder.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected boolean isSelectedPathNode(PathNode pathNode) {
    Tree node = pathNode;
    while (node.getParent() != null) {
        if (node.getParent() instanceof SelectedItemNode) {
            return true;
        }
        node = node.getParent();
    }
    return false;
}