boolean (PsiExpression expression, boolean allowBoxUnbox) { expression = PsiUtil.skipParenthesizedExprDown(expression); if (expression instanceof PsiMethodCallExpression && MethodCallUtils .isCallToStaticMethod((PsiMethodCallExpression)expression, CommonClassNames.JAVA_UTIL_FUNCTION_FUNCTION, "identity", 0)) { return true; } if (expression instanceof PsiLambdaExpression lambda) { if (LambdaUtil.isIdentityLambda(lambda)) return true; if (!allowBoxUnbox) return false; PsiExpression body = LambdaUtil.extractSingleExpressionFromBody(lambda.getBody()); PsiParameter[] parameters = lambda.getParameterList().getParameters(); if (parameters.length != 1) return false; PsiParameter parameter = parameters[0]; PsiMethodCallExpression call = tryCast(PsiUtil.skipParenthesizedExprDown(body), PsiMethodCallExpression.class); if (call == null) return false; PsiReferenceExpression methodExpression = call.getMethodExpression(); String referenceName = methodExpression.getReferenceName(); if (referenceName == null || !BOX_UNBOX_NAMES.contains(referenceName)) return false; PsiExpression qualifier = methodExpression.getQualifierExpression(); PsiExpression[] args = call.getArgumentList().getExpressions(); if (ExpressionUtils.isReferenceTo(qualifier, parameter) && args.length > 0) return false; if (args.length != 1 || !ExpressionUtils.isReferenceTo(args[0], parameter)) return false; return isBoxUnboxMethod(call.resolveMethod()); } if (!allowBoxUnbox || !(expression instanceof PsiMethodReferenceExpression methodRef)) return false; String referenceName = methodRef.getReferenceName(); if (referenceName == null || !BOX_UNBOX_NAMES.contains(referenceName)) return false; PsiMethod method = tryCast(methodRef.resolve(), PsiMethod.class); return isBoxUnboxMethod(method); }