List<CommonProblemDescriptor[]> (boolean sortedByPosition, @Nullable Set<? super VirtualFile> readOnlyFilesSink, boolean allowResolved, @NotNull List<? extends InspectionTreeNode> nodes) { MultiMap<Object, CommonProblemDescriptor> parentToChildNode = new MultiMap<>(); TreeTraversal.PLAIN_BFS.traversal( nodes, (InspectionTreeNode n) -> myModel.getChildren(n)) .filter(ProblemDescriptionNode.class) .filter(node -> node.getDescriptor() != null && isNodeValidAndIncluded(node, allowResolved)) .consumeEach(node -> { Object key = getVirtualFileOrEntity(node.getElement()); parentToChildNode.putValue(key, node.getDescriptor()); }); final List<CommonProblemDescriptor[]> descriptors = new ArrayList<>(); for (Map.Entry<Object, Collection<CommonProblemDescriptor>> entry : parentToChildNode.entrySet()) { Object key = entry.getKey(); if (readOnlyFilesSink != null && key instanceof VirtualFile && !((VirtualFile)key).isWritable()) { readOnlyFilesSink.add((VirtualFile)key); } Stream<CommonProblemDescriptor> stream = entry.getValue().stream(); if (sortedByPosition) { stream = stream.sorted(DESCRIPTOR_COMPARATOR); } descriptors.add(stream.distinct().toArray(CommonProblemDescriptor.ARRAY_FACTORY::create)); } return descriptors; }