CallHandler<CallChainSimplification> () { return CallHandler.of(INT_STREAM_RANGE, call -> { PsiExpression[] args = call.getArgumentList().getExpressions(); PsiMethodCallExpression maybeMap = ExpressionUtils.getCallForQualifier(call); if (!STREAM_INT_MAP_TO_ALL.test(maybeMap)) return null; PsiExpression arg = maybeMap.getArgumentList().getExpressions()[0]; PsiLambdaExpression lambda = tryCast(arg, PsiLambdaExpression.class); if (lambda == null) return null; PsiParameter[] parameters = lambda.getParameterList().getParameters(); if (parameters.length != 1) return null; PsiExpression lambdaExpr = tryCast(lambda.getBody(), PsiExpression.class); if (lambdaExpr == null) return null; PsiArrayAccessExpression arrayAccess = tryCast(skipParenthesizedExprDown(lambdaExpr), PsiArrayAccessExpression.class); if (arrayAccess == null) return null; PsiExpression index = arrayAccess.getIndexExpression(); if (!ExpressionUtils.isReferenceTo(index, parameters[0])) return null; PsiExpression arrayExpr = arrayAccess.getArrayExpression(); PsiArrayType arrayType = tryCast(arrayExpr.getType(), PsiArrayType.class); if (arrayType == null) return null; if (!StreamApiUtil.isSupportedStreamElement(arrayType.getComponentType())) return null; if (VariableAccessUtils.variableIsUsed(parameters[0], arrayExpr)) return null; PsiExpression leftBound = args[0]; PsiExpression rightBound = args[1]; return new RangeToArrayStreamFix( JAVA_UTIL_ARRAYS + ".stream(" + arrayExpr.getText() + "," + leftBound.getText() + "," + rightBound.getText() + ")"); }); }