本文整理汇总了Java中com.intellij.codeInsight.lookup.CharFilter类的典型用法代码示例。如果您正苦于以下问题:Java CharFilter类的具体用法?Java CharFilter怎么用?Java CharFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CharFilter类属于com.intellij.codeInsight.lookup包,在下文中一共展示了CharFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getLookupAction
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
static CharFilter.Result getLookupAction(final char charTyped, final LookupImpl lookup) {
final CharFilter.Result filtersDecision = getFiltersDecision(charTyped, lookup);
final LookupElement currentItem = lookup.getCurrentItem();
if (currentItem != null && charTyped != ' ') {
String postfix = lookup.getAdditionalPrefix() + charTyped;
final PrefixMatcher matcher = lookup.itemMatcher(currentItem);
for (String lookupString : currentItem.getAllLookupStrings()) {
if (lookupString.startsWith(matcher.getPrefix() + postfix)) {
return CharFilter.Result.ADD_TO_PREFIX;
}
}
}
if (filtersDecision != null) {
return filtersDecision;
}
throw new AssertionError("Typed char not handler by char filter: c=" + charTyped +
"; prefix=" + currentItem +
"; filters=" + Arrays.toString(getFilters()));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:LookupTypedHandler.java
示例2: getFiltersDecision
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Nullable
private static CharFilter.Result getFiltersDecision(char charTyped, LookupImpl lookup) {
lookup.checkValid();
LookupElement item = lookup.getCurrentItem();
int prefixLength = item == null ? lookup.getAdditionalPrefix().length(): lookup.itemPattern(item).length();
for (final CharFilter extension : getFilters()) {
final CharFilter.Result result = extension.acceptChar(charTyped, prefixLength, lookup);
if (result != null) {
return result;
}
if (lookup.isLookupDisposed()) {
throw new AssertionError("Lookup disposed after " + extension);
}
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:LookupTypedHandler.java
示例3: acceptChar
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Nullable
@Override
public CharFilter.Result acceptChar(char c, int prefixLength, Lookup lookup) {
if (c != '.' || !lookup.isCompletion()) {
return null;
}
if (!(lookup.getPsiFile() instanceof XPathFile)) {
// could be an XML file during XML autocompletion
final LookupElement item = lookup.getCurrentItem();
if (item == null || !(item.getObject() instanceof org.intellij.lang.xpath.completion.Lookup)) {
// current completion item isn't something XPath related, continue with other handlers
return null;
}
}
// typed '.' should appear literally in editor, it has no meaning for completion
return Result.HIDE_LOOKUP;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:XPathCharFilter.java
示例4: executeInLookup
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Override
protected void executeInLookup(LookupImpl lookup, DataContext context) {
final Editor editor = lookup.getEditor();
final int offset = editor.getCaretModel().getOffset();
CharSequence seq = editor.getDocument().getCharsSequence();
if (seq.length() <= offset || !lookup.isCompletion()) {
myOriginalHandler.execute(editor, context);
return;
}
char c = seq.charAt(offset);
CharFilter.Result lookupAction = LookupTypedHandler.getLookupAction(c, lookup);
if (lookupAction != CharFilter.Result.ADD_TO_PREFIX || Character.isWhitespace(c)) {
myOriginalHandler.execute(editor, context);
return;
}
if (!lookup.performGuardedChange(new Runnable() {
@Override
public void run() {
editor.getSelectionModel().removeSelection();
editor.getCaretModel().moveToOffset(offset + 1);
}
})) {
return;
}
lookup.appendPrefix(c);
final CompletionProgressIndicator completion = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
if (completion != null) {
completion.prefixUpdated();
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:35,代码来源:LookupActionHandler.java
示例5: getFiltersDecision
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Nullable
private static CharFilter.Result getFiltersDecision(char charTyped, LookupImpl lookup) {
LookupElement item = lookup.getCurrentItem();
int prefixLength = item == null ? lookup.getAdditionalPrefix().length(): lookup.itemPattern(item).length();
for (final CharFilter extension : getFilters()) {
final CharFilter.Result result = extension.acceptChar(charTyped, prefixLength, lookup);
if (result != null) {
return result;
}
}
return null;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:14,代码来源:LookupTypedHandler.java
示例6: getLookupAction
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
static CharFilter.Result getLookupAction(final char charTyped, final LookupImpl lookup) {
final CharFilter.Result filtersDecision = getFiltersDecision(charTyped, lookup);
if (filtersDecision != null) {
return filtersDecision;
}
throw new AssertionError("Typed char not handler by char filter: c=" + charTyped +
"; prefix=" + lookup.getCurrentItem() +
"; filters=" + Arrays.toString(getFilters()));
}
开发者ID:consulo,项目名称:consulo,代码行数:10,代码来源:LookupTypedHandler.java
示例7: acceptChar
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Override
public Result acceptChar(char c, final int prefixLength, final Lookup lookup) {
if (!lookup.getPsiFile().getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
return null;
}
LookupElement item = lookup.getCurrentItem();
if (item == null) return null;
final Object o = item.getObject();
if (c == '!') {
if (o instanceof PsiVariable) {
if (PsiType.BOOLEAN.isAssignableFrom(((PsiVariable)o).getType())) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
if (o instanceof PsiMethod) {
final PsiType type = ((PsiMethod)o).getReturnType();
if (type != null && PsiType.BOOLEAN.isAssignableFrom(type)) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
if (o instanceof PsiKeyword && ((PsiKeyword)o).textMatches(PsiKeyword.INSTANCEOF)) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return null;
}
if (c == '.' && isWithinLiteral(lookup)) return Result.ADD_TO_PREFIX;
if (c == ':') {
PsiFile file = lookup.getPsiFile();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(lookup.getEditor().getDocument());
PsiElement leaf = file.findElementAt(lookup.getEditor().getCaretModel().getOffset() - 1);
if (PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_8)) {
PsiStatement statement = PsiTreeUtil.getParentOfType(leaf, PsiStatement.class);
if (statement == null ||
statement.getTextRange().getStartOffset() != leaf.getTextRange().getStartOffset()) { // not typing a statement label
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
}
if (PsiTreeUtil.getParentOfType(leaf, PsiSwitchLabelStatement.class) != null ||
PsiTreeUtil.getParentOfType(leaf, PsiConditionalExpression.class) != null) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return Result.HIDE_LOOKUP;
}
if (c == '[' || c == ']' || c == ')' || c == '>') return CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '<' && o instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '(') {
if (o instanceof PsiClass) {
if (PsiJavaPatterns.psiElement().afterLeaf(PsiKeyword.NEW).accepts(lookup.getPsiElement())) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return Result.HIDE_LOOKUP;
}
if (o instanceof PsiType) {
return Result.HIDE_LOOKUP;
}
}
if ((c == ',' || c == '=') && o instanceof PsiVariable) {
int lookupStart = lookup.getLookupStart();
String name = ((PsiVariable)o).getName();
if (lookupStart >= 0 && name != null && name.equals(lookup.itemPattern(item))) {
return Result.HIDE_LOOKUP;
}
}
if (c == '#' && PsiTreeUtil.getParentOfType(lookup.getPsiElement(), PsiDocComment.class) != null) {
if (o instanceof PsiClass) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
}
if (c == '(' && PsiKeyword.RETURN.equals(item.getLookupString())) {
return Result.HIDE_LOOKUP;
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:77,代码来源:JavaCharFilter.java
示例8: getFilters
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
private static CharFilter[] getFilters() {
return Extensions.getExtensions(CharFilter.EP_NAME);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:LookupTypedHandler.java
示例9: acceptChar
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Override
@Nullable
public Result acceptChar(char c, int prefixLength, Lookup lookup) {
final PsiFile psiFile = lookup.getPsiFile();
if (psiFile != null && !psiFile.getViewProvider().getLanguages().contains(GroovyLanguage.INSTANCE)) return null;
LookupElement item = lookup.getCurrentItem();
if (item == null) return null;
if (Character.isJavaIdentifierPart(c) || c == '\'') {
return Result.ADD_TO_PREFIX;
}
int caret = lookup.getEditor().getCaretModel().getOffset();
if (c == '.' && prefixLength == 0 && !lookup.isSelectionTouched() && caret > 0 &&
lookup.getEditor().getDocument().getCharsSequence().charAt(caret - 1) == '.') {
return Result.HIDE_LOOKUP;
}
if (c == ':') {
PsiFile file = lookup.getPsiFile();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(lookup.getEditor().getDocument());
PsiElement element = file.findElementAt(Math.max(caret - 1, 0));
if (PsiJavaPatterns.psiElement().withParent(
PsiJavaPatterns.psiElement(GrReferenceExpression.class).withParent(
StandardPatterns.or(PsiJavaPatterns.psiElement(GrCaseLabel.class),
PsiJavaPatterns.psiElement(GrConditionalExpression.class)))).accepts(element)) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
if (item.getObject() instanceof NamedArgumentDescriptor &&
(MapArgumentCompletionProvider.IN_ARGUMENT_LIST_OF_CALL.accepts(element) ||
MapArgumentCompletionProvider.IN_LABEL.accepts(element))) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return Result.HIDE_LOOKUP;
}
if (c == '[' || c == ']' || c == ')' || c == '>') return CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '<' && item.getObject() instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '(' && PsiKeyword.RETURN.equals(item.getLookupString())) {
return Result.HIDE_LOOKUP;
}
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:47,代码来源:GroovyReferenceCharFilter.java
示例10: acceptChar
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Override
public Result acceptChar(char c, final int prefixLength, final Lookup lookup) {
if (!lookup.getPsiFile().getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
return null;
}
LookupElement item = lookup.getCurrentItem();
if (item == null) return null;
final Object o = item.getObject();
if (c == '!') {
if (o instanceof PsiVariable) {
if (PsiType.BOOLEAN.isAssignableFrom(((PsiVariable)o).getType())) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
if (o instanceof PsiMethod) {
final PsiType type = ((PsiMethod)o).getReturnType();
if (type != null && PsiType.BOOLEAN.isAssignableFrom(type)) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return null;
}
if (c == '.' && isWithinLiteral(lookup)) return Result.ADD_TO_PREFIX;
if (c == ':') {
PsiFile file = lookup.getPsiFile();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(lookup.getEditor().getDocument());
PsiElement leaf = file.findElementAt(lookup.getEditor().getCaretModel().getOffset() - 1);
if (PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_8)) {
PsiStatement statement = PsiTreeUtil.getParentOfType(leaf, PsiStatement.class);
if (statement == null ||
statement.getTextRange().getStartOffset() != leaf.getTextRange().getStartOffset()) { // not typing a statement label
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
}
if (PsiTreeUtil.getParentOfType(leaf, PsiSwitchLabelStatement.class) != null ||
PsiTreeUtil.getParentOfType(leaf, PsiConditionalExpression.class) != null) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return Result.HIDE_LOOKUP;
}
if (c == '[' || c == ']' || c == ')' || c == '>') return CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '<' && o instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '(') {
if (o instanceof PsiClass) {
if (PsiJavaPatterns.psiElement().afterLeaf(PsiKeyword.NEW).accepts(lookup.getPsiElement())) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return Result.HIDE_LOOKUP;
}
if (o instanceof PsiType) {
return Result.HIDE_LOOKUP;
}
}
if ((c == ',' || c == '=') && o instanceof PsiVariable) {
int lookupStart = ((LookupImpl)lookup).getLookupStart();
String name = ((PsiVariable)o).getName();
if (lookupStart >= 0 && name != null && name.equals(lookup.itemPattern(item))) {
return Result.HIDE_LOOKUP;
}
}
if (c == '#' && PsiTreeUtil.getParentOfType(lookup.getPsiElement(), PsiDocComment.class) != null) {
if (o instanceof PsiClass) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
}
if (c == '(' && PsiKeyword.RETURN.equals(item.getLookupString())) {
return Result.HIDE_LOOKUP;
}
return null;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:74,代码来源:JavaCharFilter.java
示例11: acceptChar
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Nullable
public Result acceptChar(char c, int prefixLength, Lookup lookup) {
final PsiFile psiFile = lookup.getPsiFile();
if (psiFile != null && !psiFile.getViewProvider().getLanguages().contains(GroovyFileType.GROOVY_LANGUAGE)) return null;
LookupElement item = lookup.getCurrentItem();
if (item == null) return null;
if (Character.isJavaIdentifierPart(c) || c == '\'') {
return Result.ADD_TO_PREFIX;
}
int caret = lookup.getEditor().getCaretModel().getOffset();
if (c == '.' && prefixLength == 0 && !lookup.isSelectionTouched() && caret > 0 &&
lookup.getEditor().getDocument().getCharsSequence().charAt(caret - 1) == '.') {
return Result.HIDE_LOOKUP;
}
if (c == ':') {
PsiFile file = lookup.getPsiFile();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(lookup.getEditor().getDocument());
PsiElement element = file.findElementAt(Math.max(caret - 1, 0));
if (psiElement().withParent(
psiElement(GrReferenceExpression.class).withParent(
StandardPatterns.or(psiElement(GrCaseLabel.class),
psiElement(GrConditionalExpression.class)))).accepts(element)) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
if (item.getObject() instanceof NamedArgumentDescriptor &&
(MapArgumentCompletionProvider.IN_ARGUMENT_LIST_OF_CALL.accepts(element) ||
MapArgumentCompletionProvider.IN_LABEL.accepts(element))) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return Result.HIDE_LOOKUP;
}
if (c == '[' || c == ']' || c == ')' || c == '>') return CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '<' && item.getObject() instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '(' && PsiKeyword.RETURN.equals(item.getLookupString())) {
return Result.HIDE_LOOKUP;
}
return null;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:46,代码来源:GroovyReferenceCharFilter.java
示例12: executeInLookup
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Override
protected void executeInLookup(LookupImpl lookup, DataContext context, final Caret caret) {
final Editor editor = lookup.getEditor();
final int offset = editor.getCaretModel().getOffset();
final CharSequence seq = editor.getDocument().getCharsSequence();
if (seq.length() <= offset || !lookup.isCompletion()) {
myOriginalHandler.execute(editor, caret, context);
return;
}
char c = seq.charAt(offset);
CharFilter.Result lookupAction = LookupTypedHandler.getLookupAction(c, lookup);
if (lookupAction != CharFilter.Result.ADD_TO_PREFIX || Character.isWhitespace(c)) {
myOriginalHandler.execute(editor, caret, context);
return;
}
if (!lookup.performGuardedChange(() -> {
CaretAction action = new CaretAction() {
@Override
public void perform(Caret caret1) {
caret1.removeSelection();
int caretOffset = caret1.getOffset();
if (caretOffset < seq.length()) {
caret1.moveToOffset(caretOffset + 1);
}
}
};
if (caret == null) {
editor.getCaretModel().runForEachCaret(action);
}
else {
action.perform(caret);
}
})) {
return;
}
lookup.appendPrefix(c);
final CompletionProgressIndicator completion = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
if (completion != null) {
completion.prefixUpdated();
}
}
开发者ID:consulo,项目名称:consulo,代码行数:46,代码来源:LookupActionHandler.java
示例13: acceptChar
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Override
@Nullable
public CharFilter.Result acceptChar(char c) {
if (!mySeparators.contains(c)) return CharFilter.Result.ADD_TO_PREFIX;
return CharFilter.Result.HIDE_LOOKUP;
}
开发者ID:consulo,项目名称:consulo,代码行数:7,代码来源:ValuesCompletionProvider.java
示例14: acceptChar
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Nullable
CharFilter.Result acceptChar(char c);
开发者ID:consulo,项目名称:consulo,代码行数:3,代码来源:TextCompletionProvider.java
示例15: acceptChar
import com.intellij.codeInsight.lookup.CharFilter; //导入依赖的package包/类
@Override
public Result acceptChar(char c, final int prefixLength, final Lookup lookup) {
if (!lookup.getPsiFile().getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
return null;
}
LookupElement item = lookup.getCurrentItem();
if (item == null) return null;
final Object o = item.getObject();
if (c == '!') {
if (o instanceof PsiVariable) {
if (PsiType.BOOLEAN.isAssignableFrom(((PsiVariable)o).getType())) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
if (o instanceof PsiMethod) {
final PsiType type = ((PsiMethod)o).getReturnType();
if (type != null && PsiType.BOOLEAN.isAssignableFrom(type)) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return null;
}
if (c == '.' && isWithinLiteral(lookup)) return Result.ADD_TO_PREFIX;
if (c == ':') {
PsiFile file = lookup.getPsiFile();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(lookup.getEditor().getDocument());
PsiElement element = lookup.getPsiElement();
if (PsiTreeUtil.getParentOfType(element, PsiSwitchLabelStatement.class) != null ||
PsiTreeUtil.getParentOfType(element, PsiConditionalExpression.class) != null) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return Result.HIDE_LOOKUP;
}
if (c == '[' || c == ']' || c == ')' || c == '>') return CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '<' && o instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
if (c == '(') {
if (o instanceof PsiClass) {
if (PsiJavaPatterns.psiElement().afterLeaf(PsiKeyword.NEW).accepts(lookup.getPsiElement())) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
return Result.HIDE_LOOKUP;
}
if (o instanceof PsiType) {
return Result.HIDE_LOOKUP;
}
}
if ((c == ',' || c == '=') && o instanceof PsiVariable) {
int lookupStart = ((LookupImpl)lookup).getLookupStart();
String name = ((PsiVariable)o).getName();
if (lookupStart >= 0 && name != null && name.equals(lookup.itemPattern(item))) {
return Result.HIDE_LOOKUP;
}
}
if (c == '#' && PsiTreeUtil.getParentOfType(lookup.getPsiElement(), PsiDocComment.class) != null) {
if (o instanceof PsiClass) {
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
}
}
if (c == '(' && PsiKeyword.RETURN.equals(item.getLookupString())) {
return Result.HIDE_LOOKUP;
}
return null;
}
开发者ID:consulo,项目名称:consulo-java,代码行数:67,代码来源:JavaCharFilter.java
注:本文中的com.intellij.codeInsight.lookup.CharFilter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论