Search in sources :

Example 66 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.

the class JavaConstructorCallElement method markClassItemWrapped.

private void markClassItemWrapped(@NotNull LookupElement classItem) {
    LookupElement delegate = classItem;
    while (true) {
        delegate.putUserData(WRAPPING_CONSTRUCTOR_CALL, this);
        if (!(delegate instanceof LookupElementDecorator))
            break;
        delegate = ((LookupElementDecorator) delegate).getDelegate();
    }
}
Also used : LookupElementDecorator(com.intellij.codeInsight.lookup.LookupElementDecorator) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 67 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.

the class JavaGenerateMemberCompletionContributor method addGetterSetterElements.

private static void addGetterSetterElements(CompletionResultSet result, PsiClass parent, Set<MethodSignature> addedSignatures) {
    int count = 0;
    for (PsiField field : parent.getFields()) {
        if (field instanceof PsiEnumConstant)
            continue;
        List<PsiMethod> prototypes = ContainerUtil.newSmartList();
        Collections.addAll(prototypes, GetterSetterPrototypeProvider.generateGetterSetters(field, true));
        Collections.addAll(prototypes, GetterSetterPrototypeProvider.generateGetterSetters(field, false));
        for (final PsiMethod prototype : prototypes) {
            if (parent.findMethodBySignature(prototype, false) == null && addedSignatures.add(prototype.getSignature(PsiSubstitutor.EMPTY))) {
                Icon icon = prototype.getIcon(Iconable.ICON_FLAG_VISIBILITY);
                result.addElement(createGenerateMethodElement(prototype, PsiSubstitutor.EMPTY, icon, "", new InsertHandler<LookupElement>() {

                    @Override
                    public void handleInsert(InsertionContext context, LookupElement item) {
                        removeLookupString(context);
                        insertGenerationInfos(context, Collections.singletonList(new PsiGenerationInfo<>(prototype)));
                    }
                }));
                if (count++ > 100)
                    return;
            }
        }
    }
}
Also used : RowIcon(com.intellij.ui.RowIcon) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 68 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.

the class SmartCompletionDecorator method computeTailType.

@Override
protected TailType computeTailType(InsertionContext context) {
    if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
        return TailType.NONE;
    }
    if (LookupItem.getDefaultTailType(context.getCompletionChar()) != null) {
        return null;
    }
    LookupElement delegate = getDelegate();
    LookupItem item = as(LookupItem.CLASS_CONDITION_KEY);
    Object object = delegate.getObject();
    if (!CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && (object instanceof PsiMethod || object instanceof PsiClass)) {
        return TailType.NONE;
    }
    final PsiExpression enclosing = PsiTreeUtil.getContextOfType(myPosition, PsiExpression.class, true);
    if (enclosing != null) {
        final PsiType type = JavaCompletionUtil.getLookupElementType(delegate);
        final TailType itemType = item != null ? item.getTailType() : TailType.NONE;
        if (type != null && type.isValid()) {
            Set<TailType> voidTyped = new HashSet<>();
            Set<TailType> sameTyped = new HashSet<>();
            Set<TailType> assignableTyped = new HashSet<>();
            for (ExpectedTypeInfo info : myExpectedTypeInfos) {
                final PsiType infoType = info.getType();
                final PsiType originalInfoType = JavaCompletionUtil.originalize(infoType);
                if (PsiType.VOID.equals(infoType)) {
                    voidTyped.add(info.getTailType());
                } else if (infoType.equals(type) || originalInfoType.equals(type)) {
                    sameTyped.add(info.getTailType());
                } else if ((info.getKind() == ExpectedTypeInfo.TYPE_OR_SUBTYPE && (infoType.isAssignableFrom(type) || originalInfoType.isAssignableFrom(type))) || (info.getKind() == ExpectedTypeInfo.TYPE_OR_SUPERTYPE && (type.isAssignableFrom(infoType) || type.isAssignableFrom(originalInfoType)))) {
                    assignableTyped.add(info.getTailType());
                }
            }
            if (!sameTyped.isEmpty()) {
                return sameTyped.size() == 1 ? sameTyped.iterator().next() : itemType;
            }
            if (!assignableTyped.isEmpty()) {
                return assignableTyped.size() == 1 ? assignableTyped.iterator().next() : itemType;
            }
            if (!voidTyped.isEmpty()) {
                return voidTyped.size() == 1 ? voidTyped.iterator().next() : itemType;
            }
        } else {
            if (myExpectedTypeInfos.size() == 1) {
                return myExpectedTypeInfos.iterator().next().getTailType();
            }
        }
        return itemType;
    }
    return null;
}
Also used : ExpectedTypeInfo(com.intellij.codeInsight.ExpectedTypeInfo) LookupItem(com.intellij.codeInsight.lookup.LookupItem) LookupElement(com.intellij.codeInsight.lookup.LookupElement) TailType(com.intellij.codeInsight.TailType) THashSet(gnu.trove.THashSet) HashSet(java.util.HashSet)

Example 69 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement 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 70 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.

the class XmlBasicToClassNameDelegator method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull final CompletionResultSet result) {
    PsiElement position = parameters.getPosition();
    PsiFile file = position.getContainingFile();
    if (parameters.getCompletionType() != CompletionType.BASIC || !JavaCompletionContributor.mayStartClassName(result) || !file.getLanguage().isKindOf(StdLanguages.XML)) {
        return;
    }
    final boolean empty = result.runRemainingContributors(parameters, true).isEmpty();
    if (!empty && parameters.getInvocationCount() == 0) {
        result.restartCompletionWhenNothingMatches();
    }
    if (empty && JavaClassReferenceCompletionContributor.findJavaClassReference(file, parameters.getOffset()) != null || parameters.isExtendedCompletion()) {
        CompletionService.getCompletionService().getVariantsFromContributors(parameters.delegateToClassName(), null, completionResult -> {
            LookupElement lookupElement = completionResult.getLookupElement();
            JavaPsiClassReferenceElement classElement = lookupElement.as(JavaPsiClassReferenceElement.CLASS_CONDITION_KEY);
            if (classElement != null) {
                classElement.setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
            }
            lookupElement.putUserData(XmlCompletionContributor.WORD_COMPLETION_COMPATIBLE, Boolean.TRUE);
            result.passResult(completionResult);
        });
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

LookupElement (com.intellij.codeInsight.lookup.LookupElement)183 PsiElement (com.intellij.psi.PsiElement)33 NotNull (org.jetbrains.annotations.NotNull)32 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)20 Nullable (org.jetbrains.annotations.Nullable)17 ArrayList (java.util.ArrayList)14 Project (com.intellij.openapi.project.Project)12 LookupElementPresentation (com.intellij.codeInsight.lookup.LookupElementPresentation)10 Document (com.intellij.openapi.editor.Document)10 PsiFile (com.intellij.psi.PsiFile)10 Editor (com.intellij.openapi.editor.Editor)9 THashSet (gnu.trove.THashSet)8 LinkedHashSet (java.util.LinkedHashSet)8 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)7 XmlTag (com.intellij.psi.xml.XmlTag)7 Consumer (com.intellij.util.Consumer)7 HashSet (java.util.HashSet)7 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)6 PsiTypeLookupItem (com.intellij.codeInsight.lookup.PsiTypeLookupItem)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6