Find PsiClass knowing only the name and the context, but not the package


I'd like to find a PsiClass knowing only the name, but not the package.

For example, I could be inside a file that imports java.lang.String and declares another class.

Now I'd like to get the PsiClass of String, without knowing from which package it comes from.

I've tried using the command below, but with no luck.

ClassUtils.findClass("String", field.getContext())


Any suggestion?

1 comment
Official comment

Please try PsiShortNamesCache#getClassesByName

Please sign in to leave a comment.