Search code examples
intellij-ideastatic-analysisintellij-plugin

Get a PsiClass from a class name


I'm trying to determine if a method is available on a particular class, using

psiClass.getMethods();
// filter methods down to the one I'm looking for

I can get a PsiType using the FQCN, but don't know how to get the PsiClass from the PsiType, or if that's entirely the wrong way.

String className = "com.foo.Bar";
PsiType type = PsiElementFactory.SERVICE.getInstance(project).getTypeByFQClassName(className);

What is the right way to get a class, given its FQCN?


Solution

  • As described in the documentation, the right way to find a PsiClass by qualified name is to use JavaPsiFacade.findClass().