use of com.intellij.codeInsight.lookup.LookupElement in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoCompletionTestBase method selectLookupItem.
protected void selectLookupItem(@NotNull String selectItem) {
LookupElement[] lookupElements = myFixture.getLookupElements();
assertNotNull("Lookup is empty", lookupElements);
LookupElement toSelect = null;
for (LookupElement lookupElement : lookupElements) {
if (selectItem.equals(lookupElement.getLookupString())) {
toSelect = lookupElement;
break;
}
}
assertNotNull(selectItem + " not found in lookup", toSelect);
myFixture.getLookup().setCurrentItem(toSelect);
myFixture.type(Lookup.NORMAL_SELECT_CHAR);
}
use of com.intellij.codeInsight.lookup.LookupElement in project smali by JesusFreke.
the class SmaliCodeFragmentFactoryTest method assertCompletionContains.
private void assertCompletionContains(String completionText, PsiElement context, String[] expectedItems, String[] disallowedItems) {
SmaliCodeFragmentFactory codeFragmentFactory = new SmaliCodeFragmentFactory();
JavaCodeFragment fragment = codeFragmentFactory.createCodeFragment(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, completionText), context, getProject());
Editor editor = createEditor(fragment.getVirtualFile());
editor.getCaretModel().moveToOffset(completionText.length());
new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(getProject(), editor);
List<LookupElement> elements = LookupManager.getInstance(getProject()).getActiveLookup().getItems();
HashSet expectedSet = Sets.newHashSet(expectedItems);
HashSet disallowedSet = Sets.newHashSet(disallowedItems);
for (LookupElement element : elements) {
expectedSet.remove(element.toString());
Assert.assertFalse(disallowedSet.contains(element.toString()));
}
Assert.assertTrue(expectedSet.size() == 0);
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class MethodsChainLookupRangingHelper method chainsToWeightableLookupElements.
public static List<LookupElement> chainsToWeightableLookupElements(final List<MethodsChain> chains, final ChainCompletionContext context) {
final CachedRelevantStaticMethodSearcher staticMethodSearcher = new CachedRelevantStaticMethodSearcher(context);
final List<LookupElement> lookupElements = new ArrayList<>(chains.size());
for (final MethodsChain chain : chains) {
final LookupElement lookupElement = chainToWeightableLookupElement(chain, context, staticMethodSearcher);
if (lookupElement != null) {
lookupElements.add(lookupElement);
}
}
return lookupElements;
}
use of com.intellij.codeInsight.lookup.LookupElement in project android by JetBrains.
the class ThemeEditorGuiTestUtils method getCompletionPopup.
/**
* Returns a {@link JListFixture} for the auto-completion popup
*/
@NotNull
public static JListFixture getCompletionPopup(@NotNull Robot robot) {
JBList list = GuiTests.waitUntilFound(robot, new GenericTypeMatcher<JBList>(JBList.class) {
@Override
protected boolean isMatching(@NotNull JBList component) {
ListModel listModel = component.getModel();
return listModel.getSize() > 0 && listModel.getElementAt(0) instanceof LookupElement;
}
});
JListFixture listFixture = new JListFixture(robot, list);
listFixture.replaceCellReader((jList, index) -> ((LookupElement) jList.getModel().getElementAt(index)).getLookupString());
return listFixture;
}
use of com.intellij.codeInsight.lookup.LookupElement in project android by JetBrains.
the class ResourceTypeCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull final CompletionParameters parameters, @NotNull final CompletionResultSet result) {
//if (parameters.getCompletionType() != CompletionType.SMART) return;
PsiElement pos = parameters.getPosition();
if (JavaKeywordCompletion.AFTER_DOT.accepts(pos)) {
return;
}
AndroidFacet facet = AndroidFacet.getInstance(pos);
if (facet == null) {
return;
}
ResourceTypeInspection.Constraints allowedValues = getAllowedValues(pos);
if (allowedValues == null)
return;
final Set<PsiElement> allowed = new THashSet<PsiElement>(new TObjectHashingStrategy<PsiElement>() {
@Override
public int computeHashCode(PsiElement object) {
return 0;
}
@Override
public boolean equals(PsiElement o1, PsiElement o2) {
return parameters.getOriginalFile().getManager().areElementsEquivalent(o1, o2);
}
});
// Suggest resource types
if (allowedValues instanceof ResourceTypeInspection.ResourceTypeAllowedValues) {
for (ResourceType resourceType : ((ResourceTypeInspection.ResourceTypeAllowedValues) allowedValues).types) {
// are markers for @ColorInt and @Px
if (resourceType == COLOR_INT_MARKER_TYPE || resourceType == DIMENSION_MARKER_TYPE) {
continue;
}
PsiElementFactory factory = JavaPsiFacade.getElementFactory(pos.getProject());
String code = "R." + resourceType.getName();
// Look up the fully qualified name of the application package
String fqcn = MergedManifest.get(facet).getPackage();
String qualifiedCode = fqcn + "." + code;
Project project = facet.getModule().getProject();
PsiClass cls = JavaPsiFacade.getInstance(project).findClass(qualifiedCode, GlobalSearchScope.allScope(project));
if (cls != null) {
result.addElement(new JavaPsiClassReferenceElement(cls));
} else {
PsiExpression type = factory.createExpressionFromText(code, pos);
result.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(type, code), PRIORITY - 1));
allowed.add(type);
}
}
} else if (allowedValues instanceof ResourceTypeInspection.AllowedValues) {
ResourceTypeInspection.AllowedValues a = (ResourceTypeInspection.AllowedValues) allowedValues;
if (a.canBeOred) {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(pos.getProject());
PsiExpression zero = factory.createExpressionFromText("0", pos);
result.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(zero, "0"), PRIORITY - 1));
PsiExpression minusOne = factory.createExpressionFromText("-1", pos);
result.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(minusOne, "-1"), PRIORITY - 1));
allowed.add(zero);
allowed.add(minusOne);
}
List<ExpectedTypeInfo> types = Arrays.asList(JavaSmartCompletionContributor.getExpectedTypes(parameters));
for (PsiAnnotationMemberValue value : a.values) {
if (value instanceof PsiReference) {
PsiElement resolved = ((PsiReference) value).resolve();
if (resolved instanceof PsiNamedElement) {
LookupElement lookupElement = LookupItemUtil.objectToLookupItem(resolved);
if (lookupElement instanceof VariableLookupItem) {
((VariableLookupItem) lookupElement).setSubstitutor(PsiSubstitutor.EMPTY);
}
LookupElement element = PrioritizedLookupElement.withPriority(lookupElement, PRIORITY);
element = decorate(parameters, types, element);
result.addElement(element);
allowed.add(resolved);
continue;
}
}
LookupElement element = LookupElementBuilder.create(value, value.getText());
element = decorate(parameters, types, element);
result.addElement(element);
allowed.add(value);
}
}
result.runRemainingContributors(parameters, new Consumer<CompletionResult>() {
@Override
public void consume(CompletionResult completionResult) {
LookupElement element = completionResult.getLookupElement();
Object object = element.getObject();
if (object instanceof PsiElement && allowed.contains(object)) {
return;
}
result.passResult(completionResult);
}
});
}
Aggregations