use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class GenericDomValueReference method getVariants.
@Override
@NotNull
public Object[] getVariants() {
final Converter<T> converter = getConverter();
if (converter instanceof EnumConverter || converter == ResolvingConverter.BOOLEAN_CONVERTER) {
if (DomCompletionContributor.isSchemaEnumerated(getElement()))
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
if (converter instanceof ResolvingConverter) {
final ResolvingConverter<T> resolvingConverter = (ResolvingConverter<T>) converter;
ArrayList<Object> result = new ArrayList<>();
final ConvertContext convertContext = getConvertContext();
for (T variant : resolvingConverter.getVariants(convertContext)) {
LookupElement lookupElement = resolvingConverter.createLookupElement(variant);
if (lookupElement != null) {
result.add(lookupElement);
continue;
}
String name = converter.toString(variant, convertContext);
if (name != null) {
result.add(ElementPresentationManager.getInstance().createVariant(variant, name, ((ResolvingConverter) converter).getPsiElement(variant)));
}
}
for (final String string : resolvingConverter.getAdditionalVariants(convertContext)) {
result.add(LookupValueFactory.createLookupValue(string, null));
}
return result.toArray();
}
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class MavenUtil method getPhaseVariants.
public static List<LookupElement> getPhaseVariants(MavenProjectsManager manager) {
Set<String> goals = new HashSet<>();
goals.addAll(MavenConstants.PHASES);
for (MavenProject mavenProject : manager.getProjects()) {
for (MavenPlugin plugin : mavenProject.getPlugins()) {
MavenPluginInfo pluginInfo = MavenArtifactUtil.readPluginInfo(manager.getLocalRepository(), plugin.getMavenId());
if (pluginInfo != null) {
for (MavenPluginInfo.Mojo mojo : pluginInfo.getMojos()) {
goals.add(mojo.getDisplayName());
}
}
}
}
List<LookupElement> res = new ArrayList<>(goals.size());
for (String goal : goals) {
res.add(LookupElementBuilder.create(goal).withIcon(MavenIcons.Phase));
}
return res;
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class PyModuleType method getCompletionVariantsAsLookupElements.
public List<LookupElement> getCompletionVariantsAsLookupElements(PsiElement location, ProcessingContext context, boolean wantAllSubmodules, boolean suppressParentheses) {
List<LookupElement> result = new ArrayList<>();
Set<String> namesAlready = context.get(CTX_NAMES);
PointInImport point = ResolveImportUtil.getPointInImport(location);
for (PyModuleMembersProvider provider : Extensions.getExtensions(PyModuleMembersProvider.EP_NAME)) {
for (PyCustomMember member : provider.getMembers(myModule, point)) {
final String name = member.getName();
if (namesAlready != null) {
namesAlready.add(name);
}
if (PyUtil.isClassPrivateName(name)) {
continue;
}
final CompletionVariantsProcessor processor = createCompletionVariantsProcessor(location, suppressParentheses, point);
final PsiElement resolved = member.resolve(location);
if (resolved != null) {
processor.execute(resolved, ResolveState.initial());
final List<LookupElement> lookupList = processor.getResultList();
if (!lookupList.isEmpty()) {
final LookupElement element = lookupList.get(0);
if (name.equals(element.getLookupString())) {
result.add(element);
continue;
}
}
}
result.add(LookupElementBuilder.create(name).withIcon(member.getIcon()).withTypeText(member.getShortType()));
}
}
if (point == PointInImport.NONE || point == PointInImport.AS_NAME) {
// when not imported from, add regular attributes
final CompletionVariantsProcessor processor = createCompletionVariantsProcessor(location, suppressParentheses, point);
myModule.processDeclarations(processor, ResolveState.initial(), null, location);
if (namesAlready != null) {
for (LookupElement le : processor.getResultList()) {
String name = le.getLookupString();
if (!namesAlready.contains(name)) {
result.add(le);
namesAlready.add(name);
}
}
} else {
result.addAll(processor.getResultList());
}
}
if (PyUtil.isPackage(myModule)) {
// our module is a dir, not a single file
if (point == PointInImport.AS_MODULE || point == PointInImport.AS_NAME || wantAllSubmodules) {
// when imported from somehow, add submodules
result.addAll(getSubModuleVariants(myModule.getContainingDirectory(), location, namesAlready));
} else {
result.addAll(collectImportedSubmodulesAsLookupElements(myModule, location, namesAlready));
}
}
return result;
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class MapKeysCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement element = parameters.getPosition();
GrReferenceExpression expression = (GrReferenceExpression) element.getParent();
GrExpression qualifierExpression = expression.getQualifierExpression();
if (qualifierExpression == null)
return;
PsiType mapType = qualifierExpression.getType();
if (!InheritanceUtil.isInheritor(mapType, CommonClassNames.JAVA_UTIL_MAP)) {
return;
}
PsiElement resolve = null;
if (qualifierExpression instanceof GrMethodCall) {
resolve = ((GrMethodCall) qualifierExpression).resolveMethod();
} else if (qualifierExpression instanceof GrReferenceExpression) {
resolve = ((GrReferenceExpression) qualifierExpression).resolve();
}
for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
GroovyMapCompletionUtil.addKeyVariants(provider, qualifierExpression, resolve, result);
}
if (mapType instanceof GrMapType) {
for (String key : ((GrMapType) mapType).getStringKeys()) {
LookupElement lookup = LookupElementBuilder.create(key);
lookup = PrioritizedLookupElement.withPriority(lookup, 1);
result.addElement(lookup);
}
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class GrMainCompletionProvider method completeReference.
@NotNull
static Runnable completeReference(final CompletionParameters parameters, final GrReferenceElement reference, final JavaCompletionSession inheritorsHolder, final PrefixMatcher matcher, final Consumer<LookupElement> _consumer) {
final Consumer<LookupElement> consumer = new Consumer<LookupElement>() {
final Set<LookupElement> added = ContainerUtil.newHashSet();
@Override
public void consume(LookupElement element) {
if (added.add(element)) {
_consumer.consume(element);
}
}
};
final Map<PsiModifierListOwner, LookupElement> staticMembers = ContainerUtil.newHashMap();
final PsiElement qualifier = reference.getQualifier();
final PsiType qualifierType = GroovyCompletionUtil.getQualifierType(qualifier);
if (reference instanceof GrReferenceExpression && (qualifier instanceof GrExpression || qualifier == null)) {
for (String string : CompleteReferencesWithSameQualifier.getVariantsWithSameQualifier((GrReferenceExpression) reference, matcher, (GrExpression) qualifier)) {
consumer.consume(LookupElementBuilder.create(string).withItemTextUnderlined(true));
}
if (parameters.getInvocationCount() < 2 && qualifier != null && qualifierType == null && !(qualifier instanceof GrReferenceExpression && ((GrReferenceExpression) qualifier).resolve() instanceof PsiPackage)) {
if (parameters.getInvocationCount() == 1) {
showInfo();
}
return EmptyRunnable.INSTANCE;
}
}
final List<LookupElement> zeroPriority = ContainerUtil.newArrayList();
PsiClass qualifierClass = com.intellij.psi.util.PsiUtil.resolveClassInClassTypeOnly(qualifierType);
final boolean honorExcludes = qualifierClass == null || !JavaCompletionUtil.isInExcludedPackage(qualifierClass, false);
GroovyCompletionUtil.processVariants(reference, matcher, parameters, lookupElement -> {
Object object = lookupElement.getObject();
if (object instanceof GroovyResolveResult) {
object = ((GroovyResolveResult) object).getElement();
}
if (isLightElementDeclaredDuringCompletion(object)) {
return;
}
if (!(lookupElement instanceof LookupElementBuilder) && inheritorsHolder.alreadyProcessed(lookupElement)) {
return;
}
if (honorExcludes && object instanceof PsiMember && JavaCompletionUtil.isInExcludedPackage((PsiMember) object, true)) {
return;
}
if (!(object instanceof PsiClass)) {
int priority = assignPriority(lookupElement, qualifierType);
lookupElement = JavaCompletionUtil.highlightIfNeeded(qualifierType, PrioritizedLookupElement.withPriority(lookupElement, priority), object, reference);
}
if ((object instanceof PsiMethod || object instanceof PsiField) && ((PsiModifierListOwner) object).hasModifierProperty(PsiModifier.STATIC)) {
if (lookupElement.getLookupString().equals(((PsiMember) object).getName())) {
staticMembers.put(CompletionUtil.getOriginalOrSelf((PsiModifierListOwner) object), lookupElement);
}
}
PrioritizedLookupElement prio = lookupElement.as(PrioritizedLookupElement.CLASS_CONDITION_KEY);
if (prio == null || prio.getPriority() == 0) {
zeroPriority.add(lookupElement);
} else {
consumer.consume(lookupElement);
}
});
for (LookupElement element : zeroPriority) {
consumer.consume(element);
}
if (qualifier == null) {
return addStaticMembers(parameters, matcher, staticMembers, consumer);
}
return EmptyRunnable.INSTANCE;
}
Aggregations