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()]);
}
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());
}
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"));
}
}
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");
}
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;
}
Aggregations