@Nullable public ProblemDescriptor[] checkFile( @NotNull PsiFile psiFile, @NotNull InspectionManager inspectionManager, boolean isOnTheFly) { if (!(psiFile instanceof GroovyFileBase)) { return super.checkFile(psiFile, inspectionManager, isOnTheFly); } final GroovyFileBase groovyFile = (GroovyFileBase) psiFile; final ProblemsHolder problemsHolder = new ProblemsHolder(inspectionManager, psiFile, isOnTheFly); final BaseInspectionVisitor visitor = buildGroovyVisitor(problemsHolder, isOnTheFly); groovyFile.accept(visitor); final List<ProblemDescriptor> problems = problemsHolder.getResults(); return problems.toArray(new ProblemDescriptor[problems.size()]); }
private static ProblemDescriptor runLocalTool( @NotNull PsiElement psiElement, @NotNull InspectionManager inspectionManager, @NotNull OfflineProblemDescriptor offlineProblemDescriptor, @NotNull LocalInspectionToolWrapper toolWrapper) { PsiFile containingFile = psiElement.getContainingFile(); final ProblemsHolder holder = new ProblemsHolder(inspectionManager, containingFile, false); final LocalInspectionTool localTool = toolWrapper.getTool(); final int startOffset = psiElement.getTextRange().getStartOffset(); final int endOffset = psiElement.getTextRange().getEndOffset(); LocalInspectionToolSession session = new LocalInspectionToolSession(containingFile, startOffset, endOffset); final PsiElementVisitor visitor = localTool.buildVisitor(holder, false, session); localTool.inspectionStarted(session, false); final PsiElement[] elementsInRange = getElementsIntersectingRange(containingFile, startOffset, endOffset); for (PsiElement element : elementsInRange) { element.accept(visitor); } localTool.inspectionFinished(session, holder); if (holder.hasResults()) { final List<ProblemDescriptor> list = holder.getResults(); final int idx = offlineProblemDescriptor.getProblemIndex(); int curIdx = 0; for (ProblemDescriptor descriptor : list) { final PsiNamedElement member = localTool.getProblemElement(descriptor.getPsiElement()); if (psiElement instanceof PsiFile || member != null && member.equals(psiElement)) { if (curIdx == idx) { return descriptor; } curIdx++; } } } return null; }