mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 18:27:49 +08:00
Merge branch 'artspb-master'
This commit is contained in:
commit
9f20959d78
@ -2,7 +2,7 @@
|
||||
* [Quick Start Guide](basics.md)
|
||||
* [Main Types of Plugins](basics/types_of_plugins.md)
|
||||
* [Creating Your First Plugin](basics/getting_started.md)
|
||||
* [Setting Up Development Environment](basics/getting_started/setting_up_environment.md)
|
||||
* [Setting Up a Development Environment](basics/getting_started/setting_up_environment.md)
|
||||
* [Creating a Plugin Project](basics/getting_started/creating_plugin_project.md)
|
||||
* [Build Number Ranges](basics/getting_started/build_number_ranges.md)
|
||||
* [Creating an Action](basics/getting_started/creating_an_action.md)
|
||||
|
@ -5,7 +5,7 @@ title: Architectural Overview
|
||||
This topic describes the architecture of IntelliJ Platform from a plugin developer's point of view. It is organized in a task-based manner to answer specific questions like "what can I do with this object?", "how do I get to this object?" and so on.
|
||||
|
||||
Before proceeding please make sure you're familiar with the basic concepts of IntelliJ Platform plugin development. If not, consider starting with the live demo and tutorials at
|
||||
[http://www.jetbrains.com/idea/plugins/index.html](http://www.jetbrains.com/idea/plugins/index.html)
|
||||
[www.jetbrains.com/idea/plugins/](http://www.jetbrains.com/idea/plugins/)
|
||||
and then returning to this document.
|
||||
|
||||
The following subjects are covered:
|
||||
|
@ -27,7 +27,7 @@ class. For example, to get the PSI tree for XML, use `fileViewProvider.getPsi(St
|
||||
## How do I extend FVP?
|
||||
|
||||
To create a file type that has multiple interspersing trees for different languages, your plugin must contain an extension to the _fileType.fileViewProviderFactory_
|
||||
[extension point](http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_extensions_and_extension_points.html)
|
||||
[extension point](/basics/plugin_structure/plugin_extensions_and_extension_points.html)
|
||||
available in the IntelliJ Platform core.
|
||||
This extension point is declared using the
|
||||
[FileTypeExtensionPoint](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/core-api/src/com/intellij/openapi/fileTypes/FileTypeExtensionPoint.java)
|
||||
|
@ -15,7 +15,7 @@ class is the common base class for PSI elements.
|
||||
|
||||
* 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.
|
||||
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()`
|
||||
|
||||
|
@ -49,7 +49,7 @@ The `VirtualFileManager.addVirtualFileListener()` method allows you to receive n
|
||||
To provide an alternative file system implementation (for example, an FTP file system), implement the
|
||||
[VirtualFileSystem](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileSystem.java)
|
||||
class (most likely you'll also need to implement `VirtualFile`), and register your implementation as an
|
||||
[application component](http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_components.html).
|
||||
[application component](/basics/plugin_structure/plugin_components.md).
|
||||
To hook into operations performed in the local file system (for example, if you are developing a version control system integration that needs custom rename/move handling), implement the
|
||||
[LocalFileOperationsHandler](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/platform-api/src/com/intellij/openapi/vfs/LocalFileOperationsHandler.java)
|
||||
interface and register it through the`LocalFileSystem.registerAuxiliaryFileOperationsHandler` method.
|
||||
@ -57,5 +57,5 @@ interface and register it through the`LocalFileSystem.registerAuxiliaryFileOpera
|
||||
#### What are the rules for working with VFS?
|
||||
|
||||
See
|
||||
[IntelliJ Platform Virtual File System](http://www.jetbrains.org/intellij/sdk/docs/basics/virtual_file_system.html)
|
||||
[IntelliJ Platform Virtual File System](/basics/virtual_file_system.md)
|
||||
for a detailed description of the VFS architecture and usage guidelines.
|
||||
|
@ -3,7 +3,7 @@ title: Plugin Compatibility with IntelliJ Platform Products
|
||||
---
|
||||
|
||||
<!--TODO link to sample_plugin file-->
|
||||
All products based on IntelliJ Platform (IntelliJ IDEA, RubyMine, WebStorm, PhpStorm, PyCharm and AppCode) share the same underlying platform API.
|
||||
All products based on IntelliJ Platform (IntelliJ IDEA, RubyMine, WebStorm, PhpStorm, PyCharm, AppCode, etc.) share the same underlying platform API.
|
||||
Thus, a plugin that does not use any Java-specific functionality may be marked as compatible with these other products in addition to IntelliJ IDEA.
|
||||
This is done by specifying *module dependencies* in the `plugin.xml` file.
|
||||
|
||||
@ -20,7 +20,7 @@ For example:
|
||||
```
|
||||
|
||||
<!--TODO link to sample_plugin file-->
|
||||
If a plugin does not include any module dependency tags in its `plugin.xml`, it's assumed to be a legacy plugin and is loaded only in a IntelliJ-Platform-based product.
|
||||
If a plugin does not include any module dependency tags in its `plugin.xml`, it's assumed to be a legacy plugin and is loaded only in IntelliJ IDEA.
|
||||
|
||||
<!--TODO link to sample_plugin file-->
|
||||
If the `plugin.xml` includes one or more such tags, the plugin is loaded if the product contains all of the modules on which the plugin depends.
|
||||
@ -68,7 +68,7 @@ If your plugin works with all products but provides some Java-specific functiona
|
||||
</depends>
|
||||
```
|
||||
|
||||
Before marking a plugin as compatible with all products, you should verify that it doesn't use any APIs that are specific to IntelliJ Platform. To do so, create an IntelliJ Platform SDK pointing to an installation of RubyMine/PyCharm/etc., compile your plugin against that SDK, and verify that everything compiles.
|
||||
Before marking a plugin as compatible with all products, you should verify that it doesn't use any APIs that are specific to IntelliJ IDEA. To do so, create an IntelliJ Platform SDK pointing to an installation of RubyMine/PyCharm/etc., compile your plugin against that SDK, and verify that everything compiles.
|
||||
|
||||
The
|
||||
[IntelliJ plugin repository](http://plugins.jetbrains.com/)
|
||||
|
@ -7,7 +7,7 @@ title: Running and Debugging a Plugin
|
||||
|
||||
*IntelliJ Platform* allows you to run and debug a plugin without leaving the IDE.
|
||||
To run or debug the plugin from within *IntelliJ IDEA*, you need a configured special profile (a Run/Debug configuration) that specifies the class to run, VM parameters and other specific options.
|
||||
In most cases, you can use the default *Run\/Debug* configuration profiles for your plugin projects.
|
||||
In most cases, you can use the default *Run/Debug* configuration profiles for your plugin projects.
|
||||
For information on how to change the Run/Debug configuration profile, refer to
|
||||
[Run/Debug Configuration](http://www.jetbrains.com/idea/help/run-debug-configuration.html)
|
||||
and
|
||||
@ -17,8 +17,8 @@ Using IntelliJ IDEA's debugger, you can find out the origin of the run-time erro
|
||||
|
||||
**To debug a plugin**
|
||||
|
||||
* Select *Run \| Debug* in the main menu, or press *Shift + F9*.
|
||||
* Select **Run \| Debug** in the main menu, or press *Shift + F9*.
|
||||
|
||||
**To run a plugin**
|
||||
|
||||
* Select *Run \| Run* in the main menu, or press *Shift + F10*.
|
||||
* Select **Run \| Run** in the main menu, or press *Shift + F10*.
|
||||
|
@ -52,7 +52,7 @@ Optionally, application-level component's implementation class may implement the
|
||||
interface.
|
||||
An application component that has no dependencies should have a constructor with no parameters which will be used for its instantiation.
|
||||
If an application component depends on other application components, it can specify these components as constructor parameters. IntelliJ IDEA will ensure that the components are instantiated in the correct order to satisfy the dependencies.
|
||||
Note that application-level components must be registered in the `<application-components>` section of the plugin.xml file (see Plugin Configuration File below).
|
||||
Note that application-level components must be registered in the `<application-components>` section of the plugin.xml file (see [Plugin Configuration File](plugin_configuration_file.md)).
|
||||
|
||||
#### Quick creation of application components
|
||||
|
||||
@ -81,7 +81,7 @@ The constructor of a project-level component can have a parameter of the
|
||||
type, if it needs the project instance.
|
||||
It can also specify other application-level or project-level components as parameters, if it depends on those components.
|
||||
|
||||
Note that project-level components must be registered in the `<project-components>` section of the *plugin.xml* file (see Plugin Configuration File below).
|
||||
Note that project-level components must be registered in the `<project-components>` section of the *plugin.xml* file (see [Plugin Configuration File](plugin_configuration_file.md)).
|
||||
|
||||
#### Quick creation of project components
|
||||
|
||||
@ -110,7 +110,7 @@ interface.
|
||||
The constructor of a module-level component can have a parameter of the Module type, if it needs the module instance.
|
||||
It can also specify other application-level, project-level or module-level components as parameters, if it depends on those components.
|
||||
|
||||
Note that module-level components must be registered in the `<module-components>` section of the `plugin.xml` file (see Plugin Configuration File below).
|
||||
Note that module-level components must be registered in the `<module-components>` section of the `plugin.xml` file (see [Plugin Configuration File](plugin_configuration_file.md)).
|
||||
|
||||
#### Quick creation of module components
|
||||
|
||||
|
@ -25,7 +25,7 @@ Depending on the logical and functional requirements to the project, you can cre
|
||||
|
||||
#### Module
|
||||
|
||||
A _module_ is a discrete unit of functionality that can be run, tested, and debugged independently. Modules includes such things as source code, build scripts, unit tests, deployment descriptors, etc. In the project, each module can use a specific SDK or inherit SDK defined on the project level (see the SDK section later in this document). A module can depend on other modules of the project.
|
||||
A _module_ is a discrete unit of functionality that can be run, tested, and debugged independently. Modules includes such things as source code, build scripts, unit tests, deployment descriptors, etc. In the project, each module can use a specific SDK or inherit SDK defined on the project level (see the [SDK](/reference_guide/project_model/sdk.html) section later in this document). A module can depend on other modules of the project.
|
||||
|
||||
#### Library
|
||||
|
||||
@ -102,7 +102,7 @@ To work with projects and project files, you can use the following classes and i
|
||||
|
||||
Note that you don't need to access project files directly to load or save settings.
|
||||
See
|
||||
[Persisting State of Components](http://www.jetbrains.org/intellij/sdk/docs/basics/persisting_state_of_components.html)
|
||||
[Persisting State of Components](persisting_state_of_components.md)
|
||||
for more information.
|
||||
|
||||
Note that hereafter, the `project` variable is of the `Project` type.
|
||||
@ -139,10 +139,10 @@ Use the `ProjectRootManager.getFileIndex()` method. For example:
|
||||
##### How do I get a module to which a file belongs?
|
||||
|
||||
To determine a module in the project in question to which the specified
|
||||
[virtual file](http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/virtual_file.html)
|
||||
[virtual file](architectural_overview/virtual_file.md)
|
||||
belongs, use the `ProjectFileIndex.getModuleForFile(virtualFile)` method:
|
||||
|
||||
```
|
||||
```java
|
||||
Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(virtualFile);
|
||||
```
|
||||
|
||||
@ -150,15 +150,18 @@ Note that this method returns `null` if the file does not belong to any module.
|
||||
|
||||
You can also use the `ProjectFileIndex.getContentRootForFile` method to get the module content root to which the specified file or directory belongs:
|
||||
|
||||
`VirtualFile moduleContentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(virtualFileorDirectory);`
|
||||
|
||||
```java
|
||||
VirtualFile moduleContentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(virtualFileorDirectory);
|
||||
```
|
||||
|
||||
##### How do I get the module source root or library source root to which the specified file or directory belongs?
|
||||
|
||||
Use the `ProjectFileIndex.getSourceRootForFile` method. For example:
|
||||
|
||||
```VirtualFile moduleSourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(virtualFileorDirectory);
|
||||
```java
|
||||
VirtualFile moduleSourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(virtualFileorDirectory);
|
||||
```
|
||||
|
||||
Note that this method returns `null` if the file or directory does not belong to any source root of modules in the project.
|
||||
|
||||
##### How do I check whether a file or directory is related to the project libraries?
|
||||
@ -271,7 +274,7 @@ String moduleName = module == null ? "Module not found" : module.getName();
|
||||
```
|
||||
|
||||
* To get the project module to which the specified
|
||||
[PSI element](http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi_elements.html)
|
||||
[PSI element](architectural_overview/psi_elements.md)
|
||||
belongs, use the `ModuleUtil.findModuleForPsiElement(psiElement)` method.
|
||||
|
||||
#### How do I work with libraries available within a module?
|
||||
|
@ -3,7 +3,7 @@ title: Run Configurations
|
||||
---
|
||||
|
||||
|
||||
Run configurations allow users to run a certain type of external processes from within the IDE, i.e a script, an application, a server, etc.
|
||||
Run configurations allow users to run a certain type of external processes from within the IDE, i.e. a script, an application, a server, etc.
|
||||
You can provide UI for the user to specify execution options, as well as an option to create run configuration based on a specific location in the source code.
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ The standard execution of a run action goes through the following steps:
|
||||
The
|
||||
[Executor](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/lang-api/src/com/intellij/execution/Executor.java)
|
||||
interface describes a specific way of executing any possible run configuration.
|
||||
The three default executors provided by the IntelliJ Platform by default are _Run_, _Debug_ and (in IntelliJ IDEA Ultimate and certain platform-based IDEs) _Run with Coverage_.
|
||||
The three default executors provided by the IntelliJ Platform by default are _Run_, _Debug_ and _Run with Coverage_.
|
||||
Each executor gets its own toolbar button, which starts the selected run configuration using this executor, and its own context menu item for starting a configuration using this executor.
|
||||
|
||||
As a plugin developer, you normally don't need to implement the _Executor_ interface.
|
||||
@ -82,7 +82,7 @@ and
|
||||
## Starting a Run Configuration from Code
|
||||
|
||||
If you have an existing run configuration that you need to execute, the easiest way to do so is to use
|
||||
[ProgramRunnerUtil.executeConfiguration](https://github.com/JetBrains/intellij-community/blob/master/platform/lang-impl/src/com/intellij/execution/ProgramRunnerUtil.java#L110).
|
||||
[ProgramRunnerUtil.executeConfiguration()](https://github.com/JetBrains/intellij-community/blob/master/platform/lang-impl/src/com/intellij/execution/ProgramRunnerUtil.java#L110).
|
||||
The method takes a Project, a RunnerAndConfigurationSettings, as well as an Executor.
|
||||
To get the RunnerAndConfigurationSettings for an existing configuration, you can use, for example, `RunManager.getConfigurationSettings(ConfigurationType)`.
|
||||
As the last parameter, you normally pass either `DefaultRunExecutor.getRunExecutorInstance()` or `DefaultDebugExecutor.getDebugExecutorInstance()`.
|
||||
|
@ -37,7 +37,7 @@ Refresh operations are explicitly invoked from the IntelliJ IDEA or plugin code
|
||||
The VFS will be updated during the next refresh operation which includes the file in its scope.
|
||||
|
||||
IntelliJ Platform refreshes the entire project contents asynchronously on startup.
|
||||
By default, it performs a refresh operation when the user switches to it from another app, but users can turn this off via **Settings \| Synchronize** files on frame activation.
|
||||
By default, it performs a refresh operation when the user switches to it from another app, but users can turn this off via **Settings \| Appearance & Behavior \| System Settings \| Synchronize files on frame activation**.
|
||||
|
||||
On Windows, Mac and Linux IntelliJ Platform starts a native file watcher process that receives file change notifications from the file system and reports them to IntelliJ Platform.
|
||||
If a file watcher is available, a refresh operation looks only at the files that have been reported as changed by the file watcher.
|
||||
@ -63,7 +63,7 @@ In fact, the refresh operations are executed according to their own threading po
|
||||
|
||||
Both synchronous and asynchronous refreshes can be initiated from any thread.
|
||||
If a refresh is initiated from a background thread, the calling thread must not hold a read action, because otherwise a deadlock would occur.
|
||||
See [IntelliJ Platform Architectural Overview] for more details on the threading model and read/write actions.
|
||||
See [IntelliJ Platform Architectural Overview](/basics/architectural_overview/general_threading_rules.html) for more details on the threading model and read/write actions.
|
||||
The same threading requirements also apply to functions like
|
||||
[LocalFileSystem.refreshAndFindFileByPath()](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/platform-api/src/com/intellij/openapi/vfs/LocalFileSystem.java),
|
||||
which perform a partial refresh if the file with the specified path is not found in the snapshot.
|
||||
@ -72,7 +72,6 @@ In nearly all cases, using asynchronous refreshes is strongly preferred.
|
||||
If there is some code that needs to be executed after the refresh is complete, the code should be passed as a postRunnable parameter to one of the refresh methods:
|
||||
|
||||
* [RefreshQueue.createSession()](https://github.com/JetBrains/intellij-community/blob/master/platform/platform-api/src/com/intellij/openapi/vfs/newvfs/RefreshQueue.java#L36)
|
||||
|
||||
* [VirtualFile.refresh()](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java#L681)
|
||||
|
||||
Synchronous refreshes can cause deadlocks in some cases, depending on which locks are held by the thread invoking the refresh operation.
|
||||
@ -83,12 +82,12 @@ All changes happening in the virtual file system, either as a result of refresh
|
||||
VFS events are always fired in the event dispatch thread, and in a write action.
|
||||
|
||||
The most efficient way to listen to VFS events is to implement the BulkFileListener interface and to subscribe with it to the
|
||||
[VirtualFileManager.VFS_CHANGES](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java#L34)
|
||||
[VirtualFileManager.VFS_CHANGES](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java#L34)
|
||||
topic.
|
||||
|
||||
This API gives you all the changes detected during the refresh operation in one list, and lets you process them in batch.
|
||||
Alternatively, you can implement the VirtualFileListener interface and register it using
|
||||
[VirtualFileManager.addVirtualFileListener()](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java#L113).
|
||||
[VirtualFileManager.addVirtualFileListener()](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileManager.java#L113).
|
||||
This will let you process the events one by one.
|
||||
|
||||
Note that the VFS listeners are application-level, and will receive events for changes happening in all the projects opened by the user.
|
||||
@ -100,7 +99,7 @@ However, it is still present in the VFS snapshot, and you can access its last co
|
||||
|
||||
Note that a refresh operation fires events only for changes in files that have been loaded in the snapshot.
|
||||
For example, if you accessed a VirtualFile for a directory but never loaded its contents using
|
||||
[VirtualFile.getChildren()](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java#L315),
|
||||
you may not get fileCreated notifications when files are created in that directory.
|
||||
[VirtualFile.getChildren()](https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java#L135),
|
||||
you may not get fileCreated notifications when files are created in that directory.
|
||||
If you loaded only a single file in a directory using VirtualFile.findChild(), you will get notifications for changes to that file, but you may not get created/deleted notifications for other files in the same directory.
|
||||
|
||||
|
@ -44,7 +44,7 @@ To support smart/semantic *Join Lines* see
|
||||
*Semantic highlight usages* (e.g. exit points) can be achieved using
|
||||
[HighlightUsagesHandlerFactory](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/lang-impl/src/com/intellij/codeInsight/highlighting/HighlightUsagesHandlerFactory.java).
|
||||
|
||||
*View\|Parameter Info* is provided via
|
||||
*View \| Parameter Info* is provided via
|
||||
[ParameterInfoHandler](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/lang-api/src/com/intellij/lang/parameterInfo/ParameterInfoHandler.java)
|
||||
(extension point `codeInsight.parameterInfo`).
|
||||
|
||||
@ -67,6 +67,6 @@ to use, possibly depending on the passed in
|
||||
[PsiElement](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/core-api/src/com/intellij/psi/PsiElement.java)
|
||||
(or `EMPTY_TOKENIZER` for no spellchecking).
|
||||
|
||||
New in 13: user-configurable *reference injections* can be provided via `referenceInjector` extension point (
|
||||
**New in IntelliJ IDEA 13**: user-configurable *reference injections* can be provided via `referenceInjector` extension point (
|
||||
[ReferenceInjector](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/lang-api/src/com/intellij/psi/injection/ReferenceInjector.java)
|
||||
) (IntelliLang plugin required).
|
||||
|
@ -70,8 +70,7 @@ The return value of `createIndentOptions()` determines the default indent size.
|
||||
|
||||
### Rearranger
|
||||
|
||||
**New in 12:**
|
||||
|
||||
**New in IntelliJ IDEA 12:**
|
||||
Allows custom languages to provide user-configurable arrangement/grouping rules for element types supported by language plugin.
|
||||
Rules can be refined via modifiers and name, ordering can be applied additionally.
|
||||
Please see
|
||||
|
@ -69,7 +69,7 @@ Lexers must never abort prematurely because of an invalid character.
|
||||
**Example**:
|
||||
[Lexer](https://github.com/JetBrains/intellij-community/blob/master/plugins/properties/src/com/intellij/lang/properties/parsing/Properties.flex)
|
||||
definition for
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/blob/master/plugins/properties/src/com/intellij/lang/properties/)
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/tree/master/plugins/properties)
|
||||
|
||||
|
||||
Types of tokens for lexers are defined by instances of
|
||||
@ -88,7 +88,7 @@ instance should be returned every time a particular token type is encountered by
|
||||
**Example:**
|
||||
[Token types](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/plugins/properties/properties-psi-api/src/com/intellij/lang/properties/parsing/PropertiesTokenTypes.java)
|
||||
for
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/blob/master/plugins/properties/)
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/tree/master/plugins/properties)
|
||||
|
||||
|
||||
An important feature which can be implemented at lexer level is mixing languages within a file, for example, embedding fragments of Java code in some template language.
|
||||
|
@ -33,7 +33,7 @@ method.
|
||||
**Example**:
|
||||
[ParserDefinition](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertiesParserDefinition.java)
|
||||
for
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/blob/master/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/)
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/tree/master/plugins/properties)
|
||||
|
||||
|
||||
The lifecycle of the PSI is described in more detail in
|
||||
|
@ -32,7 +32,7 @@ to a ResourceBundle in the
|
||||
|
||||
|
||||
There's a set of interfaces which can be used as a base for implementing resolve support, namely the
|
||||
[PsiScopeProcessor interface](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/core-api/src/com/intellij/psi/scope/PsiScopeProcessor.java) and the
|
||||
[PsiScopeProcessor](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/core-api/src/com/intellij/psi/scope/PsiScopeProcessor.java) interface and the
|
||||
[PsiElement.processDeclarations()](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/core-api/src/com/intellij/psi/PsiElement.java)
|
||||
method.
|
||||
These interfaces have a number of extra complexities which are not necessary for most custom languages (like support for substituting Java generics types), but they are required if the custom language can have references to Java code.
|
||||
|
@ -44,7 +44,8 @@ at all.
|
||||
|
||||
**Example**:
|
||||
[RenameHandler](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/plugins/properties/src/com/intellij/lang/properties/refactoring/rename/ResourceBundleFromEditorRenameHandler.java)
|
||||
for renaming a resource bundle
|
||||
for renaming a resource bundle in the
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/tree/master/plugins/properties)
|
||||
|
||||
|
||||
If you're fine with the standard UI but need to extend the default logic of renaming, you can provide an implementation of the
|
||||
|
@ -30,4 +30,5 @@ This is done by implementing the `SafeDeleteProcessorDelegate` interface.
|
||||
|
||||
**Example**:
|
||||
[SafeDeleteProcessorDelegate](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/plugins/properties/src/com/intellij/lang/properties/refactoring/PropertiesFilesSafeDeleteProcessor.java)
|
||||
implementation for a .properties file
|
||||
implementation for
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/tree/master/plugins/properties)
|
||||
|
@ -16,7 +16,8 @@ interface, which is registered in the `com.intellij.lang.psiStructureViewFactory
|
||||
|
||||
**Example:**
|
||||
[PsiStructureViewFactory](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/plugins/properties/src/com/intellij/lang/properties/structureView/PropertiesStructureViewBuilderFactory.java)
|
||||
for .properties files
|
||||
for
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/tree/master/plugins/properties)
|
||||
|
||||
|
||||
To reuse the *IntelliJ Platform* implementation of the
|
||||
@ -32,7 +33,8 @@ and by overriding methods of this subclass it customizes the structure view for
|
||||
|
||||
**Example**:
|
||||
[StructureViewModel](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/structureView/PropertiesFileStructureViewModel.java)
|
||||
for .properties files
|
||||
for
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/tree/master/plugins/properties)
|
||||
|
||||
|
||||
The main method to override is `getRoot()`, which returns the instance of a class implementing the
|
||||
@ -51,5 +53,5 @@ The latter method returns an array of `PsiElement`\-derived classes which can be
|
||||
|
||||
**Example:**
|
||||
[StructureViewElement](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/structureView/PropertiesStructureViewElement.java)
|
||||
for a
|
||||
for
|
||||
[Properties language plugin](https://github.com/JetBrains/intellij-community/tree/master/plugins/properties/)
|
||||
|
@ -1,3 +1,6 @@
|
||||
---
|
||||
---
|
||||
|
||||
# Purpose
|
||||
|
||||
This page provides high-level overview of *External System* sub-system.
|
||||
@ -80,4 +83,4 @@ Though main development is performed at the 'master' branch, there is a special
|
||||
1. Download external-system.zip;
|
||||
2. Unpack it and define *external-system.jar* as a library dependency;
|
||||
3. Configure sources from *external-system-src.jar* if necessary;
|
||||
4. Add definitions from *ExternalSystemExtensionPoints.xml* and *ExternalSystemExtensions.xml* to your *plugin.xml* (that **.xml files are bundled into *external-system-src.jar*). *Note:** it's very important to use custom namespace there because there is a possible case that more than one external system integration uses this approach to be compatible with 12.1.x;
|
||||
4. Add definitions from *ExternalSystemExtensionPoints.xml* and *ExternalSystemExtensions.xml* to your *plugin.xml* (that **.xml files are bundled into *external-system-src.jar*). *Note:** it's very important to use custom namespace there because there is a possible case that more than one external system integration uses this approach to be compatible with 12.1.x;
|
||||
|
@ -26,7 +26,7 @@ OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile));
|
||||
|
||||
## Checking Belonging to a Library
|
||||
|
||||
The ProjectFileIndex interface implements a number of methods you can use to check whether the specified file belongs to the project library classes or library sources.
|
||||
The [ProjectFileIndex](https://github.com/JetBrains/intellij-community/blob/master/platform/projectModel-api/src/com/intellij/openapi/roots/ProjectFileIndex.java) interface implements a number of methods you can use to check whether the specified file belongs to the project library classes or library sources.
|
||||
You can use the following methods:
|
||||
|
||||
* To check if a specified virtual file is a compiled class file use
|
||||
|
@ -3,7 +3,7 @@ title: Module
|
||||
---
|
||||
A module is a discrete unit of functionality that can be run, tested, and debugged independently.
|
||||
Modules includes such things as source code, build scripts, unit tests, deployment descriptors, etc.
|
||||
In the project, each module can use a specific SDK or inherit SDK defined on the project level (see the SDK section later in this document).
|
||||
In the project, each module can use a specific SDK or inherit SDK defined on the project level (see the [SDK](sdk.md) section later in this document).
|
||||
A module can depend on other modules of the project.
|
||||
|
||||
## Getting Current Module
|
||||
@ -16,7 +16,7 @@ Module module = ProjectRootManager.getInstance(project).getFileIndex().getModule
|
||||
|
||||
|
||||
## Accessing Module Roots
|
||||
Information about model roots can be accessed via the class
|
||||
Information about module roots can be accessed via the class
|
||||
[ModuleRootManager.java](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/projectModel-api/src/com/intellij/openapi/roots/ModuleRootManager.java),
|
||||
for example, an instance of
|
||||
[ModuleFileIndex.java](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/projectModel-api/src/com/intellij/openapi/roots/ModuleFileIndex.java)
|
||||
@ -30,12 +30,9 @@ ModuleRootManager.getInstance(currentModule).getFileIndex()
|
||||
|
||||
### Checking Belonging to a Module Source Root
|
||||
|
||||
To check if a virtual file or directory belongs to a module source root, use the
|
||||
`ProjectFileIndex.getSourceRootForFile`
|
||||
method.
|
||||
To check if a virtual file or directory belongs to a module source root, use the `ProjectFileIndex.getSourceRootForFile` method.
|
||||
This method returns null if the file or directory does not belong to any source root of modules in the project.
|
||||
|
||||
|
||||
```java
|
||||
VirtualFile moduleSourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(virtualFileOrDirectory);
|
||||
```
|
||||
|
@ -60,8 +60,8 @@ Use the ProjectRootManager.getFileIndex() method. For example:
|
||||
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
```
|
||||
|
||||
Note that this method returns null if the file does not belong to any module.
|
||||
You can also use the ProjectFileIndex.getContentRootForFile method to get the module content root to which the specified file or directory belongs:
|
||||
Note that this method returns `null` if the file does not belong to any module.
|
||||
You can also use the `ProjectFileIndex.getContentRootForFile()` method to get the module content root to which the specified file or directory belongs:
|
||||
|
||||
```java
|
||||
VirtualFile moduleContentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(virtualFileOrDirectory);
|
||||
|
@ -12,9 +12,9 @@ and
|
||||
[Configuring Global, Project and Module SDKs](https://www.jetbrains.com/idea/help/configuring-global-project-and-module-sdks.html)
|
||||
in IntelliJ IDEA Web Help.
|
||||
|
||||
### Getting Project Sdk Information
|
||||
### Getting Project SDK Information
|
||||
|
||||
Main information about the project Sdk can be accessed via
|
||||
Main information about the project SDK can be accessed via
|
||||
[ProjectRootManager.java](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/projectModel-api/src/com/intellij/openapi/roots/ProjectRootManager.java)
|
||||
like the following example shows
|
||||
|
||||
|
@ -12,21 +12,15 @@ Let's consider a literal which starts with *"simple:"* as a usage of our propert
|
||||
```java
|
||||
package com.simpleplugin;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.lang.annotation.Annotation;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SyntaxHighlighterColors;
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiLiteralExpression;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.simpleplugin.psi.SimpleProperty;
|
||||
import org.intellij.lang.regexp.intention.CheckRegExpIntentionAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@ -39,12 +33,13 @@ public class SimpleAnnotator implements Annotator {
|
||||
String value = (String) literalExpression.getValue();
|
||||
if (value != null && value.startsWith("simple:")) {
|
||||
Project project = element.getProject();
|
||||
List<SimpleProperty> properties = SimpleUtil.findProperties(project, value.substring(7));
|
||||
String key = value.substring(7);
|
||||
List<SimpleProperty> properties = SimpleUtil.findProperties(project, key);
|
||||
if (properties.size() == 1) {
|
||||
TextRange range = new TextRange(element.getTextRange().getStartOffset() + 7,
|
||||
element.getTextRange().getStartOffset() + 7);
|
||||
Annotation annotation = holder.createInfoAnnotation(range, null);
|
||||
annotation.setTextAttributes(SyntaxHighlighterColors.LINE_COMMENT);
|
||||
annotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT);
|
||||
} else if (properties.size() == 0) {
|
||||
TextRange range = new TextRange(element.getTextRange().getStartOffset() + 8,
|
||||
element.getTextRange().getEndOffset());
|
||||
|
@ -13,7 +13,6 @@ package com.simpleplugin;
|
||||
import com.intellij.lang.cacheBuilder.DefaultWordsScanner;
|
||||
import com.intellij.lang.cacheBuilder.WordsScanner;
|
||||
import com.intellij.lang.findUsages.FindUsagesProvider;
|
||||
import com.intellij.lexer.FlexAdapter;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
@ -22,11 +21,9 @@ import com.simpleplugin.psi.SimpleTypes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.Reader;
|
||||
|
||||
public class SimpleFindUsagesProvider implements FindUsagesProvider {
|
||||
private static final DefaultWordsScanner WORDS_SCANNER =
|
||||
new DefaultWordsScanner(new FlexAdapter(new SimpleLexer((Reader) null)),
|
||||
new DefaultWordsScanner(new SimpleLexerAdapter(),
|
||||
TokenSet.create(SimpleTypes.KEY), TokenSet.create(SimpleTypes.COMMENT), TokenSet.EMPTY);
|
||||
|
||||
@Nullable
|
||||
|
@ -45,7 +45,7 @@ public class SimpleFoldingBuilder extends FoldingBuilderEx {
|
||||
if (properties.size() == 1) {
|
||||
descriptors.add(new FoldingDescriptor(literalExpression.getNode(),
|
||||
new TextRange(literalExpression.getTextRange().getStartOffset() + 1,
|
||||
literalExpression.getTextRange().getEndOffset() * 1), group) {
|
||||
literalExpression.getTextRange().getEndOffset() - 1), group) {
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPlaceholderText() {
|
||||
|
@ -96,7 +96,7 @@ public class SimpleFormattingModelBuilder implements FormattingModelBuilder {
|
||||
}
|
||||
|
||||
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
|
||||
return new SpacingBuilder(settings).
|
||||
return new SpacingBuilder(settings, SimpleLanguage.INSTANCE).
|
||||
around(SimpleTypes.SEPARATOR).spaceIf(settings.SPACE_AROUND_ASSIGNMENT_OPERATORS).
|
||||
before(SimpleTypes.PROPERTY).none();
|
||||
}
|
||||
|
@ -67,10 +67,9 @@ Choose the project root directory.
|
||||
|
||||

|
||||
|
||||
After that the IDE will generates two classes:
|
||||
*com.simpleplugin.SimpleLexer* and *com.simpleplugin.SimpleLexerAdapter*.
|
||||
After that the IDE will generate lexer: *com.simpleplugin.SimpleLexer*.
|
||||
|
||||
Make sure you've added the corresponding changes to the *com.simpleplugin.SimpleLexerAdapter* class:
|
||||
### 4.3. Define an adapter
|
||||
|
||||
```java
|
||||
package com.simpleplugin;
|
||||
@ -86,7 +85,7 @@ public class SimpleLexerAdapter extends FlexAdapter {
|
||||
}
|
||||
```
|
||||
|
||||
### 4.3 Define a file
|
||||
### 4.4. Define a file
|
||||
|
||||
```java
|
||||
package com.simpleplugin.psi;
|
||||
@ -123,7 +122,7 @@ public class SimpleFile extends PsiFileBase {
|
||||
}
|
||||
```
|
||||
|
||||
### 4.4. Define a parser definition
|
||||
### 4.5. Define a parser definition
|
||||
|
||||
```java
|
||||
package com.simpleplugin;
|
||||
@ -132,7 +131,6 @@ import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.ParserDefinition;
|
||||
import com.intellij.lang.PsiParser;
|
||||
import com.intellij.lexer.FlexAdapter;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
@ -146,8 +144,6 @@ import com.simpleplugin.psi.SimpleFile;
|
||||
import com.simpleplugin.psi.SimpleTypes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Reader;
|
||||
|
||||
public class SimpleParserDefinition implements ParserDefinition{
|
||||
public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE);
|
||||
public static final TokenSet COMMENTS = TokenSet.create(SimpleTypes.COMMENT);
|
||||
@ -157,7 +153,7 @@ public class SimpleParserDefinition implements ParserDefinition{
|
||||
@NotNull
|
||||
@Override
|
||||
public Lexer createLexer(Project project) {
|
||||
return new FlexAdapter(new SimpleLexer((Reader) null));
|
||||
return new SimpleLexerAdapter();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -200,13 +196,13 @@ public class SimpleParserDefinition implements ParserDefinition{
|
||||
}
|
||||
```
|
||||
|
||||
### 4.5. Register the parser definition
|
||||
### 4.6. Register the parser definition
|
||||
|
||||
```xml
|
||||
<lang.parserDefinition language="Simple" implementationClass="com.simpleplugin.SimpleParserDefinition"/>
|
||||
```
|
||||
|
||||
### 4.6. Run the project
|
||||
### 4.7. Run the project
|
||||
|
||||
Create a properties file with the following content:
|
||||
|
||||
|
@ -51,6 +51,7 @@ package com.simpleplugin;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
@ -61,13 +62,18 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.search.FileTypeIndex;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.indexing.FileBasedIndex;
|
||||
import com.simpleplugin.psi.SimpleElementFactory;
|
||||
import com.simpleplugin.psi.SimpleFile;
|
||||
import com.simpleplugin.psi.SimpleProperty;
|
||||
import com.simpleplugin.psi.SimpleTypes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class CreatePropertyQuickFix extends BaseIntentionAction {
|
||||
private String key;
|
||||
|
||||
@ -97,29 +103,39 @@ class CreatePropertyQuickFix extends BaseIntentionAction {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE);
|
||||
descriptor.setRoots(project.getBaseDir());
|
||||
final VirtualFile file = FileChooser.chooseFile(descriptor, project, null);
|
||||
if (file != null) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(file);
|
||||
ASTNode lastChildNode = simpleFile.getNode().getLastChildNode();
|
||||
if (lastChildNode != null && !lastChildNode.getElementType().equals(SimpleTypes.CRLF)) {
|
||||
simpleFile.getNode().addChild(SimpleElementFactory.createCRLF(project).getNode());
|
||||
}
|
||||
SimpleProperty property = SimpleElementFactory.createProperty(project, key, "");
|
||||
simpleFile.getNode().addChild(property.getNode());
|
||||
((Navigatable) property.getLastChild().getNavigationElement()).navigate(true);
|
||||
FileEditorManager.getInstance(project).getSelectedTextEditor().getCaretModel().
|
||||
moveCaretRelatively(2, 0, false, false, false);
|
||||
}
|
||||
});
|
||||
Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE,
|
||||
GlobalSearchScope.allScope(project));
|
||||
if (virtualFiles.size() == 1) {
|
||||
createProperty(project, virtualFiles.iterator().next());
|
||||
} else {
|
||||
final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(SimpleFileType.INSTANCE);
|
||||
descriptor.setRoots(project.getBaseDir());
|
||||
final VirtualFile file = FileChooser.chooseFile(descriptor, project, null);
|
||||
if (file != null) {
|
||||
createProperty(project, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createProperty(final Project project, final VirtualFile file) {
|
||||
new WriteCommandAction.Simple(project) {
|
||||
@Override
|
||||
public void run() {
|
||||
SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(file);
|
||||
ASTNode lastChildNode = simpleFile.getNode().getLastChildNode();
|
||||
if (lastChildNode != null && !lastChildNode.getElementType().equals(SimpleTypes.CRLF)) {
|
||||
simpleFile.getNode().addChild(SimpleElementFactory.createCRLF(project).getNode());
|
||||
}
|
||||
SimpleProperty property = SimpleElementFactory.createProperty(project, key, "");
|
||||
simpleFile.getNode().addChild(property.getNode());
|
||||
((Navigatable) property.getLastChild().getNavigationElement()).navigate(true);
|
||||
FileEditorManager.getInstance(project).getSelectedTextEditor().getCaretModel().
|
||||
moveCaretRelatively(2, 0, false, false, false);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -131,7 +147,7 @@ package com.simpleplugin;
|
||||
import com.intellij.lang.annotation.Annotation;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.openapi.editor.SyntaxHighlighterColors;
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@ -155,7 +171,7 @@ public class SimpleAnnotator implements Annotator {
|
||||
TextRange range = new TextRange(element.getTextRange().getStartOffset() + 7,
|
||||
element.getTextRange().getStartOffset() + 7);
|
||||
Annotation annotation = holder.createInfoAnnotation(range, null);
|
||||
annotation.setTextAttributes(SyntaxHighlighterColors.LINE_COMMENT);
|
||||
annotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT);
|
||||
} else if (properties.size() == 0) {
|
||||
TextRange range = new TextRange(element.getTextRange().getStartOffset() + 8,
|
||||
element.getTextRange().getEndOffset());
|
||||
|
@ -14,6 +14,7 @@ import com.intellij.ide.structureView.StructureViewBuilder;
|
||||
import com.intellij.ide.structureView.StructureViewModel;
|
||||
import com.intellij.ide.structureView.TreeBasedStructureViewBuilder;
|
||||
import com.intellij.lang.PsiStructureViewFactory;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -25,7 +26,7 @@ public class SimpleStructureViewFactory implements PsiStructureViewFactory {
|
||||
return new TreeBasedStructureViewBuilder() {
|
||||
@NotNull
|
||||
@Override
|
||||
public StructureViewModel createStructureViewModel() {
|
||||
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
|
||||
return new SimpleStructureViewModel(psiFile);
|
||||
}
|
||||
};
|
||||
|
@ -8,30 +8,24 @@ title: 5. Syntax Highlighter and Color Settings Page
|
||||
```java
|
||||
package com.simpleplugin;
|
||||
|
||||
import com.intellij.lexer.FlexAdapter;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.openapi.editor.SyntaxHighlighterColors;
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
||||
import com.intellij.openapi.editor.HighlighterColors;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.simpleplugin.psi.SimpleTypes;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.Reader;
|
||||
|
||||
import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;
|
||||
|
||||
public class SimpleSyntaxHighlighter extends SyntaxHighlighterBase {
|
||||
public static final TextAttributesKey SEPARATOR = createTextAttributesKey("SIMPLE_SEPARATOR", SyntaxHighlighterColors.OPERATION_SIGN);
|
||||
public static final TextAttributesKey KEY = createTextAttributesKey("SIMPLE_KEY", SyntaxHighlighterColors.KEYWORD);
|
||||
public static final TextAttributesKey VALUE = createTextAttributesKey("SIMPLE_VALUE", SyntaxHighlighterColors.STRING);
|
||||
public static final TextAttributesKey COMMENT = createTextAttributesKey("SIMPLE_COMMENT", SyntaxHighlighterColors.LINE_COMMENT);
|
||||
|
||||
static final TextAttributesKey BAD_CHARACTER = createTextAttributesKey("SIMPLE_BAD_CHARACTER",
|
||||
new TextAttributes(Color.RED, null, null, null, Font.BOLD));
|
||||
public static final TextAttributesKey SEPARATOR = createTextAttributesKey("SIMPLE_SEPARATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN);
|
||||
public static final TextAttributesKey KEY = createTextAttributesKey("SIMPLE_KEY", DefaultLanguageHighlighterColors.KEYWORD);
|
||||
public static final TextAttributesKey VALUE = createTextAttributesKey("SIMPLE_VALUE", DefaultLanguageHighlighterColors.STRING);
|
||||
public static final TextAttributesKey COMMENT = createTextAttributesKey("SIMPLE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
|
||||
public static final TextAttributesKey BAD_CHARACTER = createTextAttributesKey("SIMPLE_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);
|
||||
|
||||
private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER};
|
||||
private static final TextAttributesKey[] SEPARATOR_KEYS = new TextAttributesKey[]{SEPARATOR};
|
||||
@ -43,7 +37,7 @@ public class SimpleSyntaxHighlighter extends SyntaxHighlighterBase {
|
||||
@NotNull
|
||||
@Override
|
||||
public Lexer getHighlightingLexer() {
|
||||
return new FlexAdapter(new SimpleLexer((Reader) null));
|
||||
return new SimpleLexerAdapter();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -29,6 +29,6 @@ section.
|
||||
[DataContext](https://upsource.jetbrains.com/idea-community/file/1731d054af4ca27aa827c03929e27eeb0e6a8366/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/DataContext.java)
|
||||
|
||||
**Related topics:**
|
||||
[Action System](/tutorials/action_system/action_system.md)
|
||||
[Action System](/tutorials/action_system.md)
|
||||
|
||||
|
||||
|
@ -14,8 +14,8 @@ Create a file *FoldingTestData.java*.
|
||||
|
||||
```java
|
||||
public class Test {
|
||||
public static void main(String[] args) <fold text='{...}'>{
|
||||
System.out.println("<fold text='http://en.wikipedia.org/'>simple:website</fold>");
|
||||
public static void main(String[] args)<fold text=' { '> {
|
||||
</fold>System.out.println("<fold text='http://en.wikipedia.org/'>simple:website</fold>");<fold text=' }'>
|
||||
}</fold>
|
||||
}
|
||||
```
|
||||
|
@ -34,12 +34,12 @@ tab :\u0009
|
||||
public void testFormatter() {
|
||||
myFixture.configureByFiles("FormatterTestData.simple");
|
||||
CodeStyleSettingsManager.getSettings(getProject()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
public void run() {
|
||||
protected void run() throws Throwable {
|
||||
CodeStyleManager.getInstance(getProject()).reformat(myFixture.getFile());
|
||||
}
|
||||
});
|
||||
}.execute();
|
||||
myFixture.checkResultByFile("DefaultTestData.simple");
|
||||
}
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user