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-community by JetBrains.
the class CommitCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
PsiFile file = parameters.getOriginalFile();
Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if (document == null)
return;
CommitMessage commitMessage = document.getUserData(CommitMessage.DATA_KEY);
if (commitMessage == null)
return;
result.stopHere();
if (parameters.getInvocationCount() <= 0)
return;
List<ChangeList> lists = commitMessage.getChangeLists();
if (lists.isEmpty())
return;
String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters);
CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix));
for (ChangeList list : lists) {
for (Change change : list.getChanges()) {
ContentRevision revision = change.getAfterRevision() == null ? change.getBeforeRevision() : change.getAfterRevision();
if (revision != null) {
FilePath filePath = revision.getFile();
LookupElementBuilder element = LookupElementBuilder.create(filePath.getName()).withIcon(filePath.getFileType().getIcon());
insensitive.addElement(element);
}
}
}
}
use of com.intellij.codeInsight.lookup.LookupElementBuilder in project intellij-community by JetBrains.
the class TextFieldWithAutoCompletionListProvider method addCompletionElements.
private static <T> void addCompletionElements(final CompletionResultSet result, final TextCompletionValueDescriptor<T> descriptor, final Collection<T> items, final int index) {
final AutoCompletionPolicy completionPolicy = ApplicationManager.getApplication().isUnitTestMode() ? AutoCompletionPolicy.ALWAYS_AUTOCOMPLETE : AutoCompletionPolicy.NEVER_AUTOCOMPLETE;
int grouping = index;
for (final T item : items) {
if (item == null) {
LOG.error("Null item from " + descriptor);
continue;
}
LookupElementBuilder builder = descriptor.createLookupBuilder(item);
result.addElement(PrioritizedLookupElement.withGrouping(builder.withAutoCompletionPolicy(completionPolicy), grouping--));
}
}
use of com.intellij.codeInsight.lookup.LookupElementBuilder in project intellij-community by JetBrains.
the class AntDomPropertyReference method getVariants.
@NotNull
@Override
public Object[] getVariants() {
final AntDomProject project = myInvocationContextElement.getParentOfType(AntDomProject.class, true);
if (project != null) {
final Collection<String> variants = PropertyResolver.resolve(project.getContextAntProject(), getCanonicalText(), myInvocationContextElement).getSecond();
Object[] result = new Object[variants.size()];
int idx = 0;
for (String variant : variants) {
final LookupElementBuilder builder = LookupElementBuilder.create(variant).withCaseSensitivity(false);
final LookupElement element = AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE.applyPolicy(builder);
result[idx++] = element;
}
return result;
}
return EMPTY_ARRAY;
}
use of com.intellij.codeInsight.lookup.LookupElementBuilder in project intellij-community by JetBrains.
the class AntDomTargetReference method getVariants.
@NotNull
public Object[] getVariants() {
final TargetResolver.Result result = doResolve(getCanonicalText());
if (result == null) {
return EMPTY_ARRAY;
}
final Map<String, AntDomTarget> variants = result.getVariants();
final List resVariants = new ArrayList();
final Set<String> existing = getExistingNames();
for (String s : variants.keySet()) {
if (existing.contains(s)) {
continue;
}
final LookupElementBuilder builder = LookupElementBuilder.create(s).withCaseSensitivity(false);
final LookupElement element = AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE.applyPolicy(builder);
resVariants.add(element);
}
return ContainerUtil.toArray(resVariants, new Object[resVariants.size()]);
}
Aggregations