void () { CommonCodeStyleSettings.IndentOptions indentOptions = CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE).getIndentOptions(); assertNotNull(indentOptions); boolean keepIndents = indentOptions.KEEP_INDENTS_ON_EMPTY_LINES; EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance(); String stripSpaces = editorSettings.getStripTrailingSpaces(); try { editorSettings.setStripTrailingSpaces(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE); indentOptions.KEEP_INDENTS_ON_EMPTY_LINES = true; final String initial = """ <caret>package com.acme; class Foo { Integer[] foo() { \s \s return new Integer[]{0, 1}; } \s }"""; final String expected = """ package com.acme; class Foo { Integer[] foo() { \s \s return new Integer[]{0, 1}; } \s }"""; configureFromFileText(getTestName(false) + ".java", initial); //WriteCommandAction.runWriteCommandAction(getProject(), () -> CodeStyleManager.getInstance(getProject()) // .reformatText(getFile(), 0, getEditor().getDocument().getTextLength())); Document doc = getEditor().getDocument(); EditorTestUtil.performTypingAction(getEditor(), ' '); PsiDocumentManager.getInstance(getProject()).commitDocument(doc); FileDocumentManager.getInstance().saveAllDocuments(); checkResultByText(expected); } finally { indentOptions.KEEP_INDENTS_ON_EMPTY_LINES = keepIndents; editorSettings.setStripTrailingSpaces(stripSpaces); } }