private static void reportMixedLanguages(@NotNull PsiElement element,
                                           @NotNull String text,
                                           @NotNull ProblemsHolder holder,
                                           @Nullable("null means natural range") TextRange elementRange) {
    int nonAsciiStart = -1;
    int codePoint;
    int endOffset = elementRange == null ? text.length() : elementRange.getEndOffset();
    int startOffset = elementRange == null ? 0 : elementRange.getStartOffset();

    for (int i = startOffset; i <= endOffset; i += Character.charCount(codePoint)) {
      codePoint = i == endOffset ? 0 : text.codePointAt(i);
      if (codePoint != 0 && ignoreScript(Character.UnicodeScript.of(codePoint))) {
        if (i==startOffset) startOffset++; // to calculate "isHighlightWholeWord" correctly
        continue;
      }
      if (isAsciiCodePoint(codePoint)) {
        boolean isHighlightWholeWord = i - nonAsciiStart == endOffset - startOffset;
        if (nonAsciiStart != -1 && !isHighlightWholeWord) {
          // report non-ascii range [nonAsciiStart..i) inside ascii word
          // but trim the trailing COMMON script characters first
          int j = i;
          for (; j > nonAsciiStart; j -= Character.charCount(codePoint)) {
            codePoint = text.codePointAt(j-Character.charCount(codePoint));
            if (!ignoreScript(Character.UnicodeScript.of(codePoint))) break;
          }
          
          holder.registerProblem(element, new TextRange(nonAsciiStart, j), CodeInsightBundle.message("non.ascii.chars.inspection.message.symbols.from.different.languages.found"));
          nonAsciiStart = -1;
        }
      }
      else if (nonAsciiStart == -1) {
        nonAsciiStart = i;
      }
    }
  }
private static void reportMixedLanguages(@NotNull PsiElement element,
                                           @NotNull String text,
                                           @NotNull ProblemsHolder holder,
                                           @Nullable("null means natural range") TextRange elementRange)