private static TextRange calculateLimitRange(final PsiFile file, final Document doc, final int line) {
    final int offset = doc.getLineStartOffset(line);
    if (offset > 0) {
      PsiMethod method = PsiTreeUtil.getParentOfType(file.findElementAt(offset), PsiMethod.class, false);
      if (method != null) {
        final TextRange elemRange = method.getTextRange();
        return new TextRange(doc.getLineNumber(elemRange.getStartOffset()), doc.getLineNumber(elemRange.getEndOffset()));
      }
    }
    return new TextRange(0, doc.getLineCount() - 1);
  }
private static TextRange calculateLimitRange(final PsiFile file, final Document doc, final int line)