本文整理汇总了Java中com.intellij.codeInsight.completion.PrefixMatcher类的典型用法代码示例。如果您正苦于以下问题:Java PrefixMatcher类的具体用法?Java PrefixMatcher怎么用?Java PrefixMatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrefixMatcher类属于com.intellij.codeInsight.completion包,在下文中一共展示了PrefixMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateLookupItems
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
if (params.length == 0) return LookupElement.EMPTY_ARRAY;
Result paramResult = params[0].calculateQuickResult(context);
if (paramResult instanceof PsiTypeResult) {
final PsiType type = ((PsiTypeResult)paramResult).getType();
final PsiFile file = PsiDocumentManager.getInstance(context.getProject()).getPsiFile(context.getEditor().getDocument());
final PsiElement element = file.findElementAt(context.getStartOffset());
final Set<LookupElement> set = new LinkedHashSet<LookupElement>();
JavaTemplateUtil.addTypeLookupItem(set, type);
CodeInsightUtil.processSubTypes(type, element, false, PrefixMatcher.ALWAYS_TRUE, new Consumer<PsiType>() {
@Override
public void consume(PsiType psiType) {
JavaTemplateUtil.addTypeLookupItem(set, psiType);
}
});
return set.toArray(new LookupElement[set.size()]);
}
return LookupElement.EMPTY_ARRAY;
}
示例2: MembersGetter
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
protected MembersGetter(StaticMemberProcessor processor, @NotNull final PsiElement place) {
myPlace = place;
processor.processMembersOfRegisteredClasses(PrefixMatcher.ALWAYS_TRUE, new PairConsumer<PsiMember, PsiClass>() {
@Override
public void consume(PsiMember member, PsiClass psiClass) {
myImportedStatically.add(member);
}
});
PsiClass current = PsiTreeUtil.getContextOfType(place, PsiClass.class);
while (current != null) {
current = CompletionUtil.getOriginalOrSelf(current);
myPlaceClasses.add(current);
current = PsiTreeUtil.getContextOfType(current, PsiClass.class);
}
PsiMethod eachMethod = PsiTreeUtil.getContextOfType(place, PsiMethod.class);
while (eachMethod != null) {
eachMethod = CompletionUtil.getOriginalOrSelf(eachMethod);
myPlaceMethods.add(eachMethod);
eachMethod = PsiTreeUtil.getContextOfType(eachMethod, PsiMethod.class);
}
}
示例3: completeTillTypedCharOccurrence
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
private static boolean completeTillTypedCharOccurrence(char charTyped, LookupImpl lookup, LookupElement item) {
PrefixMatcher matcher = lookup.itemMatcher(item);
final String oldPrefix = matcher.getPrefix() + lookup.getAdditionalPrefix();
PrefixMatcher expanded = matcher.cloneWithPrefix(oldPrefix + charTyped);
if (expanded.prefixMatches(item)) {
for (String s : item.getAllLookupStrings()) {
if (matcher.prefixMatches(s)) {
int i = -1;
while (true) {
i = s.indexOf(charTyped, i + 1);
if (i < 0) break;
final String newPrefix = s.substring(0, i + 1);
if (expanded.prefixMatches(newPrefix)) {
lookup.replacePrefix(oldPrefix, newPrefix);
return true;
}
}
}
}
}
return false;
}
示例4: getLookupAction
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的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()));
}
示例5: CompleteReferenceProcessor
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
protected CompleteReferenceProcessor(GrReferenceExpression place, Consumer<LookupElement> consumer, @NotNull PrefixMatcher matcher, CompletionParameters parameters) {
super(null, EnumSet.allOf(ResolveKind.class), place, PsiType.EMPTY_ARRAY);
myConsumer = consumer;
myMatcher = matcher;
myParameters = parameters;
myPreferredFieldNames = addAllRestrictedProperties(place);
mySkipPackages = shouldSkipPackages(place);
myEventListener = JavaPsiFacade.getInstance(place.getProject()).findClass("java.util.EventListener", place.getResolveScope());
myPropertyNames.addAll(myPreferredFieldNames);
myFieldPointerOperator = place.hasAt();
myMethodPointerOperator = place.getDotTokenType() == GroovyTokenTypes.mMEMBER_POINTER;
myIsMap = isMap(place);
final PsiType thisType = GrReferenceResolveUtil.getQualifierType(place);
mySubstitutorComputer = new SubstitutorComputer(thisType, PsiType.EMPTY_ARRAY, PsiType.EMPTY_ARRAY, true, place, place.getParent());
}
示例6: prefixReplaced
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
public final void prefixReplaced(Lookup lookup, String newPrefix) {
//noinspection unchecked
Map<LookupElement, PrefixMatcher> newMatchers = new LinkedHashMap(EqualityPolicy.IDENTITY);
for (LookupElement item : myItems) {
if (item.isValid()) {
PrefixMatcher matcher = itemMatcher(item).cloneWithPrefix(newPrefix);
if (matcher.prefixMatches(item)) {
newMatchers.put(item, matcher);
}
}
}
myMatchers.clear();
myMatchers.putAll(newMatchers);
myItems.clear();
myItems.addAll(newMatchers.keySet());
prefixChanged(lookup);
}
示例7: MembersGetter
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
protected MembersGetter(StaticMemberProcessor processor, @NotNull final PsiElement place)
{
myPlace = place;
processor.processMembersOfRegisteredClasses(PrefixMatcher.ALWAYS_TRUE, (member, psiClass) -> myImportedStatically.add(member));
PsiClass current = PsiTreeUtil.getContextOfType(place, PsiClass.class);
while(current != null)
{
current = CompletionUtil.getOriginalOrSelf(current);
myPlaceClasses.add(current);
current = PsiTreeUtil.getContextOfType(current, PsiClass.class);
}
PsiMethod eachMethod = PsiTreeUtil.getContextOfType(place, PsiMethod.class);
while(eachMethod != null)
{
eachMethod = CompletionUtil.getOriginalOrSelf(eachMethod);
myPlaceMethods.add(eachMethod);
eachMethod = PsiTreeUtil.getContextOfType(eachMethod, PsiMethod.class);
}
}
示例8: getAllVirtualTypeElementNames
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
public Collection<String> getAllVirtualTypeElementNames(PrefixMatcher prefixMatcher, final GlobalSearchScope scope) {
Collection<String> keys =
FileBasedIndex.getInstance().getAllKeys(VirtualTypeIndex.KEY, project);
keys.removeIf(k -> !prefixMatcher.prefixMatches(k));
return keys;
}
示例9: processMembers
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
public void processMembers(final Consumer<LookupElement> results, @Nullable final PsiClass where,
final boolean acceptMethods, final boolean searchInheritors) {
if (where == null || isPrimitiveClass(where)) return;
final boolean searchFactoryMethods = searchInheritors &&
!CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName()) &&
!isPrimitiveClass(where);
final Project project = myPlace.getProject();
final GlobalSearchScope scope = myPlace.getResolveScope();
final PsiClassType baseType = JavaPsiFacade.getElementFactory(project).createType(where);
Consumer<PsiType> consumer = new Consumer<PsiType>() {
@Override
public void consume(PsiType psiType) {
PsiClass psiClass = PsiUtil.resolveClassInType(psiType);
if (psiClass == null) {
return;
}
psiClass = CompletionUtil.getOriginalOrSelf(psiClass);
if (mayProcessMembers(psiClass)) {
final FilterScopeProcessor<PsiElement> declProcessor = new FilterScopeProcessor<PsiElement>(TrueFilter.INSTANCE);
psiClass.processDeclarations(declProcessor, ResolveState.initial(), null, myPlace);
doProcessMembers(acceptMethods, results, psiType == baseType, declProcessor.getResults());
String name = psiClass.getName();
if (name != null && searchFactoryMethods) {
Collection<PsiMember> factoryMethods = JavaStaticMemberTypeIndex.getInstance().getStaticMembers(name, project, scope);
doProcessMembers(acceptMethods, results, false, factoryMethods);
}
}
}
};
consumer.consume(baseType);
if (searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName())) {
CodeInsightUtil.processSubTypes(baseType, myPlace, true, PrefixMatcher.ALWAYS_TRUE, consumer);
}
}
示例10: addCompletions
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
public static void addCompletions(@NotNull final JavaSmartCompletionParameters parameters,
@NotNull Consumer<LookupElement> result, final PrefixMatcher matcher) {
PsiType expectedType = parameters.getDefaultType();
if (!InheritanceUtil.isInheritor(expectedType, CommonClassNames.JAVA_LANG_CLASS)) {
expectedType = parameters.getExpectedType();
if (!InheritanceUtil.isInheritor(expectedType, CommonClassNames.JAVA_LANG_CLASS)) {
return;
}
}
PsiType classParameter = PsiUtil.substituteTypeParameter(expectedType, CommonClassNames.JAVA_LANG_CLASS, 0, false);
boolean addInheritors = false;
PsiElement position = parameters.getPosition();
if (classParameter instanceof PsiWildcardType) {
final PsiWildcardType wildcardType = (PsiWildcardType)classParameter;
classParameter = wildcardType.isSuper() ? wildcardType.getSuperBound() : wildcardType.getExtendsBound();
addInheritors = wildcardType.isExtends() && classParameter instanceof PsiClassType;
} else if (!matcher.getPrefix().isEmpty()) {
addInheritors = true;
classParameter = PsiType.getJavaLangObject(position.getManager(), position.getResolveScope());
}
if (classParameter != null) {
PsiFile file = position.getContainingFile();
addClassLiteralLookupElement(classParameter, result, file);
if (addInheritors) {
addInheritorClassLiterals(file, classParameter, result, matcher);
}
}
}
示例11: addInheritorClassLiterals
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
private static void addInheritorClassLiterals(final PsiFile context,
final PsiType classParameter,
final Consumer<LookupElement> result, PrefixMatcher matcher) {
final String canonicalText = classParameter.getCanonicalText();
if (CommonClassNames.JAVA_LANG_OBJECT.equals(canonicalText) && StringUtil.isEmpty(matcher.getPrefix())) {
return;
}
CodeInsightUtil.processSubTypes(classParameter, context, true, matcher, new Consumer<PsiType>() {
@Override
public void consume(PsiType type) {
addClassLiteralLookupElement(type, result, context);
}
});
}
示例12: getBestMatchingDegree
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
public static int getBestMatchingDegree(LookupElement element, PrefixMatcher matcher) {
int max = Integer.MIN_VALUE;
for (String lookupString : element.getAllLookupStrings()) {
max = Math.max(max, matcher.matchingDegree(lookupString));
}
return -max;
}
示例13: prefixMatches
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
private boolean prefixMatches(LookupImpl lookup, LookupElement item) {
PrefixMatcher matcher = lookup.itemMatcherNullable(item);
if (matcher == null) {
return false;
}
if (!myAdditionalPrefix.isEmpty()) {
matcher = matcher.cloneWithPrefix(matcher.getPrefix() + myAdditionalPrefix);
}
return matcher.prefixMatches(item);
}
示例14: CompleteReferencesWithSameQualifier
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
private CompleteReferencesWithSameQualifier(@NotNull GrReferenceExpression refExpr,
@NotNull PrefixMatcher matcher,
@Nullable GrExpression qualifier) {
myRefExpr = refExpr;
myMatcher = matcher;
myQualifier = qualifier;
}
示例15: CompleteReferenceExpression
import com.intellij.codeInsight.completion.PrefixMatcher; //导入依赖的package包/类
private CompleteReferenceExpression(@NotNull PrefixMatcher matcher,
@NotNull Consumer<LookupElement> consumer,
@NotNull GrReferenceExpressionImpl refExpr,
@NotNull CompletionParameters parameters) {
myMatcher = matcher;
myConsumer = consumer;
myParameters = parameters;
myRefExpr = refExpr;
myProcessor = new CompleteReferenceProcessor();
}