protected HighlightSeverity getSeverity(@NotNull RefElement element) {
    final PsiElement psiElement = element.getPointer().getContainingFile();
    if (psiElement != null) {
      final GlobalInspectionContextImpl context = getContext();
      final String shortName = getSeverityDelegateName();
      final Tools tools = context.getTools().get(shortName);
      if (tools != null) {
        for (ScopeToolState state : tools.getTools()) {
          InspectionToolWrapper toolWrapper = state.getTool();
          if (toolWrapper == getToolWrapper()) {
            return context
                .getCurrentProfile()
                .getErrorLevel(HighlightDisplayKey.find(shortName), psiElement)
                .getSeverity();
          }
        }
      }

      final InspectionProfile profile =
          InspectionProjectProfileManager.getInstance(context.getProject()).getInspectionProfile();
      final HighlightDisplayLevel level =
          profile.getErrorLevel(HighlightDisplayKey.find(shortName), psiElement);
      return level.getSeverity();
    }
    return null;
  }
 @NotNull
 @Override
 public FileStatus getElementStatus(final RefEntity element) {
   final GlobalInspectionContextImpl context = getContext();
   if (!isDisposed() && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN) {
     if (myOldProblemElements != null) {
       final boolean old = RefUtil.contains(element, myOldProblemElements.keySet());
       final boolean current = RefUtil.contains(element, getProblemElements().keySet());
       return calcStatus(old, current);
     }
   }
   return FileStatus.NOT_CHANGED;
 }
 @Override
 @NotNull
 public FileStatus getProblemStatus(@NotNull final CommonProblemDescriptor descriptor) {
   final GlobalInspectionContextImpl context = getContext();
   if (!isDisposed() && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN) {
     if (myOldProblemElements != null) {
       final Set<CommonProblemDescriptor> allAvailable = new HashSet<CommonProblemDescriptor>();
       for (CommonProblemDescriptor[] descriptors : myOldProblemElements.values()) {
         if (descriptors != null) {
           ContainerUtil.addAll(allAvailable, descriptors);
         }
       }
       final boolean old = containsDescriptor(descriptor, allAvailable);
       final boolean current = containsDescriptor(descriptor, getProblemToElements().keySet());
       return calcStatus(old, current);
     }
   }
   return FileStatus.NOT_CHANGED;
 }
 @Override
 public boolean hasReportedProblems() {
   final GlobalInspectionContextImpl context = getContext();
   if (!isDisposed() && context.getUIOptions().SHOW_ONLY_DIFF) {
     for (CommonProblemDescriptor descriptor : getProblemToElements().keySet()) {
       if (getProblemStatus(descriptor) != FileStatus.NOT_CHANGED) {
         return true;
       }
     }
     if (myOldProblemElements != null) {
       for (RefEntity entity : myOldProblemElements.keySet()) {
         if (getElementStatus(entity) != FileStatus.NOT_CHANGED) {
           return true;
         }
       }
     }
     return false;
   }
   if (!getProblemElements().isEmpty()) return true;
   return !isDisposed()
       && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN
       && myOldProblemElements != null
       && !myOldProblemElements.isEmpty();
 }
  @Override
  public void addProblemElement(
      final RefEntity refElement,
      boolean filterSuppressed,
      @NotNull final CommonProblemDescriptor... descriptors) {
    if (refElement == null) return;
    if (descriptors.length == 0) return;
    if (filterSuppressed) {
      if (!isOutputPathSet() || !(myToolWrapper instanceof LocalInspectionToolWrapper)) {
        synchronized (lock) {
          Map<RefEntity, CommonProblemDescriptor[]> problemElements = getProblemElements();
          CommonProblemDescriptor[] problems = problemElements.get(refElement);
          problems = problems == null ? descriptors : mergeDescriptors(problems, descriptors);
          problemElements.put(refElement, problems);
        }
        for (CommonProblemDescriptor description : descriptors) {
          getProblemToElements().put(description, refElement);
          collectQuickFixes(description.getFixes(), refElement);
        }
      } else {
        writeOutput(descriptors, refElement);
      }
    } else { // just need to collect problems
      for (CommonProblemDescriptor descriptor : descriptors) {
        getProblemToElements().put(descriptor, refElement);
      }
    }

    final GlobalInspectionContextImpl context = getContext();
    if (myToolWrapper instanceof LocalInspectionToolWrapper) {
      final InspectionResultsView view = context.getView();
      if (view == null || !(refElement instanceof RefElement)) {
        return;
      }
      UIUtil.invokeLaterIfNeeded(
          new Runnable() {
            @Override
            public void run() {
              if (!isDisposed()) {
                final InspectionNode toolNode;
                synchronized (myToolLock) {
                  if (myToolNode == null) {
                    final HighlightSeverity currentSeverity = getSeverity((RefElement) refElement);
                    toolNode =
                        view.addTool(
                            myToolWrapper,
                            HighlightDisplayLevel.find(currentSeverity),
                            context.getUIOptions().GROUP_BY_SEVERITY);
                  } else {
                    toolNode = myToolNode;
                    if (toolNode.isTooBigForOnlineRefresh()) {
                      return;
                    }
                  }
                }
                final Map<RefEntity, CommonProblemDescriptor[]> problems =
                    new HashMap<RefEntity, CommonProblemDescriptor[]>();
                problems.put(refElement, descriptors);
                final Map<String, Set<RefEntity>> contents = new HashMap<String, Set<RefEntity>>();
                final String groupName =
                    refElement.getRefManager().getGroupName((RefElement) refElement);
                Set<RefEntity> content = contents.get(groupName);
                if (content == null) {
                  content = new HashSet<RefEntity>();
                  contents.put(groupName, content);
                }
                content.add(refElement);

                view.getProvider()
                    .appendToolNodeContent(
                        context,
                        toolNode,
                        (InspectionTreeNode) toolNode.getParent(),
                        context.getUIOptions().SHOW_STRUCTURE,
                        contents,
                        problems,
                        (DefaultTreeModel) view.getTree().getModel());
                context.addView(view);
              }
            }
          });
    }
  }
 @Override
 public boolean isOldProblemsIncluded() {
   final GlobalInspectionContextImpl context = getContext();
   return context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN && getOldContent() != null;
 }