public void freshenParentAndChildIndexesDeeply(int offset) { int n = getChildCount(); for (int c = offset; c < n; c++) { BaseTree child = (BaseTree)getChild(c); child.setChildIndex(c); child.setParent(this); child.freshenParentAndChildIndexesDeeply(); } }
/** Add all elements of kids list as children of this node */ public void addChildren(List<? extends Tree> kids) { for (int i = 0; i < kids.size(); i++) { Tree t = kids.get(i); addChild(t); } }
/** Insert child t at child position i (0..n-1) by shifting children i+1..n-1 to the right one position. Set parent / indexes properly but does NOT collapse nil-rooted t's that come in here like addChild. */ public void insertChild(int i, Object t) { if (i < 0 || i > getChildCount()) { throw new IndexOutOfBoundsException(i+" out or range"); } if (children == null) { children = createChildrenList(); } children.add(i, t); // walk others to increment their child indexes // set index, parent of this one too this.freshenParentAndChildIndexes(i); }
public void sanityCheckParentAndChildIndexes(Tree parent, int i) { if ( parent!=this.getParent() ) { throw new IllegalStateException("parents don't match; expected "+parent+" found "+this.getParent()); } if ( i!=this.getChildIndex() ) { throw new IllegalStateException("child indexes don't match; expected "+i+" found "+this.getChildIndex()); } int n = this.getChildCount(); for (int c = 0; c < n; c++) { CommonTree child = (CommonTree)this.getChild(c); child.sanityCheckParentAndChildIndexes(this, c); } }
if ( childTree.isNil() ) { // t is an empty node possibly with children if ( this.children!=null && this.children == childTree.children ) { throw new RuntimeException("attempt to add child list to itself"); this.freshenParentAndChildIndexes(); children = createChildrenList(); // create children list on demand childTree.setParent(this); childTree.setChildIndex(children.size()-1);
public void freshenParentAndChildIndexes(int offset) { int n = getChildCount(); for (int c = offset; c < n; c++) { Tree child = getChild(c); child.setChildIndex(c); child.setParent(this); } }
/** Print out a whole tree not just a node */ public String toStringTree() { if ( children==null || children.size()==0 ) { return this.toString(); } StringBuffer buf = new StringBuffer(); if ( !isNil() ) { buf.append("("); buf.append(this.toString()); buf.append(' '); } for (int i = 0; children!=null && i < children.size(); i++) { Tree t = (Tree)children.get(i); if ( i>0 ) { buf.append(' '); } buf.append(t.toStringTree()); } if ( !isNil() ) { buf.append(")"); } return buf.toString(); }
/** Set the parent and child index values for all child of t */ @Override public void freshenParentAndChildIndexes() { freshenParentAndChildIndexes(0); }
/** Walk upwards looking for ancestor with this token type. */ @Override public boolean hasAncestor(int ttype) { return getAncestor(ttype)!=null; }
public void sanityCheckParentAndChildIndexes() { sanityCheckParentAndChildIndexes(null, -1); }
public void setChild(int i, Tree t) { if ( t==null ) { return; } if ( t.isNil() ) { throw new IllegalArgumentException("Can't set single child to a list"); } if ( children==null ) { children = createChildrenList(); } children.set(i, t); t.setParent(this); t.setChildIndex(i); }
/** Return a list of all ancestors of this node. The first node of * list is the root and the last is the parent of this node. */ public List getAncestors() { if ( getParent()==null ) return null; List ancestors = new ArrayList(); Tree t = this; t = t.getParent(); while ( t!=null ) { ancestors.add(0, t); // insert at start t = t.getParent(); } return ancestors; }
if ( childTree.isNil() ) { // t is an empty node possibly with children if ( this.children!=null && this.children == childTree.children ) { throw new RuntimeException("attempt to add child list to itself"); this.freshenParentAndChildIndexes(); children = createChildrenList(); // create children list on demand childTree.setParent(this); childTree.setChildIndex(children.size()-1);
public void sanityCheckParentAndChildIndexes(Tree parent, int i) { if ( parent!=this.getParent() ) { throw new IllegalStateException("parents don't match; expected "+parent+" found "+this.getParent()); } if ( i!=this.getChildIndex() ) { throw new IllegalStateException("child indexes don't match; expected "+i+" found "+this.getChildIndex()); } int n = this.getChildCount(); for (int c = 0; c < n; c++) { CommonTree child = (CommonTree)this.getChild(c); child.sanityCheckParentAndChildIndexes(this, c); } }
public void freshenParentAndChildIndexes(int offset) { int n = getChildCount(); for (int c = offset; c < n; c++) { Tree child = getChild(c); child.setChildIndex(c); child.setParent(this); } }
/** Print out a whole tree not just a node */ @Override public String toStringTree() { if ( children==null || children.isEmpty() ) { return this.toString(); } StringBuilder buf = new StringBuilder(); if ( !isNil() ) { buf.append("("); buf.append(this.toString()); buf.append(' '); } for (int i = 0; children!=null && i < children.size(); i++) { Tree t = (Tree)children.get(i); if ( i>0 ) { buf.append(' '); } buf.append(t.toStringTree()); } if ( !isNil() ) { buf.append(")"); } return buf.toString(); }
/** Set the parent and child index values for all child of t */ @Override public void freshenParentAndChildIndexes() { freshenParentAndChildIndexes(0); }
/** Walk upwards looking for ancestor with this token type. */ @Override public boolean hasAncestor(int ttype) { return getAncestor(ttype)!=null; }
public void sanityCheckParentAndChildIndexes() { sanityCheckParentAndChildIndexes(null, -1); }
@Override public void setChild(int i, Tree t) { if ( t==null ) { return; } if ( t.isNil() ) { throw new IllegalArgumentException("Can't set single child to a list"); } if ( children==null ) { children = createChildrenList(); } children.set(i, t); t.setParent(this); t.setChildIndex(i); }