Java Code Examples for com.intellij.psi.codeStyle.CommonCodeStyleSettings#IndentOptions
The following examples show how to use
com.intellij.psi.codeStyle.CommonCodeStyleSettings#IndentOptions .
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: FormatterImpl.java From consulo with Apache License 2.0 | 6 votes |
public void formatWithoutModifications(final FormattingDocumentModel model, final Block rootBlock, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final TextRange affectedRange) throws IncorrectOperationException { SequentialTask task = new MyFormattingTask() { @Nonnull @Override protected FormatProcessor buildProcessor() { FormatProcessor result = new FormatProcessor(model, rootBlock, settings, indentOptions, new FormatTextRanges(affectedRange, true), FormattingProgressCallback.EMPTY); result.formatWithoutRealModifications(); return result; } }; execute(task); }
Example 2
Source File: FormatterImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void format(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final FormatTextRanges affectedRanges) throws IncorrectOperationException { try { validateModel(model); SequentialTask task = new MyFormattingTask() { @Nonnull @Override protected FormatProcessor buildProcessor() { FormatOptions options = new FormatOptions(settings, indentOptions, affectedRanges); FormatProcessor processor = new FormatProcessor(model.getDocumentModel(), model.getRootBlock(), options, getProgressCallback()); processor.format(model, true); return processor; } }; execute(task); } catch (FormattingModelInconsistencyException e) { LOG.error(e); } }
Example 3
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 4
Source File: AbstractBlockWrapper.java From consulo with Apache License 2.0 | 6 votes |
public IndentData calculateChildOffset(final CommonCodeStyleSettings.IndentOptions indentOption, final ChildAttributes childAttributes, int index) { IndentImpl childIndent = (IndentImpl)childAttributes.getChildIndent(); if (childIndent == null) childIndent = (IndentImpl)Indent.getContinuationWithoutFirstIndent(indentOption.USE_RELATIVE_INDENTS); IndentData indent = getIndent(indentOption, index, childIndent); if (childIndent.isRelativeToDirectParent()) { return new IndentData(indent.getIndentSpaces() + CoreFormatterUtil.getStartColumn(CoreFormatterUtil.getFirstLeaf(this)), indent.getSpaces()); } if (myParent == null || (myFlags & CAN_USE_FIRST_CHILD_INDENT_AS_BLOCK_INDENT) != 0 && getWhiteSpace().containsLineFeeds()) { return indent.add(getWhiteSpace()); } else { IndentData offsetFromParent = myParent.getChildOffset(this, indentOption, -1); return indent.add(offsetFromParent); } }
Example 5
Source File: FormatProcessor.java From consulo with Apache License 2.0 | 6 votes |
public FormatProcessor(final FormattingDocumentModel model, Block block, FormatOptions options, @Nonnull FormattingProgressCallback callback) { myProgressCallback = callback; CommonCodeStyleSettings.IndentOptions defaultIndentOption = options.myIndentOptions; CodeStyleSettings settings = options.mySettings; BlockIndentOptions blockIndentOptions = new BlockIndentOptions(settings, defaultIndentOption, block); myDocument = model.getDocument(); myReformatContext = options.isReformatWithContext(); final InitialInfoBuilder builder = prepareToBuildBlocksSequentially(block, model, options, defaultIndentOption, myProgressCallback); myWrapState = new WrapBlocksState(builder, blockIndentOptions); FormatTextRanges ranges = options.myAffectedRanges; if (ranges != null && myReformatContext) { AdjustFormatRangesState adjustRangesState = new AdjustFormatRangesState(block, ranges, model); myStateProcessor = new StateProcessor(adjustRangesState); myStateProcessor.setNextState(myWrapState); } else { myStateProcessor = new StateProcessor(myWrapState); } }
Example 6
Source File: FluidFileIndentOptionsProvider.java From idea-php-typo3-plugin with MIT License | 5 votes |
@Nullable @Override public CommonCodeStyleSettings.IndentOptions getIndentOptions(@NotNull CodeStyleSettings settings, @NotNull PsiFile file) { if (file instanceof FluidFile) { if (file.getViewProvider() instanceof TemplateLanguageFileViewProvider) { Language language = ((TemplateLanguageFileViewProvider) file.getViewProvider()).getTemplateDataLanguage(); return settings.getCommonSettings(language).getIndentOptions(); } } return null; }
Example 7
Source File: CodeStyleBean.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull protected final CommonCodeStyleSettings.IndentOptions getIndentOptions(boolean isWritable) { CommonCodeStyleSettings.IndentOptions indentOptions = getCommonSettings().getIndentOptions(); if (indentOptions == null && isWritable) { indentOptions = getCommonSettings().initIndentOptions(); } return indentOptions != null ? indentOptions : myRootSettings.OTHER_INDENT_OPTIONS; }
Example 8
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 9
Source File: BaseIndentEnterHandler.java From consulo with Apache License 2.0 | 5 votes |
protected String getNewIndent( @Nonnull final PsiFile file, @Nonnull final Document document, @Nonnull final CharSequence oldIndent) { CharSequence nonEmptyIndent = oldIndent; final CharSequence editorCharSequence = document.getCharsSequence(); final int nLines = document.getLineCount(); for (int line = 0; line < nLines && nonEmptyIndent.length() == 0; ++line) { final int lineStart = document.getLineStartOffset(line); final int indentEnd = EditorActionUtil.findFirstNonSpaceOffsetOnTheLine(document, line); if (lineStart < indentEnd) { nonEmptyIndent = editorCharSequence.subSequence(lineStart, indentEnd); } } final boolean usesSpacesForIndentation = nonEmptyIndent.length() > 0 && nonEmptyIndent.charAt(nonEmptyIndent.length() - 1) == ' '; final boolean firstIndent = nonEmptyIndent.length() == 0; final CodeStyleSettings currentSettings = CodeStyleSettingsManager.getSettings(file.getProject()); final CommonCodeStyleSettings.IndentOptions indentOptions = currentSettings.getIndentOptions(file.getFileType()); if (firstIndent && indentOptions.USE_TAB_CHARACTER || !firstIndent && !usesSpacesForIndentation) { int nTabsToIndent = indentOptions.INDENT_SIZE / indentOptions.TAB_SIZE; if (indentOptions.INDENT_SIZE % indentOptions.TAB_SIZE != 0) { ++nTabsToIndent; } return oldIndent + StringUtil.repeatSymbol('\t', nTabsToIndent); } return oldIndent + StringUtil.repeatSymbol(' ', indentOptions.INDENT_SIZE); }
Example 10
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 11
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 12
Source File: IndentInfo.java From consulo with Apache License 2.0 | 5 votes |
/** * Builds string that contains line feeds, white spaces and tabulation symbols known to the current {@link IndentInfo} object. * * @param options indentation formatting options */ public String generateNewWhiteSpace(CommonCodeStyleSettings.IndentOptions options) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < myLineFeeds; i ++) { if (options.KEEP_INDENTS_ON_EMPTY_LINES && i > 0) { int spaces = myIndentEmptyLines ? myIndentSpaces + options.INDENT_SIZE : myIndentSpaces; generateLineWhitespace(buffer, options, spaces, 0, true); } buffer.append('\n'); } generateLineWhitespace(buffer, options, myIndentSpaces, mySpaces, !myForceSkipTabulationsUsage || myLineFeeds > 0); return buffer.toString(); }
Example 13
Source File: CypherLanguageCodeStyleSettingsProvider.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 5 votes |
@Nullable @Override public CommonCodeStyleSettings getDefaultCommonSettings() { CommonCodeStyleSettings settings = new CommonCodeStyleSettings(getLanguage()); CommonCodeStyleSettings.IndentOptions indentOptions = settings.initIndentOptions(); indentOptions.INDENT_SIZE = 2; indentOptions.CONTINUATION_INDENT_SIZE = 2; indentOptions.TAB_SIZE = 2; indentOptions.USE_TAB_CHARACTER = false; return settings; }
Example 14
Source File: BlockIndentOptions.java From consulo with Apache License 2.0 | 4 votes |
public BlockIndentOptions(@Nonnull CodeStyleSettings settings, @Nonnull CommonCodeStyleSettings.IndentOptions indentOptions, Block block) { mySettings = settings; myIndentOptions = indentOptions; myRightMargin = calcRightMargin(block); }
Example 15
Source File: FormatterEx.java From consulo with Apache License 2.0 | 4 votes |
public abstract void adjustLineIndentsForRange(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final TextRange rangeToAdjust);
Example 16
Source File: IndentInside.java From consulo with Apache License 2.0 | 4 votes |
public int getTabsCount(final CommonCodeStyleSettings.IndentOptions options) { final int tabsFromSpaces = whiteSpaces / options.TAB_SIZE; return tabs + tabsFromSpaces; }
Example 17
Source File: IndentOptionsDetector.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull CommonCodeStyleSettings.IndentOptions getIndentOptions();
Example 18
Source File: ContinuationOption.java From consulo with Apache License 2.0 | 4 votes |
public void apply(@Nonnull CommonCodeStyleSettings.IndentOptions options) { if (mySupported && myField != null) { mySetter.accept(options, myField.getValue()); } }
Example 19
Source File: FusionLanguageCodeStyleSettingsProvider.java From intellij-neos with GNU General Public License v3.0 | 4 votes |
@Override protected void customizeDefaults(@NotNull CommonCodeStyleSettings commonSettings, @NotNull CommonCodeStyleSettings.IndentOptions indentOptions) { indentOptions.INDENT_SIZE = 4; // strip all blank lines by default commonSettings.KEEP_BLANK_LINES_IN_CODE = 0; }
Example 20
Source File: IndentOptionsEditor.java From consulo with Apache License 2.0 | 4 votes |
public void reset(@Nonnull CodeStyleSettings settings, @Nonnull CommonCodeStyleSettings.IndentOptions options) { ((IntegerField)myTabSizeField).setValue(options.TAB_SIZE); myCbUseTab.setSelected(options.USE_TAB_CHARACTER); ((IntegerField)myIndentField).setValue(options.INDENT_SIZE); }