private static Map<ProblemDescriptor, HighlightDisplayLevel> runInspectionTool( final PsiFile file, final LocalInspectionTool inspectionTool, final HighlightDisplayLevel level) { Map<ProblemDescriptor, HighlightDisplayLevel> problemsMap = new LinkedHashMap<ProblemDescriptor, HighlightDisplayLevel>(); for (ProblemDescriptor descriptor : runInspectionOnFile(file, inspectionTool)) { final ProblemHighlightType highlightType = descriptor.getHighlightType(); final HighlightDisplayLevel highlightDisplayLevel; if (highlightType == ProblemHighlightType.WEAK_WARNING) { highlightDisplayLevel = HighlightDisplayLevel.WEAK_WARNING; } else if (highlightType == ProblemHighlightType.INFORMATION) { highlightDisplayLevel = HighlightDisplayLevel.DO_NOT_SHOW; } else { highlightDisplayLevel = level; } problemsMap.put(descriptor, highlightDisplayLevel); } return problemsMap; }
private boolean reportProblems( CompileContext context, Map<ProblemDescriptor, HighlightDisplayLevel> problemsMap) { if (problemsMap.isEmpty()) { return false; } boolean errorsReported = false; for (Map.Entry<ProblemDescriptor, HighlightDisplayLevel> entry : problemsMap.entrySet()) { ProblemDescriptor problemDescriptor = entry.getKey(); final PsiElement element = problemDescriptor.getPsiElement(); final PsiFile psiFile = element.getContainingFile(); if (psiFile == null) continue; final VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile == null) continue; final CompilerMessageCategory category = myValidator.getCategoryByHighlightDisplayLevel(entry.getValue(), virtualFile, context); final Document document = myPsiDocumentManager.getDocument(psiFile); final int offset = problemDescriptor.getStartElement().getTextOffset(); assert document != null; final int line = document.getLineNumber(offset); final int column = offset - document.getLineStartOffset(line); context.addMessage( category, problemDescriptor.getDescriptionTemplate(), virtualFile.getUrl(), line + 1, column + 1); if (CompilerMessageCategory.ERROR == category) { errorsReported = true; } } return errorsReported; }