Microsoft.Cci.SourceDocumentWithInclusion.GetCorrespondingSourceLocation C# (CSharp) Method

GetCorrespondingSourceLocation() public method

Returns a source location in this document that corresponds to the given source location from a previous version of this document.
public GetCorrespondingSourceLocation ( ISourceLocation sourceLocationInPreviousVersionOfDocument ) : ISourceLocation
sourceLocationInPreviousVersionOfDocument ISourceLocation
return ISourceLocation
    public ISourceLocation GetCorrespondingSourceLocation(ISourceLocation sourceLocationInPreviousVersionOfDocument)
      //^^ requires this.IsUpdatedVersionOf(sourceLocationInPreviousVersionOfDocument.SourceDocument);
    {
      ISourceDocument previousSourceDocument = sourceLocationInPreviousVersionOfDocument.SourceDocument;
      //^ assume previousSourceDocument is SourceDocumentWithInclusion; //otherwise this could not be an updated version of previousSourceDocument
      ISourceDocument previousWrappedDocument = ((SourceDocumentWithInclusion)previousSourceDocument).WrappedDocument;
      int position = sourceLocationInPreviousVersionOfDocument.StartIndex;
      //^ assert position >= 0 && (position < sourceLocationInPreviousVersionOfDocument.SourceDocument.Length || position == 0); //follows from post condition
      //^ assume position >= 0 && (position < previousWrappedDocument.Length || position == 0); //assume that things stay the same when unwrapping
      int prevLength = sourceLocationInPreviousVersionOfDocument.Length;
      //^ assert prevLength >= 0 && sourceLocationInPreviousVersionOfDocument.StartIndex+prevLength <= sourceLocationInPreviousVersionOfDocument.SourceDocument.Length;
      //^ assume prevLength <= previousWrappedDocument.Length && position+prevLength <= previousWrappedDocument.Length; //assume that things stay the same when unwrapping
      ISourceLocation previousWrappedLocation = previousWrappedDocument.GetSourceLocation(position, prevLength);
      ISourceDocument wrappedDocument = this.WrappedDocument;
      //^ assume wrappedDocument.IsUpdatedVersionOf(previousWrappedLocation.SourceDocument);
      ISourceLocation newWrappedLocation = wrappedDocument.GetCorrespondingSourceLocation(previousWrappedLocation);
      int newLength = newWrappedLocation.Length;
      //^ assume newLength <= this.Length; //assume that things stay the same when unwrapping
      //^ assume false;
      return this.GetSourceLocation(newWrappedLocation.StartIndex, newLength);
    }