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

The following examples show how to use org.antlr.v4.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: ParsingUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Get ancestors where the first element of the list is the parent of t */
public static List<? extends Tree> getAncestors(Tree t) {
	if ( t.getParent()==null ) return Collections.emptyList();
	List<Tree> ancestors = new ArrayList<>();
	t = t.getParent();
	while ( t!=null ) {
		ancestors.add(t); // insert at start
		t = t.getParent();
	}
	return ancestors;
}
 
Example 2
Source File: RefactorUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static ParseTree getAncestorWithType(ParseTree t, Class<? extends ParseTree> clazz) {
	if ( t==null || clazz==null || t.getParent()==null ) return null;
	Tree p = t.getParent();
	while ( p!=null ) {
		if ( p.getClass()==clazz ) return (ParseTree)p;
		p = p.getParent();
	}
	return null;
}
 
Example 3
Source File: TreeLayoutAdaptor.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public boolean isChildOfParent(Tree node, Tree parentNode) {
	return node.getParent() == parentNode;
}