use anyhow::Result;
use std::path::Path;
pub trait LanguageAnalyzer: Send + Sync {
fn analyze_file(&self, path: &Path, content: &str) -> Result<crate::core::FileMetrics>;
fn language(&self) -> crate::core::Language;
fn can_handle(&self, path: &Path) -> bool {
crate::core::Language::from_path(path) == self.language()
}
}
pub trait CallGraphAnalyzer: Send + Sync {
fn build_call_graph(&self, content: &str, path: &Path) -> Result<CallGraph>;
fn find_dependencies(&self, function: &str, graph: &CallGraph) -> Vec<String>;
}
#[derive(Debug, Clone)]
pub struct CallGraph {
pub nodes: Vec<CallNode>,
pub edges: Vec<CallEdge>,
}
#[derive(Debug, Clone)]
pub struct CallNode {
pub name: String,
pub file: std::path::PathBuf,
pub line: usize,
}
#[derive(Debug, Clone)]
pub struct CallEdge {
pub from: String,
pub to: String,
pub call_type: CallType,
}
#[derive(Debug, Clone)]
pub enum CallType {
Direct,
Trait,
Generic,
Closure,
}
pub trait TypeTracker: Send + Sync {
fn track_type(&mut self, symbol: &str, type_info: TypeInfo);
fn get_type(&self, symbol: &str) -> Option<&TypeInfo>;
fn clear(&mut self);
}
#[derive(Debug, Clone)]
pub struct TypeInfo {
pub name: String,
pub kind: TypeKind,
pub generic_params: Vec<String>,
}
#[derive(Debug, Clone)]
pub enum TypeKind {
Struct,
Enum,
Trait,
Function,
Primitive,
Generic,
}
pub trait TestDetector: Send + Sync {
fn is_test_function(&self, name: &str, attributes: &[String]) -> bool;
fn is_test_module(&self, path: &Path) -> bool;
fn extract_test_metadata(&self, content: &str) -> TestMetadata;
}
#[derive(Debug, Clone, Default)]
pub struct TestMetadata {
pub test_count: usize,
pub assertion_count: usize,
pub has_setup: bool,
pub has_teardown: bool,
pub test_frameworks: Vec<String>,
}
pub trait PurityAnalyzer: Send + Sync {
fn is_pure(&self, function: &str, body: &str) -> (bool, f32);
fn find_side_effects(&self, body: &str) -> Vec<SideEffect>;
}
#[derive(Debug, Clone)]
pub struct SideEffect {
pub kind: SideEffectKind,
pub location: usize,
pub description: String,
}
#[derive(Debug, Clone)]
pub enum SideEffectKind {
IO,
Mutation,
GlobalState,
ExternalCall,
Unsafe,
}