TerminalGenerator (PsiPolyadicExpression polyadicExpression) { IElementType tokenType = polyadicExpression.getOperationTokenType(); if (tokenType.equals(JavaTokenType.OROR)) { return (elementType, lambda, ct) -> ".anyMatch(" + lambda + ")"; } else if (tokenType.equals(JavaTokenType.ANDAND)) { return (elementType, lambda, ct) -> ".allMatch(" + lambda + ")"; } else if (tokenType.equals(JavaTokenType.PLUS)) { PsiType type = polyadicExpression.getType(); if (type instanceof PsiPrimitiveType) { if (!StreamApiUtil.isSupportedStreamElement(type)) return null; return (elementType, lambda, ct) -> "." + getMapOperationName(elementType, type) + "(" + lambda + ").sum()"; } if (!TypeUtils.isJavaLangString(type)) return null; PsiExpression[] operands = polyadicExpression.getOperands(); String mapToString; PsiType operandType = operands[0].getType(); if (!InheritanceUtil.isInheritor(operandType, JAVA_LANG_CHAR_SEQUENCE)) { if (!StreamApiUtil.isSupportedStreamElement(operandType)) return null; mapToString = "."+getMapOperationName(operandType, type)+"(String::valueOf)"; } else { mapToString = ""; } PsiExpression delimiter = null; PsiExpression rest = null; if (operands.length > 4 && ExpressionUtils.isSafelyRecomputableExpression(operands[1]) && IntStreamEx.range(1, operands.length, 2).elements(operands) .pairMap(EquivalenceChecker.getCanonicalPsiEquivalence()::expressionsAreEquivalent) .allMatch(Boolean.TRUE::equals)) { delimiter = operands[1]; if (!InheritanceUtil.isInheritor(delimiter.getType(), JAVA_LANG_CHAR_SEQUENCE) && !(delimiter instanceof PsiLiteralExpression && PsiTypes.charType().equals(delimiter.getType()))) { return null; } if (operands.length % 2 == 0) { rest = ArrayUtil.getLastElement(operands); } } return new JoiningTerminalGenerator(operandType, mapToString, delimiter, rest); } return null; }