/**
  * @return position <code>x</code> for which <code>
  *     myDocument.getText().substring(x, startOffset)</code> contains <code>blankLinesNumber
  *     </code> line feeds and <code>myDocument.getText.charAt(x-1) == '\n'</code>
  */
 private int getBlankLineOffset(int blankLinesNumber, int startOffset) {
   int startLine = myDocument.getLineNumber(startOffset);
   if (startLine <= 0) {
     return 0;
   }
   CharSequence text = myDocument.getCharsSequence();
   for (int i = myDocument.getLineStartOffset(startLine - 1) - 1;
       i >= 0;
       i = CharArrayUtil.lastIndexOf(text, "\n", i - 1)) {
     if (--blankLinesNumber <= 0) {
       return i + 1;
     }
   }
   return 0;
 }
 @NotNull
 private String calcText() {
   StringBuilder text = new StringBuilder();
   CharSequence hostText = myDelegate.getCharsSequence();
   synchronized (myLock) {
     for (PsiLanguageInjectionHost.Shred shred : myShreds) {
       Segment hostRange = shred.getHostRangeMarker();
       if (hostRange != null) {
         text.append(shred.getPrefix());
         text.append(hostText, hostRange.getStartOffset(), hostRange.getEndOffset());
         text.append(shred.getSuffix());
       }
     }
   }
   return text.toString();
 }