Search in sources :

Example 26 with LookupElementBuilder

use of com.intellij.codeInsight.lookup.LookupElementBuilder in project intellij-plugins by JetBrains.

the class BeanPropertyPathReference method getVariants.

@NotNull
public Object[] getVariants() {
    final PsiClass psiClass = getPsiClass();
    if (psiClass == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final Map<String, PsiMethod> properties = PropertyUtil.getAllProperties(psiClass, true, !isLast() || referenceSet.isSupportsReadOnlyProperties());
    final Object[] variants = new Object[properties.size()];
    int i = 0;
    for (final Map.Entry<String, PsiMethod> entry : properties.entrySet()) {
        final String propertyName = entry.getKey();
        final PsiMethod psiMethod = entry.getValue();
        final PsiType propertyType = PropertyUtil.getPropertyType(psiMethod);
        assert propertyType != null;
        final LookupElementBuilder variant = LookupElementBuilder.create(psiMethod, propertyName).withIcon(psiMethod.getIcon(0)).withStrikeoutness(psiMethod.isDeprecated()).withTypeText(propertyType.getPresentableText());
        variants[i++] = variant;
    }
    return variants;
}
Also used : LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with LookupElementBuilder

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

the class JavaModuleCompletion method lookupElement.

private static LookupElementBuilder lookupElement(PsiNamedElement e) {
    LookupElementBuilder lookup = LookupElementBuilder.create(e).withInsertHandler(FQN_INSERT_HANDLER);
    String fqn = e instanceof PsiClass ? ((PsiClass) e).getQualifiedName() : ((PsiQualifiedNamedElement) e).getQualifiedName();
    return fqn != null ? lookup.withPresentableText(fqn) : lookup;
}
Also used : LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder)

Example 28 with LookupElementBuilder

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

the class AntDomPropertyReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    final AntDomProject project = myInvocationContextElement.getParentOfType(AntDomProject.class, true);
    if (project != null) {
        final Collection<String> variants = PropertyResolver.resolve(project.getContextAntProject(), getCanonicalText(), myInvocationContextElement).getSecond();
        Object[] result = new Object[variants.size()];
        int idx = 0;
        for (String variant : variants) {
            final LookupElementBuilder builder = LookupElementBuilder.create(variant).withCaseSensitivity(false);
            final LookupElement element = AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE.applyPolicy(builder);
            result[idx++] = element;
        }
        return result;
    }
    return EMPTY_ARRAY;
}
Also used : LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with LookupElementBuilder

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

the class AntDomTargetReference method getVariants.

@NotNull
public Object[] getVariants() {
    final TargetResolver.Result result = doResolve(getCanonicalText());
    if (result == null) {
        return EMPTY_ARRAY;
    }
    final Map<String, AntDomTarget> variants = result.getVariants();
    final List resVariants = new ArrayList();
    final Set<String> existing = getExistingNames();
    for (String s : variants.keySet()) {
        if (existing.contains(s)) {
            continue;
        }
        final LookupElementBuilder builder = LookupElementBuilder.create(s).withCaseSensitivity(false);
        final LookupElement element = AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE.applyPolicy(builder);
        resVariants.add(element);
    }
    return ContainerUtil.toArray(resVariants, new Object[resVariants.size()]);
}
Also used : LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with LookupElementBuilder

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

the class AntDomMacrodefAttributeReference method getVariants.

@NotNull
public Object[] getVariants() {
    final AntDomMacroDef parentMacrodef = getParentMacrodef();
    if (parentMacrodef != null) {
        final List variants = new ArrayList();
        for (AntDomMacrodefAttribute attribute : parentMacrodef.getMacroAttributes()) {
            final String attribName = attribute.getName().getStringValue();
            if (attribName != null && attribName.length() > 0) {
                final LookupElementBuilder builder = LookupElementBuilder.create(attribName);
                final LookupElement element = AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE.applyPolicy(builder);
                variants.add(element);
            }
        }
        return ContainerUtil.toArray(variants, new Object[variants.size()]);
    }
    return EMPTY_ARRAY;
}
Also used : ArrayList(java.util.ArrayList) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) ArrayList(java.util.ArrayList) List(java.util.List) LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)53 LookupElement (com.intellij.codeInsight.lookup.LookupElement)19 NotNull (org.jetbrains.annotations.NotNull)16 PsiElement (com.intellij.psi.PsiElement)12 Nullable (org.jetbrains.annotations.Nullable)9 PsiFile (com.intellij.psi.PsiFile)6 Document (com.intellij.openapi.editor.Document)5 ArrayList (java.util.ArrayList)4 PrioritizedLookupElement (com.intellij.codeInsight.completion.PrioritizedLookupElement)3 Editor (com.intellij.openapi.editor.Editor)3 TextRange (com.intellij.openapi.util.TextRange)3 PsiPresentableMetaData (com.intellij.psi.meta.PsiPresentableMetaData)3 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlExtension (com.intellij.xml.XmlExtension)3 com.intellij.codeInsight.completion (com.intellij.codeInsight.completion)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2 ParenthesesInsertHandler (com.intellij.codeInsight.completion.util.ParenthesesInsertHandler)2 AutoCompletionPolicy (com.intellij.codeInsight.lookup.AutoCompletionPolicy)2 AllIcons (com.intellij.icons.AllIcons)2 FileType (com.intellij.openapi.fileTypes.FileType)2