CallHandler<CallChainSimplification> () { return CallHandler.of(STREAM_MAP_TO_ALL, call -> { PsiMethodCallExpression qualifierCall = getQualifierMethodCall(call); List<String> methods = new ArrayList<>(Arrays.asList("getKey", "getValue")); while (STREAM_FILTER.test(qualifierCall)) { String methodName = getSingleCalledMethodName(qualifierCall.getArgumentList().getExpressions()[0]); if (methodName == null || !methods.contains(methodName)) return null; methods = Collections.singletonList(methodName); qualifierCall = getQualifierMethodCall(qualifierCall); } if (!COLLECTION_STREAM.test(qualifierCall)) return null; PsiMethodCallExpression qualifierQualifierCall = getQualifierMethodCall(qualifierCall); if (!MAP_ENTRY_SET.test(qualifierQualifierCall)) return null; PsiExpression arg = call.getArgumentList().getExpressions()[0]; for (String method : methods) { if (FunctionalExpressionUtils.isFunctionalReferenceTo(arg, JAVA_UTIL_MAP_ENTRY, null, method)) { return new EntrySetMapFix(method, "map".equals(call.getMethodExpression().getReferenceName())); } } String methodName = getSingleCalledMethodName(arg); if (methodName != null && methods.contains(methodName)) { return new EntrySetMapFix(methodName, false); } return null; }); }