JetFile: BinaryTree.kt
  PACKAGE_DIRECTIVE
    <empty list>
  IMPORT_LIST
    <empty list>
  CLASS
    PsiElement(class)('class')
    PsiWhiteSpace(' ')
    PsiElement(IDENTIFIER)('BinaryTree')
    TYPE_PARAMETER_LIST
      PsiElement(LT)('<')
      TYPE_PARAMETER
        PsiElement(IDENTIFIER)('T')
      PsiElement(GT)('>')
    PsiWhiteSpace(' ')
    PsiElement(COLON)(':')
    PsiWhiteSpace(' ')
    DELEGATION_SPECIFIER_LIST
      DELEGATOR_SUPER_CLASS
        TYPE_REFERENCE
          USER_TYPE
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('IMutableSet')
            TYPE_ARGUMENT_LIST
              PsiElement(LT)('<')
              TYPE_PROJECTION
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('T')
              PsiElement(GT)('>')
    PsiWhiteSpace(' ')
    CLASS_BODY
      PsiElement(LBRACE)('{')
      PsiWhiteSpace('\n  ')
      CLASS
        MODIFIER_LIST
          PsiElement(private)('private')
        PsiWhiteSpace(' ')
        PsiElement(class)('class')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('TreeNode')
        PRIMARY_CONSTRUCTOR
          VALUE_PARAMETER_LIST
            PsiElement(LPAR)('(')
            PsiWhiteSpace('\n    ')
            VALUE_PARAMETER
              PsiElement(var)('var')
              PsiWhiteSpace(' ')
              PsiElement(IDENTIFIER)('value')
              PsiWhiteSpace(' ')
              PsiElement(COLON)(':')
              PsiWhiteSpace(' ')
              TYPE_REFERENCE
                USER_TYPE
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('T')
            PsiElement(COMMA)(',')
            PsiWhiteSpace(' ')
            VALUE_PARAMETER
              PsiElement(var)('var')
              PsiWhiteSpace(' ')
              PsiElement(IDENTIFIER)('parent')
              PsiWhiteSpace(' ')
              PsiElement(COLON)(':')
              PsiWhiteSpace(' ')
              TYPE_REFERENCE
                USER_TYPE
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('TreeNode')
            PsiWhiteSpace('\n  ')
            PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        CLASS_BODY
          PsiElement(LBRACE)('{')
          PsiWhiteSpace('\n    ')
          PROPERTY
            PsiElement(var)('var')
            PsiWhiteSpace(' ')
            PsiElement(IDENTIFIER)('left')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('TreeNode')
          PsiWhiteSpace('\n    ')
          PROPERTY
            PsiElement(var)('var')
            PsiWhiteSpace(' ')
            PsiElement(IDENTIFIER)('right')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('TreeNode')
          PsiWhiteSpace('\n\n  ')
          PsiElement(RBRACE)('}')
      PsiWhiteSpace('\n\n  ')
      PROPERTY
        MODIFIER_LIST
          PsiElement(private)('private')
        PsiWhiteSpace(' ')
        PsiElement(val)('val')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('compare')
        PsiWhiteSpace(' ')
        PsiElement(COLON)(':')
        PsiWhiteSpace(' ')
        TYPE_REFERENCE
          USER_TYPE
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('MatchableComparison')
            TYPE_ARGUMENT_LIST
              PsiElement(LT)('<')
              TYPE_PROJECTION
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('T')
              PsiElement(GT)('>')
      PsiWhiteSpace('\n  ')
      PROPERTY
        MODIFIER_LIST
          PsiElement(private)('private')
        PsiWhiteSpace(' ')
        PsiElement(var)('var')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('root')
        PsiWhiteSpace(' ')
        PsiElement(COLON)(':')
        PsiWhiteSpace(' ')
        TYPE_REFERENCE
          USER_TYPE
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('TreeNode')
      PsiWhiteSpace('\n  ')
      PROPERTY
        MODIFIER_LIST
          PsiElement(private)('private')
        PsiWhiteSpace(' ')
        PsiElement(var)('var')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('version')
        PsiWhiteSpace(' ')
        PsiElement(EQ)('=')
        PsiWhiteSpace(' ')
        INTEGER_CONSTANT
          PsiElement(INTEGER_LITERAL)('0')
      PsiWhiteSpace('\n\n')
      PsiComment(EOL_COMMENT)('//  override var size : Int { get; private set; }')
      PsiWhiteSpace('\n\n  ')
      SECONDARY_CONSTRUCTOR
        PsiElement(constructor)('constructor')
        VALUE_PARAMETER_LIST
          PsiElement(LPAR)('(')
          VALUE_PARAMETER
            PsiElement(IDENTIFIER)('compare')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('Comparison')
                TYPE_ARGUMENT_LIST
                  PsiElement(LT)('<')
                  TYPE_PROJECTION
                    TYPE_REFERENCE
                      USER_TYPE
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('T')
                  PsiElement(GT)('>')
          PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        CONSTRUCTOR_DELEGATION_CALL
          CONSTRUCTOR_DELEGATION_REFERENCE
            <empty list>
        BLOCK
          PsiElement(LBRACE)('{')
          PsiWhiteSpace('\n    ')
          BINARY_EXPRESSION
            DOT_QUALIFIED_EXPRESSION
              THIS_EXPRESSION
                REFERENCE_EXPRESSION
                  PsiElement(this)('this')
              PsiElement(DOT)('.')
              REFERENCE_EXPRESSION
                PsiElement(IDENTIFIER)('compare')
            PsiWhiteSpace(' ')
            OPERATION_REFERENCE
              PsiElement(EQ)('=')
            PsiWhiteSpace(' ')
            CALL_EXPRESSION
              REFERENCE_EXPRESSION
                PsiElement(IDENTIFIER)('asMatchableComparison')
              VALUE_ARGUMENT_LIST
                PsiElement(LPAR)('(')
                VALUE_ARGUMENT
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('comparison')
                PsiElement(RPAR)(')')
          PsiWhiteSpace('\n  ')
          PsiElement(RBRACE)('}')
      PsiWhiteSpace('\n\n  ')
      SECONDARY_CONSTRUCTOR
        PsiElement(constructor)('constructor')
        VALUE_PARAMETER_LIST
          PsiElement(LPAR)('(')
          PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        PsiElement(COLON)(':')
        PsiWhiteSpace(' ')
        CONSTRUCTOR_DELEGATION_CALL
          CONSTRUCTOR_DELEGATION_REFERENCE
            PsiElement(this)('this')
          VALUE_ARGUMENT_LIST
            PsiElement(LPAR)('(')
            VALUE_ARGUMENT
              CALL_EXPRESSION
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('naturalOrder')
                TYPE_ARGUMENT_LIST
                  PsiElement(LT)('<')
                  TYPE_PROJECTION
                    TYPE_REFERENCE
                      USER_TYPE
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('T')
                  PsiElement(GT)('>')
                VALUE_ARGUMENT_LIST
                  PsiElement(LPAR)('(')
                  PsiElement(RPAR)(')')
            PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        BLOCK
          PsiElement(LBRACE)('{')
          PsiWhiteSpace('\n  ')
          PsiElement(RBRACE)('}')
      PsiWhiteSpace('\n\n  ')
      FUN
        MODIFIER_LIST
          PsiElement(private)('private')
          PsiWhiteSpace(' ')
          ANNOTATION
            PsiElement(AT)('@')
            PsiElement(LBRACKET)('[')
            ANNOTATION_ENTRY
              CONSTRUCTOR_CALLEE
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('operator')
            PsiElement(RBRACKET)(']')
        PsiWhiteSpace(' ')
        PsiElement(fun)('fun')
        PsiWhiteSpace(' ')
        TYPE_REFERENCE
          USER_TYPE
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('T')
        PsiElement(DOT)('.')
        PsiElement(IDENTIFIER)('compareTo')
        VALUE_PARAMETER_LIST
          PsiElement(LPAR)('(')
          VALUE_PARAMETER
            PsiElement(IDENTIFIER)('other')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('T')
          PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        PsiElement(COLON)(':')
        PsiWhiteSpace(' ')
        TYPE_REFERENCE
          USER_TYPE
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('Int')
        PsiWhiteSpace(' ')
        PsiElement(EQ)('=')
        PsiWhiteSpace(' ')
        CALL_EXPRESSION
          REFERENCE_EXPRESSION
            PsiElement(IDENTIFIER)('compare')
          VALUE_ARGUMENT_LIST
            PsiElement(LPAR)('(')
            VALUE_ARGUMENT
              THIS_EXPRESSION
                REFERENCE_EXPRESSION
                  PsiElement(this)('this')
            PsiElement(COMMA)(',')
            PsiWhiteSpace(' ')
            VALUE_ARGUMENT
              REFERENCE_EXPRESSION
                PsiElement(IDENTIFIER)('other')
            PsiElement(RPAR)(')')
      PsiWhiteSpace('\n\n  ')
      FUN
        MODIFIER_LIST
          PsiElement(override)('override')
        PsiWhiteSpace(' ')
        PsiElement(fun)('fun')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('contains')
        VALUE_PARAMETER_LIST
          PsiElement(LPAR)('(')
          VALUE_PARAMETER
            PsiElement(IDENTIFIER)('item')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('T')
          PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        PsiElement(COLON)(':')
        PsiWhiteSpace(' ')
        TYPE_REFERENCE
          USER_TYPE
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('Boolean')
        PsiWhiteSpace(' ')
        BLOCK
          PsiElement(LBRACE)('{')
          PsiWhiteSpace('\n    ')
          RETURN
            PsiElement(return)('return')
            PsiWhiteSpace(' ')
            CALL_EXPRESSION
              REFERENCE_EXPRESSION
                PsiElement(IDENTIFIER)('contains')
              VALUE_ARGUMENT_LIST
                PsiElement(LPAR)('(')
                VALUE_ARGUMENT
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('root')
                PsiElement(COMMA)(',')
                PsiWhiteSpace(' ')
                VALUE_ARGUMENT
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('item')
                PsiElement(RPAR)(')')
          PsiWhiteSpace('\n\n    ')
          FUN
            PsiElement(fun)('fun')
            PsiWhiteSpace(' ')
            PsiElement(IDENTIFIER)('contains')
            VALUE_PARAMETER_LIST
              PsiElement(LPAR)('(')
              VALUE_PARAMETER
                PsiElement(IDENTIFIER)('node')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('TreeNode')
              PsiElement(COMMA)(',')
              PsiWhiteSpace(' ')
              VALUE_PARAMETER
                PsiElement(IDENTIFIER)('item')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('T')
              PsiElement(RPAR)(')')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('Boolean')
            PsiWhiteSpace(' ')
            BLOCK
              PsiElement(LBRACE)('{')
              PsiWhiteSpace('\n      ')
              IF
                PsiElement(if)('if')
                PsiWhiteSpace(' ')
                PsiElement(LPAR)('(')
                CONDITION
                  BINARY_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('node')
                    PsiWhiteSpace(' ')
                    OPERATION_REFERENCE
                      PsiElement(EQEQ)('==')
                    PsiWhiteSpace(' ')
                    NULL
                      PsiElement(null)('null')
                PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                THEN
                  RETURN
                    PsiElement(return)('return')
                    PsiWhiteSpace(' ')
                    BOOLEAN_CONSTANT
                      PsiElement(false)('false')
              PsiWhiteSpace('\n      ')
              WHEN
                PsiElement(when)('when')
                PsiElement(LPAR)('(')
                CALL_EXPRESSION
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('compare')
                  VALUE_ARGUMENT_LIST
                    PsiElement(LPAR)('(')
                    VALUE_ARGUMENT
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('item')
                    PsiElement(COMMA)(',')
                    PsiWhiteSpace(' ')
                    VALUE_ARGUMENT
                      DOT_QUALIFIED_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('node')
                        PsiElement(DOT)('.')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('value')
                    PsiElement(RPAR)(')')
                PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                PsiElement(LBRACE)('{')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('EQ')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace(' ')
                  BOOLEAN_CONSTANT
                    PsiElement(true)('true')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('LS')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace(' ')
                  CALL_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('contains')
                    VALUE_ARGUMENT_LIST
                      PsiElement(LPAR)('(')
                      VALUE_ARGUMENT
                        DOT_QUALIFIED_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('node')
                          PsiElement(DOT)('.')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('left')
                      PsiElement(COMMA)(',')
                      PsiWhiteSpace(' ')
                      VALUE_ARGUMENT
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('item')
                      PsiElement(RPAR)(')')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('GT')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace(' ')
                  CALL_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('contains')
                    VALUE_ARGUMENT_LIST
                      PsiElement(LPAR)('(')
                      VALUE_ARGUMENT
                        DOT_QUALIFIED_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('node')
                          PsiElement(DOT)('.')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('right')
                      PsiElement(COMMA)(',')
                      PsiWhiteSpace(' ')
                      VALUE_ARGUMENT
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('item')
                      PsiElement(RPAR)(')')
                PsiWhiteSpace('\n      ')
                PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n    ')
              PsiElement(RBRACE)('}')
          PsiWhiteSpace('\n  ')
          PsiElement(RBRACE)('}')
      PsiWhiteSpace('\n\n  ')
      FUN
        MODIFIER_LIST
          PsiElement(override)('override')
        PsiWhiteSpace(' ')
        PsiElement(fun)('fun')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('add')
        VALUE_PARAMETER_LIST
          PsiElement(LPAR)('(')
          VALUE_PARAMETER
            PsiElement(IDENTIFIER)('item')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('T')
          PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        PsiElement(COLON)(':')
        PsiWhiteSpace(' ')
        TYPE_REFERENCE
          USER_TYPE
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('Boolean')
        PsiWhiteSpace(' ')
        BLOCK
          PsiElement(LBRACE)('{')
          PsiWhiteSpace('\n    ')
          IF
            PsiElement(if)('if')
            PsiWhiteSpace(' ')
            PsiElement(LPAR)('(')
            CONDITION
              CALL_EXPRESSION
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('add')
                VALUE_ARGUMENT_LIST
                  PsiElement(LPAR)('(')
                  VALUE_ARGUMENT
                    CALL_EXPRESSION
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('Ref')
                      VALUE_ARGUMENT_LIST
                        PsiElement(LPAR)('(')
                        VALUE_ARGUMENT
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('root')
                        PsiElement(RPAR)(')')
                  PsiElement(COMMA)(',')
                  PsiWhiteSpace(' ')
                  VALUE_ARGUMENT
                    NULL
                      PsiElement(null)('null')
                  PsiElement(RPAR)(')')
            PsiElement(RPAR)(')')
            PsiWhiteSpace(' ')
            THEN
              BLOCK
                PsiElement(LBRACE)('{')
                PsiWhiteSpace('\n      ')
                POSTFIX_EXPRESSION
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('size')
                  OPERATION_REFERENCE
                    PsiElement(PLUSPLUS)('++')
                PsiWhiteSpace('\n      ')
                POSTFIX_EXPRESSION
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('version')
                  OPERATION_REFERENCE
                    PsiElement(PLUSPLUS)('++')
                PsiWhiteSpace('\n      ')
                RETURN
                  PsiElement(return)('return')
                  PsiWhiteSpace(' ')
                  BOOLEAN_CONSTANT
                    PsiElement(true)('true')
                PsiWhiteSpace('\n    ')
                PsiElement(RBRACE)('}')
          PsiWhiteSpace('\n    ')
          RETURN
            PsiElement(return)('return')
            PsiWhiteSpace(' ')
            BOOLEAN_CONSTANT
              PsiElement(false)('false')
          PsiWhiteSpace('\n\n    ')
          FUN
            PsiComment(EOL_COMMENT)('// In principle, this has access to item anyway, but then it's unreachable code')
            PsiWhiteSpace('\n    ')
            PsiComment(EOL_COMMENT)('// BAD: the naive implementation of ref will create H(T) ref objects, but can be optimized to create only one')
            PsiWhiteSpace('\n    ')
            PsiElement(fun)('fun')
            PsiWhiteSpace(' ')
            PsiElement(IDENTIFIER)('add')
            VALUE_PARAMETER_LIST
              PsiElement(LPAR)('(')
              VALUE_PARAMETER
                PsiElement(IDENTIFIER)('node')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('Ref')
                    TYPE_ARGUMENT_LIST
                      PsiElement(LT)('<')
                      TYPE_PROJECTION
                        TYPE_REFERENCE
                          NULLABLE_TYPE
                            USER_TYPE
                              REFERENCE_EXPRESSION
                                PsiElement(IDENTIFIER)('TreeNode')
                            PsiElement(QUEST)('?')
                      PsiElement(GT)('>')
              PsiElement(COMMA)(',')
              PsiWhiteSpace(' ')
              VALUE_PARAMETER
                PsiElement(IDENTIFIER)('parent')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('TreeNode')
              PsiElement(RPAR)(')')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('Boolean')
            PsiWhiteSpace(' ')
            BLOCK
              PsiElement(LBRACE)('{')
              PsiWhiteSpace('\n      ')
              IF
                PsiElement(if)('if')
                PsiWhiteSpace(' ')
                PsiElement(LPAR)('(')
                CONDITION
                  BINARY_EXPRESSION
                    DOT_QUALIFIED_EXPRESSION
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('node')
                      PsiElement(DOT)('.')
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('value')
                    PsiWhiteSpace(' ')
                    OPERATION_REFERENCE
                      PsiElement(EQEQ)('==')
                    PsiWhiteSpace(' ')
                    NULL
                      PsiElement(null)('null')
                PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                THEN
                  BLOCK
                    PsiElement(LBRACE)('{')
                    PsiWhiteSpace('\n        ')
                    BINARY_EXPRESSION
                      DOT_QUALIFIED_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('node')
                        PsiElement(DOT)('.')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('value')
                      PsiWhiteSpace(' ')
                      OPERATION_REFERENCE
                        PsiElement(EQ)('=')
                      PsiWhiteSpace(' ')
                      CALL_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('TreeNode')
                        VALUE_ARGUMENT_LIST
                          PsiElement(LPAR)('(')
                          VALUE_ARGUMENT
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('item')
                          PsiElement(COMMA)(',')
                          PsiWhiteSpace(' ')
                          VALUE_ARGUMENT
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('parent')
                          PsiElement(RPAR)(')')
                    PsiWhiteSpace('\n        ')
                    RETURN
                      PsiElement(return)('return')
                      PsiWhiteSpace(' ')
                      BOOLEAN_CONSTANT
                        PsiElement(true)('true')
                    PsiWhiteSpace('\n      ')
                    PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n      ')
              WHEN
                PsiElement(when)('when')
                PsiWhiteSpace(' ')
                PsiElement(LPAR)('(')
                CALL_EXPRESSION
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('compare')
                  VALUE_ARGUMENT_LIST
                    PsiElement(LPAR)('(')
                    VALUE_ARGUMENT
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('item')
                    PsiElement(COMMA)(',')
                    PsiWhiteSpace(' ')
                    VALUE_ARGUMENT
                      DOT_QUALIFIED_EXPRESSION
                        DOT_QUALIFIED_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('node')
                          PsiElement(DOT)('.')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('value')
                        PsiElement(DOT)('.')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('value')
                    PsiElement(RPAR)(')')
                PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                PsiElement(LBRACE)('{')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('EQ')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace(' ')
                  BOOLEAN_CONSTANT
                    PsiElement(false)('false')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('LS')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace(' ')
                  CALL_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('add')
                    VALUE_ARGUMENT_LIST
                      PsiElement(LPAR)('(')
                      VALUE_ARGUMENT
                        BINARY_EXPRESSION
                          BINARY_EXPRESSION
                            BINARY_EXPRESSION
                              REFERENCE_EXPRESSION
                                PsiElement(IDENTIFIER)('ref')
                              PsiWhiteSpace(' ')
                              OPERATION_REFERENCE
                                PsiElement(IDENTIFIER)('node')
                              PsiErrorElement:Expecting an element
                                PsiElement(DOT)('.')
                            OPERATION_REFERENCE
                              PsiElement(IDENTIFIER)('value')
                            PsiErrorElement:Expecting an element
                              PsiElement(DOT)('.')
                          OPERATION_REFERENCE
                            PsiElement(IDENTIFIER)('left')
                          PsiErrorElement:Expecting an element
                            <empty list>
                      PsiElement(COMMA)(',')
                      PsiWhiteSpace(' ')
                      VALUE_ARGUMENT
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('node')
                      PsiElement(RPAR)(')')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('GT')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace(' ')
                  CALL_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('add')
                    VALUE_ARGUMENT_LIST
                      PsiElement(LPAR)('(')
                      VALUE_ARGUMENT
                        BINARY_EXPRESSION
                          BINARY_EXPRESSION
                            BINARY_EXPRESSION
                              REFERENCE_EXPRESSION
                                PsiElement(IDENTIFIER)('ref')
                              PsiWhiteSpace(' ')
                              OPERATION_REFERENCE
                                PsiElement(IDENTIFIER)('node')
                              PsiErrorElement:Expecting an element
                                PsiElement(DOT)('.')
                            OPERATION_REFERENCE
                              PsiElement(IDENTIFIER)('value')
                            PsiErrorElement:Expecting an element
                              PsiElement(DOT)('.')
                          OPERATION_REFERENCE
                            PsiElement(IDENTIFIER)('right')
                          PsiErrorElement:Expecting an element
                            <empty list>
                      PsiElement(COMMA)(',')
                      PsiWhiteSpace(' ')
                      VALUE_ARGUMENT
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('node')
                      PsiElement(RPAR)(')')
                PsiWhiteSpace('\n      ')
                PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n    ')
              PsiElement(RBRACE)('}')
          PsiWhiteSpace('\n\n    ')
          FUN
            PsiComment(EOL_COMMENT)('// In principle, this has access to item anyway')
            PsiWhiteSpace('\n    ')
            PsiElement(fun)('fun')
            PsiWhiteSpace(' ')
            PsiElement(IDENTIFIER)('addNoRef')
            VALUE_PARAMETER_LIST
              PsiElement(LPAR)('(')
              VALUE_PARAMETER
                PsiElement(IDENTIFIER)('node')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('TreeNode')
              PsiElement(RPAR)(')')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('Boolean')
            PsiWhiteSpace(' ')
            BLOCK
              PsiElement(LBRACE)('{')
              PsiWhiteSpace('\n      ')
              IF
                PsiElement(if)('if')
                PsiWhiteSpace(' ')
                PsiElement(LPAR)('(')
                CONDITION
                  BINARY_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('node')
                    PsiWhiteSpace(' ')
                    OPERATION_REFERENCE
                      PsiElement(EQEQ)('==')
                    PsiWhiteSpace(' ')
                    NULL
                      PsiElement(null)('null')
                PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                THEN
                  BLOCK
                    PsiElement(LBRACE)('{')
                    PsiWhiteSpace('\n        ')
                    BINARY_EXPRESSION
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('root')
                      PsiWhiteSpace(' ')
                      OPERATION_REFERENCE
                        PsiElement(EQ)('=')
                      PsiWhiteSpace(' ')
                      CALL_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('TreeNode')
                        VALUE_ARGUMENT_LIST
                          PsiElement(LPAR)('(')
                          VALUE_ARGUMENT
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('item')
                          PsiElement(COMMA)(',')
                          PsiWhiteSpace(' ')
                          VALUE_ARGUMENT
                            NULL
                              PsiElement(null)('null')
                          PsiElement(RPAR)(')')
                    PsiWhiteSpace('\n        ')
                    RETURN
                      PsiElement(return)('return')
                      PsiWhiteSpace(' ')
                      BOOLEAN_CONSTANT
                        PsiElement(true)('true')
                    PsiWhiteSpace('\n      ')
                    PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n      ')
              WHEN
                PsiElement(when)('when')
                PsiWhiteSpace(' ')
                PsiElement(LPAR)('(')
                CALL_EXPRESSION
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('compare')
                  VALUE_ARGUMENT_LIST
                    PsiElement(LPAR)('(')
                    VALUE_ARGUMENT
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('item')
                    PsiElement(COMMA)(',')
                    PsiWhiteSpace(' ')
                    VALUE_ARGUMENT
                      DOT_QUALIFIED_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('node')
                        PsiElement(DOT)('.')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('value')
                    PsiElement(RPAR)(')')
                PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                PsiElement(LBRACE)('{')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('EQ')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace(' ')
                  RETURN
                    PsiElement(return)('return')
                    PsiWhiteSpace(' ')
                    BOOLEAN_CONSTANT
                      PsiElement(false)('false')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('LS')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace('\n          ')
                  IF
                    PsiElement(if)('if')
                    PsiWhiteSpace(' ')
                    PsiElement(LPAR)('(')
                    CONDITION
                      BINARY_EXPRESSION
                        DOT_QUALIFIED_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('node')
                          PsiElement(DOT)('.')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('left')
                        PsiWhiteSpace(' ')
                        OPERATION_REFERENCE
                          PsiElement(EQEQ)('==')
                        PsiWhiteSpace(' ')
                        NULL
                          PsiElement(null)('null')
                    PsiElement(RPAR)(')')
                    PsiWhiteSpace(' ')
                    THEN
                      BLOCK
                        PsiElement(LBRACE)('{')
                        PsiWhiteSpace('\n            ')
                        BINARY_EXPRESSION
                          DOT_QUALIFIED_EXPRESSION
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('node')
                            PsiElement(DOT)('.')
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('left')
                          PsiWhiteSpace(' ')
                          OPERATION_REFERENCE
                            PsiElement(EQ)('=')
                          PsiWhiteSpace(' ')
                          CALL_EXPRESSION
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('TreeNode')
                            VALUE_ARGUMENT_LIST
                              PsiElement(LPAR)('(')
                              VALUE_ARGUMENT
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('item')
                              PsiElement(COMMA)(',')
                              PsiWhiteSpace(' ')
                              VALUE_ARGUMENT
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('node')
                              PsiElement(RPAR)(')')
                        PsiWhiteSpace('\n            ')
                        RETURN
                          PsiElement(return)('return')
                          PsiWhiteSpace(' ')
                          BOOLEAN_CONSTANT
                            PsiElement(true)('true')
                        PsiWhiteSpace('\n          ')
                        PsiElement(RBRACE)('}')
                    PsiWhiteSpace(' ')
                    PsiElement(else)('else')
                    PsiWhiteSpace(' ')
                    ELSE
                      RETURN
                        PsiElement(return)('return')
                        PsiWhiteSpace(' ')
                        CALL_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('add')
                          VALUE_ARGUMENT_LIST
                            PsiElement(LPAR)('(')
                            VALUE_ARGUMENT
                              DOT_QUALIFIED_EXPRESSION
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('node')
                                PsiElement(DOT)('.')
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('left')
                            PsiElement(RPAR)(')')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('GT')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace('\n          ')
                  IF
                    PsiElement(if)('if')
                    PsiWhiteSpace(' ')
                    PsiElement(LPAR)('(')
                    CONDITION
                      BINARY_EXPRESSION
                        DOT_QUALIFIED_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('node')
                          PsiElement(DOT)('.')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('right')
                        PsiWhiteSpace(' ')
                        OPERATION_REFERENCE
                          PsiElement(EQEQ)('==')
                        PsiWhiteSpace(' ')
                        NULL
                          PsiElement(null)('null')
                    PsiElement(RPAR)(')')
                    PsiWhiteSpace(' ')
                    THEN
                      BLOCK
                        PsiElement(LBRACE)('{')
                        PsiWhiteSpace('\n            ')
                        BINARY_EXPRESSION
                          DOT_QUALIFIED_EXPRESSION
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('node')
                            PsiElement(DOT)('.')
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('right')
                          PsiWhiteSpace(' ')
                          OPERATION_REFERENCE
                            PsiElement(EQ)('=')
                          PsiWhiteSpace(' ')
                          CALL_EXPRESSION
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('TreeNode')
                            VALUE_ARGUMENT_LIST
                              PsiElement(LPAR)('(')
                              VALUE_ARGUMENT
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('item')
                              PsiElement(COMMA)(',')
                              PsiWhiteSpace(' ')
                              VALUE_ARGUMENT
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('node')
                              PsiElement(RPAR)(')')
                        PsiWhiteSpace('\n            ')
                        RETURN
                          PsiElement(return)('return')
                          PsiWhiteSpace(' ')
                          BOOLEAN_CONSTANT
                            PsiElement(true)('true')
                        PsiWhiteSpace('\n          ')
                        PsiElement(RBRACE)('}')
                    PsiWhiteSpace(' ')
                    PsiElement(else)('else')
                    PsiWhiteSpace(' ')
                    ELSE
                      RETURN
                        PsiElement(return)('return')
                        PsiWhiteSpace(' ')
                        CALL_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('add')
                          VALUE_ARGUMENT_LIST
                            PsiElement(LPAR)('(')
                            VALUE_ARGUMENT
                              DOT_QUALIFIED_EXPRESSION
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('node')
                                PsiElement(DOT)('.')
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('right')
                            PsiElement(RPAR)(')')
                PsiWhiteSpace('\n      ')
                PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n    ')
              PsiElement(RBRACE)('}')
          PsiWhiteSpace('\n  ')
          PsiElement(RBRACE)('}')
      PsiWhiteSpace('\n\n  ')
      FUN
        MODIFIER_LIST
          PsiElement(override)('override')
        PsiWhiteSpace(' ')
        PsiElement(fun)('fun')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('remove')
        VALUE_PARAMETER_LIST
          PsiElement(LPAR)('(')
          VALUE_PARAMETER
            PsiElement(IDENTIFIER)('item')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('T')
          PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        PsiElement(COLON)(':')
        PsiWhiteSpace(' ')
        TYPE_REFERENCE
          USER_TYPE
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('Boolean')
        PsiWhiteSpace(' ')
        BLOCK
          PsiElement(LBRACE)('{')
          PsiWhiteSpace('\n    ')
          PROPERTY
            PsiElement(val)('val')
            PsiWhiteSpace(' ')
            PsiElement(IDENTIFIER)('toRemove')
            PsiWhiteSpace(' ')
            PsiElement(EQ)('=')
            PsiWhiteSpace(' ')
            CALL_EXPRESSION
              REFERENCE_EXPRESSION
                PsiElement(IDENTIFIER)('find')
              VALUE_ARGUMENT_LIST
                PsiElement(LPAR)('(')
                VALUE_ARGUMENT
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('root')
                PsiElement(COMMA)(',')
                PsiWhiteSpace(' ')
                VALUE_ARGUMENT
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('item')
                PsiElement(RPAR)(')')
          PsiWhiteSpace('\n    ')
          IF
            PsiElement(if)('if')
            PsiWhiteSpace(' ')
            PsiElement(LPAR)('(')
            CONDITION
              BINARY_EXPRESSION
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('toRemove')
                PsiWhiteSpace(' ')
                OPERATION_REFERENCE
                  PsiElement(EQEQ)('==')
                PsiWhiteSpace(' ')
                NULL
                  PsiElement(null)('null')
            PsiElement(RPAR)(')')
            PsiWhiteSpace(' ')
            THEN
              RETURN
                PsiElement(return)('return')
                PsiWhiteSpace(' ')
                BOOLEAN_CONSTANT
                  PsiElement(false)('false')
          PsiWhiteSpace('\n    ')
          CALL_EXPRESSION
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('remove')
            VALUE_ARGUMENT_LIST
              PsiElement(LPAR)('(')
              VALUE_ARGUMENT
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('toRemove')
              PsiElement(RPAR)(')')
          PsiWhiteSpace('\n    ')
          POSTFIX_EXPRESSION
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('size')
            OPERATION_REFERENCE
              PsiElement(MINUSMINUS)('--')
          PsiWhiteSpace('\n    ')
          POSTFIX_EXPRESSION
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('version')
            OPERATION_REFERENCE
              PsiElement(PLUSPLUS)('++')
          PsiWhiteSpace('\n    ')
          RETURN
            PsiElement(return)('return')
            PsiWhiteSpace(' ')
            BOOLEAN_CONSTANT
              PsiElement(true)('true')
          PsiWhiteSpace('\n\n    ')
          FUN
            PsiElement(fun)('fun')
            PsiWhiteSpace(' ')
            PsiElement(IDENTIFIER)('find')
            VALUE_PARAMETER_LIST
              PsiElement(LPAR)('(')
              VALUE_PARAMETER
                PsiElement(IDENTIFIER)('node')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('TreeNode')
              PsiElement(RPAR)(')')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('TreeNode')
            PsiWhiteSpace(' ')
            BLOCK
              PsiElement(LBRACE)('{')
              PsiWhiteSpace('\n      ')
              IF
                PsiElement(if)('if')
                PsiWhiteSpace(' ')
                PsiElement(LPAR)('(')
                CONDITION
                  BINARY_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('node')
                    PsiWhiteSpace(' ')
                    OPERATION_REFERENCE
                      PsiElement(EQEQ)('==')
                    PsiWhiteSpace(' ')
                    NULL
                      PsiElement(null)('null')
                PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                THEN
                  RETURN
                    PsiElement(return)('return')
                    PsiWhiteSpace(' ')
                    NULL
                      PsiElement(null)('null')
              PsiWhiteSpace('\n      ')
              WHEN
                PsiElement(when)('when')
                PsiWhiteSpace(' ')
                PsiElement(LPAR)('(')
                CALL_EXPRESSION
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('compare')
                  VALUE_ARGUMENT_LIST
                    PsiElement(LPAR)('(')
                    VALUE_ARGUMENT
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('item')
                    PsiElement(COMMA)(',')
                    PsiWhiteSpace(' ')
                    VALUE_ARGUMENT
                      DOT_QUALIFIED_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('node')
                        PsiElement(DOT)('.')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('value')
                    PsiElement(RPAR)(')')
                PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                PsiElement(LBRACE)('{')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('EQ')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace(' ')
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('node')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('LS')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace(' ')
                  CALL_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('find')
                    VALUE_ARGUMENT_LIST
                      PsiElement(LPAR)('(')
                      VALUE_ARGUMENT
                        DOT_QUALIFIED_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('node')
                          PsiElement(DOT)('.')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('left')
                      PsiElement(RPAR)(')')
                PsiWhiteSpace('\n        ')
                WHEN_ENTRY
                  WHEN_CONDITION_WITH_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('GT')
                  PsiWhiteSpace(' ')
                  PsiElement(ARROW)('->')
                  PsiWhiteSpace(' ')
                  CALL_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('find')
                    VALUE_ARGUMENT_LIST
                      PsiElement(LPAR)('(')
                      VALUE_ARGUMENT
                        DOT_QUALIFIED_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('node')
                          PsiElement(DOT)('.')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('right')
                      PsiElement(RPAR)(')')
                PsiWhiteSpace('\n      ')
                PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n    ')
              PsiElement(RBRACE)('}')
          PsiWhiteSpace('\n  ')
          PsiElement(RBRACE)('}')
      PsiWhiteSpace('\n\n  ')
      FUN
        MODIFIER_LIST
          PsiElement(private)('private')
        PsiWhiteSpace(' ')
        PsiElement(fun)('fun')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('remove')
        VALUE_PARAMETER_LIST
          PsiElement(LPAR)('(')
          VALUE_PARAMETER
            PsiElement(IDENTIFIER)('node')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('TreeNode')
          PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        BLOCK
          PsiElement(LBRACE)('{')
          PsiWhiteSpace('\n    ')
          WHEN
            PsiElement(when)('when')
            PsiWhiteSpace(' ')
            PsiElement(LPAR)('(')
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('node')
            PsiElement(RPAR)(')')
            PsiWhiteSpace(' ')
            PsiElement(LBRACE)('{')
            PsiWhiteSpace('\n      ')
            PsiComment(EOL_COMMENT)('//is TreeNode  #(null, null) -> replace(node, null)')
            PsiWhiteSpace('\n      ')
            PsiComment(EOL_COMMENT)('//is TreeNode  #(null, right) -> replace(node, right)')
            PsiWhiteSpace('\n      ')
            PsiComment(EOL_COMMENT)('//is TreeNode  #(left, null) -> replace(node, left)')
            PsiWhiteSpace('\n      ')
            PsiComment(EOL_COMMENT)('//is TreeNode  #(left, right) -> {')
            PsiWhiteSpace('\n      ')
            PsiComment(EOL_COMMENT)('//  val min = min(node.right)')
            PsiWhiteSpace('\n      ')
            PsiComment(EOL_COMMENT)('//  node.value = min.value')
            PsiWhiteSpace('\n      ')
            PsiComment(EOL_COMMENT)('//  remove(min)')
            PsiWhiteSpace('\n      ')
            PsiComment(EOL_COMMENT)('//}')
            PsiWhiteSpace('\n    ')
            PsiElement(RBRACE)('}')
          PsiWhiteSpace('\n\n    ')
          FUN
            PsiElement(fun)('fun')
            PsiWhiteSpace(' ')
            PsiElement(IDENTIFIER)('replace')
            VALUE_PARAMETER_LIST
              PsiElement(LPAR)('(')
              VALUE_PARAMETER
                PsiElement(IDENTIFIER)('node')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('TreeNode')
              PsiElement(COMMA)(',')
              PsiWhiteSpace(' ')
              VALUE_PARAMETER
                PsiElement(IDENTIFIER)('replace')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('TreeNode')
              PsiElement(RPAR)(')')
            PsiWhiteSpace(' ')
            BLOCK
              PsiElement(LBRACE)('{')
              PsiWhiteSpace('\n      ')
              IF
                PsiElement(if)('if')
                PsiWhiteSpace(' ')
                PsiElement(LPAR)('(')
                CONDITION
                  BINARY_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('node')
                    PsiWhiteSpace(' ')
                    OPERATION_REFERENCE
                      PsiElement(EQEQ)('==')
                    PsiWhiteSpace(' ')
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('root')
                PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                THEN
                  BLOCK
                    PsiElement(LBRACE)('{')
                    PsiWhiteSpace('\n        ')
                    BINARY_EXPRESSION
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('root')
                      PsiWhiteSpace(' ')
                      OPERATION_REFERENCE
                        PsiElement(EQ)('=')
                      PsiWhiteSpace(' ')
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('replace')
                    PsiWhiteSpace('\n        ')
                    RETURN
                      PsiElement(return)('return')
                    PsiWhiteSpace('\n      ')
                    PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n      ')
              IF
                PsiElement(if)('if')
                PsiWhiteSpace(' ')
                PsiElement(LPAR)('(')
                CONDITION
                  BINARY_EXPRESSION
                    DOT_QUALIFIED_EXPRESSION
                      DOT_QUALIFIED_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('node')
                        PsiElement(DOT)('.')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('parent')
                      PsiElement(DOT)('.')
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('left')
                    PsiWhiteSpace(' ')
                    OPERATION_REFERENCE
                      PsiElement(EQEQ)('==')
                    PsiWhiteSpace(' ')
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('node')
                PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                THEN
                  BLOCK
                    PsiElement(LBRACE)('{')
                    PsiWhiteSpace('\n        ')
                    BINARY_EXPRESSION
                      DOT_QUALIFIED_EXPRESSION
                        DOT_QUALIFIED_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('node')
                          PsiElement(DOT)('.')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('parent')
                        PsiElement(DOT)('.')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('left')
                      PsiWhiteSpace(' ')
                      OPERATION_REFERENCE
                        PsiElement(EQ)('=')
                      PsiWhiteSpace(' ')
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('replace')
                    PsiWhiteSpace('\n      ')
                    PsiElement(RBRACE)('}')
                PsiWhiteSpace(' ')
                PsiElement(else)('else')
                PsiWhiteSpace(' ')
                ELSE
                  IF
                    PsiElement(if)('if')
                    PsiWhiteSpace(' ')
                    PsiElement(LPAR)('(')
                    CONDITION
                      BINARY_EXPRESSION
                        DOT_QUALIFIED_EXPRESSION
                          DOT_QUALIFIED_EXPRESSION
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('node')
                            PsiElement(DOT)('.')
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('parent')
                          PsiElement(DOT)('.')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('right')
                        PsiWhiteSpace(' ')
                        OPERATION_REFERENCE
                          PsiElement(EQEQ)('==')
                        PsiWhiteSpace(' ')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('node')
                    PsiElement(RPAR)(')')
                    PsiWhiteSpace(' ')
                    THEN
                      BLOCK
                        PsiElement(LBRACE)('{')
                        PsiWhiteSpace('\n        ')
                        BINARY_EXPRESSION
                          DOT_QUALIFIED_EXPRESSION
                            DOT_QUALIFIED_EXPRESSION
                              REFERENCE_EXPRESSION
                                PsiElement(IDENTIFIER)('node')
                              PsiElement(DOT)('.')
                              REFERENCE_EXPRESSION
                                PsiElement(IDENTIFIER)('parent')
                            PsiElement(DOT)('.')
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('right')
                          PsiWhiteSpace(' ')
                          OPERATION_REFERENCE
                            PsiElement(EQ)('=')
                          PsiWhiteSpace(' ')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('replace')
                        PsiWhiteSpace('\n      ')
                        PsiElement(RBRACE)('}')
                    PsiWhiteSpace(' ')
                    PsiElement(else)('else')
                    PsiWhiteSpace(' ')
                    ELSE
                      CALL_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('Assert')
                        VALUE_ARGUMENT_LIST
                          PsiElement(LPAR)('(')
                          VALUE_ARGUMENT
                            BOOLEAN_CONSTANT
                              PsiElement(false)('false')
                          PsiElement(RPAR)(')')
              PsiWhiteSpace('\n    ')
              PsiElement(RBRACE)('}')
          PsiWhiteSpace('\n  ')
          PsiElement(RBRACE)('}')
      PsiWhiteSpace('\n\n  ')
      FUN
        PsiComment(EOL_COMMENT)('// Relies on tail-recursion optimization')
        PsiWhiteSpace('\n  ')
        MODIFIER_LIST
          PsiElement(private)('private')
        PsiWhiteSpace(' ')
        PsiElement(fun)('fun')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('min')
        VALUE_PARAMETER_LIST
          PsiElement(LPAR)('(')
          VALUE_PARAMETER
            PsiElement(IDENTIFIER)('node')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            TYPE_REFERENCE
              USER_TYPE
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('TreeNode')
          PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        BLOCK
          PsiElement(LBRACE)('{')
          PsiWhiteSpace('\n    ')
          IF
            PsiElement(if)('if')
            PsiWhiteSpace(' ')
            PsiElement(LPAR)('(')
            CONDITION
              BINARY_EXPRESSION
                DOT_QUALIFIED_EXPRESSION
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('node')
                  PsiElement(DOT)('.')
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('left')
                PsiWhiteSpace(' ')
                OPERATION_REFERENCE
                  PsiElement(EQEQ)('==')
                PsiWhiteSpace(' ')
                NULL
                  PsiElement(null)('null')
            PsiElement(RPAR)(')')
            PsiWhiteSpace(' ')
            THEN
              REFERENCE_EXPRESSION
                PsiElement(IDENTIFIER)('node')
            PsiWhiteSpace(' ')
            PsiElement(else)('else')
            PsiWhiteSpace(' ')
            ELSE
              CALL_EXPRESSION
                REFERENCE_EXPRESSION
                  PsiElement(IDENTIFIER)('min')
                VALUE_ARGUMENT_LIST
                  PsiElement(LPAR)('(')
                  VALUE_ARGUMENT
                    DOT_QUALIFIED_EXPRESSION
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('node')
                      PsiElement(DOT)('.')
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('left')
                  PsiElement(RPAR)(')')
          PsiWhiteSpace('\n  ')
          PsiElement(RBRACE)('}')
      PsiWhiteSpace('\n\n  ')
      FUN
        MODIFIER_LIST
          PsiElement(override)('override')
        PsiWhiteSpace(' ')
        PsiElement(fun)('fun')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('iterator')
        VALUE_PARAMETER_LIST
          PsiElement(LPAR)('(')
          PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        PsiElement(COLON)(':')
        PsiWhiteSpace(' ')
        TYPE_REFERENCE
          USER_TYPE
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('IIterator')
            TYPE_ARGUMENT_LIST
              PsiElement(LT)('<')
              TYPE_PROJECTION
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('T')
              PsiElement(GT)('>')
        PsiWhiteSpace(' ')
        PsiElement(EQ)('=')
        PsiWhiteSpace(' ')
        CALL_EXPRESSION
          REFERENCE_EXPRESSION
            PsiElement(IDENTIFIER)('mutableIterator')
          VALUE_ARGUMENT_LIST
            PsiElement(LPAR)('(')
            PsiElement(RPAR)(')')
      PsiWhiteSpace('\n\n  ')
      FUN
        MODIFIER_LIST
          PsiElement(override)('override')
        PsiWhiteSpace(' ')
        PsiElement(fun)('fun')
        PsiWhiteSpace(' ')
        PsiElement(IDENTIFIER)('mutableIterator')
        VALUE_PARAMETER_LIST
          PsiElement(LPAR)('(')
          PsiElement(RPAR)(')')
        PsiWhiteSpace(' ')
        PsiElement(COLON)(':')
        PsiWhiteSpace(' ')
        TYPE_REFERENCE
          USER_TYPE
            REFERENCE_EXPRESSION
              PsiElement(IDENTIFIER)('IMutableIterator')
            TYPE_ARGUMENT_LIST
              PsiElement(LT)('<')
              TYPE_PROJECTION
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('T')
              PsiElement(GT)('>')
        PsiWhiteSpace(' ')
        PsiElement(EQ)('=')
        PsiWhiteSpace(' ')
        OBJECT_LITERAL
          OBJECT_DECLARATION
            PsiElement(object)('object')
            PsiWhiteSpace(' ')
            PsiElement(COLON)(':')
            PsiWhiteSpace(' ')
            DELEGATION_SPECIFIER_LIST
              DELEGATOR_SUPER_CLASS
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('IMutableIterator')
            PsiWhiteSpace(' ')
            CLASS_BODY
              PsiElement(LBRACE)('{')
              PsiWhiteSpace('\n    ')
              PROPERTY
                PsiElement(val)('val')
                PsiWhiteSpace(' ')
                PsiElement(IDENTIFIER)('version')
                PsiWhiteSpace(' ')
                PsiElement(EQ)('=')
                PsiWhiteSpace(' ')
                DOT_QUALIFIED_EXPRESSION
                  DOT_QUALIFIED_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('BinaryTree')
                    PsiElement(DOT)('.')
                    THIS_EXPRESSION
                      REFERENCE_EXPRESSION
                        PsiElement(this)('this')
                  PsiElement(DOT)('.')
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('version')
              PsiWhiteSpace('\n    ')
              PROPERTY
                PsiElement(val)('val')
                PsiWhiteSpace(' ')
                PsiElement(IDENTIFIER)('down')
                PsiWhiteSpace(' ')
                PsiElement(EQ)('=')
                PsiWhiteSpace(' ')
                CALL_EXPRESSION
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('Stack')
                  TYPE_ARGUMENT_LIST
                    PsiElement(LT)('<')
                    TYPE_PROJECTION
                      TYPE_REFERENCE
                        USER_TYPE
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('TreeNode')
                    PsiElement(GT)('>')
                  VALUE_ARGUMENT_LIST
                    PsiElement(LPAR)('(')
                    PsiElement(RPAR)(')')
              PsiWhiteSpace('\n    ')
              PROPERTY
                PsiElement(val)('val')
                PsiWhiteSpace(' ')
                PsiElement(IDENTIFIER)('up')
                PsiWhiteSpace(' ')
                PsiElement(EQ)('=')
                PsiWhiteSpace(' ')
                CALL_EXPRESSION
                  REFERENCE_EXPRESSION
                    PsiElement(IDENTIFIER)('Stack')
                  TYPE_ARGUMENT_LIST
                    PsiElement(LT)('<')
                    TYPE_PROJECTION
                      TYPE_REFERENCE
                        USER_TYPE
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('TreeNode')
                    PsiElement(GT)('>')
                  VALUE_ARGUMENT_LIST
                    PsiElement(LPAR)('(')
                    PsiElement(RPAR)(')')
              PsiWhiteSpace('\n    ')
              PROPERTY
                PsiElement(var)('var')
                PsiWhiteSpace(' ')
                PsiElement(IDENTIFIER)('lastNode')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('TreeNode')
              PsiWhiteSpace('\n\n    ')
              ANONYMOUS_INITIALIZER
                PsiElement(init)('init')
                PsiWhiteSpace(' ')
                BLOCK
                  PsiElement(LBRACE)('{')
                  PsiWhiteSpace('\n      ')
                  IF
                    PsiElement(if)('if')
                    PsiWhiteSpace(' ')
                    PsiElement(LPAR)('(')
                    CONDITION
                      BINARY_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('root')
                        PsiWhiteSpace(' ')
                        OPERATION_REFERENCE
                          PsiElement(EXCLEQ)('!=')
                        PsiWhiteSpace(' ')
                        NULL
                          PsiElement(null)('null')
                    PsiElement(RPAR)(')')
                    PsiWhiteSpace('\n        ')
                    THEN
                      DOT_QUALIFIED_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('down')
                        PsiElement(DOT)('.')
                        CALL_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('push')
                          VALUE_ARGUMENT_LIST
                            PsiElement(LPAR)('(')
                            VALUE_ARGUMENT
                              REFERENCE_EXPRESSION
                                PsiElement(IDENTIFIER)('root')
                            PsiElement(RPAR)(')')
                  PsiWhiteSpace('    \n    ')
                  PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n\n    ')
              FUN
                MODIFIER_LIST
                  PsiElement(override)('override')
                PsiWhiteSpace(' ')
                PsiElement(fun)('fun')
                PsiWhiteSpace(' ')
                PsiElement(IDENTIFIER)('next')
                VALUE_PARAMETER_LIST
                  PsiElement(LPAR)('(')
                  PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('T')
                PsiWhiteSpace(' ')
                BLOCK
                  PsiElement(LBRACE)('{')
                  PsiWhiteSpace('\n      ')
                  IF
                    PsiElement(if)('if')
                    PsiWhiteSpace(' ')
                    PsiElement(LPAR)('(')
                    CONDITION
                      PREFIX_EXPRESSION
                        OPERATION_REFERENCE
                          PsiElement(EXCL)('!')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('hasNext')
                    PsiElement(RPAR)(')')
                    PsiWhiteSpace('\n        ')
                    THEN
                      THROW
                        PsiElement(throw)('throw')
                        PsiWhiteSpace(' ')
                        CALL_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('NoMoreElementsException')
                          VALUE_ARGUMENT_LIST
                            PsiElement(LPAR)('(')
                            PsiElement(RPAR)(')')
                  PsiWhiteSpace('\n      ')
                  CALL_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('checkVersion')
                    VALUE_ARGUMENT_LIST
                      PsiElement(LPAR)('(')
                      PsiElement(RPAR)(')')
                  PsiWhiteSpace('\n\n      ')
                  BINARY_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('lastNode')
                    PsiWhiteSpace(' ')
                    OPERATION_REFERENCE
                      PsiElement(EQ)('=')
                    PsiWhiteSpace(' ')
                    CALL_EXPRESSION
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('nextNode')
                      VALUE_ARGUMENT_LIST
                        PsiElement(LPAR)('(')
                        PsiElement(RPAR)(')')
                  PsiWhiteSpace('\n      ')
                  RETURN
                    PsiElement(return)('return')
                    PsiWhiteSpace(' ')
                    DOT_QUALIFIED_EXPRESSION
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('lastNode')
                      PsiElement(DOT)('.')
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('value')
                  PsiWhiteSpace('\n    ')
                  PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n\n    ')
              FUN
                MODIFIER_LIST
                  PsiElement(private)('private')
                PsiWhiteSpace(' ')
                PsiElement(fun)('fun')
                PsiWhiteSpace(' ')
                PsiElement(IDENTIFIER)('nextNode')
                VALUE_PARAMETER_LIST
                  PsiElement(LPAR)('(')
                  PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('TreeNode')
                PsiWhiteSpace(' ')
                BLOCK
                  PsiElement(LBRACE)('{')
                  PsiWhiteSpace('\n      ')
                  WHILE
                    PsiElement(while)('while')
                    PsiWhiteSpace(' ')
                    PsiElement(LPAR)('(')
                    CONDITION
                      BOOLEAN_CONSTANT
                        PsiElement(true)('true')
                    PsiElement(RPAR)(')')
                    PsiWhiteSpace(' ')
                    BODY
                      BLOCK
                        PsiElement(LBRACE)('{')
                        PsiWhiteSpace('\n        ')
                        IF
                          PsiElement(if)('if')
                          PsiWhiteSpace(' ')
                          PsiElement(LPAR)('(')
                          CONDITION
                            PREFIX_EXPRESSION
                              OPERATION_REFERENCE
                                PsiElement(EXCL)('!')
                              DOT_QUALIFIED_EXPRESSION
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('down')
                                PsiElement(DOT)('.')
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('isEmpty')
                          PsiElement(RPAR)(')')
                          PsiWhiteSpace(' ')
                          THEN
                            BLOCK
                              PsiElement(LBRACE)('{')
                              PsiWhiteSpace('\n          ')
                              PROPERTY
                                PsiElement(val)('val')
                                PsiWhiteSpace(' ')
                                PsiElement(IDENTIFIER)('curNode')
                                PsiWhiteSpace(' ')
                                PsiElement(EQ)('=')
                                PsiWhiteSpace(' ')
                                DOT_QUALIFIED_EXPRESSION
                                  REFERENCE_EXPRESSION
                                    PsiElement(IDENTIFIER)('down')
                                  PsiElement(DOT)('.')
                                  CALL_EXPRESSION
                                    REFERENCE_EXPRESSION
                                      PsiElement(IDENTIFIER)('pop')
                                    VALUE_ARGUMENT_LIST
                                      PsiElement(LPAR)('(')
                                      PsiElement(RPAR)(')')
                              PsiWhiteSpace('\n          ')
                              IF
                                PsiElement(if)('if')
                                PsiWhiteSpace(' ')
                                PsiElement(LPAR)('(')
                                CONDITION
                                  BINARY_EXPRESSION
                                    DOT_QUALIFIED_EXPRESSION
                                      REFERENCE_EXPRESSION
                                        PsiElement(IDENTIFIER)('curNode')
                                      PsiElement(DOT)('.')
                                      REFERENCE_EXPRESSION
                                        PsiElement(IDENTIFIER)('left')
                                    PsiWhiteSpace(' ')
                                    OPERATION_REFERENCE
                                      PsiElement(EXCLEQ)('!=')
                                    PsiWhiteSpace(' ')
                                    NULL
                                      PsiElement(null)('null')
                                PsiElement(RPAR)(')')
                                PsiWhiteSpace(' ')
                                THEN
                                  BLOCK
                                    PsiElement(LBRACE)('{')
                                    PsiWhiteSpace('\n            ')
                                    DOT_QUALIFIED_EXPRESSION
                                      REFERENCE_EXPRESSION
                                        PsiElement(IDENTIFIER)('up')
                                      PsiElement(DOT)('.')
                                      CALL_EXPRESSION
                                        REFERENCE_EXPRESSION
                                          PsiElement(IDENTIFIER)('push')
                                        VALUE_ARGUMENT_LIST
                                          PsiElement(LPAR)('(')
                                          VALUE_ARGUMENT
                                            REFERENCE_EXPRESSION
                                              PsiElement(IDENTIFIER)('curNode')
                                          PsiElement(RPAR)(')')
                                    PsiWhiteSpace('\n            ')
                                    DOT_QUALIFIED_EXPRESSION
                                      REFERENCE_EXPRESSION
                                        PsiElement(IDENTIFIER)('down')
                                      PsiElement(DOT)('.')
                                      CALL_EXPRESSION
                                        REFERENCE_EXPRESSION
                                          PsiElement(IDENTIFIER)('push')
                                        VALUE_ARGUMENT_LIST
                                          PsiElement(LPAR)('(')
                                          VALUE_ARGUMENT
                                            DOT_QUALIFIED_EXPRESSION
                                              REFERENCE_EXPRESSION
                                                PsiElement(IDENTIFIER)('curNode')
                                              PsiElement(DOT)('.')
                                              REFERENCE_EXPRESSION
                                                PsiElement(IDENTIFIER)('left')
                                          PsiElement(RPAR)(')')
                                    PsiWhiteSpace('\n          ')
                                    PsiElement(RBRACE)('}')
                                PsiWhiteSpace(' ')
                                PsiElement(else)('else')
                                PsiWhiteSpace(' ')
                                ELSE
                                  BLOCK
                                    PsiElement(LBRACE)('{')
                                    PsiWhiteSpace('\n            ')
                                    IF
                                      PsiElement(if)('if')
                                      PsiWhiteSpace(' ')
                                      PsiElement(LPAR)('(')
                                      CONDITION
                                        BINARY_EXPRESSION
                                          DOT_QUALIFIED_EXPRESSION
                                            REFERENCE_EXPRESSION
                                              PsiElement(IDENTIFIER)('curNode')
                                            PsiElement(DOT)('.')
                                            REFERENCE_EXPRESSION
                                              PsiElement(IDENTIFIER)('right')
                                          PsiWhiteSpace(' ')
                                          OPERATION_REFERENCE
                                            PsiElement(EXCLEQ)('!=')
                                          PsiWhiteSpace(' ')
                                          NULL
                                            PsiElement(null)('null')
                                      PsiElement(RPAR)(')')
                                      PsiWhiteSpace(' ')
                                      THEN
                                        BLOCK
                                          PsiElement(LBRACE)('{')
                                          PsiWhiteSpace('\n              ')
                                          DOT_QUALIFIED_EXPRESSION
                                            REFERENCE_EXPRESSION
                                              PsiElement(IDENTIFIER)('down')
                                            PsiElement(DOT)('.')
                                            CALL_EXPRESSION
                                              REFERENCE_EXPRESSION
                                                PsiElement(IDENTIFIER)('push')
                                              VALUE_ARGUMENT_LIST
                                                PsiElement(LPAR)('(')
                                                VALUE_ARGUMENT
                                                  DOT_QUALIFIED_EXPRESSION
                                                    REFERENCE_EXPRESSION
                                                      PsiElement(IDENTIFIER)('curNode')
                                                    PsiElement(DOT)('.')
                                                    REFERENCE_EXPRESSION
                                                      PsiElement(IDENTIFIER)('right')
                                                PsiElement(RPAR)(')')
                                          PsiWhiteSpace('\n            ')
                                          PsiElement(RBRACE)('}')
                                    PsiWhiteSpace('\n            ')
                                    RETURN
                                      PsiElement(return)('return')
                                      PsiWhiteSpace(' ')
                                      REFERENCE_EXPRESSION
                                        PsiElement(IDENTIFIER)('curNode')
                                    PsiElement(SEMICOLON)(';')
                                    PsiWhiteSpace('\n          ')
                                    PsiElement(RBRACE)('}')
                              PsiWhiteSpace('\n        ')
                              PsiElement(RBRACE)('}')
                          PsiWhiteSpace(' ')
                          PsiElement(else)('else')
                          PsiWhiteSpace(' ')
                          ELSE
                            BLOCK
                              PsiElement(LBRACE)('{')
                              PsiWhiteSpace('\n          ')
                              PROPERTY
                                PsiElement(val)('val')
                                PsiWhiteSpace(' ')
                                PsiElement(IDENTIFIER)('curNode')
                                PsiWhiteSpace(' ')
                                PsiElement(EQ)('=')
                                PsiWhiteSpace(' ')
                                DOT_QUALIFIED_EXPRESSION
                                  REFERENCE_EXPRESSION
                                    PsiElement(IDENTIFIER)('up')
                                  PsiElement(DOT)('.')
                                  CALL_EXPRESSION
                                    REFERENCE_EXPRESSION
                                      PsiElement(IDENTIFIER)('pop')
                                    VALUE_ARGUMENT_LIST
                                      PsiElement(LPAR)('(')
                                      PsiElement(RPAR)(')')
                              PsiWhiteSpace('\n          ')
                              IF
                                PsiElement(if)('if')
                                PsiWhiteSpace(' ')
                                PsiElement(LPAR)('(')
                                CONDITION
                                  BINARY_EXPRESSION
                                    DOT_QUALIFIED_EXPRESSION
                                      REFERENCE_EXPRESSION
                                        PsiElement(IDENTIFIER)('curNode')
                                      PsiElement(DOT)('.')
                                      REFERENCE_EXPRESSION
                                        PsiElement(IDENTIFIER)('right')
                                    PsiWhiteSpace(' ')
                                    OPERATION_REFERENCE
                                      PsiElement(EXCLEQ)('!=')
                                    PsiWhiteSpace(' ')
                                    NULL
                                      PsiElement(null)('null')
                                PsiElement(RPAR)(')')
                                PsiWhiteSpace(' ')
                                THEN
                                  BLOCK
                                    PsiElement(LBRACE)('{')
                                    PsiWhiteSpace('\n            ')
                                    DOT_QUALIFIED_EXPRESSION
                                      REFERENCE_EXPRESSION
                                        PsiElement(IDENTIFIER)('down')
                                      PsiElement(DOT)('.')
                                      CALL_EXPRESSION
                                        REFERENCE_EXPRESSION
                                          PsiElement(IDENTIFIER)('push')
                                        VALUE_ARGUMENT_LIST
                                          PsiElement(LPAR)('(')
                                          VALUE_ARGUMENT
                                            DOT_QUALIFIED_EXPRESSION
                                              REFERENCE_EXPRESSION
                                                PsiElement(IDENTIFIER)('curNode')
                                              PsiElement(DOT)('.')
                                              REFERENCE_EXPRESSION
                                                PsiElement(IDENTIFIER)('right')
                                          PsiElement(RPAR)(')')
                                    PsiWhiteSpace('\n          ')
                                    PsiElement(RBRACE)('}')
                              PsiWhiteSpace('\n          ')
                              RETURN
                                PsiElement(return)('return')
                                PsiWhiteSpace(' ')
                                REFERENCE_EXPRESSION
                                  PsiElement(IDENTIFIER)('curNode')
                              PsiWhiteSpace('\n        ')
                              PsiElement(RBRACE)('}')
                        PsiWhiteSpace('\n      ')
                        PsiElement(RBRACE)('}')
                  PsiWhiteSpace('\n    ')
                  PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n\n    ')
              PROPERTY
                MODIFIER_LIST
                  PsiElement(override)('override')
                PsiWhiteSpace(' ')
                PsiElement(val)('val')
                PsiWhiteSpace(' ')
                PsiElement(IDENTIFIER)('hasNext')
                PsiWhiteSpace(' ')
                PsiElement(COLON)(':')
                PsiWhiteSpace(' ')
                TYPE_REFERENCE
                  USER_TYPE
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('Boolean')
                PsiWhiteSpace('\n      ')
                PROPERTY_ACCESSOR
                  PsiElement(get)('get')
                  PsiElement(LPAR)('(')
                  PsiElement(RPAR)(')')
                  PsiWhiteSpace(' ')
                  PsiElement(EQ)('=')
                  PsiWhiteSpace(' ')
                  BINARY_EXPRESSION
                    PREFIX_EXPRESSION
                      OPERATION_REFERENCE
                        PsiElement(EXCL)('!')
                      DOT_QUALIFIED_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('down')
                        PsiElement(DOT)('.')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('isEmpty')
                    PsiWhiteSpace(' ')
                    OPERATION_REFERENCE
                      PsiElement(OROR)('||')
                    PsiWhiteSpace(' ')
                    PREFIX_EXPRESSION
                      OPERATION_REFERENCE
                        PsiElement(EXCL)('!')
                      DOT_QUALIFIED_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('up')
                        PsiElement(DOT)('.')
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('isEmpty')
              PsiWhiteSpace('\n\n\n    ')
              FUN
                MODIFIER_LIST
                  PsiElement(override)('override')
                PsiWhiteSpace(' ')
                PsiElement(fun)('fun')
                PsiWhiteSpace(' ')
                PsiElement(IDENTIFIER)('remove')
                VALUE_PARAMETER_LIST
                  PsiElement(LPAR)('(')
                  PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                BLOCK
                  PsiElement(LBRACE)('{')
                  PsiWhiteSpace('\n      ')
                  CALL_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('checkVersion')
                    VALUE_ARGUMENT_LIST
                      PsiElement(LPAR)('(')
                      PsiElement(RPAR)(')')
                  PsiWhiteSpace('\n      ')
                  IF
                    PsiElement(if)('if')
                    PsiWhiteSpace(' ')
                    PsiElement(LPAR)('(')
                    CONDITION
                      BINARY_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('lastNode')
                        PsiWhiteSpace(' ')
                        OPERATION_REFERENCE
                          PsiElement(EQEQ)('==')
                        PsiWhiteSpace(' ')
                        NULL
                          PsiElement(null)('null')
                    PsiElement(RPAR)(')')
                    PsiWhiteSpace('\n        ')
                    THEN
                      THROW
                        PsiElement(throw)('throw')
                        PsiWhiteSpace(' ')
                        CALL_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('IterationException')
                          VALUE_ARGUMENT_LIST
                            PsiElement(LPAR)('(')
                            VALUE_ARGUMENT
                              STRING_TEMPLATE
                                PsiElement(OPEN_QUOTE)('"')
                                LITERAL_STRING_TEMPLATE_ENTRY
                                  PsiElement(REGULAR_STRING_PART)('Nothing to remove')
                                PsiElement(CLOSING_QUOTE)('"')
                            PsiElement(RPAR)(')')
                  PsiWhiteSpace('\n      ')
                  CALL_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('remove')
                    VALUE_ARGUMENT_LIST
                      PsiElement(LPAR)('(')
                      VALUE_ARGUMENT
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('lastNode')
                      PsiElement(RPAR)(')')
                  PsiWhiteSpace('\n      ')
                  POSTFIX_EXPRESSION
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('version')
                    OPERATION_REFERENCE
                      PsiElement(PLUSPLUS)('++')
                  PsiWhiteSpace('\n      ')
                  BINARY_EXPRESSION
                    DOT_QUALIFIED_EXPRESSION
                      DOT_QUALIFIED_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('BinaryTree')
                        PsiElement(DOT)('.')
                        THIS_EXPRESSION
                          REFERENCE_EXPRESSION
                            PsiElement(this)('this')
                      PsiElement(DOT)('.')
                      REFERENCE_EXPRESSION
                        PsiElement(IDENTIFIER)('version')
                    PsiWhiteSpace(' ')
                    OPERATION_REFERENCE
                      PsiElement(EQ)('=')
                    PsiWhiteSpace(' ')
                    REFERENCE_EXPRESSION
                      PsiElement(IDENTIFIER)('version')
                  PsiWhiteSpace('\n    ')
                  PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n\n    ')
              FUN
                MODIFIER_LIST
                  PsiElement(private)('private')
                PsiWhiteSpace(' ')
                PsiElement(fun)('fun')
                PsiWhiteSpace(' ')
                PsiElement(IDENTIFIER)('checkVersion')
                VALUE_PARAMETER_LIST
                  PsiElement(LPAR)('(')
                  PsiElement(RPAR)(')')
                PsiWhiteSpace(' ')
                BLOCK
                  PsiElement(LBRACE)('{')
                  PsiWhiteSpace('\n      ')
                  IF
                    PsiElement(if)('if')
                    PsiWhiteSpace(' ')
                    PsiElement(LPAR)('(')
                    CONDITION
                      BINARY_EXPRESSION
                        REFERENCE_EXPRESSION
                          PsiElement(IDENTIFIER)('version')
                        PsiWhiteSpace(' ')
                        OPERATION_REFERENCE
                          PsiElement(EXCLEQ)('!=')
                        PsiWhiteSpace(' ')
                        DOT_QUALIFIED_EXPRESSION
                          DOT_QUALIFIED_EXPRESSION
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('BinaryTree')
                            PsiElement(DOT)('.')
                            THIS_EXPRESSION
                              REFERENCE_EXPRESSION
                                PsiElement(this)('this')
                          PsiElement(DOT)('.')
                          REFERENCE_EXPRESSION
                            PsiElement(IDENTIFIER)('version')
                    PsiElement(RPAR)(')')
                    PsiWhiteSpace(' ')
                    THEN
                      BLOCK
                        PsiElement(LBRACE)('{')
                        PsiWhiteSpace('\n        ')
                        THROW
                          PsiElement(throw)('throw')
                          PsiWhiteSpace(' ')
                          CALL_EXPRESSION
                            REFERENCE_EXPRESSION
                              PsiElement(IDENTIFIER)('ConcurrentModificationException')
                            VALUE_ARGUMENT_LIST
                              PsiElement(LPAR)('(')
                              PsiElement(RPAR)(')')
                        PsiWhiteSpace('\n      ')
                        PsiElement(RBRACE)('}')
                  PsiWhiteSpace('                                              \n    ')
                  PsiElement(RBRACE)('}')
              PsiWhiteSpace('\n  ')
              PsiElement(RBRACE)('}')
      PsiWhiteSpace('\n\n')
      PsiElement(RBRACE)('}')
