mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 18:27:49 +08:00
psi_files.md/documents.md: cleanup, more links
This commit is contained in:
parent
2d8392437f
commit
b76e2018dc
@ -1,7 +1,7 @@
|
||||
<!-- Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -->
|
||||
|
||||
# Documents
|
||||
|
||||
<!-- Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -->
|
||||
|
||||
<link-summary>Introduction to documents - an editable sequence of Unicode characters, typically storing the content of a virtual file.</link-summary>
|
||||
|
||||
A [`Document`](%gh-ic%/platform/core-api/src/com/intellij/openapi/editor/Document.java) is an editable sequence of Unicode characters, typically corresponding to the text contents of a [virtual file](virtual_file.md).
|
||||
@ -24,7 +24,7 @@ You may perform any operations that access or modify the file contents on the "p
|
||||
## Where does a Document come from?
|
||||
|
||||
Document instances are created when some operation needs to access the text contents of a file (in particular, this is necessary to build the PSI for a file).
|
||||
Also, document instances not linked to any virtual files can be created temporarily, for example, representing the contents of a text editor field in a dialog.
|
||||
Also, document instances not linked to any [](virtual_file.md) can be created temporarily, for example, representing the contents of a text editor field in a dialog.
|
||||
|
||||
## How long does a Document persist?
|
||||
|
||||
|
@ -8,7 +8,9 @@ A PSI (Program Structure Interface) file is the root of a structure representing
|
||||
|
||||
The [`PsiFile`](%gh-ic%/platform/core-api/src/com/intellij/psi/PsiFile.java) class is the common base class for all PSI files, while files in a specific language are usually represented by its subclasses. For example, the [`PsiJavaFile`](%gh-ic%/java/java-psi-api/src/com/intellij/psi/PsiJavaFile.java) class represents a Java file, and the [`XmlFile`](%gh-ic%/xml/xml-psi-api/src/com/intellij/psi/xml/XmlFile.java) class represents an XML file.
|
||||
|
||||
Unlike [](virtual_file.md) and [](documents.md), which have application scope (even if multiple projects are open, each file is represented by the same `VirtualFile` instance), PSI has project scope: the same file is represented by multiple `PsiFile` instances if the file belongs to multiple projects open at the same time.
|
||||
Unlike [](virtual_file.md) and [](documents.md), which have application scope (even if multiple projects are open, each file is represented by the same
|
||||
[`VirtualFile`](%gh-ic%/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java) instance), PSI has [](project.md) scope:
|
||||
the same file is represented by multiple `PsiFile` instances if the file belongs to multiple projects open at the same time.
|
||||
|
||||
## How do I get a PSI file?
|
||||
|
||||
@ -44,17 +46,17 @@ LanguageParserDefinitions.INSTANCE
|
||||
.createFile(fileViewProvider);
|
||||
```
|
||||
|
||||
Like documents, PSI files are created on-demand when the PSI is accessed for a particular file.
|
||||
Like [](documents.md), PSI files are created on-demand when the PSI is accessed for a particular file.
|
||||
|
||||
## How long do PSI files persist?
|
||||
|
||||
Like documents, PSI files are weakly referenced from the corresponding `VirtualFile` instances and can be garbage-collected if not referenced by anyone.
|
||||
Like [](documents.md), PSI files are weakly referenced from the corresponding `VirtualFile` instances and can be garbage-collected if not referenced by anyone.
|
||||
|
||||
## How do I create a PSI file?
|
||||
|
||||
[`PsiFileFactory.createFileFromText()`](%gh-ic%/platform/core-api/src/com/intellij/psi/PsiFileFactory.java) creates an in-memory PSI file with the specified contents.
|
||||
|
||||
To save the PSI file to disk, use [`PsiDirectory.add()`](%gh-ic%/platform/core-api/src/com/intellij/psi/PsiDirectory.java).
|
||||
To save the PSI file to disk, use its parent directory's [`PsiDirectory.add()`](%gh-ic%/platform/core-api/src/com/intellij/psi/PsiDirectory.java).
|
||||
|
||||
## How do I get notified when PSI files change?
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user