2

私は自分のプロジェクト用に Intellij IDEA プラグインを作成していますが、問題に直面しましたPsiMethod。コードからメソッド ( ) に関するインゴを取得できません。

まず、このメソッドが公開されていることを知りたいです。次に、パラメーター クラスの完全修飾名を取得します。現在、私は次のようにしています:

method.getReturnTypeNoResolve().getInternalCanonicalText()

Stringただし、や などの標準 JVM クラスの完全な名前 (パッケージ名を含む) は提供されませんList

更新次のコードで解決された最初の問題:

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

しかし、まだ完全修飾クラス名を取得できません

UPDATE 2これが私のコードの完全なリストです:

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);
            }
        }
    }
4

1 に答える 1

0

解決済み - 私のテスト IDEA インスタンスに間違った Java SDK が接続されています。

于 2013-11-03T15:14:52.170 に答える