Search in sources :

Example 1 with PsiMethodImpl

use of com.intellij.psi.impl.source.PsiMethodImpl in project android by JetBrains.

the class OnClickEnumSupport method getAllValues.

@Override
@NotNull
public List<ValueWithDisplayString> getAllValues() {
    Module module = myProperty.getModel().getModule();
    Configuration configuration = myProperty.getModel().getConfiguration();
    String activityClassName = configuration.getActivity();
    JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
    Collection<PsiClass> classes;
    if (activityClassName != null) {
        if (activityClassName.startsWith(".")) {
            MergedManifest manifest = MergedManifest.get(module);
            String pkg = StringUtil.notNullize(manifest.getPackage());
            activityClassName = pkg + activityClassName;
        }
        PsiClass activityClass = facade.findClass(activityClassName, module.getModuleScope());
        if (activityClass != null) {
            classes = Collections.singletonList(activityClass);
        } else {
            classes = Collections.emptyList();
        }
    } else {
        GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
        PsiClass activityClass = facade.findClass(CLASS_ACTIVITY, scope);
        if (activityClass != null) {
            classes = ClassInheritorsSearch.search(activityClass, scope, true).findAll();
        } else {
            classes = Collections.emptyList();
        }
    }
    List<ValueWithDisplayString> values = new ArrayList<>();
    Set<String> found = new HashSet<>();
    for (PsiClass psiClass : classes) {
        for (PsiMethod method : psiClass.getAllMethods()) {
            if (OnClickConverter.CONVERTER_FOR_LAYOUT.checkSignature(method) && found.add(method.getName()) && method instanceof PsiMethodImpl) {
                values.add(new ValueWithDisplayString(method.getName(), method.getName(), psiClass.getName()));
            }
        }
    }
    return values;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Configuration(com.android.tools.idea.configurations.Configuration) MergedManifest(com.android.tools.idea.model.MergedManifest) PsiMethod(com.intellij.psi.PsiMethod) PsiMethodImpl(com.intellij.psi.impl.source.PsiMethodImpl) PsiClass(com.intellij.psi.PsiClass) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Configuration (com.android.tools.idea.configurations.Configuration)1 MergedManifest (com.android.tools.idea.model.MergedManifest)1 Module (com.intellij.openapi.module.Module)1 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)1 PsiClass (com.intellij.psi.PsiClass)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiMethodImpl (com.intellij.psi.impl.source.PsiMethodImpl)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 NotNull (org.jetbrains.annotations.NotNull)1