mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-28 01:07:49 +08:00
3.2 KiB
3.2 KiB
A PSI (Program Structure Interface) file represents a hierarchy of PSI elements (so-called PSI trees). A single PSI file (itself being a PSI element) may expose several PSI trees in specific programming languages (see ). A PSI element, in its turn, can have child PSI elements.
PSI elements and operations at the level of individual PSI elements are used to explore the source code's internal structure as it is interpreted by the IntelliJ Platform. For example, you can use PSI elements to perform code analysis, such as code inspections or intention actions.
The PsiElement
class is the common base class for PSI elements.
How do I get a PSI element?
Context | API |
---|---|
Action | AnActionEvent.getData(CommonDataKeys.PSI_ELEMENT) Note: If an editor is currently open and the element under caret is a reference, this will return the result of resolving the reference. |
PSI File | PsiFile.findElementAt(offset) - This returns a leaf element at the specified offset, normally a lexer token. Use PsiTreeUtil.getParentOfType() to find the element of the exact type.PsiRecursiveElementWalkingVisitor |
Reference | PsiReference.resolve() |