I'm writing an inspection that checks annotations of the package of a java class. What I basically do is I get the PsiPackage from PsiClass and then use the AnnotationUtil.
To get the PsiPackage from PsiClass I first get the PsiJavaFile with getParent() and get packageStatement and the package reference. Finally I resolve the reference to get the PsiPackage.
This works fine for classes that are defined locally in a module. But for classes like java.lang.String this does not work, since it's package statement is of type ClsPackageStatementImpl and this class do not implement the method getPackageReference().
How can I check if it's possible to get the package reference without comparing classes like below?
if (csiClass.getParent().getClass().equals(PsiJavaFileImpl.class)) ...
Or is there a better way to browse packages of a psiClass?