PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) { PsiFile file = session.getFile(); if (!isFileWorthIt(file)) return PsiElementVisitor.EMPTY_VISITOR; SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(file.getFileType(), file.getProject(), file.getVirtualFile()); return new PsiElementVisitor() { @Override public void visitElement(@NotNull PsiElement element) { if (!(element instanceof LeafElement) // optimization: ignore very frequent white space element || element instanceof PsiWhiteSpace) { return; } PsiElementKind kind = getKind(element, syntaxHighlighter); TextRange valueRange; // the range inside element with the actual contents with quotes/comment prefixes stripped out switch (kind) { case STRING -> { if (CHECK_FOR_NOT_ASCII_STRING_LITERAL || CHECK_FOR_DIFFERENT_LANGUAGES_IN_STRING) { String text = element.getText(); valueRange = StringUtil.isQuotedString(text) ? new TextRange(1, text.length() - 1) : null; if (CHECK_FOR_DIFFERENT_LANGUAGES_IN_STRING) { reportMixedLanguages(element, text, holder, valueRange); } if (CHECK_FOR_NOT_ASCII_STRING_LITERAL) { reportNonAsciiRange(element, text, holder, valueRange); } } } case IDENTIFIER -> { if (CHECK_FOR_NOT_ASCII_IDENTIFIER_NAME) { reportNonAsciiRange(element, element.getText(), holder, null); } if (CHECK_FOR_DIFFERENT_LANGUAGES_IN_IDENTIFIER_NAME) { reportMixedLanguages(element, element.getText(), holder, null); } } case COMMENT -> { if (CHECK_FOR_NOT_ASCII_COMMENT || CHECK_FOR_DIFFERENT_LANGUAGES_IN_COMMENTS) { String text = element.getText(); valueRange = getCommentRange(element, text); if (CHECK_FOR_NOT_ASCII_COMMENT) { reportNonAsciiRange(element, text, holder, valueRange); } if (CHECK_FOR_DIFFERENT_LANGUAGES_IN_COMMENTS) { reportMixedLanguages(element, text, holder, valueRange); } } } case OTHER -> { if (CHECK_FOR_NOT_ASCII_IN_ANY_OTHER_WORD) { String text = element.getText(); iterateWordsInLeafElement(text, range -> reportMixedLanguages(element, text, holder, range)); } if (CHECK_FOR_DIFFERENT_LANGUAGES_IN_ANY_OTHER_WORD) { String text = element.getText(); iterateWordsInLeafElement(text, range -> reportMixedLanguages(element, text, holder, range)); } } } } @Override public void visitFile(@NotNull PsiFile file) { super.visitFile(file); if (CHECK_FOR_FILES_CONTAINING_BOM) { checkBOM(file, holder); } } }; }