Inspectopedia 2026.1 Help

Instance IElementType field

Reports instance fields initialized with IElementType or its subtypes.

IElementType instances represent token types in the IntelliJ Platform's lexer/parser infrastructure and should be defined as static constants to ensure they are singletons. When defined as instance fields, a new IElementType instance is created for each class instance. All such instances are registered in IElementType internal storage and kept there until the app is closed. Currently, the infrastructure allows storing only ~16k of element types, which is not that many.

The inspection suggests converting instance fields to static constants in Java or moving them to a companion object in Kotlin.

Bad pattern (Java):

class MyTokens { // New IElementType created for each MyTokens instance IElementType myToken = new IElementType("MY_TOKEN"); }

Good pattern (Java):

class MyTokens { // Singleton IElementType shared across all instances static final IElementType MY_TOKEN = new IElementType("MY_TOKEN"); }

Bad pattern (Kotlin):

class MyTokens { // New IElementType created for each MyTokens instance val myToken = IElementType("MY_TOKEN") }

Good pattern (Kotlin):

class MyTokens { companion object { // Singleton IElementType shared across all instances val MY_TOKEN = IElementType("MY_TOKEN") } }

Alternatively in Kotlin, token types can be defined as top-level or object declarations:

// Top-level constant private val MY_TOKEN = IElementType("MY_TOKEN") // Or in an object object MyTokens { val MY_TOKEN = IElementType("MY_TOKEN") }

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.

InstanceIElementTypeField
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

Inspection ID: InstanceIElementTypeField

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection InstanceIElementTypeField

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2026.1, Qodana for JVM 2026.1,

Last modified: 31 March 2026