Local inspection PsiElement source query
Hi,
I am interested to know whether
PsiManager.isInProject(psiElement)
is the way to go for finding out whether an element is part of the project files or otherwise part of the project sdk/libraries inside a local inspection?
My inspection is meant to highlight some code smells, but unless the user can do something about it, there's not much point in prioritising it.
Likewise, for elements that come from libraries, I found that
if (psiElement instanceof PsiCompiledElement)
is quite a good proxy, but this wouldn't suffice in detecting whether the element is say from the JDK, hence it wouldn't cover all the cases I need.
Best,
Radu
请先登录再写评论。
Does anyone have an answer?
is a correct way to detect if element belongs to a project. If you want to distinguish different libraries/jdks, please use com.intellij.openapi.roots.ProjectFileIndex#getOrderEntriesForFile would give you different items depending on where the file you ask is located.
BTW Please note that if your dependency has sources attached, then resolve would go to PsiCompiledElements though the navigation should go to attached sources.
Anna