mod cycles;
mod graph;
pub(crate) mod metrics;
pub(crate) mod sdp;
#[derive(Debug, Clone, Default)]
pub struct ModuleGraph {
pub modules: Vec<String>,
pub forward: Vec<Vec<usize>>,
}
#[derive(Debug, Clone)]
pub struct CouplingMetrics {
pub module_name: String,
pub afferent: usize,
pub efferent: usize,
pub instability: f64,
pub incoming: Vec<String>,
pub outgoing: Vec<String>,
pub suppressed: bool,
pub warning: bool,
}
#[derive(Debug, Clone)]
pub struct CycleReport {
pub modules: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct CouplingAnalysis {
pub metrics: Vec<CouplingMetrics>,
pub cycles: Vec<CycleReport>,
pub sdp_violations: Vec<sdp::SdpViolation>,
pub graph: ModuleGraph,
}
pub fn analyze_coupling(parsed: &[(String, String, syn::File)]) -> CouplingAnalysis {
let graph = graph::build_module_graph(parsed);
let metrics = metrics::compute_coupling_metrics(&graph);
let cycles = cycles::detect_cycles(&graph);
CouplingAnalysis {
metrics,
cycles,
sdp_violations: Vec::new(),
graph,
}
}
pub fn populate_sdp_violations(analysis: &mut CouplingAnalysis) {
analysis.sdp_violations = sdp::check_sdp(&analysis.graph, &analysis.metrics);
}
#[cfg(test)]
mod tests;