Java Code Examples for com.intellij.psi.codeStyle.CodeStyleSettings#getIndentOptions()
The following examples show how to use
com.intellij.psi.codeStyle.CodeStyleSettings#getIndentOptions() .
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: 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 2
Source File: HaxeFormatterTest.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override public void setTestStyleSettings() { Project project = getProject(); CodeStyleSettings currSettings = CodeStyleSettingsManager.getSettings(project); assertNotNull(currSettings); CodeStyleSettings tempSettings = currSettings.clone(); CodeStyleSettings.IndentOptions indentOptions = tempSettings.getIndentOptions(HaxeFileType.HAXE_FILE_TYPE); assertNotNull(indentOptions); defineStyleSettings(tempSettings); CodeStyleSettingsManager.getInstance(project).setTemporarySettings(tempSettings); }
Example 3
Source File: HaxeCodeInsightFixtureTestCase.java From intellij-haxe with Apache License 2.0 | 5 votes |
public void setTestStyleSettings(int indent) { Project project = getProject(); CodeStyleSettings currSettings = CodeStyleSettingsManager.getSettings(project); assertNotNull(currSettings); CodeStyleSettings tempSettings = currSettings.clone(); CodeStyleSettings.IndentOptions indentOptions = tempSettings.getIndentOptions(HaxeFileType.HAXE_FILE_TYPE); indentOptions.INDENT_SIZE = indent; assertNotNull(indentOptions); CodeStyleSettingsManager.getInstance(project).setTemporarySettings(tempSettings); }
Example 4
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 5
Source File: BuildEnterHandler.java From intellij with Apache License 2.0 | 4 votes |
/** * Returns null if an appropriate indent cannot be found. In that case we do nothing, and pass it * along to the next EnterHandler. */ @Nullable private static Integer determineIndent( PsiFile file, Editor editor, int offset, CodeStyleSettings settings) { if (offset == 0) { return null; } Document doc = editor.getDocument(); PsiElement element = getRelevantElement(file, doc, offset); PsiElement parent = element != null ? element.getParent() : null; if (parent == null) { return null; } IndentOptions indentOptions = settings.getIndentOptions(file.getFileType()); BuildCodeStyleSettings buildSettings = settings.getCustomSettings(BuildCodeStyleSettings.class); if (endsBlock(element)) { // current line indent subtract block indent return Math.max(0, getIndent(doc, element) - indentOptions.INDENT_SIZE); } if (parent instanceof BuildListType) { BuildListType list = (BuildListType) parent; if (endsList(list, element) && element.getTextOffset() < offset) { return null; } int listOffset = list.getStartOffset(); LogicalPosition caretPosition = editor.getCaretModel().getLogicalPosition(); LogicalPosition listStart = editor.offsetToLogicalPosition(listOffset); if (listStart.line != caretPosition.line) { // take the minimum of the current line's indent and the current caret position return indentOfLineUpToCaret(doc, caretPosition.line, offset); } BuildElement firstChild = ((BuildListType) parent).getFirstElement(); if (firstChild != null && firstChild.getNode().getStartOffset() < offset) { return getIndent(doc, firstChild); } return lineIndent(doc, listStart.line) + additionalIndent(parent, buildSettings, indentOptions); } if (parent instanceof StatementListContainer && afterColon(doc, offset)) { return getIndent(doc, parent) + additionalIndent(parent, buildSettings, indentOptions); } return null; }