use std::collections::HashMap;
use crate::callgraph::cross_file_types::CallSite;
pub(crate) fn qualify_name(prefix: Option<&str>, name: &str, separator: &str) -> String {
match prefix {
Some(value) if !value.is_empty() => format!("{value}{separator}{name}"),
_ => name.to_string(),
}
}
pub(crate) fn receiver_from_target(target: &str, separator: char) -> Option<String> {
target
.rfind(separator)
.map(|idx| target[..idx].to_string())
.filter(|receiver| !receiver.is_empty())
}
pub(crate) fn extend_calls_if_any(
calls_by_func: &mut HashMap<String, Vec<CallSite>>,
caller: impl Into<String>,
calls: Vec<CallSite>,
) {
if calls.is_empty() {
return;
}
calls_by_func
.entry(caller.into())
.or_default()
.extend(calls);
}
pub(crate) fn insert_calls_if_any(
calls_by_func: &mut HashMap<String, Vec<CallSite>>,
caller: impl Into<String>,
calls: Vec<CallSite>,
) {
if calls.is_empty() {
return;
}
calls_by_func.insert(caller.into(), calls);
}