void (@NotNull MatchVariableConstraint constraint, @NotNull String condition) { final int length = condition.length(); final StringBuilder text = new StringBuilder(); boolean invert = false; boolean optionExpected = true; for (int i = 0; i < length; i++) { char c = condition.charAt(i); if (Character.isWhitespace(c)) { if (text.length() == 0) continue; handleOption(constraint, text.toString(), "", invert); optionExpected = false; } else if (c == '(') { if (text.length() == 0) throw new MalformedPatternException(SSRBundle.message("error.expected.condition.name")); final String option = text.toString(); if (!option.startsWith("_") && !knownOptions.contains(option)) { throw new MalformedPatternException(SSRBundle.message("option.is.not.recognized.error.message", option)); } text.setLength(0); int spaces = 0; // balance spaces surrounding content between parentheses while (++i < length && condition.charAt(i) == ' ') spaces++; i--; boolean quoted = false; boolean closed = false; while (++i < length) { c = condition.charAt(i); if (condition.charAt(i - 1) != '\\') { if (c == '"') { quoted = !quoted; } else if (c == ')' && !quoted) { int j = 1; while (j <= spaces && condition.charAt(i - j) == ' ') j++; if (j - 1 == spaces) { closed = true; break; } } } text.append(c); } if (text.length() == 0) throw new MalformedPatternException(SSRBundle.message("error.argument.expected", option)); if (quoted) throw new MalformedPatternException(SSRBundle.message("error.expected.value", "\"")); if (!closed) throw new MalformedPatternException(SSRBundle.message("error.expected.value", " ".repeat(spaces) + ")")); handleOption(constraint, option, text.toString(), invert); text.setLength(0); invert = false; optionExpected = false; } else if (c == '&') { if (text.length() != 0) { handleOption(constraint, text.toString(), "", invert); optionExpected = false; } if (++i == length || condition.charAt(i) != '&' || optionExpected) { throw new MalformedPatternException(SSRBundle.message("error.unexpected.value", "&")); } text.setLength(0); invert = false; optionExpected = true; } else if (!optionExpected) { throw new MalformedPatternException(SSRBundle.message("error.expected.value", "&&")); } else if (c == '!') { if (text.length() != 0) throw new MalformedPatternException(SSRBundle.message("error.unexpected.value", "!")); invert = !invert; } else { text.append(c); } } if (text.length() != 0) { handleOption(constraint, text.toString(), "", invert); } else if (invert) { throw new MalformedPatternException(SSRBundle.message("error.expected.condition", "!")); } else if (optionExpected) throw new MalformedPatternException(SSRBundle.message("error.expected.condition", length == 0 ? "[" : "&&")); }