GetIndex() public method

public GetIndex ( CodeLocation location ) : int
location CodeLocation
return int
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();
 }
Example #2
0
 public void ConvertToIndicies(
     StructuredCode code, out int inclusiveStart, out int exclusiveEnd)
 {
     inclusiveStart = code.GetIndex(StartLocation);
     exclusiveEnd   = code.GetIndex(EndLocation);
 }