void (@NotNull Environment env) { PsiDocumentManager.getInstance(getProject()).commitDocument(getDocument()); int randomOffset = generatePsiOffset(env, null); PsiElement leaf = getFile().findElementAt(randomOffset); TextRange leafRange = leaf != null ? leaf.getTextRange() : null; int insertOffset = leafRange != null ? leafRange.getEndOffset() : 0; env.logMessage("Inserting '" + StringUtil.escapeStringCharacters(myToInsert) + "' at " + MadTestingUtil.getPositionDescription(insertOffset, getDocument())); WriteCommandAction.runWriteCommandAction(getProject(), () -> getDocument().insertString(insertOffset, myToInsert)); }