@Override
 @NotNull
 public String getLineSeparator(@Nullable VirtualFile file, @Nullable Project project) {
   String lineSeparator = file == null ? null : LoadTextUtil.getDetectedLineSeparator(file);
   if (lineSeparator == null) {
     CodeStyleFacade settingsManager =
         project == null ? CodeStyleFacade.getInstance() : CodeStyleFacade.getInstance(project);
     lineSeparator = settingsManager.getLineSeparator();
   }
   return lineSeparator;
 }
  public static String calcStringToFillVirtualSpace(Editor editor, int afterLineEnd) {
    final Project project = editor.getProject();
    StringBuilder buf = new StringBuilder();
    final Document doc = editor.getDocument();
    final int caretOffset = editor.getCaretModel().getOffset();
    boolean atLineStart =
        caretOffset >= doc.getTextLength()
            || doc.getLineStartOffset(doc.getLineNumber(caretOffset)) == caretOffset;
    if (atLineStart && project != null) {
      int offset = editor.getCaretModel().getOffset();
      PsiDocumentManager.getInstance(project)
          .commitDocument(doc); // Sync document and PSI before formatting.
      String properIndent =
          offset >= doc.getTextLength()
              ? ""
              : CodeStyleFacade.getInstance(project).getLineIndent(doc, offset);
      if (properIndent != null) {
        int tabSize = editor.getSettings().getTabSize(project);
        for (int i = 0; i < properIndent.length(); i++) {
          if (properIndent.charAt(i) == ' ') {
            afterLineEnd--;
          } else if (properIndent.charAt(i) == '\t') {
            if (afterLineEnd < tabSize) {
              break;
            }
            afterLineEnd -= tabSize;
          }
          buf.append(properIndent.charAt(i));
          if (afterLineEnd == 0) break;
        }
      }
    }

    for (int i = 0; i < afterLineEnd; i++) {
      buf.append(' ');
    }

    return buf.toString();
  }