int (@NotNull CharSequence chars, int startOffset) { int currentPos = startOffset; if (currentPos > 0 && currentPos - 1 + BRACE_LENGTH >= chars.length() && isBrace(chars.subSequence(currentPos - 1, currentPos - 1 + BRACE_LENGTH))) { return currentPos - 1; // inside brace token <I] or [I> } while (currentPos >= BRACE_LENGTH - 1 && Character.isWhitespace(chars.charAt(currentPos))) { currentPos--; } if (currentPos >= BRACE_LENGTH - 1 && isBrace(chars.subSequence(currentPos + 1 - BRACE_LENGTH, currentPos + 1))) { return currentPos + 1 - BRACE_LENGTH; } currentPos = startOffset; int length = chars.length(); while (currentPos + BRACE_LENGTH <= length && Character.isWhitespace(chars.charAt(currentPos))) { currentPos++; } if (currentPos + BRACE_LENGTH <= length && isBrace(chars.subSequence(currentPos, currentPos + BRACE_LENGTH))) { return currentPos; } return -1; }