GetRange() public method

public GetRange ( int startIndex, int exclusiveEndIndex ) : CodeRange
startIndex int
exclusiveEndIndex int
return CodeRange
Example #1
0
 private static List<SeedNode> CreateSeedNodes(StructuredCode structuredCode, CstNode cst, IEnumerable<SelectedFragment> fragments) {
     var lastIndex = -1;
     return fragments.Select(fragment => {
         var startLineIndex = Math.Max(lastIndex + 1, structuredCode.GetIndex(fragment.StartLine, 0));
         var surroundingIndex = structuredCode.Code.IndexOf(fragment.SurroundingText, startLineIndex);
         var targetIndex = structuredCode.Code.IndexOf(fragment.TargetText, surroundingIndex);
         if (surroundingIndex < 0 || targetIndex < 0) {
             throw new Exception("The selected code fragment is invalid.");
         }
         var surroundingRange = structuredCode.GetRange(surroundingIndex,
                 surroundingIndex + fragment.SurroundingText.Length);
         var targetRange = structuredCode.GetRange(targetIndex,
                 targetIndex + fragment.TargetText.Length);
         var node = targetRange.FindOutermostNode(cst);
         lastIndex = surroundingIndex;
         return new SeedNode(node, targetRange, surroundingRange);
     }).ToList();
 }