PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { PsiFile file = holder.getFile(); final int codeStyleRightMargin = CodeStyle.getSettings(file).getRightMargin(file.getLanguage()); final VirtualFile vFile = file.getVirtualFile(); if (vFile instanceof VirtualFileWindow) { return PsiElementVisitor.EMPTY_VISITOR; } final Document document = FileDocumentManager.getInstance().getDocument(vFile); if (document == null) { return PsiElementVisitor.EMPTY_VISITOR; } return new PsiElementVisitor() { @Override public void visitElement(@NotNull PsiElement element) { int length = element.getTextLength(); if (element.getTextLength() != 0 && element.getFirstChild() == null && !ignoreFor(element)) { int offset = element.getTextOffset(); int endOffset = offset + length; int startLine = document.getLineNumber(offset); if (offset > document.getLineStartOffset(startLine) + codeStyleRightMargin) { startLine++; } int endLine = document.getLineNumber(endOffset - 1); for (int l = startLine; l <= endLine; l++) { int lineEndOffset = document.getLineEndOffset(l); int lineMarginOffset = document.getLineStartOffset(l) + codeStyleRightMargin; if (lineEndOffset > lineMarginOffset) { int highlightingStartOffset = lineMarginOffset - offset; int highlightingEndOffset = Math.min(endOffset, lineEndOffset) - offset; if (highlightingStartOffset < highlightingEndOffset) { TextRange exceedingRange = new TextRange(highlightingStartOffset, highlightingEndOffset); holder.registerProblem(element, exceedingRange, LangBundle.message("inspection.message.line.longer.than.allowed.by.code.style.columns", codeStyleRightMargin)); } } } } } }; }