CollectTerminal (@NotNull TerminalBlock tb, @Nullable List<PsiVariable> nonFinalVariables) { GroupingTerminal groupingTerminal = GroupingTerminal.tryExtract(tb, nonFinalVariables); if(groupingTerminal != null) return groupingTerminal; if(nonFinalVariables != null && !nonFinalVariables.isEmpty()) { return null; } PsiMethodCallExpression call; call = tb.getSingleMethodCall(); if (call == null) return null; PsiReferenceExpression methodExpression = call.getMethodExpression(); PsiExpression qualifierExpression = methodExpression.getQualifierExpression(); if (tb.dependsOn(qualifierExpression)) return null; List<BiFunction<TerminalBlock, PsiMethodCallExpression, CollectTerminal>> extractors = Arrays .asList(AddingTerminal::tryExtract, GroupingTerminal::tryExtractJava8Style, ToMapTerminal::tryExtract, AddingAllTerminal::tryExtractAddAll); CollectTerminal terminal = StreamEx.of(extractors).map(extractor -> extractor.apply(tb, call)).nonNull().findFirst().orElse(null); if (terminal != null) { if (terminal.getStatus() == ControlFlowUtils.InitializerUsageStatus.UNKNOWN) return null; terminal = includePostStatements(terminal, PsiTreeUtil.skipWhitespacesAndCommentsForward(tb.getStreamSourceStatement())); } return terminal; }