private static boolean checkJavaIdentifier(@NotNull CharSequence text,
                                             @NotNull StringSearcher searcher,
                                             int index) {
    if (!searcher.isJavaIdentifier()) {
      return true;
    }

    if (index > 0) {
      char c = text.charAt(index - 1);
      if (Character.isJavaIdentifierPart(c) && c != '$') {
        if (!searcher.isHandleEscapeSequences() || index < 2 || StringUtil.isEscapedBackslash(text, 0, index - 2)) { //escape sequence
          return false;
        }
      }
      else if (searcher.isHandleEscapeSequences() && !StringUtil.isEscapedBackslash(text, 0, index - 1)) {
        return false;
      }
    }

    final int patternLength = searcher.getPattern().length();
    if (index + patternLength < text.length()) {
      char c = text.charAt(index + patternLength);
      return !Character.isJavaIdentifierPart(c) || c == '$';
    }
    return true;
  }
private static boolean checkJavaIdentifier(@NotNull CharSequence text,
                                             @NotNull StringSearcher searcher,
                                             int index)