void (@NotNull Project project, @NotNull Editor editor, int howtoReformat, int startOffset, int endOffset, int anchorColumn, boolean indentBeforeReformat) { if (startOffset < 0 || endOffset > editor.getDocument().getTextLength() || endOffset < startOffset) { throw new IllegalArgumentException("Invalid offsets: startOffset="+startOffset+"; endOffset="+endOffset+"; document length="+editor.getDocument().getTextLength()); } PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()); switch (howtoReformat) { case CodeInsightSettings.INDENT_BLOCK -> indentBlock(project, editor, startOffset, endOffset, anchorColumn); case CodeInsightSettings.INDENT_EACH_LINE -> indentEachLine(project, editor, startOffset, endOffset); case CodeInsightSettings.REFORMAT_BLOCK -> { final RangeMarker bounds = editor.getDocument().createRangeMarker(startOffset, endOffset); if (indentBeforeReformat) { indentEachLine(project, editor, startOffset, endOffset); // this is needed for example when inserting a comment before method } reformatRange(project, editor, bounds.getStartOffset(), bounds.getEndOffset()); bounds.dispose(); } } }