Question

I'm writing Intellij IDEA plugin for my project, and I've faced a problem - I cannot get some ingo about method (PsiMethod) from my code.

First, I want to know is this method public. And second, I want to get fully-qualified names of the parameter classes. Currently I'm doing it like this:

method.getReturnTypeNoResolve().getInternalCanonicalText()

But it doesn't provide full name (with package name) for the standard JVM classes like String and List.

UPDATE First problem solved with the following code:

PsiUtil.getAccessLevel(method.getModifierList()) == PsiUtil.ACCESS_LEVEL_PUBLIC

But I still cannot get fully qualified class name

UPDATE 2 Here is the full listing of my code:

Project currentProject = DataKeys.PROJECT.getData(e.getDataContext());

    PsiClass abstractComponentClass = JavaPsiFacade.getInstance(currentProject).findClass("com.mjolnirr.lib.component.AbstractComponent", GlobalSearchScope.allScope(currentProject));

    TreeClassChooser result = TreeClassChooserFactory
            .getInstance(currentProject)
            .createInheritanceClassChooser("Choose the class to generate manifest",
                    GlobalSearchScope.projectScope(currentProject),
                    abstractComponentClass,
                    false,
                    false,
                    null);
    result.showDialog();

    PsiClass classToGenerate = result.getSelected();

    List<ManifestMethod> methods = new ArrayList<ManifestMethod>();

    for (PsiMethod method : classToGenerate.getAllMethods()) {
        //  If this method is inherited from the Object class we don't need it
        if (isComponentInitialize(method)) {
            continue;
        }

        List<ManifestParameter> parameters = new ArrayList<ManifestParameter>();

        for (PsiParameter param : method.getParameterList().getParameters()) {
            parameters.add(new ManifestParameter(param.getType().getCanonicalText().replaceAll("\\<.*?\\>", "")));
        }

        if (method.getReturnType() != null) {
            ManifestMethod manifestMethod = new ManifestMethod(method.getName(),
                    method.getReturnTypeNoResolve().getInternalCanonicalText().replaceAll("\\<.*?\\>", ""),
                    parameters);

            if (!methods.contains(manifestMethod) && isPublic(method)) {
                System.out.println("->" + method.getReturnType().getCanonicalText());

                methods.add(manifestMethod);
            }
        }
    }
Was it helpful?

Solution

Solved - my test IDEA instance has wrong Java SDK connected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top