A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://plugins.jetbrains.com/docs/intellij/code-intentions.html below:

Intentions | IntelliJ Platform Plugin SDK

Intentions

This topic describes the conditional_operator_intention, a sample plugin that adds a new intention action to the IDE Intentions list. In addition, the sample plugin contains a JUnit-based test.

About Intention Actions

The IntelliJ Platform analyzes your code and helps handle situations that may result in errors. When a possible problem is suspected, the IDE suggests an appropriate intention action, denoted with special icons.

See the Inspections topic in UI Guidelines on naming, writing description, and message texts for inspections/intentions.

You can view a list of all available intention actions as well as enable/disable them using the Intentions List in .

See the Intention Action Preview topic on providing a preview of changes that can be made by executing an intention.

Techniques Used

The conditional_operator_intention sample plugin illustrates the use of the following techniques:

In the case of providing multiple intention actions for a single element, their ordering is indeterministic due to performance reasons. It is possible to push specific items up or down by implementing HighPriorityAction or LowPriorityAction respectively.

Sample Plugin

When launched, the sample plugin adds the SDK: Convert ternary operator to if statement item to the SDK intentions group in the .

Running the Plugin

See Code Samples on how to set up and run the plugin.

How does it work?

The plugin analyzes symbols under the cursor in your code opened in the editor. If the cursor is positioned on the ? conditional operator, IntelliJ IDEA proposes to replace this conditional (ternary) operator with the "if-then-else" statement:

Invoking SDK: Convert ternary operator to if statement intention action will result in transforming expression to the form visible in the preview popup (code fragment on the right).

Intention Description and examples

The intention description is available in the UI in two places:

The before/after examples are available in the UI under .

The plugin provides description and before/after examples files in the resources/intentionDescriptions/ConditionalOperatorConverter directory:

By default, the intention description directory name is the same as the intention class name. It can be customized with the <descriptionDirectoryName> element in <intentionAction> in plugin.xml.

If your intention class names are obfuscated in the plugin distribution, always declare the <descriptionDirectoryName> element.

"Before" and "after" filenames pattern is before.$LANG_FILE_EXTENSION$.template and after.$LANG_FILE_EXTENSION$.template respectively. If before/after preview is not needed, specify <skipBeforeAfter>true</skipBeforeAfter> in the <intentionAction> in plugin.xml.

If a plugin project is multi-module, and it combines resources into a single JAR, make sure that all intention description files have unique names or paths. Otherwise, only the last packed description file will exist in the distribution package.

See the Bundled Translations section for information about how to provide intention description translations in plugins.

Testing the Plugin

Note that running the test requires setting system property idea.home.path in the test task configuration of the Gradle build script.

The sample plugin contains the ConditionalOperatorConverterTest Java class and the test data in the test/testData/ directory. To perform the plugin test, run the ConditionalOperatorConverterTest.testIntention() method.

27 January 2025


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4