@Override
    public void visitFile(@NotNull PsiFile file) {
      super.visitFile(file);
      if (InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file) || !file.isPhysical()) {
        return;
      }
      final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
      if (document == null) {
        return;
      }
      final VirtualFile virtualFile = file.getVirtualFile();
      final String text = file.getText();
      final Charset charset = LoadTextUtil.extractCharsetFromFileContent(file.getProject(), virtualFile, text);
      final CharsetEncoder encoder = charset.newEncoder().onUnmappableCharacter(CodingErrorAction.REPORT);
      final CharBuffer charBuffer = CharBuffer.allocate(1);
      final ByteBuffer byteBuffer = ByteBuffer.allocate(10);
      final int length = text.length();
      for (int i = 0; i < length; i++) {
        final char c = text.charAt(i);
        if (c != '\\') {
          continue;
        }
        boolean isEscape = true;
        int previousChar = i - 1;
        while (previousChar >= 0 && text.charAt(previousChar) == '\\') {
          isEscape = !isEscape;
          previousChar--;
        }
        if (!isEscape) {
          continue;
        }
        int nextChar = i + 1;
        while (nextChar < length && text.charAt(nextChar) == 'u') {
          nextChar++; // \uuuuFFFD is a legal Unicode escape
        }
        if (nextChar == i + 1 || nextChar + 3 >= length) {
          continue;
        }
        if (StringUtil.isHexDigit(text.charAt(nextChar)) &&
            StringUtil.isHexDigit(text.charAt(nextChar + 1)) &&
            StringUtil.isHexDigit(text.charAt(nextChar + 2)) &&
            StringUtil.isHexDigit(text.charAt(nextChar + 3))) {
          final int escapeEnd = nextChar + 4;
          final char d = (char)Integer.parseInt(text.substring(nextChar, escapeEnd), 16);
          if (d == '\uFFFD') {
            // this character is used as a replacement when a unicode character can't be displayed
            // replacing the escape with the character may cause confusion, so ignore it.
            continue;
          }
          final int type = Character.getType(d);
          if (type == Character.CONTROL && d != '\n' && d != '\t') {
            continue;
          }
          else if (type == Character.FORMAT ||
                   type == Character.PRIVATE_USE ||
                   type == Character.SURROGATE ||
                   type == Character.UNASSIGNED ||
                   type == Character.LINE_SEPARATOR ||
                   type == Character.PARAGRAPH_SEPARATOR) {
            continue;
          }
          if (type == Character.SPACE_SEPARATOR && d != ' ') {
            continue;
          }
          byteBuffer.clear();
          charBuffer.clear();
          charBuffer.put(d).rewind();
          final CoderResult coderResult = encoder.encode(charBuffer, byteBuffer, true);
          if (coderResult.isError()) {
            continue;
          }
          PsiElement element = file.findElementAt(i);
          if (element == null) {
            return;
          }
          final RangeMarker rangeMarker = document.createRangeMarker(i, escapeEnd);
          TextRange range = element.getTextRange();
          while (escapeEnd > range.getEndOffset()) {
            element = element.getParent();
            range = element.getTextRange();
          }
          registerErrorAtOffset(element, i - range.getStartOffset(), escapeEnd - i, Character.valueOf(d), rangeMarker);
        }
      }
    }
@Override
    public void visitFile(@NotNull PsiFile file)