@Override public int adjustLineIndent(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final int offset, final TextRange affectedRange) throws IncorrectOperationException { disableFormatting(); try { validateModel(model); if (model instanceof PsiBasedFormattingModel) { ((PsiBasedFormattingModel)model).canModifyAllWhiteSpaces(); } final FormattingDocumentModel documentModel = model.getDocumentModel(); final Block block = model.getRootBlock(); final FormatProcessor processor = buildProcessorAndWrapBlocks( documentModel, block, settings, indentOptions, new FormatTextRanges(affectedRange, true), offset ); final LeafBlockWrapper blockAfterOffset = processor.getBlockAtOrAfter(offset); if (blockAfterOffset != null && blockAfterOffset.contains(offset)) { return offset; } WhiteSpace whiteSpace = blockAfterOffset != null ? blockAfterOffset.getWhiteSpace() : processor.getLastWhiteSpace(); return adjustLineIndent(offset, documentModel, processor, indentOptions, model, whiteSpace, blockAfterOffset != null ? blockAfterOffset.getNode() : null); } catch (FormattingModelInconsistencyException e) { LOG.error(e); } finally { enableFormatting(); } return offset; }
@Override public int adjustLineIndent(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final int offset, final TextRange affectedRange) throws IncorrectOperationException { disableFormatting(); if (model instanceof PsiBasedFormattingModel) { ((PsiBasedFormattingModel)model).canModifyAllWhiteSpaces(); } try { final FormattingDocumentModel documentModel = model.getDocumentModel(); final Block block = model.getRootBlock(); final FormatProcessor processor = buildProcessorAndWrapBlocks( documentModel, block, settings, indentOptions, new FormatTextRanges(affectedRange, true), offset ); final LeafBlockWrapper blockAfterOffset = processor.getBlockAfter(offset); if (blockAfterOffset != null && blockAfterOffset.contains(offset)) { return offset; } WhiteSpace whiteSpace = blockAfterOffset != null ? blockAfterOffset.getWhiteSpace() : processor.getLastWhiteSpace(); return adjustLineIndent(offset, documentModel, processor, indentOptions, model, whiteSpace); } finally { enableFormatting(); } }
@NotNull @Override public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) { final PsiFile file = element.getContainingFile(); FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile()); Block rootBlock = new CSharpFormattingBlock(file.getNode(), null, null, settings); return new PsiBasedFormattingModel(file, rootBlock, model); }
@Override public int adjustLineIndent(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final int offset, final TextRange affectedRange) throws IncorrectOperationException { disableFormatting(); try { validateModel(model); if (model instanceof PsiBasedFormattingModel) { ((PsiBasedFormattingModel)model).canModifyAllWhiteSpaces(); } final FormattingDocumentModel documentModel = model.getDocumentModel(); final Block block = model.getRootBlock(); final FormatProcessor processor = buildProcessorAndWrapBlocks( documentModel, block, settings, indentOptions, new FormatTextRanges(affectedRange, true), offset ); final LeafBlockWrapper blockAfterOffset = processor.getBlockRangesMap().getBlockAtOrAfter(offset); if (blockAfterOffset != null && blockAfterOffset.contains(offset)) { return offset; } WhiteSpace whiteSpace = blockAfterOffset != null ? blockAfterOffset.getWhiteSpace() : processor.getLastWhiteSpace(); return adjustLineIndent(offset, documentModel, processor, indentOptions, model, whiteSpace, blockAfterOffset != null ? blockAfterOffset.getNode() : null); } catch (FormattingModelInconsistencyException e) { LOG.error(e); } finally { enableFormatting(); } return offset; }
@NotNull @Override public FormattingModel createModel(PsiElement element, CodeStyleSettings codeStyleSettings) { final PsiFile file = element.getContainingFile(); FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile()); Block rootBlock = new CssFormattingBlock(element.getNode(), null, null); return new PsiBasedFormattingModel(file, rootBlock, model); }
@Override public FormattingModel createFormattingModelForPsiFile(final PsiFile file, @NotNull final Block rootBlock, final CodeStyleSettings settings) { return new PsiBasedFormattingModel(file, rootBlock, FormattingDocumentModelImpl.createOn(file)); }
@Override public FormattingModel createFormattingModelForPsiFile(final PsiFile file, @Nonnull final Block rootBlock, final CodeStyleSettings settings) { return new PsiBasedFormattingModel(file, rootBlock, FormattingDocumentModelImpl.createOn(file)); }