IntelliJ Platform Plugin SDK
 
IntelliJ Platform Explorer

Element Patterns

Edit pageLast modified: 18 November 2024

Element patterns provide a generic way to specify conditions on objects.

Plugin authors use them to check whether PSI elements match a particular structure. Just as regular expressions for strings test whether a (sub-)string matches a particular pattern, element patterns are used to put conditions on the nested structure of PSI elements. Their two main applications inside the IntelliJ Platform are:

  1. Specifying where auto-completion should occur when implementing a completion contributor for a custom language.

  2. Specifying PSI elements that provide further references via a PSI reference contributor.

However, plugin authors rarely implement the ElementPattern interface directly. Instead, we recommend using the high-level pattern classes provided by the IntelliJ Platform:

Some built-in languages in the IntelliJ Platform implement their own pattern classes and can provide additional examples:

  • XmlPatterns provides patterns for XML attributes, values, entities, and texts.

  • PsiJavaPatterns provides patterns for literals, strings, arguments, and function/method arguments for Java.

  • DomPatterns builds upon XmlPatterns and acts as a wrapper to provide further patterns for DOM-API.