Search in sources :

Example 76 with LookupElement

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

the class AndroidXmlResourcesDomTest method testCustomXmlFileCompletion2.

public void testCustomXmlFileCompletion2() throws Throwable {
    VirtualFile file = copyFileToProject(getTestName(true) + ".xml");
    myFixture.configureFromExistingVirtualFile(file);
    myFixture.complete(CompletionType.BASIC);
    final LookupElement[] lookupElements = myFixture.getLookupElements();
    assertNotNull(lookupElements);
    for (LookupElement element : lookupElements) {
        if ("http://www.w3.org/1999/xhtml".equals(element.getLookupString())) {
            return;
        }
    }
    fail(Arrays.asList(lookupElements).toString());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 77 with LookupElement

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

the class AngularJavaScriptCompletionContributor method addCompletionVariants.

static void addCompletionVariants(@NotNull CompletionResultSet result, Collection<String> keys, @Nullable final String comment) {
    for (String key : keys) {
        if (StringUtil.isEmptyOrSpaces(key)) {
            continue;
        }
        LookupElementBuilder builder = LookupElementBuilder.create(key);
        if (comment != null) {
            builder = builder.withTailText(comment, true);
        }
        final LookupElement item = JSCompletionUtil.withJSLookupPriority(builder, JSLookupPriority.LOCAL_SCOPE_MAX_PRIORITY);
        result.addElement(item);
    }
}
Also used : LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 78 with LookupElement

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

the class DataBindingCompletionUtil method fillClassNames.

private static void fillClassNames(@NotNull CompletionResultSet resultSet, @NotNull String packagePrefix, @NotNull Module module) {
    final Project project = module.getProject();
    JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
    PsiPackage basePackage = javaPsiFacade.findPackage(packagePrefix);
    if (basePackage == null) {
        PsiClass aClass = javaPsiFacade.findClass(packagePrefix, module.getModuleWithDependenciesAndLibrariesScope(false));
        if (aClass != null) {
            PsiClass[] innerClasses = aClass.getInnerClasses();
            for (PsiClass innerClass : innerClasses) {
                resultSet.addElement(new JavaPsiClassReferenceElement(innerClass));
            }
        }
    // TODO: add completions for java.lang classes
    } else {
        GlobalSearchScope scope = module.getModuleWithDependenciesAndLibrariesScope(false);
        PsiPackage[] subPackages = basePackage.getSubPackages(scope);
        for (PsiPackage pkg : subPackages) {
            // many res folders also show up as package suggestions - eg. drawable-hdpi, which is clearly not a package.
            if (pkg.getSubPackages(scope).length > 0 || pkg.getClasses(scope).length > 0) {
                // For some reason, we see some invalid packages here - eg. META-INF. Filter them out.
                String name = pkg.getName();
                boolean invalidPkg = false;
                // can only be null for default package, which this is not, as it's a subpackage.
                assert name != null;
                for (int i = 0; i < name.length(); i++) {
                    if (!Character.isJavaIdentifierPart(name.charAt(i))) {
                        invalidPkg = true;
                        break;
                    }
                }
                if (invalidPkg) {
                    // skip adding this package.
                    continue;
                }
                LookupElement element = new TailTypeDecorator<LookupElement>(LookupElementBuilder.createWithIcon(pkg)) {

                    @Nullable
                    @Override
                    protected TailType computeTailType(InsertionContext context) {
                        return TailType.DOT;
                    }

                    @Override
                    public void handleInsert(InsertionContext context) {
                        super.handleInsert(context);
                        AutoPopupController.getInstance(project).scheduleAutoPopup(context.getEditor());
                    }
                };
                resultSet.addElement(element);
            }
        }
        for (PsiClass psiClass : basePackage.getClasses(scope)) {
            resultSet.addElement(new JavaPsiClassReferenceElement(psiClass));
        }
    }
}
Also used : TailTypeDecorator(com.intellij.codeInsight.lookup.TailTypeDecorator) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 79 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.

the class CallDefinitionClauseTest method testIssue457ShorterName.

/*
     * Tests
     */
public void testIssue457ShorterName() {
    String name = "fo";
    LookupElement lookupElement = lookupElement(name);
    LookupElementPresentation lookupElementPresentation = new LookupElementPresentation();
    lookupElement.renderElement(lookupElementPresentation);
    assertEquals(name, lookupElementPresentation.getItemText());
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 80 with LookupElement

use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.

the class CallDefinitionClauseTest method testIssue457LongerNameIssue503.

public void testIssue457LongerNameIssue503() {
    String name = "fooo";
    LookupElement lookupElement = lookupElement(name);
    LookupElementPresentation lookupElementPresentation = new LookupElementPresentation();
    lookupElement.renderElement(lookupElementPresentation);
    assertEquals(name, lookupElementPresentation.getItemText());
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

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