mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 18:27:49 +08:00
120 lines
6.6 KiB
HTML
120 lines
6.6 KiB
HTML
|
|
|
|
|
|
<!doctype html>
|
|
<html lang="en-US">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>PSI Elements / IntelliJ Platform SDK DevGuide</title>
|
|
<link rel="stylesheet" href="/intellij-sdk-docs/app/css/styles.min.css">
|
|
|
|
<!-- non-retina iPad pre iOS 7 -->
|
|
<link rel="apple-touch-icon" href="/intellij-sdk-docs/apple-touch-icon-72x72.png" sizes="72x72">
|
|
|
|
<!-- retina iPhone pre iOS 7 -->
|
|
<link rel="apple-touch-icon" href="/intellij-sdk-docs/apple-touch-icon-114x114.png" sizes="114x114">
|
|
|
|
<!-- retina iPad pre iOS 7 -->
|
|
<link rel="apple-touch-icon" href="/intellij-sdk-docs/apple-touch-icon-144x144.png" sizes="144x144">
|
|
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/intellij-sdk-docs/apple-touch-icon-precomposed.png">
|
|
|
|
<!-- normal favicon -->
|
|
<link rel="shortcut icon" type="image/x-icon" href="/intellij-sdk-docs/favicon.ico">
|
|
<link rel="icon" type="image/png" href="/intellij-sdk-docs/favicon.png">
|
|
<link rel="stylesheet" href="/intellij-sdk-docs/styles/styles.css"></head>
|
|
<body data-id="basics/architectural_overview/psi_elements">
|
|
<div class="wrapper">
|
|
<section class="panel _nav">
|
|
<header class="panel__header">
|
|
<div class="container">
|
|
<form class="search-box">
|
|
<label for="search-box__input" class="search-box__label">
|
|
<input type="text" class="search-box__input" id="search-box__input" placeholder="Search IntelliJ Platform SDK DevGuide">
|
|
</label>
|
|
<div class="search-box__clear" title="Clear"></div>
|
|
</form>
|
|
</div>
|
|
</header>
|
|
<nav class="panel__content">
|
|
<div class="container _nav">
|
|
<menu class="nav-tree"></menu>
|
|
</div>
|
|
<div class="container _footer panel__footer">
|
|
<p><a href="https://youtrack.jetbrains.com/issues/IJSDK">Send feedback</a></p>
|
|
<p>© 2000–2016 <a href="//www.jetbrains.com">JetBrains</a> s.r.o.<br>
|
|
All rights reserved.</p>
|
|
</div>
|
|
</nav>
|
|
</section>
|
|
|
|
<main class="panel _main" role="main">
|
|
<header class="panel__header">
|
|
<div class="container">
|
|
<h3>IntelliJ Platform SDK DevGuide</h3>
|
|
|
|
<div class="shortcuts-switcher"><label for="switch-shortcuts">Keymap:</label><select id="switch-shortcuts" class="select _shortcuts" height="1">
|
|
<option data-group="primary" value="default" selected>Default</option>
|
|
<option data-group="primary" value="default_for_gnome">GNOME</option>
|
|
<option data-group="primary" value="default_for_kde">KDE</option>
|
|
<option data-group="primary" value="default_for_xwin">XWindow</option>
|
|
<option data-group="primary" value="emacs">Emacs</option>
|
|
<option data-group="primary" value="jbuilder">JBuilder</option>
|
|
<option data-group="primary" value="visual_studio">Visual Studio</option>
|
|
<option data-group="primary" value="netbeans_6.5">NetBeans 6.5</option>
|
|
<option data-group="primary" value="eclipse">Eclipse</option>
|
|
<option data-group="secondary" value="mac_os_x_10.5_">OS X 10.5+</option>
|
|
<option data-group="secondary" value="mac_os_x">OS X</option>
|
|
<option data-group="secondary" value="eclipse_mac_os_x">OS X Eclipse</option></select>
|
|
</div>
|
|
|
|
<div class="panel-trigger"></div>
|
|
</div>
|
|
</header>
|
|
<section class="panel__content">
|
|
<div class="container">
|
|
<article class="article" data-shortcut-switcher="false">
|
|
|
|
<h1>PSI Elements</h1>
|
|
<p>A PSI (Program Structure Interface) file represents a hierarchy of PSI elements (so-called <em>PSI trees</em>). A single PSI file may include several PSI trees in a particular programming language. A PSI element, in its turn, can have child PSI elements.</p>
|
|
|
|
<p>PSI elements and operations on the level of individual PSI elements are used to explore the internal structure of source code as it is interpreted by the <strong>IntelliJ Platform</strong>. For example, you can use PSI elements to perform code analysis, such as <a href="http://www.jetbrains.com/idea/help/code-inspection.html" data-bypass="yes" target="_blank"><span>code inspections</span></a> or <a href="http://www.jetbrains.com/idea/help/intention-actions.html" data-bypass="yes" target="_blank"><span>intention actions</span></a>.</p>
|
|
|
|
<p>The <a href="https://upsource.jetbrains.com/idea-ce/file/idea-ce-1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/core-api/src/com/intellij/psi/PsiElement.java" data-bypass="yes" target="_blank"><span>PsiElement</span></a> class is the common base class for PSI elements.</p>
|
|
|
|
<a name="how-do-i-get-a-psi-element" class="elem-anchor"></a>
|
|
<h2>How do I get a PSI element?<a href="#how-do-i-get-a-psi-element" class="anchor-link"><span></span></a></h2>
|
|
|
|
<ul>
|
|
<li>From an action: <code class="code highlight language-text">e.getData(LangDataKeys.PSI_ELEMENT)</code>. 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.</li>
|
|
<li>From a file by offset: <code class="code highlight language-text">PsiFile.findElementAt()</code>. Note: this returns the lowest level element at the specified offset, which is normally a lexer token.
|
|
Most likely you should use <code class="code highlight language-text">PsiTreeUtil.getParentOfType()</code> to find the element you really need.</li>
|
|
<li>By iterating through a PSI file: using a <code class="code highlight language-text">PsiRecursiveElementWalkingVisitor</code>.</li>
|
|
<li>By resolving a reference: <code class="code highlight language-text">PsiReference.resolve()</code></li>
|
|
</ul>
|
|
|
|
<a name="what-can-i-do-with-psi-elements" class="elem-anchor"></a>
|
|
<h2>What can I do with PSI elements?<a href="#what-can-i-do-with-psi-elements" class="anchor-link"><span></span></a></h2>
|
|
|
|
<p>See <a href="/intellij-sdk-docs/basics/psi_cookbook.html"><span>PSI Cook Book</span></a></p>
|
|
|
|
|
|
<div class="last-modified">
|
|
Last modified: 30 November 2015
|
|
</div>
|
|
</article>
|
|
|
|
<section class="disqus">
|
|
<div id="disqus_thread"></div>
|
|
</section>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
</div>
|
|
|
|
|
|
<script data-main="/intellij-sdk-docs/app/js/main.build" data-baseurl="/intellij-sdk-docs/" src="/intellij-sdk-docs/app/js/vendor/requirejs/require.js"></script>
|
|
|
|
</body>
|
|
</html>
|
|
|