Search in sources :

Example 1 with CompletionElement

use of com.intellij.codeInsight.completion.scope.CompletionElement in project intellij-community by JetBrains.

the class SuperCalls method suggestQualifyingSuperCalls.

static Set<LookupElement> suggestQualifyingSuperCalls(PsiElement element, PsiJavaReference javaReference, ElementFilter elementFilter, JavaCompletionProcessor.Options options, Condition<String> nameCondition) {
    Set<LookupElement> set = ContainerUtil.newLinkedHashSet();
    for (final String className : getContainingClassNames(element)) {
        PsiReferenceExpression fakeSuper = JavaCompletionUtil.createReference(className + ".super.rulez", element);
        PsiElement leaf = ObjectUtils.assertNotNull(fakeSuper.getReferenceNameElement());
        JavaCompletionProcessor superProcessor = new JavaCompletionProcessor(leaf, elementFilter, options, nameCondition);
        fakeSuper.processVariants(superProcessor);
        for (CompletionElement completionElement : superProcessor.getResults()) {
            for (LookupElement item : JavaCompletionUtil.createLookupElements(completionElement, javaReference)) {
                set.add(withQualifiedSuper(className, item));
            }
        }
    }
    return set;
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) JavaCompletionProcessor(com.intellij.codeInsight.completion.scope.JavaCompletionProcessor) CompletionElement(com.intellij.codeInsight.completion.scope.CompletionElement)

Example 2 with CompletionElement

use of com.intellij.codeInsight.completion.scope.CompletionElement in project intellij-community by JetBrains.

the class JavaCompletionUtil method processJavaQualifiedReference.

private static Set<LookupElement> processJavaQualifiedReference(PsiElement element, PsiJavaReference javaReference, ElementFilter elementFilter, JavaCompletionProcessor.Options options, final PrefixMatcher matcher, CompletionParameters parameters) {
    final Set<LookupElement> set = new LinkedHashSet<>();
    final Condition<String> nameCondition = matcher::prefixMatches;
    final JavaCompletionProcessor processor = new JavaCompletionProcessor(element, elementFilter, options, nameCondition);
    final PsiType plainQualifier = processor.getQualifierType();
    PsiType qualifierType = plainQualifier;
    PsiType runtimeQualifier = getQualifierCastType(javaReference, parameters);
    if (runtimeQualifier != null) {
        PsiType composite = qualifierType == null ? runtimeQualifier : PsiIntersectionType.createIntersection(qualifierType, runtimeQualifier);
        PsiElement ctx = createContextWithXxxVariable(element, composite);
        javaReference = createReference("xxx.xxx", ctx);
        qualifierType = runtimeQualifier;
        processor.setQualifierType(qualifierType);
    }
    javaReference.processVariants(processor);
    final PsiTypeLookupItem castItem = runtimeQualifier == null ? null : PsiTypeLookupItem.createLookupItem(runtimeQualifier, (PsiReferenceExpression) javaReference);
    final boolean pkgContext = inSomePackage(element);
    PsiClass qualifierClass = PsiUtil.resolveClassInClassTypeOnly(qualifierType);
    final boolean honorExcludes = qualifierClass == null || !isInExcludedPackage(qualifierClass, false);
    final Set<PsiMember> mentioned = new THashSet<>();
    for (CompletionElement completionElement : processor.getResults()) {
        for (LookupElement item : createLookupElements(completionElement, javaReference)) {
            item.putUserData(QUALIFIER_TYPE_ATTR, qualifierType);
            final Object o = item.getObject();
            if (o instanceof PsiClass && !isSourceLevelAccessible(element, (PsiClass) o, pkgContext)) {
                continue;
            }
            if (o instanceof PsiMember) {
                if (honorExcludes && isInExcludedPackage((PsiMember) o, true)) {
                    continue;
                }
                mentioned.add(CompletionUtil.getOriginalOrSelf((PsiMember) o));
            }
            set.add(highlightIfNeeded(qualifierType, castQualifier(item, castItem, plainQualifier, processor), o, element));
        }
    }
    if (javaReference instanceof PsiJavaCodeReferenceElement) {
        PsiElement refQualifier = ((PsiJavaCodeReferenceElement) javaReference).getQualifier();
        if (refQualifier == null) {
            final StaticMemberProcessor memberProcessor = new JavaStaticMemberProcessor(parameters);
            memberProcessor.processMembersOfRegisteredClasses(matcher, (member, psiClass) -> {
                if (!mentioned.contains(member) && processor.satisfies(member, ResolveState.initial())) {
                    set.add(memberProcessor.createLookupElement(member, psiClass, true));
                }
            });
        } else if (refQualifier instanceof PsiSuperExpression && ((PsiSuperExpression) refQualifier).getQualifier() == null) {
            set.addAll(SuperCalls.suggestQualifyingSuperCalls(element, javaReference, elementFilter, options, nameCondition));
        }
    }
    return set;
}
Also used : THashSet(gnu.trove.THashSet) CompletionElement(com.intellij.codeInsight.completion.scope.CompletionElement) JavaCompletionProcessor(com.intellij.codeInsight.completion.scope.JavaCompletionProcessor) FakePsiElement(com.intellij.psi.impl.FakePsiElement)

Aggregations

CompletionElement (com.intellij.codeInsight.completion.scope.CompletionElement)2 JavaCompletionProcessor (com.intellij.codeInsight.completion.scope.JavaCompletionProcessor)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 FakePsiElement (com.intellij.psi.impl.FakePsiElement)1 THashSet (gnu.trove.THashSet)1