Search in sources :

Example 36 with LookupElementBuilder

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

the class AndroidActivityAliasCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    if (parameters.getCompletionType() != CompletionType.BASIC) {
        return;
    }
    final Editor editor = parameters.getEditor();
    LaunchOptionConfigurableContext context = editor.getUserData(LaunchOptionConfigurableContext.KEY);
    if (context == null) {
        return;
    }
    final Module module = context.getModule();
    if (module == null) {
        return;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return;
    }
    final String prefix = parameters.getEditor().getDocument().getText().substring(0, parameters.getOffset());
    result = result.withPrefixMatcher(prefix);
    final PsiClass activityClass = JavaPsiFacade.getInstance(module.getProject()).findClass(AndroidUtils.ACTIVITY_BASE_CLASS_NAME, module.getModuleWithDependenciesAndLibrariesScope(false));
    if (activityClass != null) {
        final CompletionResultSet finalResult = result;
        ClassInheritorsSearch.search(activityClass, module.getModuleWithDependenciesScope(), true, true, false).forEach(new Processor<PsiClass>() {

            @Override
            public boolean process(PsiClass psiClass) {
                final PsiModifierList modifierList = psiClass.getModifierList();
                if (modifierList != null && modifierList.hasModifierProperty(PsiModifier.PUBLIC) && !modifierList.hasModifierProperty(PsiModifier.ABSTRACT)) {
                    final String qName = psiClass.getQualifiedName();
                    if (qName != null && qName.length() > 0) {
                        finalResult.addElement(JavaLookupElementBuilder.forClass(psiClass, qName));
                    }
                }
                return true;
            }
        });
    }
    final Set<String> aliases = collectActivityAliases(facet);
    if (aliases.size() > 0) {
        for (String alias : aliases) {
            LookupElementBuilder element = LookupElementBuilder.create(alias);
            final String shortName = StringUtilRt.getShortName(alias);
            if (!shortName.equals(alias)) {
                element = element.withLookupString(shortName);
            }
            result.addElement(element);
        }
    }
    result.stopHere();
}
Also used : LaunchOptionConfigurableContext(com.android.tools.idea.run.editor.LaunchOptionConfigurableContext) PsiClass(com.intellij.psi.PsiClass) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) Editor(com.intellij.openapi.editor.Editor) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) PsiModifierList(com.intellij.psi.PsiModifierList)

Example 37 with LookupElementBuilder

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

the class CommitCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiFile file = parameters.getOriginalFile();
    Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    if (document == null)
        return;
    CommitMessage commitMessage = document.getUserData(CommitMessage.DATA_KEY);
    if (commitMessage == null)
        return;
    result.stopHere();
    if (parameters.getInvocationCount() <= 0)
        return;
    List<ChangeList> lists = commitMessage.getChangeLists();
    if (lists.isEmpty())
        return;
    String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters);
    CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix));
    for (ChangeList list : lists) {
        for (Change change : list.getChanges()) {
            ContentRevision revision = change.getAfterRevision() == null ? change.getBeforeRevision() : change.getAfterRevision();
            if (revision != null) {
                FilePath filePath = revision.getFile();
                LookupElementBuilder element = LookupElementBuilder.create(filePath.getName()).withIcon(filePath.getFileType().getIcon());
                insensitive.addElement(element);
            }
        }
    }
}
Also used : CommitMessage(com.intellij.openapi.vcs.ui.CommitMessage) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PsiFile(com.intellij.psi.PsiFile) Change(com.intellij.openapi.vcs.changes.Change) Document(com.intellij.openapi.editor.Document) CamelHumpMatcher(com.intellij.codeInsight.completion.impl.CamelHumpMatcher)

Example 38 with LookupElementBuilder

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

the class TextFieldWithAutoCompletionListProvider method addCompletionElements.

private static <T> void addCompletionElements(final CompletionResultSet result, final TextCompletionValueDescriptor<T> descriptor, final Collection<T> items, final int index) {
    final AutoCompletionPolicy completionPolicy = ApplicationManager.getApplication().isUnitTestMode() ? AutoCompletionPolicy.ALWAYS_AUTOCOMPLETE : AutoCompletionPolicy.NEVER_AUTOCOMPLETE;
    int grouping = index;
    for (final T item : items) {
        if (item == null) {
            LOG.error("Null item from " + descriptor);
            continue;
        }
        LookupElementBuilder builder = descriptor.createLookupBuilder(item);
        result.addElement(PrioritizedLookupElement.withGrouping(builder.withAutoCompletionPolicy(completionPolicy), grouping--));
    }
}
Also used : LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) AutoCompletionPolicy(com.intellij.codeInsight.lookup.AutoCompletionPolicy)

Example 39 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 40 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)

Aggregations

LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)57 LookupElement (com.intellij.codeInsight.lookup.LookupElement)20 NotNull (org.jetbrains.annotations.NotNull)16 PsiElement (com.intellij.psi.PsiElement)13 Nullable (org.jetbrains.annotations.Nullable)9 PsiFile (com.intellij.psi.PsiFile)7 Document (com.intellij.openapi.editor.Document)5 ArrayList (java.util.ArrayList)5 PlainPrefixMatcher (com.intellij.codeInsight.completion.PlainPrefixMatcher)3 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 InsertionContext (com.intellij.codeInsight.completion.InsertionContext)2 ParenthesesInsertHandler (com.intellij.codeInsight.completion.util.ParenthesesInsertHandler)2 AutoCompletionPolicy (com.intellij.codeInsight.lookup.AutoCompletionPolicy)2