void (PsiFile psiFile, int startOffset, int endOffset) { FormattingService formattingService = FormattingServiceUtil.findService(psiFile, false, false); FormatTextRanges formatRanges = new FormatTextRanges(); formatRanges.add(new TextRange(startOffset, endOffset), true); formatRanges.setExtendToContext(true); formattingService.formatRanges(psiFile, formatRanges, true, true); }