Class IElementType

java.lang.Object
com.intellij.psi.tree.IElementType
Direct Known Subclasses:
ILazyParseableElementType, OuterLanguageElementType, TokenWrapper

public class IElementType extends Object
Interface for token types returned from lexical analysis and for types of nodes in the AST tree. All used element types are added to a registry which can be enumerated or accessed by index.
See Also:
  • Field Details

  • Constructor Details

    • IElementType

      public IElementType(@NonNls @NotNull @NonNls @NotNull String debugName, @Nullable @Nullable Language language)
      Creates and registers a new element type for the specified language.
      Parameters:
      debugName - the name of the element type, used for debugging purposes.
      language - the language with which the element type is associated.
    • IElementType

      protected IElementType(@NonNls @NotNull @NonNls @NotNull String debugName, @Nullable @Nullable Language language, boolean register)
      Allows to construct element types for some temporary purposes without registering them. This is not default behavior and not recommended. A lot of other functionality (e.g. TokenSet) won't work with such element types. Please use IElementType(String, Language) unless you know what you're doing.
  • Method Details

    • unregisterElementTypes

      public static void unregisterElementTypes(@NotNull @NotNull ClassLoader loader)
    • unregisterElementTypes

      public static void unregisterElementTypes(@NotNull @NotNull Language language)
    • getLanguage

      @NotNull public @NotNull Language getLanguage()
      Returns the language associated with the element type.
      Returns:
      the associated language.
    • getIndex

      public final short getIndex()
      Returns the index of the element type in the table of all registered element types.
      Returns:
      the element type index.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isLeftBound

      public boolean isLeftBound()
      Controls whitespace balancing behavior of PsiBuilder.

      By default, empty composite elements (containing no children) are bounded to the right (previous) neighbour, forming following tree:

        [previous_element]
        [whitespace]
        [empty_element]
          <empty>
        [next_element]
       

      Left-bound elements are bounded to the left (next) neighbour instead:

        [previous_element]
        [empty_element]
          <empty>
        [whitespace]
        [next_element]
       

      See com.intellij.lang.impl.PsiBuilderImpl.prepareLightTree() for details.

      Returns:
      true if empty elements of this type should be bound to the left.
    • find

      public static IElementType find(short idx)
      Returns the element type registered at the specified index.
      Parameters:
      idx - the index for which the element type should be returned.
      Returns:
      the element type at the specified index.
      Throws:
      IndexOutOfBoundsException - if the index is out of registered elements' range.
    • enumerate

      public static IElementType @NotNull [] enumerate(@NotNull @NotNull IElementType.Predicate p)
      Enumerates all registered token types which match the specified predicate.
      Parameters:
      p - the predicate which should be matched by the element types.
      Returns:
      the array of matching element types.