How to get qualifiedName of PsiReferenceExpression after I capture PsiMethodCallExpression?

For example: there are two files: A.java and B.java.

A.java

package XXX;

public class A {

    public void print(String name) {...}

}

B.java

package YYY;

public class B {

   public void test() {

      A a1 = new A();

     a1.print("Hello"); // HERE

   }

}

When I get `PsiMethodCallExpression` which has `PsiReferenceExpression`: a1.print, how to get `XXX.A.print` which is declaration of `print`?

Thanks. 

0
2 comments
Official comment

ref.resolve() (or methodCall.resolveMethod()) will get you a PsiMethod instance, which you can also pass to PsiUtil#getMemberQualifiedName to get `XXX.A.print` directly. You can also call getName() and getContainingClass().getQualifiedName() on the method to assemble the result yourself. Please be aware that containing class and the qualified name may be null when local/anonymous classes are used.

Avatar
Permanently deleted user

Thanks, both two solutions work.

0

Please sign in to leave a comment.