CallHandler<CallChainSimplification> () { return CallHandler.of(STREAM_MAP, mapCall -> { if (mapCall.getTypeArguments().length != 0) return null; final PsiMethodCallExpression filterCall = getQualifierMethodCall(mapCall); if (filterCall == null || filterCall.getTypeArguments().length != 0) return null; final PsiExpression mapArg = skipParenthesizedExprDown(mapCall.getArgumentList().getExpressions()[0]); final PsiMethodReferenceExpression mapMethodRef = tryCast(mapArg, PsiMethodReferenceExpression.class); if (mapMethodRef != null) { final PsiMethod resolvedCandidateToRemove = findAndResolveCandidateToRemove(mapCall); if (resolvedCandidateToRemove == null) return null; boolean isStatic = resolvedCandidateToRemove.hasModifierProperty(PsiModifier.STATIC); boolean instanceBound = !isStatic && !PsiMethodReferenceUtil.isStaticallyReferenced(mapMethodRef); if (isStatic || instanceBound) return null; final PsiManager manager = resolvedCandidateToRemove.getManager(); if (!manager.areElementsEquivalent(resolvedCandidateToRemove, mapMethodRef.resolve())) return null; return new FilterAndMapUseSameMethodChainFix(); } final PsiLambdaExpression lambda = tryCast(mapArg, PsiLambdaExpression.class); if (lambda == null) return null; final PsiElement body = skipParenthesizedExprDown(LambdaUtil.extractSingleExpressionFromBody(lambda.getBody())); final PsiMethodCallExpression calledMethodInMap = findSingleCalledMethod(mapArg); if (calledMethodInMap == null || body != calledMethodInMap) return null; final PsiMethod resolvedCandidateToRemove = findAndResolveCandidateToRemove(mapCall); if (resolvedCandidateToRemove == null) return null; final PsiManager manager = resolvedCandidateToRemove.getManager(); if (manager.areElementsEquivalent(resolvedCandidateToRemove, calledMethodInMap.resolveMethod())) { return new FilterAndMapUseSameMethodChainFix(); } return null; }); }