ReplaceComputeWithComputeIfPresentFix (PsiElement reference) { if (!(reference instanceof PsiReferenceExpression)) return null; PsiParameter parameter = tryCast(((PsiReferenceExpression)reference).resolve(), PsiParameter.class); if (parameter == null) return null; PsiParameterList parameterList = tryCast(parameter.getParent(), PsiParameterList.class); if (parameterList == null || parameterList.getParametersCount() != 2 || parameterList.getParameterIndex(parameter) != 1) return null; PsiLambdaExpression lambda = tryCast(parameterList.getParent(), PsiLambdaExpression.class); if (lambda == null) return null; PsiExpressionList arguments = tryCast(lambda.getParent(), PsiExpressionList.class); if (arguments == null || arguments.getExpressionCount() != 2 || arguments.getExpressions()[1] != lambda) return null; PsiMethodCallExpression call = tryCast(arguments.getParent(), PsiMethodCallExpression.class); if (!MAP_COMPUTE.test(call)) return null; return new ReplaceComputeWithComputeIfPresentFix(); }