Inspectopedia Help

Eager creation of action presentation

Reports any actions that are registered in the plugin.xml file and instantiate the com.intellij.openapi.actionSystem.Presentation object in their constructors.

Any of the constructors of AnAction with parameters instantiate the Presentation object. However, instantiating the Presentation object in constructor results in allocating resources, which may not be necessary. Instead of creating an instance of Presentation that stores text, description, or icon, it is more efficient to utilize no-argument constructors of AnAction and other base classes and follow the convention for setting the text, description, and icon in plugin.xml. The IDE will load text, description, and icon only when the action is actually displayed in the UI.

The convention for setting the text, description, and icon is as follows:

  • Set the id attribute for the action in the plugin.xml file.

  • Optionally, set the icon attribute if an icon is needed.

  • Set the text and description in the associated message bundle (it could be overridden in <actions>):

    • action.<action-id>.text=Translated Action Text

    • action.<action-id>.description=Translated Action Description

Bad example:

// NewKotlinFileAction.kt internal class NewKotlinFileAction : AnAction( KotlinBundle.message("action.new.file.text"), KotlinBundle.message("action.new.file.description"), KotlinIcons.FILE )
<!-- plugin.xml --> <action class="org.jetbrains.kotlin.idea.actions.NewKotlinFileAction" </action>

Good example:

// NewKotlinFileAction.kt internal class NewKotlinFileAction : AnAction()
<!-- plugin.xml --> <action id="Kotlin.NewFile" class="org.jetbrains.kotlin.idea.actions.NewKotlinFileAction" icon="org.jetbrains.kotlin.idea.KotlinIcons.FILE"> </action>
# KotlinBundle.properties action.Kotlin.NewFile.text=Kotlin Class/File action.Kotlin.NewFile.description=Creates a new Kotlin class or file

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

ActionPresentationInstantiatedInCtor
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Plugin DevKit | Code

New in 2023.2

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.2, Qodana for JVM 2024.2,

Can be installed with plugin:

Plugin DevKit, 242.22892

Last modified: 11 September 2024