PlainJoiningTerminal (@NotNull TerminalBlock terminalBlock, @Nullable List<PsiVariable> nonFinalVariables) { if (nonFinalVariables != null && !nonFinalVariables.isEmpty()) return null; List<PsiStatement> statements = Arrays.asList(terminalBlock.getStatements()); List<PsiExpression> mainJoinParts = extractJoinParts(statements); if (mainJoinParts == null || mainJoinParts.isEmpty()) return null; if (statements.isEmpty()) return null; PsiVariable targetBuilder = extractStringBuilder(statements.get(0)); if (targetBuilder == null) return null; PsiStatement loop = terminalBlock.getStreamSourceStatement(); PrefixSuffixContext context = PrefixSuffixContext.extractAndVerifyRefs(loop, loop, targetBuilder, terminalBlock, emptyList(), new HashSet<>(emptyList())); if (context == null) return null; return new PlainJoiningTerminal(targetBuilder, terminalBlock.getVariable(), mainJoinParts, context, terminalBlock); }