ProblemDescriptor (@NotNull PsiElement psiElement, @NotNull OfflineProblemDescriptor offlineProblemDescriptor, @NotNull LocalInspectionToolWrapper toolWrapper, @NotNull GlobalInspectionContextImpl context) { PsiFile containingFile = psiElement.getContainingFile(); LocalInspectionTool localTool = toolWrapper.getTool(); TextRange textRange = psiElement.getTextRange(); LOG.assertTrue(textRange != null, "text range must be not null here; " + "isValid = " + psiElement.isValid() + ", " + "isPhysical = " + psiElement.isPhysical() + ", " + "containingFile = " + containingFile.getName() + ", " + "inspection = " + toolWrapper.getShortName()); PsiElement[] elementsInRange = getElementsIntersectingRange(containingFile, textRange.getStartOffset(), textRange.getEndOffset()); Collection<PsiFile> injectedFiles = new HashSet<>(); InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(context.getProject()); for (PsiElement element : elementsInRange) { List<Pair<PsiElement, TextRange>> injectedPsiFiles = injectedLanguageManager.getInjectedPsiFiles(element); if (injectedPsiFiles != null) { for (Pair<PsiElement, TextRange> pair : injectedPsiFiles) { injectedFiles.add(pair.getFirst().getContainingFile()); } } } Map<LocalInspectionToolWrapper, List<ProblemDescriptor>> map = InspectionEngine.inspectEx(Collections.singletonList(toolWrapper), containingFile, textRange, containingFile.getTextRange(), true, false, true, new DaemonProgressIndicator(), PairProcessor.alwaysTrue()); List<ProblemDescriptor> list = new ArrayList<>(); map.values().forEach(problemsList -> list.addAll(problemsList)); for (PsiFile injectedFile : injectedFiles) { Map<LocalInspectionToolWrapper, List<ProblemDescriptor>> injectedMap = InspectionEngine.inspectEx(Collections.singletonList(toolWrapper), injectedFile, injectedFile.getTextRange(), injectedFile.getTextRange(), true, false, true, new DaemonProgressIndicator(), PairProcessor.alwaysTrue()); list.addAll(ContainerUtil.flatten(injectedMap.values())); } int idx = offlineProblemDescriptor.getProblemIndex(); int curIdx = 0; for (ProblemDescriptor descriptor : list) { PsiNamedElement member = BatchModeDescriptorsUtil.getContainerElement(descriptor.getPsiElement(), localTool, context); PsiElement element = psiElement instanceof LightElement ? psiElement.getNavigationElement() : psiElement; if (psiElement instanceof PsiFile || element.equals(member)) { if (curIdx == idx) { return descriptor; } curIdx++; } } return null; }