SortedSet<ChainOpAndOccurrences<MethodCall>> (@NotNull String rawReturnType, @SignatureData.IteratorKind byte iteratorKind, @NotNull ChainCompletionContext context) { try { if (!myReadDataLock.tryLock()) { return Collections.emptySortedSet(); } try { if (myReader == null) { throw new ReferenceIndexUnavailableException(); } final int type = myReader.getNameEnumerator().tryEnumerate(rawReturnType); if (type == 0) { return Collections.emptySortedSet(); } return Stream.of(new SignatureData(type, iteratorKind, true), new SignatureData(type, iteratorKind, false)) .flatMap(sd -> StreamEx.of(myReader.getMembersFor(sd)) .peek(r -> ProgressManager.checkCanceled()) .select(CompilerRef.JavaCompilerMethodRef.class) .flatMap(r -> { CompilerRef.NamedCompilerRef[] hierarchy = myReader.getHierarchy(r.getOwner(), false, false, ChainSearchMagicConstants.MAX_HIERARCHY_SIZE); return hierarchy == null ? Stream.empty() : Arrays.stream(hierarchy).map(c -> r.override(c.getName())); }) .distinct() .map(r -> { int count = myReader.getOccurrenceCount(r); return count <= 1 ? null : new ChainOpAndOccurrences<>( new MethodCall((CompilerRef.JavaCompilerMethodRef)r, sd, context), count); })) .filter(Objects::nonNull) .collect(Collectors.groupingBy(x -> x.getOperation(), Collectors.summarizingInt(x -> x.getOccurrenceCount()))) .entrySet() .stream() .map(e -> new ChainOpAndOccurrences<>(e.getKey(), (int)e.getValue().getSum())) .collect(Collectors.toCollection(TreeSet::new)); } finally { myReadDataLock.unlock(); } } catch (Exception e) { onException(e, "find methods"); return Collections.emptySortedSet(); } }