use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class GroovySmartCompletionContributor method addExpectedClassMembers.
static void addExpectedClassMembers(CompletionParameters params, final CompletionResultSet result) {
for (final TypeConstraint info : getExpectedTypeInfos(params)) {
Consumer<LookupElement> consumer = element -> result.addElement(element);
PsiType type = info.getType();
PsiType defType = info.getDefaultType();
boolean searchInheritors = params.getInvocationCount() > 1;
if (type instanceof PsiClassType) {
new GroovyMembersGetter((PsiClassType) type, params).processMembers(searchInheritors, consumer);
}
if (!defType.equals(type) && defType instanceof PsiClassType) {
new GroovyMembersGetter((PsiClassType) defType, params).processMembers(searchInheritors, consumer);
}
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class MapArgumentCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement mapOrArgumentList = findMapOrArgumentList(parameters);
if (mapOrArgumentList == null) {
return;
}
if (isMapKeyCompletion(parameters)) {
result.stopHere();
}
final Map<String, NamedArgumentDescriptor> map = ContainerUtil.newHashMap(calculateNamedArguments(mapOrArgumentList));
for (GrNamedArgument argument : getSiblingNamedArguments(mapOrArgumentList)) {
map.remove(argument.getLabelName());
}
for (Map.Entry<String, NamedArgumentDescriptor> entry : map.entrySet()) {
LookupElementBuilder lookup = LookupElementBuilder.create(entry.getValue(), entry.getKey()).withInsertHandler(NamedArgumentInsertHandler.INSTANCE).withTailText(":");
if (entry.getValue().getPriority() == NamedArgumentDescriptor.Priority.UNLIKELY) {
lookup = lookup.withItemTextForeground(GroovySyntaxHighlighter.MAP_KEY.getDefaultAttributes().getForegroundColor());
} else {
lookup = lookup.withIcon(JetgroovyIcons.Groovy.DynamicProperty);
}
LookupElement customized = entry.getValue().customizeLookupElement(lookup);
result.addElement(customized == null ? lookup : customized);
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class ChooseTypeExpression method calculateLookupItems.
@Override
public LookupElement[] calculateLookupItems(ExpressionContext context) {
List<LookupElement> result = ContainerUtil.newArrayList();
for (SmartTypePointer item : myItems) {
PsiType type = TypesUtil.unboxPrimitiveTypeWrapper(item.getType());
if (type == null)
continue;
PsiTypeLookupItem lookupItem = PsiTypeLookupItem.createLookupItem(type, null, PsiTypeLookupItem.isDiamond(type), IMPORT_FIXER);
result.add(lookupItem);
}
if (myForGroovy) {
LookupElementBuilder def = LookupElementBuilder.create(GrModifier.DEF).bold();
if (mySelectDef) {
result.add(0, def);
} else {
result.add(def);
}
}
return result.toArray(new LookupElement[result.size()]);
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class TestUtils method checkCompletionContains.
public static void checkCompletionContains(JavaCodeInsightTestFixture fixture, String... expectedVariants) {
LookupElement[] lookupElements = fixture.completeBasic();
Assert.assertNotNull(lookupElements);
Set<String> missedVariants = ContainerUtil.newHashSet(expectedVariants);
for (LookupElement lookupElement : lookupElements) {
String lookupString = lookupElement.getLookupString();
missedVariants.remove(lookupString);
Object object = lookupElement.getObject();
if (object instanceof ResolveResult) {
object = ((ResolveResult) object).getElement();
}
if (object instanceof PsiMethod) {
missedVariants.remove(lookupString + "()");
} else if (object instanceof PsiVariable) {
missedVariants.remove('@' + lookupString);
} else if (object instanceof NamedArgumentDescriptor) {
missedVariants.remove(lookupString + ':');
}
}
if (missedVariants.size() > 0) {
Assert.assertTrue("Some completion variants are missed " + missedVariants, false);
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class MavenVersionCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
if (parameters.getCompletionType() != CompletionType.BASIC)
return;
PsiElement element = parameters.getPosition();
PsiElement xmlText = element.getParent();
if (!(xmlText instanceof XmlText))
return;
PsiElement tagElement = xmlText.getParent();
if (!(tagElement instanceof XmlTag))
return;
XmlTag tag = (XmlTag) tagElement;
Project project = element.getProject();
DomElement domElement = DomManager.getDomManager(project).getDomElement(tag);
if (!(domElement instanceof GenericDomValue))
return;
DomElement parent = domElement.getParent();
if (parent instanceof MavenDomArtifactCoordinates && ((GenericDomValue) domElement).getConverter() instanceof MavenArtifactCoordinatesVersionConverter) {
MavenDomArtifactCoordinates coordinates = (MavenDomArtifactCoordinates) parent;
String groupId = coordinates.getGroupId().getStringValue();
String artifactId = coordinates.getArtifactId().getStringValue();
if (StringUtil.isEmptyOrSpaces(artifactId))
return;
CompletionResultSet newResultSet = result.withRelevanceSorter(CompletionService.getCompletionService().emptySorter().weigh(new LookupElementWeigher("mavenVersionWeigher") {
@Nullable
@Override
public Comparable weigh(@NotNull LookupElement element) {
return new NegatingComparable(new MavenVersionComparable(element.getLookupString()));
}
}));
MavenProjectIndicesManager indicesManager = MavenProjectIndicesManager.getInstance(project);
Set<String> versions;
if (StringUtil.isEmptyOrSpaces(groupId)) {
if (!(coordinates instanceof MavenDomPlugin))
return;
versions = indicesManager.getVersions(MavenArtifactUtil.DEFAULT_GROUPS[0], artifactId);
for (int i = 0; i < MavenArtifactUtil.DEFAULT_GROUPS.length; i++) {
versions = Sets.union(versions, indicesManager.getVersions(MavenArtifactUtil.DEFAULT_GROUPS[i], artifactId));
}
} else {
versions = indicesManager.getVersions(groupId, artifactId);
}
for (String version : versions) {
newResultSet.addElement(LookupElementBuilder.create(version));
}
newResultSet.addElement(LookupElementBuilder.create(RepositoryUtils.ReleaseVersionId));
newResultSet.addElement(LookupElementBuilder.create(RepositoryUtils.LatestVersionId));
}
}
Aggregations