private void setDocumentText(final int index, final String text, final Object[] documents) {
    final Object document = documents[index];
    if (document instanceof PlainDocument) {
      try {
        ((PlainDocument)document).remove(0, ((PlainDocument)document).getLength());
        ((PlainDocument)document).insertString(0, text, null);
      }
      catch (BadLocationException e) {
        throw new RuntimeException(e);
      }
    }
    else {
      WriteCommandAction.runWriteCommandAction(myProject, null, null,
                                               () -> ((Document)document).replaceString(0, ((Document)document).getTextLength(), text));
    }
  }
private void setDocumentText(final int index, final String text, final Object[] documents)