public SyntaxNodeOrToken GetNextSibling() { SyntaxNode parent = this.Parent; if (parent == null) { return(default(SyntaxNodeOrToken)); } ChildSyntaxList siblings = parent.ChildNodesAndTokens(); return(siblings.Count < 8 ? GetNextSiblingFromStart(siblings) : GetNextSiblingWithSearch(siblings)); }
private SyntaxNodeOrToken GetNextSiblingFromStart(ChildSyntaxList siblings) { bool returnNext = false; foreach (SyntaxNodeOrToken sibling in siblings) { if (returnNext) { return(sibling); } if (sibling == this) { returnNext = true; } } return(default(SyntaxNodeOrToken)); }
internal static int GetFirstChildIndexSpanningPosition(ChildSyntaxList list, int position) { int lo = 0; int hi = list.Count - 1; while (lo <= hi) { int r = lo + ((hi - lo) >> 1); SyntaxNodeOrToken m = list[r]; if (position < m.Position) { hi = r - 1; } else { if (position == m.Position) { // If we hit a zero width node, move left to the first such node (or the // first one in the list) for (; r > 0 && list[r - 1].FullWidth == 0; r--) { ; } return(r); } if (position >= m.EndPosition) { lo = r + 1; continue; } return(r); } } throw ExceptionUtilities.Unreachable; }
private SyntaxNodeOrToken GetNextSiblingWithSearch(ChildSyntaxList siblings) { int firstIndex = GetFirstChildIndexSpanningPosition(siblings, _position); int count = siblings.Count; bool returnNext = false; for (int i = firstIndex; i < count; i++) { if (returnNext) { return(siblings[i]); } if (siblings[i] == this) { returnNext = true; } } return(default(SyntaxNodeOrToken)); }