How to find inner / anonymous java classes in project by compiled name

Answered

Given a compiled fully qualified class name, I would like to find the corresponding psi element.

For non-compiled classes,

JavaPsiFacade.getInstance(project).findClass(name, GlobalSearchScope.allScope(project))

would do what I want; however it doesn't handle compiled class names (those containing dollar signs for inner classes). Simply replacing dollar signs with periods won't find the numerically indexed anonymous inner classes. Is there a way to do that?

4 comments
Comment actions Permalink

See com.intellij.psi.util.ClassUtil#findPsiClass() and related

0
Comment actions Permalink

That was exactly it. Thanks!

0
Comment actions Permalink

One more thing; is there possibly anything similar that would help me locate the definition of a lambda or method reference from its `class.getName()` representation?

0
Comment actions Permalink

There is no reliable mapping for these, it might even depend on the JVM version. You can try and map these by manually navigating the PSI tree and see if it matches the "guess".

0

Please sign in to leave a comment.