void (@NotNull List<? super Path> inspectionsResults, @NotNull List<? extends Tools> inspections, @NotNull Path outputDir, @Nullable XMLOutputFactory xmlOutputFactory) { if (xmlOutputFactory == null) { xmlOutputFactory = XMLOutputFactory.newDefaultFactory(); } BufferedWriter[] writers = new BufferedWriter[inspections.size()]; XMLStreamWriter[] xmlWriters = new XMLStreamWriter[inspections.size()]; try { int i = 0; for (Tools inspection : inspections) { inspectionsResults.add(InspectionsResultUtil.getInspectionResultPath(outputDir, inspection.getShortName())); try { BufferedWriter writer = InspectionsResultUtil.getWriter(outputDir, inspection.getShortName()); writers[i] = writer; XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter(writer); xmlWriters[i++] = xmlWriter; xmlWriter.writeStartElement(GlobalInspectionContextBase.PROBLEMS_TAG_NAME); xmlWriter.writeCharacters("\n"); xmlWriter.flush(); } catch (IOException | XMLStreamException e) { LOG.error(e); } } List<List<ScopeToolState>> states = new ArrayList<>(); for (Tools inspection : inspections) { states.add(inspection.getTools()); } getRefManager().iterate(new RefVisitor() { @Override public void visitElement(@NotNull RefEntity refEntity) { for (int i = 0; i < states.size(); i++) { for (ScopeToolState state : states.get(i)) { try { InspectionToolWrapper<?, ?> toolWrapper = state.getTool(); BufferedWriter writer = writers[i]; if (writer != null && (myGlobalReportedProblemFilter == null || myGlobalReportedProblemFilter.shouldReportProblem(refEntity, toolWrapper.getShortName()))) { getPresentation(toolWrapper).exportResults(e -> { try { JbXmlOutputter.collapseMacrosAndWrite(e, getProject(), writer); writer.flush(); } catch (IOException e1) { throw new RuntimeException(e1); } }, refEntity, d -> false); } else { return; } } catch (Throwable e) { LOG.error("Problem when exporting: " + refEntity.getExternalName(), e); } } } } }); for (XMLStreamWriter xmlWriter : xmlWriters) { if (xmlWriter != null) { try { xmlWriter.writeEndElement(); xmlWriter.flush(); } catch (XMLStreamException e) { LOG.error(e); } } } } finally { for (BufferedWriter writer : writers) { if (writer != null) { try { writer.close(); } catch (IOException e) { LOG.error(e); } } } } }