void (FormattingModel model, CodeStyleSettings settings, PsiFile file, TextRange textRange) { try { validateModel(model); final FormattingDocumentModel documentModel = model.getDocumentModel(); final Block block = model.getRootBlock(); final FormatProcessor processor = buildProcessorAndWrapBlocks( documentModel, block, settings, settings.getIndentOptionsByFile(file), null ); LeafBlockWrapper tokenBlock = processor.getFirstTokenBlock(); while (tokenBlock != null) { final WhiteSpace whiteSpace = tokenBlock.getWhiteSpace(); if (whiteSpace.getEndOffset() < textRange.getStartOffset() || whiteSpace.getEndOffset() > textRange.getEndOffset() + 1) { whiteSpace.setIsReadOnly(true); } else if (whiteSpace.getStartOffset() > textRange.getStartOffset() && whiteSpace.getEndOffset() < textRange.getEndOffset()) { if (whiteSpace.containsLineFeeds()) { whiteSpace.setLineFeedsAreReadOnly(true); } else { whiteSpace.setIsReadOnly(true); } } tokenBlock = tokenBlock.getNextBlock(); } processor.formatWithoutRealModifications(); processor.performModifications(model); } catch (FormattingModelInconsistencyException e) { LOG.error(e); } }