TextRange (@NotNull PsiFile source, @NotNull TextRange rangeToReformat, @NotNull CodeStyleSettings settings) { Document document = PsiDocumentManager.getInstance(source.getProject()).getDocument(source); if (document != null && settings.getCommonSettings(source.getLanguage()).WRAP_LONG_LINES && !PostprocessReformattingAspect.getInstance(source.getProject()).isViewProviderLocked(source.getViewProvider())) { RangeMarker rangeMarker = document.createRangeMarker(rangeToReformat.getStartOffset(), rangeToReformat.getEndOffset()); final int startOffset = rangeToReformat.getStartOffset(); final int endOffset = rangeToReformat.getEndOffset(); try { LineWrappingUtil.wrapLongLinesIfNecessary(source, document, startOffset, endOffset, Collections.singletonList(new TextRange(startOffset, endOffset)), settings.getRightMargin(source.getLanguage())); return rangeMarker.getTextRange(); } finally { rangeMarker.dispose(); } } return rangeToReformat; }