本文整理匯總了Java中com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions類的典型用法代碼示例。如果您正苦於以下問題:Java IndentOptions類的具體用法?Java IndentOptions怎麽用?Java IndentOptions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IndentOptions類屬於com.intellij.psi.codeStyle.CommonCodeStyleSettings包,在下文中一共展示了IndentOptions類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getIndentOptions
import com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions; //導入依賴的package包/類
@Nullable
@Override
public final IndentOptions getIndentOptions(@NotNull final CodeStyleSettings settings,
@NotNull final PsiFile file) {
final Language language = file.getLanguage();
if (!(language instanceof PythonTemplateLanguage)) {
return null; // We only care about python template files
}
// This template language has no settings, lets use parent language then
final Language templateDataLanguage = PyTemplatesUtil.getTemplateDataLanguage(file, null);
if (templateDataLanguage == null) {
return null; // No template data language
}
return settings.getIndentOptions(templateDataLanguage.getAssociatedFileType());
}
示例2: getDefaultCommonSettings
import com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions; //導入依賴的package包/類
public CommonCodeStyleSettings getDefaultCommonSettings()
{
CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(YamlLanguage.INSTANCE);
IndentOptions indentOptions = defaultSettings.initIndentOptions();
indentOptions.INDENT_SIZE = 2;
indentOptions.TAB_SIZE = 2;
indentOptions.USE_TAB_CHARACTER = false;
indentOptions.SMART_TABS = false;
return defaultSettings;
}
示例3: preprocessEnter
import com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions; //導入依賴的package包/類
@Override
public Result preprocessEnter(
PsiFile file,
Editor editor,
Ref<Integer> caretOffset,
Ref<Integer> caretAdvance,
DataContext dataContext,
EditorActionHandler originalHandler) {
int offset = caretOffset.get();
if (editor instanceof EditorWindow) {
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
offset = editor.getCaretModel().getOffset();
}
if (!isApplicable(file, dataContext)) {
return Result.Continue;
}
// Previous enter handler's (e.g. EnterBetweenBracesHandler) can introduce a mismatch
// between the editor's caret model and the offset we've been provided with.
editor.getCaretModel().moveToOffset(offset);
Document doc = editor.getDocument();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(doc);
CodeStyleSettings currentSettings = CodeStyleSettingsManager.getSettings(file.getProject());
IndentOptions indentOptions = currentSettings.getIndentOptions(file.getFileType());
Integer indent = determineIndent(file, editor, offset, indentOptions);
if (indent == null) {
return Result.Continue;
}
removeTrailingWhitespace(doc, file, offset);
originalHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), dataContext);
LogicalPosition position = editor.getCaretModel().getLogicalPosition();
if (position.column == indent) {
return Result.Stop;
}
if (position.column > indent) {
//default enter handler has added too many spaces -- remove them
int excess = position.column - indent;
doc.deleteString(
editor.getCaretModel().getOffset() - excess, editor.getCaretModel().getOffset());
} else if (position.column < indent) {
String spaces = StringUtil.repeatSymbol(' ', indent - position.column);
doc.insertString(editor.getCaretModel().getOffset(), spaces);
}
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(position.line, indent));
return Result.Stop;
}
示例4: determineIndent
import com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions; //導入依賴的package包/類
/**
* 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, IndentOptions indentOptions) {
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;
}
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, indentOptions);
}
if (parent instanceof StatementListContainer && afterColon(doc, offset)) {
return getIndent(doc, parent) + additionalIndent(parent, indentOptions);
}
return null;
}
示例5: additionalIndent
import com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions; //導入依賴的package包/類
private static int additionalIndent(PsiElement parent, IndentOptions indentOptions) {
return parent instanceof StatementListContainer
? indentOptions.INDENT_SIZE
: indentOptions.CONTINUATION_INDENT_SIZE;
}