PSI Cookbook
This page gives recipes for the most common operations for working with the PSI (Program Structure Interface).
Unlike Developing Custom Language Plugins, it is about working with the PSI of existing languages (such as Java).
tip
See also the PSI Performance section.
note
PsiJavaFile javaFile = (PsiJavaFile) psiClass.getContainingFile();
PsiPackage psiPackage = JavaPsiFacade.getInstance(project)
.findPackage(javaFile.getPackageName());
or
Use dedicated (and heavily cached) methods from JavaLibraryUtil
:
hasLibraryClass()
to check presence via known library class FQNhasLibraryJar()
using Maven coordinates (for example,io.micronaut:micronaut-core
).