use of com.intellij.codeInsight.lookup.LookupElementBuilder in project android by JetBrains.
the class AndroidCompletionContributor method addAndroidPrefixElement.
private static void addAndroidPrefixElement(PsiElement position, PsiElement parent, CompletionResultSet resultSet) {
if (position.getText().startsWith(SdkConstants.ANDROID_NS_NAME_PREFIX)) {
return;
}
final PsiElement grandparent = parent.getParent();
if (!(grandparent instanceof XmlTag)) {
return;
}
final DomElement element = DomManager.getDomManager(grandparent.getProject()).getDomElement((XmlTag) grandparent);
if (!(element instanceof LayoutElement) && !(element instanceof PreferenceElement)) {
return;
}
final String prefix = ((XmlTag) grandparent).getPrefixByNamespace(SdkConstants.NS_RESOURCES);
if (prefix == null || prefix.length() < 3) {
return;
}
final LookupElementBuilder e = LookupElementBuilder.create(prefix + ":").withTypeText("[Namespace Prefix]", true);
resultSet.addElement(PrioritizedLookupElement.withPriority(e, Double.MAX_VALUE));
}
use of com.intellij.codeInsight.lookup.LookupElementBuilder in project android by JetBrains.
the class AndroidActivityAliasCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
if (parameters.getCompletionType() != CompletionType.BASIC) {
return;
}
final Editor editor = parameters.getEditor();
LaunchOptionConfigurableContext context = editor.getUserData(LaunchOptionConfigurableContext.KEY);
if (context == null) {
return;
}
final Module module = context.getModule();
if (module == null) {
return;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return;
}
final String prefix = parameters.getEditor().getDocument().getText().substring(0, parameters.getOffset());
result = result.withPrefixMatcher(prefix);
final PsiClass activityClass = JavaPsiFacade.getInstance(module.getProject()).findClass(AndroidUtils.ACTIVITY_BASE_CLASS_NAME, module.getModuleWithDependenciesAndLibrariesScope(false));
if (activityClass != null) {
final CompletionResultSet finalResult = result;
ClassInheritorsSearch.search(activityClass, module.getModuleWithDependenciesScope(), true, true, false).forEach(new Processor<PsiClass>() {
@Override
public boolean process(PsiClass psiClass) {
final PsiModifierList modifierList = psiClass.getModifierList();
if (modifierList != null && modifierList.hasModifierProperty(PsiModifier.PUBLIC) && !modifierList.hasModifierProperty(PsiModifier.ABSTRACT)) {
final String qName = psiClass.getQualifiedName();
if (qName != null && qName.length() > 0) {
finalResult.addElement(JavaLookupElementBuilder.forClass(psiClass, qName));
}
}
return true;
}
});
}
final Set<String> aliases = collectActivityAliases(facet);
if (aliases.size() > 0) {
for (String alias : aliases) {
LookupElementBuilder element = LookupElementBuilder.create(alias);
final String shortName = StringUtilRt.getShortName(alias);
if (!shortName.equals(alias)) {
element = element.withLookupString(shortName);
}
result.addElement(element);
}
}
result.stopHere();
}
use of com.intellij.codeInsight.lookup.LookupElementBuilder in project intellij-plugins by JetBrains.
the class LanguageListCompletionContributor method doFillVariants.
private static void doFillVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
for (CodeFenceLanguageProvider provider : LanguageGuesser.INSTANCE.getCodeFenceLanguageProviders()) {
final List<LookupElement> lookups = provider.getCompletionVariantsForInfoString(parameters);
for (LookupElement lookupElement : lookups) {
result.addElement(LookupElementDecorator.withInsertHandler(lookupElement, (context, item) -> {
new MyInsertHandler(parameters).handleInsert(context, item);
lookupElement.handleInsert(context);
}));
}
}
for (Map.Entry<String, Language> entry : LanguageGuesser.INSTANCE.getLangToLanguageMap().entrySet()) {
final Language language = entry.getValue();
final LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(entry.getKey()).withIcon(new DeferredIconImpl<>(null, language, true, language1 -> {
final LanguageFileType fileType = language1.getAssociatedFileType();
return fileType != null ? fileType.getIcon() : null;
})).withTypeText(language.getDisplayName(), true).withInsertHandler(new MyInsertHandler(parameters));
result.addElement(lookupElementBuilder);
}
}
Aggregations