private static int handleTypedVarCondition(int index, @NotNull String criteria, @NotNull MatchVariableConstraint constraint) {
    final int length = criteria.length();

    char ch = criteria.charAt(index);
    if (ch == '!') {
      constraint.setInvertRegExp(true);
      ++index;
      if (index >= length) throw new MalformedPatternException(SSRBundle.message("error.expected.condition", Character.valueOf(ch)));
      ch = criteria.charAt(index);
    }
    if (ch == '+' || ch == '*') {
      // this is type axis navigation relation
      switch (ch) {
        case '+' -> constraint.setStrictlyWithinHierarchy(true);
        case '*' -> constraint.setWithinHierarchy(true);
      }

      ++index;
      if (index >= length) throw new MalformedPatternException(SSRBundle.message("error.expected.condition", Character.valueOf(ch)));
      ch = criteria.charAt(index);
    }

    if (ch == '[') {
      int spaces = 0; // balance spaces surrounding content between brackets
      while (++index < length && criteria.charAt(index) == ' ') spaces++;

      // eat complete condition
      boolean quoted = false;
      boolean closed = false;
      int endIndex = index - 1;
      while (++endIndex < length) {
        if (criteria.charAt(endIndex - 1) != '\\') {
          ch = criteria.charAt(endIndex);
          if (ch == '"') {
            quoted = !quoted;
          }
          else if (ch == ']' && !quoted) {
            int j = 1;
            while (j <= spaces && criteria.charAt(endIndex - j) == ' ') j++;
            if (j - 1 == spaces) {
              endIndex -= spaces;
              closed = true;
              break;
            }
          }
        }
      }
      if (quoted) throw new MalformedPatternException(SSRBundle.message("error.expected.value", "\""));
      if (!closed) throw new MalformedPatternException(SSRBundle.message("error.expected.value", " ".repeat(spaces) + "]"));
      if (index > endIndex) throw new MalformedPatternException(SSRBundle.message("error.expected.condition", "["));
      parseCondition(constraint, criteria.substring(index, endIndex));
      return endIndex + spaces + 1;
    }
    else {
      // eat reg exp constraint
      return handleRegExp(index, criteria, constraint);
    }
  }
private static int handleTypedVarCondition(int index, @NotNull String criteria, @NotNull MatchVariableConstraint constraint)