IDEA Plugin Dev - PSI Element

1 - About

A PSI element is an element of a PSI tree. It can have child PSI elements.

PSI elements and operations on the level of individual PSI elements are used to explore the internal structure of source code. For example, you can use PSI elements to perform code analysis, such as code inspections or intention actions.

3 - Management

3.1 - Interface

The PsiElement class is the common base class for PSI elements.

3.2 - Get

  • From an action: e.getData(LangDataKeys.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. This may or may not be what you need.
  • From a file by offset: PsiFile.findElementAt(). Note: this returns the lowest level element at the specified offset, which is normally a lexer token. Most likely you should use PsiTreeUtil.getParentOfType() to find the element you really need.
  • By iterating through a PSI file: using a PsiRecursiveElementWalkingVisitor.
  • By resolving a reference: PsiReference.resolve()

3.3 - Operations

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap