本文整理汇总了Java中com.intellij.openapi.util.text.CharFilter类的典型用法代码示例。如果您正苦于以下问题:Java CharFilter类的具体用法?Java CharFilter怎么用?Java CharFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CharFilter类属于com.intellij.openapi.util.text包,在下文中一共展示了CharFilter类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTestVariantsInner
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
protected void doTestVariantsInner(String fileName) throws Throwable {
final VirtualFile virtualFile = myFixture.copyFileToProject(fileName);
final Scanner in = new Scanner(virtualFile.getInputStream());
final CompletionType type = CompletionType.valueOf(in.next());
final int count = in.nextInt();
final CheckType checkType = CheckType.valueOf(in.next());
final List<String> variants = new ArrayList<>();
while (in.hasNext()) {
final String variant = StringUtil.strip(in.next(), CharFilter.NOT_WHITESPACE_FILTER);
if (variant.length() > 0) {
variants.add(variant);
}
}
myFixture.complete(type, count);
checkCompletion(checkType, variants);
}
示例2: doTestVariantsInner
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
protected void doTestVariantsInner(String fileName) throws Throwable {
final VirtualFile virtualFile = myFixture.copyFileToProject(fileName);
final Scanner in = new Scanner(virtualFile.getInputStream());
final CompletionType type = CompletionType.valueOf(in.next());
final int count = in.nextInt();
final CheckType checkType = CheckType.valueOf(in.next());
final List<String> variants = new ArrayList<String>();
while (in.hasNext()) {
final String variant = StringUtil.strip(in.next(), CharFilter.NOT_WHITESPACE_FILTER);
if (variant.length() > 0) {
variants.add(variant);
}
}
myFixture.complete(type, count);
checkCompletion(checkType, variants);
}
示例3: createReferences
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
protected PsiReference[] createReferences(@NotNull PsiElement element, String s, int offset, final boolean soft) {
int contentOffset = StringUtil.findFirst(s, CharFilter.NOT_WHITESPACE_FILTER);
if (contentOffset >= 0) {
offset += contentOffset;
}
return new FileReferenceSet(s.trim(), element, offset, this, true) {
@Override
protected boolean isSoft() {
return soft;
}
}.getAllReferences();
}
示例4: getStartOffset
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
private int getStartOffset(@NotNull final PsiElement element, @NotNull final Editor editor) {
if (isBunchOfElement(element)) {
final PsiElement firstElement = getFirstElement(element);
return firstElement != null? firstElement.getTextRange().getStartOffset()
: element.getTextRange().getStartOffset();
}
final int offset = editor.getCaretModel().getOffset();
final int elementTextOffset = element.getTextOffset();
final Document document = editor.getDocument();
int lineNumber = document.getLineNumber(offset);
while (lineNumber != document.getLineNumber(elementTextOffset)) {
final String text = document.getText(TextRange.create(document.getLineStartOffset(lineNumber),
document.getLineEndOffset(lineNumber)));
if (StringUtil.isEmptyOrSpaces(text)) {
lineNumber += 1;
break;
}
lineNumber -= 1;
}
final int lineStartOffset = lineNumber == document.getLineNumber(elementTextOffset) ? elementTextOffset : document.getLineStartOffset(lineNumber);
final String lineText = document
.getText(TextRange.create(lineStartOffset, document.getLineEndOffset(lineNumber)));
int shift = StringUtil.findFirst(lineText, CharFilter.NOT_WHITESPACE_FILTER);
return lineStartOffset + shift;
}
示例5: getPrefix
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
@NotNull
protected String getPrefix(@NotNull final PsiElement element) {
final PyStringLiteralExpression stringLiteralExpression =
PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class);
if (stringLiteralExpression != null) {
final String text = stringLiteralExpression.getText();
final Pair<String,String> quotes =
PythonStringUtil.getQuotes(text);
final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(stringLiteralExpression, PyDocStringOwner.class);
if (docStringOwner != null && stringLiteralExpression.equals(docStringOwner.getDocStringExpression())) {
String indent = getIndent(stringLiteralExpression);
if (quotes != null) {
final List<String> strings = StringUtil.split(text, "\n");
if (strings.get(0).trim().equals(quotes.getFirst())) {
return quotes.getFirst() + indent;
}
else {
final String value = stringLiteralExpression.getStringValue();
final int firstNotSpace = StringUtil.findFirst(value, CharFilter.NOT_WHITESPACE_FILTER);
return quotes.getFirst() + value.substring(0, firstNotSpace);
}
}
return "\"" + indent;
}
else
return quotes != null? quotes.getFirst() : "\"";
}
return element instanceof PsiComment? "# " : "";
}
示例6: findDigits
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
private static String findDigits(String s) {
int pos = StringUtil.findFirst(s, new CharFilter() {
public boolean accept(char ch) {
return Character.isDigit(ch);
}
});
if (pos >= 0) {
return s.substring(pos);
}
return s;
}
示例7: addLeadingSpaces
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
private static String addLeadingSpaces(String text, final CharFilter filter, int indentSize, String indentChar) {
final List<String> strings = StringUtil.split(text, "\n", false);
if (strings.size() > 1) {
int firstLineIndent = StringUtil.findFirst(strings.get(0), filter);
int secondLineIndent = StringUtil.findFirst(strings.get(1), filter);
final int diff = secondLineIndent - firstLineIndent;
if (diff > indentSize) {
text = StringUtil.repeat(indentChar, diff - indentSize) + text;
}
}
return text;
}
示例8: calculateIndentToRemove
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
private static int calculateIndentToRemove(@NotNull String text, @NotNull final CharFilter filter) {
final List<String> strings = StringUtil.split(text, "\n", false);
int minIndent = StringUtil.findFirst(text, filter);
for (String s : strings) {
final int indent = StringUtil.findFirst(s, filter);
if (indent < minIndent && !StringUtil.isEmptyOrSpaces(s))
minIndent = indent;
}
return minIndent >= 0 ? minIndent : 0;
}
示例9: createReferences
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
protected PsiReference[] createReferences(PsiElement element, String s, int offset, final boolean soft) {
int contentOffset = StringUtil.findFirst(s, CharFilter.NOT_WHITESPACE_FILTER);
if (contentOffset >= 0) {
offset += contentOffset;
}
return new FileReferenceSet(s.trim(), element, offset, this, true) {
@Override
protected boolean isSoft() {
return soft;
}
}.getAllReferences();
}
示例10: getStartOffset
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
private int getStartOffset(@NotNull final PsiElement element, @NotNull final Editor editor) {
if (isBunchOfElement(element)) {
final PsiElement firstElement = getFirstElement(element);
return firstElement != null? firstElement.getTextRange().getStartOffset()
: element.getTextRange().getStartOffset();
}
final int offset = editor.getCaretModel().getOffset();
final int elementTextOffset = element.getTextOffset();
final Document document = editor.getDocument();
int lineNumber = document.getLineNumber(offset);
while (lineNumber != document.getLineNumber(elementTextOffset)) {
final String text = document.getText(TextRange.create(document.getLineStartOffset(lineNumber),
document.getLineEndOffset(lineNumber)));
if (StringUtil.isEmptyOrSpaces(text)) {
lineNumber += 1;
break;
}
lineNumber -= 1;
}
final int lineStartOffset = document.getLineStartOffset(lineNumber);
final String lineText = document
.getText(TextRange.create(lineStartOffset, document.getLineEndOffset(lineNumber)));
int shift = StringUtil.findFirst(lineText, CharFilter.NOT_WHITESPACE_FILTER);
return lineStartOffset + shift;
}
示例11: getStartOffset
import com.intellij.openapi.util.text.CharFilter; //导入依赖的package包/类
private int getStartOffset(@Nonnull final PsiElement element, @Nonnull final Editor editor) {
if (isBunchOfElement(element)) {
final PsiElement firstElement = getFirstElement(element);
return firstElement != null? firstElement.getTextRange().getStartOffset()
: element.getTextRange().getStartOffset();
}
final int offset = editor.getCaretModel().getOffset();
final int elementTextOffset = element.getTextOffset();
final Document document = editor.getDocument();
int lineNumber = document.getLineNumber(offset);
while (lineNumber != document.getLineNumber(elementTextOffset)) {
final String text = document.getText(TextRange.create(document.getLineStartOffset(lineNumber),
document.getLineEndOffset(lineNumber)));
if (StringUtil.isEmptyOrSpaces(text)) {
lineNumber += 1;
break;
}
lineNumber -= 1;
}
final int lineStartOffset = lineNumber == document.getLineNumber(elementTextOffset) ? elementTextOffset : document.getLineStartOffset(lineNumber);
final String lineText = document
.getText(TextRange.create(lineStartOffset, document.getLineEndOffset(lineNumber)));
int shift = StringUtil.findFirst(lineText, CharFilter.NOT_WHITESPACE_FILTER);
return lineStartOffset + shift;
}
示例12: preprocessOnPaste
import com.intellij.openapi.util.text.CharFilter; //导入依赖的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;
}