Search in sources :

Example 36 with LookupElement

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

the class AddVariableInitializerFix method suggestInitializer.

@NotNull
public static LookupElement[] suggestInitializer(final PsiVariable variable) {
    PsiType type = variable.getType();
    final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(variable.getProject());
    final List<LookupElement> result = new SmartList<>();
    final String defaultValue = PsiTypesUtil.getDefaultValueOfType(type);
    final ExpressionLookupItem defaultExpression = new ExpressionLookupItem(elementFactory.createExpressionFromText(defaultValue, variable));
    result.add(defaultExpression);
    if (type instanceof PsiClassType) {
        final PsiClass aClass = PsiTypesUtil.getPsiClass(type);
        if (aClass != null && PsiUtil.hasDefaultConstructor(aClass)) {
            final String expressionText = PsiKeyword.NEW + " " + type.getCanonicalText(false) + "()";
            ExpressionLookupItem newExpression = new ExpressionLookupItem(elementFactory.createExpressionFromText(expressionText, variable));
            result.add(newExpression);
        }
    }
    return result.toArray(new LookupElement[result.size()]);
}
Also used : ExpressionLookupItem(com.intellij.codeInsight.lookup.ExpressionLookupItem) SmartList(com.intellij.util.SmartList) LookupElement(com.intellij.codeInsight.lookup.LookupElement) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with LookupElement

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

the class FlexCompletionTest method testNonApplicableInheritors.

@JSTestOptions({ JSTestOption.WithGumboSdk, JSTestOption.WithFlexLib, JSTestOption.WithSmartCompletion })
public void testNonApplicableInheritors() throws Exception {
    FlexTestUtils.modifyConfigs(myProject, editor -> {
        final ModifiableFlexBuildConfiguration bc1 = editor.getConfigurations(myModule)[0];
        final ModifiableFlexBuildConfiguration bc2 = editor.copyConfiguration(bc1, BuildConfigurationNature.DEFAULT);
        bc2.setName("bc 2");
        bc2.getDependencies().getModifiableEntries().clear();
    });
    LookupElement[] elements = doTest("", "as");
    assertEquals(3, elements.length);
    assertEquals("Image", elements[0].getLookupString());
    assertEquals("Base64Image", elements[1].getLookupString());
    assertEquals("ImageMap", elements[2].getLookupString());
    final FlexBuildConfigurationManager manager = FlexBuildConfigurationManager.getInstance(myModule);
    manager.setActiveBuildConfiguration(manager.findConfigurationByName("bc 2"));
    elements = doTest("", "as");
    assertEquals(1, elements.length);
    assertEquals("Image", elements[0].getLookupString());
}
Also used : FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

Example 38 with LookupElement

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

the class FlexCompletionTest method testCompletionInMxml8.

@JSTestOptions({ JSTestOption.WithJsSupportLoader, JSTestOption.WithFlexFacet })
public final void testCompletionInMxml8() throws Exception {
    LookupElement[] items = doTest("", MXML_EXTENSION);
    assertNotNull(items);
    assertTrue(items.length < 50);
    doTest("_3", MXML_EXTENSION);
    items = doTest("_2", MXML_EXTENSION);
    assertNotNull(items);
    for (LookupElement li : items) {
        assertTrue(!li.getLookupString().equals("arity"));
    }
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

Example 39 with LookupElement

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

the class FlexCompletionTest method commonFlex3NamespaceInFlex4Context.

private void commonFlex3NamespaceInFlex4Context(final String namespaceToSelect, final String... otherExpectedNamespaces) throws Exception {
    configureByFile(BASE_PATH + getTestName(false) + ".mxml");
    complete();
    final String[] expectedNamespaces = ArrayUtil.mergeArrays(new String[] { namespaceToSelect }, otherExpectedNamespaces);
    assertEquals(expectedNamespaces.length, myItems.length);
    final String[] namespaces = new String[myItems.length];
    LookupElement selectedElement = null;
    for (int i = 0; i < myItems.length; i++) {
        final LookupElement lookupElement = myItems[i];
        final LookupElementPresentation presentation = new LookupElementPresentation();
        lookupElement.renderElement(presentation);
        assertEquals("Accordion", presentation.getItemText());
        final String namespace = presentation.getTypeText();
        namespaces[i] = namespace;
        if (namespace.equals(namespaceToSelect)) {
            selectedElement = lookupElement;
        }
    }
    assertSameElements(namespaces, expectedNamespaces);
    assertNotNull(selectedElement);
    selectItem(selectedElement, Lookup.REPLACE_SELECT_CHAR);
    checkResultByFile(BASE_PATH + getTestName(false) + "_after.mxml");
}
Also used : LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 40 with LookupElement

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

the class CfmlArgumentNameReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    Collection<LookupElement> result = new LinkedList<>();
    Object[] superResult = ArrayUtil.EMPTY_OBJECT_ARRAY;
    String functionName = getFunctionName();
    if (CfmlUtil.isPredefinedFunction(functionName, getProject())) {
        CfmlFunctionDescription cfmlFunctionDescription = CfmlLangInfo.getInstance(getProject()).getFunctionParameters().get(functionName.toLowerCase());
        for (CfmlFunctionDescription.CfmlParameterDescription param : cfmlFunctionDescription.getParameters()) {
            result.add(TailTypeDecorator.withTail(LookupElementBuilder.create(param.getName()).withCaseSensitivity(false), TailType.createSimpleTailType('=')));
        }
    } else {
        CfmlArgumentList parentArgumentsList = PsiTreeUtil.getParentOfType(this, CfmlArgumentList.class);
        if (parentArgumentsList != null) {
            CfmlExpression[] arguments = parentArgumentsList.getArguments();
            if (arguments.length == 1) {
                result.add(LookupElementBuilder.create("argumentCollection").withCaseSensitivity(false));
            }
        }
    }
    PsiElement nextSibling = getNextSibling();
    while (nextSibling instanceof PsiWhiteSpace) {
        nextSibling = nextSibling.getNextSibling();
    }
    if (nextSibling != null && nextSibling.getNode().getElementType() != CfmlTokenTypes.ASSIGN) {
        superResult = super.getVariants();
    }
    CfmlParameter[] functionParameters = getFunctionParameters();
    if (functionParameters != null) {
        for (CfmlParameter param : functionParameters) {
            result.add(CfmlLookUpItemUtil.namedElementToLookupItem(param, null));
        }
    }
    if (!result.isEmpty() || superResult.length > 0) {
        return ArrayUtil.mergeArrays(superResult, ContainerUtil.map2Array(result, Object.class, (Function<LookupElement, Object>) lookupElement -> lookupElement));
    }
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) LinkedList(java.util.LinkedList) Function(com.intellij.util.Function) CfmlFunctionDescription(com.intellij.coldFusion.model.info.CfmlFunctionDescription) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) NotNull(org.jetbrains.annotations.NotNull)

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