boolean (PsiExpression expression, String className, PsiType returnType, String methodName, PsiType... parameterTypes) { expression = PsiUtil.skipParenthesizedExprDown(expression); if (expression instanceof PsiMethodReferenceExpression methodRef) { if (!methodName.equals(methodRef.getReferenceName())) return false; PsiMethod method = ObjectUtils.tryCast(methodRef.resolve(), PsiMethod.class); PsiReferenceExpression ref = ObjectUtils.tryCast(methodRef.getQualifier(), PsiReferenceExpression.class); return ref != null && method != null && MethodUtils.methodMatches(method, className, returnType, methodName, parameterTypes) && method.getContainingClass() != null && ref.isReferenceTo(method.getContainingClass()); } if (expression instanceof PsiLambdaExpression lambda) { PsiExpression body = PsiUtil.skipParenthesizedExprDown(LambdaUtil.extractSingleExpressionFromBody(lambda.getBody())); PsiMethodCallExpression call = ObjectUtils.tryCast(body, PsiMethodCallExpression.class); if (call == null || !MethodCallUtils.isCallToMethod(call, className, returnType, methodName, parameterTypes)) return false; PsiParameter[] parameters = lambda.getParameterList().getParameters(); PsiExpression[] args = call.getArgumentList().getExpressions(); PsiMethod method = call.resolveMethod(); if (method != null && !method.hasModifierProperty(PsiModifier.STATIC)) { args = ArrayUtil.prepend(call.getMethodExpression().getQualifierExpression(), args); } if (parameters.length != args.length || StreamEx.zip(args, parameters, ExpressionUtils::isReferenceTo).has(false)) return false; return MethodCallUtils.isCallToMethod(call, className, returnType, methodName, parameterTypes); } return false; }