CallHandler<CallChainSimplification> () { return CallHandler.of(STREAM_OF, call -> { PsiMethodCallExpression nextCall = ExpressionUtils.getCallForQualifier(call); if (nextCall == null) return null; if (LAMBDA_TERMINAL.test(nextCall)) { PsiExpression arg = skipParenthesizedExprDown(nextCall.getArgumentList().getExpressions()[0]); if (arg instanceof PsiReferenceExpression || arg instanceof PsiMethodCallExpression) { PsiMethod method = LambdaUtil.getFunctionalInterfaceMethod(arg.getType()); boolean negate = "noneMatch".equals(nextCall.getMethodExpression().getReferenceName()); if (method == null || negate && PsiUtil.skipParenthesizedExprUp(nextCall.getParent()) instanceof PsiExpressionStatement) { return null; } return new SimpleStreamOfFix(negate ? ReplacementMode.NEGATED_FUNCTION : ReplacementMode.FUNCTION); } } if (OPTIONAL_TERMINAL.test(nextCall)) { return new SimpleStreamOfFix(ReplacementMode.OPTIONAL); } return null; }); }