本文整理汇总了Java中com.intellij.psi.codeStyle.CodeStyleSettings.getIndentSize方法的典型用法代码示例。如果您正苦于以下问题:Java CodeStyleSettings.getIndentSize方法的具体用法?Java CodeStyleSettings.getIndentSize怎么用?Java CodeStyleSettings.getIndentSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.codeStyle.CodeStyleSettings
的用法示例。
在下文中一共展示了CodeStyleSettings.getIndentSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillIndent
import com.intellij.psi.codeStyle.CodeStyleSettings; //导入方法依赖的package包/类
public static String fillIndent(Project project, FileType fileType, int indent) {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
int indentLevel = (indent + INDENT_FACTOR / 2) / INDENT_FACTOR;
int spaceCount = indent - indentLevel * INDENT_FACTOR;
int indentLevelSize = indentLevel * settings.getIndentSize(fileType);
int totalSize = indentLevelSize + spaceCount;
StringBuilder buffer = new StringBuilder();
if (settings.useTabCharacter(fileType)) {
if (settings.isSmartTabs(fileType)) {
int tabCount = indentLevelSize / settings.getTabSize(fileType);
int leftSpaces = indentLevelSize - tabCount * settings.getTabSize(fileType);
for (int i = 0; i < tabCount; i++) {
buffer.append('\t');
}
for (int i = 0; i < leftSpaces + spaceCount; i++) {
buffer.append(' ');
}
}
else {
int size = totalSize;
while (size > 0) {
if (size >= settings.getTabSize(fileType)) {
buffer.append('\t');
size -= settings.getTabSize(fileType);
}
else {
buffer.append(' ');
size--;
}
}
}
}
else {
for (int i = 0; i < totalSize; i++) {
buffer.append(' ');
}
}
return buffer.toString();
}
示例2: preprocessOnPaste
import com.intellij.psi.codeStyle.CodeStyleSettings; //导入方法依赖的package包/类
@NotNull
@Override
public String preprocessOnPaste(Project project,
PsiFile file,
Editor editor,
String text,
RawText rawText) {
if (!CodeInsightSettings.getInstance().INDENT_TO_CARET_ON_PASTE || file.getLanguage() != PythonLanguage.getInstance()) {
return text;
}
final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(project);
final boolean useTabs = codeStyleSettings.useTabCharacter(PythonFileType.INSTANCE);
final int indentSize = codeStyleSettings.getIndentSize(PythonFileType.INSTANCE);
CharFilter NOT_INDENT_FILTER = new CharFilter() {
public boolean accept(char ch) {
return useTabs? ch != '\t' : ch != ' ';
}
};
final String indentChar = useTabs ? "\t" : " ";
final CaretModel caretModel = editor.getCaretModel();
final SelectionModel selectionModel = editor.getSelectionModel();
final Document document = editor.getDocument();
final int caretOffset = selectionModel.getSelectionStart() != selectionModel.getSelectionEnd() ?
selectionModel.getSelectionStart() : caretModel.getOffset();
final int lineNumber = document.getLineNumber(caretOffset);
final int lineStartOffset = getLineStartSafeOffset(document, lineNumber);
final int lineEndOffset = document.getLineEndOffset(lineNumber);
final PsiElement element = file.findElementAt(caretOffset);
if (PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class) != null) return text;
text = addLeadingSpaces(text, NOT_INDENT_FILTER, indentSize, indentChar);
int firstLineIndent = StringUtil.findFirst(text, NOT_INDENT_FILTER);
final String indentText = getIndentText(file, document, caretOffset, lineNumber, firstLineIndent);
int toRemove = calculateIndentToRemove(text, NOT_INDENT_FILTER);
final String toString = document.getText(TextRange.create(lineStartOffset, lineEndOffset));
if (StringUtil.isEmptyOrSpaces(indentText) && isApplicable(file, text, caretOffset)) {
caretModel.moveToOffset(lineStartOffset);
if (StringUtil.isEmptyOrSpaces(toString)) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
document.deleteString(lineStartOffset, lineEndOffset);
}
});
}
editor.getSelectionModel().setSelection(lineStartOffset, selectionModel.getSelectionEnd());
}
final List<String> strings = StringUtil.split(text, "\n", false);
String newText = "";
if (StringUtil.isEmptyOrSpaces(indentText)) {
for (String s : strings) {
newText += indentText + StringUtil.trimStart(s, StringUtil.repeat(indentChar, toRemove));
}
}
else {
newText = text;
}
if (addLinebreak(text, toString, useTabs) && selectionModel.getSelectionStart() == selectionModel.getSelectionEnd())
newText += "\n";
return newText;
}