use of com.android.tools.idea.run.editor.LaunchOptionConfigurableContext 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();
}
Aggregations