com.intellij.psi.codeStyle.CommonCodeStyleSettings Java Examples
The following examples show how to use
com.intellij.psi.codeStyle.CommonCodeStyleSettings.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GLSLFormattingModelBuilder.java From glsl4idea with GNU Lesser General Public License v3.0 | 8 votes |
private SpacingBuilder createSpacingBuilder(CodeStyleSettings codeStyleSettings) { final CommonCodeStyleSettings commonSettings = codeStyleSettings.getCommonSettings(GLSLLanguage.GLSL_LANGUAGE); return new SpacingBuilder(codeStyleSettings, GLSLLanguage.GLSL_LANGUAGE) .before(COMMA).spaceIf(commonSettings.SPACE_BEFORE_COMMA) .after(COMMA).spaceIf(commonSettings.SPACE_AFTER_COMMA) .before(SEMICOLON).none() .after(LEFT_BRACKET).none() .before(RIGHT_BRACKET).none() .after(LEFT_BRACE).spaces(1) .before(RIGHT_BRACE).spaces(1) .withinPair(LEFT_PAREN, RIGHT_PAREN).spaceIf(commonSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES) .around(FLOW_KEYWORDS).spaces(1) .before(COMMENT_LINE).spaceIf(commonSettings.LINE_COMMENT_ADD_SPACE) ; }
Example #2
Source File: HaxeFormatterTest.java From intellij-haxe with Apache License 2.0 | 6 votes |
public void testWrappingMeth() throws Exception { myTestStyleSettings.METHOD_ANNOTATION_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED; myTestStyleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true; myTestStyleSettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE = true; myTestStyleSettings.CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED; myTestStyleSettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE = true; myTestStyleSettings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = true; myTestStyleSettings.ELSE_ON_NEW_LINE = true; myTestStyleSettings.SPECIAL_ELSE_IF_TREATMENT = true; myTestStyleSettings.FOR_STATEMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED; myTestStyleSettings.FOR_STATEMENT_LPAREN_ON_NEXT_LINE = true; myTestStyleSettings.FOR_STATEMENT_RPAREN_ON_NEXT_LINE = true; myTestStyleSettings.WHILE_ON_NEW_LINE = true; myTestStyleSettings.CATCH_ON_NEW_LINE = true; myTestStyleSettings.BINARY_OPERATION_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED; myTestStyleSettings.BINARY_OPERATION_SIGN_ON_NEXT_LINE = true; myTestStyleSettings.PARENTHESES_EXPRESSION_LPAREN_WRAP = true; myTestStyleSettings.PARENTHESES_EXPRESSION_RPAREN_WRAP = true; myTestStyleSettings.ASSIGNMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED; myTestStyleSettings.PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE = true; myTestStyleSettings.TERNARY_OPERATION_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED; myTestStyleSettings.TERNARY_OPERATION_SIGNS_ON_NEXT_LINE = true; myTestStyleSettings.BLOCK_COMMENT_AT_FIRST_COLUMN = true; doTest(); }
Example #3
Source File: SoftWrapApplianceOnDocumentModificationTest.java From consulo with Apache License 2.0 | 6 votes |
public void testSoftWrapsRecalculationOnTabWidthChange() throws IOException { // Inspired by IDEA-78616 - the point is to recalculate soft wraps when tab width is changed. String text = "\t<caret> my text"; // Build soft wraps cache. init(40, text); VisualPosition caretPositionBefore = getEditor().getCaretModel().getVisualPosition(); // Change tab size. final CommonCodeStyleSettings.IndentOptions indentOptions = getCurrentCodeStyleSettings().getIndentOptions(); assertNotNull(indentOptions); indentOptions.TAB_SIZE++; ((DesktopEditorImpl)getEditor()).reinitSettings(); assertEquals( new VisualPosition(caretPositionBefore.line, caretPositionBefore.column + 1), getEditor().getCaretModel().getVisualPosition() ); }
Example #4
Source File: CoreFormatterUtil.java From consulo with Apache License 2.0 | 6 votes |
/** * Calculates indent for the given block and target start offset according to the given indent options. * * @param options indent options to use * @param block target wrapped block * @param tokenBlockStartOffset target wrapped block offset * @return indent to use for the given parameters */ public static IndentData getIndent(CommonCodeStyleSettings.IndentOptions options, AbstractBlockWrapper block, final int tokenBlockStartOffset) { final IndentImpl indent = block.getIndent(); if (indent.getType() == Indent.Type.CONTINUATION) { return new IndentData(options.CONTINUATION_INDENT_SIZE); } if (indent.getType() == Indent.Type.CONTINUATION_WITHOUT_FIRST) { if (block.getStartOffset() != block.getParent().getStartOffset() && block.getStartOffset() == tokenBlockStartOffset) { return new IndentData(options.CONTINUATION_INDENT_SIZE); } else { return new IndentData(0); } } if (indent.getType() == Indent.Type.LABEL) return new IndentData(options.LABEL_INDENT_SIZE); if (indent.getType() == Indent.Type.NONE) return new IndentData(0); if (indent.getType() == Indent.Type.SPACES) return new IndentData(indent.getSpaces(), 0); return new IndentData(options.INDENT_SIZE); }
Example #5
Source File: IndentCalculator.java From consulo with Apache License 2.0 | 6 votes |
@Nullable String getIndentString(@Nullable Language language, @Nonnull SemanticEditorPosition currPosition) { String baseIndent = getBaseIndent(currPosition); Document document = myEditor.getDocument(); PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document); if (file != null) { CommonCodeStyleSettings.IndentOptions fileOptions = CodeStyle.getIndentOptions(file); CommonCodeStyleSettings.IndentOptions options = !fileOptions.isOverrideLanguageOptions() && language != null && !(language.is(file.getLanguage()) || language.is(Language.ANY)) ? CodeStyle.getLanguageSettings(file, language) .getIndentOptions() : fileOptions; if (options != null) { return baseIndent + new IndentInfo(0, indentToSize(myIndent, options), 0, false).generateNewWhiteSpace(options); } } return null; }
Example #6
Source File: BuckBlock.java From Buck-IntelliJ-Plugin with Apache License 2.0 | 6 votes |
public BuckBlock(@Nullable final BuckBlock parent, @NotNull final ASTNode node, @NotNull CodeStyleSettings settings, @Nullable final Alignment alignment, @NotNull final Indent indent, @Nullable final Wrap wrap) { myParent = parent; myAlignment = alignment; myIndent = indent; myNode = node; myPsiElement = node.getPsi(); myWrap = wrap; mySettings = settings; mySpacingBuilder = BuckFormattingModelBuilder.createSpacingBuilder(settings); if (myPsiElement instanceof BuckArrayElements || myPsiElement instanceof BuckRuleBody || myPsiElement instanceof BuckListElements || myPsiElement instanceof BuckObjectElements) { myChildWrap = Wrap.createWrap(CommonCodeStyleSettings.WRAP_ALWAYS, true); } else { myChildWrap = null; } }
Example #7
Source File: BlockIndentOptions.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public CommonCodeStyleSettings.IndentOptions getIndentOptions(@Nonnull AbstractBlockWrapper block) { if (!myIndentOptions.isOverrideLanguageOptions()) { final Language language = block.getLanguage(); if (language != null) { final CommonCodeStyleSettings commonSettings = mySettings.getCommonSettings(language); if (commonSettings != null) { final CommonCodeStyleSettings.IndentOptions result = commonSettings.getIndentOptions(); if (result != null) { return result; } } } } return myIndentOptions; }
Example #8
Source File: FormatterImpl.java From consulo with Apache License 2.0 | 6 votes |
@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 FormatProcessor processor = buildProcessorAndWrapBlocks(model, settings, indentOptions, affectedRange, 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; }
Example #9
Source File: FormatterImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void adjustLineIndentsForRange(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final TextRange rangeToAdjust) { disableFormatting(); try { validateModel(model); final FormattingDocumentModel documentModel = model.getDocumentModel(); final Block block = model.getRootBlock(); final FormatProcessor processor = buildProcessorAndWrapBlocks(documentModel, block, settings, indentOptions, new FormatTextRanges(rangeToAdjust, true)); LeafBlockWrapper tokenBlock = processor.getFirstTokenBlock(); while (tokenBlock != null) { final WhiteSpace whiteSpace = tokenBlock.getWhiteSpace(); whiteSpace.setLineFeedsAreReadOnly(true); if (!whiteSpace.containsLineFeeds()) { whiteSpace.setIsReadOnly(true); } tokenBlock = tokenBlock.getNextBlock(); } processor.formatWithoutRealModifications(); processor.performModifications(model); } catch (FormattingModelInconsistencyException e) { LOG.error(e); } finally { enableFormatting(); } }
Example #10
Source File: SmartIndentOptionsEditor.java From consulo with Apache License 2.0 | 5 votes |
private ContinuationOption createContinuationOption(@Nonnull String labelText, Function<CommonCodeStyleSettings.IndentOptions, Integer> getter, BiConsumer<CommonCodeStyleSettings.IndentOptions, Integer> setter, int defaultValue) { ContinuationOption option = new ContinuationOption(labelText, getter, setter, defaultValue); myContinuationOptions.add(option); return option; }
Example #11
Source File: SmartIndentOptionsEditor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void apply(final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions options) { super.apply(settings, options); for (ContinuationOption continuationOption : myContinuationOptions) { continuationOption.apply(options); } options.SMART_TABS = isSmartTabValid(options.INDENT_SIZE, options.TAB_SIZE) && myCbSmartTabs.isSelected(); options.KEEP_INDENTS_ON_EMPTY_LINES = myCbKeepIndentsOnEmptyLines.isSelected(); }
Example #12
Source File: HaxeSpacingProcessor.java From intellij-haxe with Apache License 2.0 | 5 votes |
private Spacing setBraceSpace(boolean needSpaceSetting, @CommonCodeStyleSettings.BraceStyleConstant int braceStyleSetting, TextRange textRange) { final int spaces = needSpaceSetting ? 1 : 0; if (braceStyleSetting == CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED && textRange != null) { return Spacing.createDependentLFSpacing(spaces, spaces, textRange, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } else { final int lineBreaks = braceStyleSetting == CommonCodeStyleSettings.END_OF_LINE || braceStyleSetting == CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED ? 0 : 1; return Spacing.createSpacing(spaces, spaces, lineBreaks, false, 0); } }
Example #13
Source File: GenericUtil.java From intellij-spring-assistant with MIT License | 5 votes |
@NotNull public static String getCodeStyleIntent(InsertionContext insertionContext) { final CodeStyleSettings currentSettings = CodeStyleSettingsManager.getSettings(insertionContext.getProject()); final CommonCodeStyleSettings.IndentOptions indentOptions = currentSettings.getIndentOptions(insertionContext.getFile().getFileType()); return indentOptions.USE_TAB_CHARACTER ? "\t" : StringUtil.repeatSymbol(' ', indentOptions.INDENT_SIZE); }
Example #14
Source File: FormatterImpl.java From consulo with Apache License 2.0 | 5 votes |
private static FormatProcessor buildProcessorAndWrapBlocks(final FormattingDocumentModel docModel, Block rootBlock, CodeStyleSettings settings, CommonCodeStyleSettings.IndentOptions indentOptions, @Nullable FormatTextRanges affectedRanges, int interestingOffset) { FormatOptions options = new FormatOptions(settings, indentOptions, affectedRanges, interestingOffset); FormatProcessor processor = new FormatProcessor(docModel, rootBlock, options, FormattingProgressCallback.EMPTY); //noinspection StatementWithEmptyBody while (!processor.iteration()) ; return processor; }
Example #15
Source File: SmartIndentOptionsEditor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void reset(@Nonnull final CodeStyleSettings settings, @Nonnull final CommonCodeStyleSettings.IndentOptions options) { super.reset(settings, options); for (ContinuationOption continuationOption : myContinuationOptions) { continuationOption.reset(options); } myCbSmartTabs.setSelected(options.SMART_TABS); myCbKeepIndentsOnEmptyLines.setSelected(options.KEEP_INDENTS_ON_EMPTY_LINES); }
Example #16
Source File: CSharpLanguageCodeStyleSettingsProvider.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override public CommonCodeStyleSettings getDefaultCommonSettings() { CommonCodeStyleSettings settings = new CommonCodeStyleSettings(CSharpLanguage.INSTANCE); settings.initIndentOptions(); return settings; }
Example #17
Source File: CodeStyleBean.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public CommonCodeStyleSettings.WrapOnTyping getWrapOnTyping() { for (CommonCodeStyleSettings.WrapOnTyping c : CommonCodeStyleSettings.WrapOnTyping.values()) { if (c.intValue == getCommonSettings().WRAP_ON_TYPING) return c; } return CommonCodeStyleSettings.WrapOnTyping.NO_WRAP; }
Example #18
Source File: InitialInfoBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull static InitialInfoBuilder prepareToBuildBlocksSequentially(Block root, FormattingDocumentModel model, FormatProcessor.FormatOptions formatOptions, CommonCodeStyleSettings.IndentOptions options, @Nonnull FormattingProgressCallback progressCallback) { InitialInfoBuilder builder = new InitialInfoBuilder(root, model, formatOptions.myAffectedRanges, options, formatOptions.myInterestingOffset, progressCallback); builder.setCollectAlignmentsInsideFormattingRange(formatOptions.isReformatWithContext()); builder.buildFrom(root, 0, null, null, null); return builder; }
Example #19
Source File: HaxeFormatterTest.java From intellij-haxe with Apache License 2.0 | 5 votes |
protected void defineStyleSettings(CodeStyleSettings tempSettings) { myTestStyleSettings = tempSettings.getCommonSettings(HaxeLanguage.INSTANCE); myTestStyleSettings.KEEP_BLANK_LINES_IN_CODE = 2; myTestStyleSettings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE; myTestStyleSettings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE; myTestStyleSettings.ALIGN_MULTILINE_PARAMETERS = false; myTestStyleSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = false; myTestStyleSettings.KEEP_FIRST_COLUMN_COMMENT = false; }
Example #20
Source File: FormatterImpl.java From consulo with Apache License 2.0 | 5 votes |
private static FormatProcessor buildProcessorAndWrapBlocks(final FormattingDocumentModel docModel, Block rootBlock, CodeStyleSettings settings, CommonCodeStyleSettings.IndentOptions indentOptions, @Nullable FormatTextRanges affectedRanges) { return buildProcessorAndWrapBlocks(docModel, rootBlock, settings, indentOptions, affectedRanges, -1); }
Example #21
Source File: XQueryLanguageCodeStyleSettingsProvider.java From intellij-xquery with Apache License 2.0 | 5 votes |
@Override public CommonCodeStyleSettings getDefaultCommonSettings() { CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(getLanguage()); CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions(); indentOptions.INDENT_SIZE = 4; indentOptions.CONTINUATION_INDENT_SIZE = 8; indentOptions.TAB_SIZE = 4; return defaultSettings; }
Example #22
Source File: XQueryFormattingModelBuilder.java From intellij-xquery with Apache License 2.0 | 5 votes |
@NotNull @Override public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) { CommonCodeStyleSettings commonSettings = settings.getCommonSettings(XQueryLanguage.INSTANCE); XQueryCodeStyleSettings xQuerySettings = settings.getCustomSettings(XQueryCodeStyleSettings.class); final XQueryFormattingBlock block = new XQueryFormattingBlock(element.getNode(), null, null, commonSettings, createSpacingBuilder(commonSettings, xQuerySettings, settings)); FormattingModel result = createFormattingModelForPsiFile(element.getContainingFile(), block, settings); return result; }
Example #23
Source File: WhiteSpace.java From consulo with Apache License 2.0 | 5 votes |
/** * Applies new end offset to the current object. * <p/> * Namely, performs the following: * <ol> * <li>Checks if new end offset can be applied, return in case of negative answer;</li> * <li> * Processes all new symbols introduced by the new end offset value, calculates number of line feeds, * white spaces and tabulations between them and updates {@link #getLineFeeds() lineFeeds}, {@link #getSpaces() spaces}, * {@link #getIndentSpaces() indentSpaces} and {@link #getTotalSpaces() totalSpaces} properties accordingly; * </li> * </ol> * * @param newEndOffset new end offset value * @param model formatting model that is used to access to the underlying document text * @param options indent formatting options */ public void changeEndOffset(int newEndOffset, FormattingDocumentModel model, CommonCodeStyleSettings.IndentOptions options) { final int oldEndOffset = myEnd; if (newEndOffset == oldEndOffset) return; if (myStart >= newEndOffset) { myRangesAssert.assertInvalidRanges(myStart, newEndOffset, model, "some block intersects with whitespace"); } myEnd = newEndOffset; TextRange range = new TextRange(myStart, myEnd); CharSequence oldText = myInitial; myInitial = model.getText(range); if (!coveredByBlock(model)) { myRangesAssert.assertInvalidRanges(myStart, myEnd, model, "nonempty text is not covered by block"); } if (newEndOffset > oldEndOffset) { refreshStateOnEndOffsetIncrease(newEndOffset, oldEndOffset, options.TAB_SIZE); } else { refreshStateOnEndOffsetDecrease(oldText, newEndOffset, oldEndOffset, options.TAB_SIZE); } IndentInside indent = IndentInside.getLastLineIndent(myInitial); myInitialLastLinesSpaces = indent.whiteSpaces; myInitialLastLinesTabs = indent.tabs; setFlag(CONTAINS_LF_INITIALLY_MASK, getLineFeeds() > 0); final int totalSpaces = getTotalSpaces(); setFlag(CONTAINS_SPACES_INITIALLY_MASK, totalSpaces > 0); }
Example #24
Source File: CodeStyleManager.java From editorconfig-jetbrains with MIT License | 5 votes |
private void applyIndentOptions(CommonCodeStyleSettings.IndentOptions indentOptions, String indentSize, String tabWidth, String indentStyle, String filePath) { final String calculatedIndentSize = calculateIndentSize(tabWidth, indentSize); final String calculatedTabWidth = calculateTabWidth(tabWidth, indentSize); if (!calculatedIndentSize.isEmpty()) { if (applyIndentSize(indentOptions, calculatedIndentSize)) { LOG.debug(Utils.appliedConfigMessage(calculatedIndentSize, indentSizeKey, filePath)); } else { LOG.warn(Utils.invalidConfigMessage(calculatedIndentSize, indentSizeKey, filePath)); } } if (!calculatedTabWidth.isEmpty()) { if (applyTabWidth(indentOptions, calculatedTabWidth)) { LOG.debug(Utils.appliedConfigMessage(calculatedTabWidth, tabWidthKey, filePath)); } else { LOG.warn(Utils.invalidConfigMessage(calculatedTabWidth, tabWidthKey, filePath)); } } if (!indentStyle.isEmpty()) { if (applyIndentStyle(indentOptions, indentStyle)) { LOG.debug(Utils.appliedConfigMessage(indentStyle, indentStyleKey, filePath)); } else { LOG.warn(Utils.invalidConfigMessage(indentStyle, indentStyleKey, filePath)); } } }
Example #25
Source File: CodeStyleManager.java From editorconfig-jetbrains with MIT License | 5 votes |
private boolean applyIndentSize(final CommonCodeStyleSettings.IndentOptions indentOptions, final String indentSize) { try { int indent = Integer.parseInt(indentSize); indentOptions.INDENT_SIZE = indent; indentOptions.CONTINUATION_INDENT_SIZE = indent; return true; } catch (NumberFormatException e) { return false; } }
Example #26
Source File: JavaLikeLangLineIndentProvider.java From consulo with Apache License 2.0 | 5 votes |
@Nullable protected Indent getIndentInBlock(@Nonnull Project project, @Nullable Language language, @Nonnull SemanticEditorPosition blockStartPosition) { if (language != null) { CommonCodeStyleSettings settings = CodeStyle.getSettings(blockStartPosition.getEditor()).getCommonSettings(language); if (settings.BRACE_STYLE == CommonCodeStyleSettings.NEXT_LINE_SHIFTED) { return getDefaultIndentFromType(settings.METHOD_BRACE_STYLE == CommonCodeStyleSettings.NEXT_LINE_SHIFTED ? NONE : null); } } return getDefaultIndentFromType(NORMAL); }
Example #27
Source File: BuckLanguageCodeStyleSettingsProvider.java From buck with Apache License 2.0 | 5 votes |
@Override public CommonCodeStyleSettings getDefaultCommonSettings() { CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(BuckLanguage.INSTANCE); CommonCodeStyleSettings.IndentOptions indentOptions = defaultSettings.initIndentOptions(); indentOptions.INDENT_SIZE = 4; indentOptions.TAB_SIZE = 4; indentOptions.CONTINUATION_INDENT_SIZE = 4; defaultSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true; defaultSettings.KEEP_BLANK_LINES_IN_DECLARATIONS = 1; defaultSettings.KEEP_BLANK_LINES_IN_CODE = 1; defaultSettings.RIGHT_MARGIN = 100; return defaultSettings; }
Example #28
Source File: FormatProcessorUtils.java From consulo with Apache License 2.0 | 5 votes |
public static int replaceWhiteSpace(final FormattingModel model, @Nonnull final LeafBlockWrapper block, int shift, final CharSequence _newWhiteSpace, final CommonCodeStyleSettings.IndentOptions options ) { final WhiteSpace whiteSpace = block.getWhiteSpace(); final TextRange textRange = whiteSpace.getTextRange(); final TextRange wsRange = textRange.shiftRight(shift); final String newWhiteSpace = _newWhiteSpace.toString(); TextRange newWhiteSpaceRange = model instanceof FormattingModelEx ? ((FormattingModelEx) model).replaceWhiteSpace(wsRange, block.getNode(), newWhiteSpace) : model.replaceWhiteSpace(wsRange, newWhiteSpace); shift += newWhiteSpaceRange.getLength() - textRange.getLength(); if (block.isLeaf() && whiteSpace.containsLineFeeds() && block.containsLineFeeds()) { final TextRange currentBlockRange = block.getTextRange().shiftRight(shift); IndentInside oldBlockIndent = whiteSpace.getInitialLastLineIndent(); IndentInside whiteSpaceIndent = IndentInside.createIndentOn(IndentInside.getLastLine(newWhiteSpace)); final int shiftInside = calcShift(oldBlockIndent, whiteSpaceIndent, options); if (shiftInside != 0 || !oldBlockIndent.equals(whiteSpaceIndent)) { final TextRange newBlockRange = model.shiftIndentInsideRange(block.getNode(), currentBlockRange, shiftInside); shift += newBlockRange.getLength() - block.getLength(); } } return shift; }
Example #29
Source File: WrapBlocksState.java From consulo with Apache License 2.0 | 5 votes |
public WhiteSpace getLastWhiteSpace() { assertDone(); if (myLastWhiteSpace == null) { int lastBlockOffset = getLastBlock().getEndOffset(); myLastWhiteSpace = new WhiteSpace(lastBlockOffset, false); FormattingDocumentModel model = myWrapper.getFormattingDocumentModel(); CommonCodeStyleSettings.IndentOptions options = myBlockIndentOptions.getIndentOptions(); myLastWhiteSpace.changeEndOffset(Math.max(lastBlockOffset, myWrapper.getEndOffset()), model, options); } return myLastWhiteSpace; }
Example #30
Source File: TailType.java From consulo with Apache License 2.0 | 5 votes |
@Override public int processTail(final Editor editor, int tailOffset) { CommonCodeStyleSettings styleSettings = getLocalCodeStyleSettings(editor, tailOffset); if (styleSettings.SPACE_BEFORE_COMMA) tailOffset = insertChar(editor, tailOffset, ' '); tailOffset = insertChar(editor, tailOffset, ','); if (styleSettings.SPACE_AFTER_COMMA) tailOffset = insertChar(editor, tailOffset, ' '); return tailOffset; }