private void PostWalkWorker(SuiteStatement node) { if (_targetNode == null && node.StartIndex <= _start && node.EndIndex >= _end) { // figure out the range of statements we cover... int startIndex = 0, endIndex = node.Statements.Count - 1; for (int i = 0; i < node.Statements.Count; i++) { if (node.Statements[i].EndIndex >= _start) { startIndex = i; break; } } for (int i = node.Statements.Count - 1; i >= 0; i--) { if (node.Statements[i].StartIndex < _end) { endIndex = i; break; } } List <SuiteStatement> followingSuites = new List <SuiteStatement>(); for (int i = _suites.Count - 1; i >= 0; i--) { if (_suites[i] == null) { // we hit our marker, this is a function/class boundary // We don't care about any suites which come before the marker // because they live in a different scope. We insert the marker in // ShouldWalkWorker(Node node) when we have a ScopeStatement. break; } followingSuites.Add(_suites[i]); } _targetNode = new SuiteTarget( _insertLocations, _parents.ToArray(), node, followingSuites.ToArray(), _end, startIndex, endIndex ); _insertLocations[_parents[_parents.Count - 1]] = node.Statements.Count == 0 ? node.GetStartIncludingIndentation(_root) : node.Statements[startIndex].GetStartIncludingIndentation(_root); } }