use super::pub_fns::PubFnInfo;
use super::workspace_graph::canonical_name_for_pub_fn;
use super::HandlerTouchpoints;
use crate::adapters::analyzers::architecture::compiled::CompiledCallParity;
use crate::adapters::analyzers::architecture::{MatchLocation, ViolationKind};
use std::collections::HashMap;
pub(crate) fn check_no_delegation<'ast>(
pub_fns_by_layer: &HashMap<String, Vec<PubFnInfo<'ast>>>,
touchpoints: &HandlerTouchpoints,
cp: &CompiledCallParity,
) -> Vec<MatchLocation> {
let mut out = Vec::new();
for adapter_layer in &cp.adapters {
let Some(fns) = pub_fns_by_layer.get(adapter_layer) else {
continue;
};
for info in fns {
if let Some(hit) = inspect_handler(info, adapter_layer, touchpoints, cp) {
out.push(hit);
}
}
}
out
}
fn inspect_handler(
info: &PubFnInfo<'_>,
adapter_layer: &str,
touchpoints: &HandlerTouchpoints,
cp: &CompiledCallParity,
) -> Option<MatchLocation> {
let canonical = canonical_name_for_pub_fn(info);
let tps = touchpoints.get(&canonical)?;
if !tps.is_empty() {
return None;
}
Some(MatchLocation {
file: info.file.clone(),
line: info.line,
column: 0,
kind: ViolationKind::CallParityNoDelegation {
fn_name: info.fn_name.clone(),
adapter_layer: adapter_layer.to_string(),
target_layer: cp.target.clone(),
call_depth: cp.call_depth,
},
})
}