Search in sources :

Example 1 with LaunchOptionConfigurableContext

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();
}
Also used : LaunchOptionConfigurableContext(com.android.tools.idea.run.editor.LaunchOptionConfigurableContext) PsiClass(com.intellij.psi.PsiClass) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) Editor(com.intellij.openapi.editor.Editor) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) PsiModifierList(com.intellij.psi.PsiModifierList)

Aggregations

LaunchOptionConfigurableContext (com.android.tools.idea.run.editor.LaunchOptionConfigurableContext)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 Editor (com.intellij.openapi.editor.Editor)1 Module (com.intellij.openapi.module.Module)1 PsiClass (com.intellij.psi.PsiClass)1 PsiModifierList (com.intellij.psi.PsiModifierList)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1