Skip to main content

cha_core/
model.rs

1/// Extracted function info from AST.
2#[derive(Debug, Clone)]
3pub struct FunctionInfo {
4    pub name: String,
5    pub start_line: usize,
6    pub end_line: usize,
7    pub line_count: usize,
8    /// Cyclomatic complexity (1 + number of branch points).
9    pub complexity: usize,
10    /// Hash of the function body AST structure for duplicate detection.
11    pub body_hash: Option<u64>,
12    /// Whether this function is exported (pub/export).
13    pub is_exported: bool,
14    /// Number of parameters.
15    pub parameter_count: usize,
16    /// Names of external identifiers referenced in the body (for Feature Envy).
17    pub external_refs: Vec<String>,
18    /// Max method chain depth in the body (for Message Chains).
19    pub chain_depth: usize,
20    /// Number of switch/match arms (for Switch Statements).
21    pub switch_arms: usize,
22    /// Whether this function only delegates to another object's method (for Middle Man).
23    pub is_delegating: bool,
24    /// Sorted parameter type names (for Data Clumps / Primitive Obsession).
25    pub parameter_types: Vec<String>,
26    /// Number of comment lines in the function body.
27    pub comment_lines: usize,
28    /// Field names referenced in this function body (for Temporary Field).
29    pub referenced_fields: Vec<String>,
30    /// Field names checked for null/None in this function (for Null Object pattern).
31    pub null_check_fields: Vec<String>,
32    /// The field/variable name being dispatched on in switch/match (for Strategy/State).
33    pub switch_dispatch_target: Option<String>,
34    /// Number of optional parameters (for Builder pattern).
35    pub optional_param_count: usize,
36    /// Names of functions/methods called in this function body (for call graph).
37    pub called_functions: Vec<String>,
38    /// Cognitive complexity score [SonarSource 2017] — nesting-aware understandability metric.
39    pub cognitive_complexity: usize,
40}
41
42/// Extracted class/struct info from AST.
43#[derive(Debug, Clone)]
44pub struct ClassInfo {
45    pub name: String,
46    pub start_line: usize,
47    pub end_line: usize,
48    pub method_count: usize,
49    pub line_count: usize,
50    /// Whether this class is exported.
51    pub is_exported: bool,
52    /// Number of methods that only delegate to another object.
53    pub delegating_method_count: usize,
54    /// Number of fields/properties.
55    pub field_count: usize,
56    /// Field names declared in this class.
57    pub field_names: Vec<String>,
58    /// Field types (parallel to field_names).
59    pub field_types: Vec<String>,
60    /// Whether the class has non-accessor methods (business logic).
61    pub has_behavior: bool,
62    /// Whether this is an interface or abstract class.
63    pub is_interface: bool,
64    /// Parent class/trait name (for Refused Bequest).
65    pub parent_name: Option<String>,
66    /// Number of overridden methods (for Refused Bequest).
67    pub override_count: usize,
68    /// Number of self-method calls in the longest method (for Template Method).
69    pub self_call_count: usize,
70    /// Whether the class has a listener/callback collection field.
71    pub has_listener_field: bool,
72    /// Whether the class has a notify/emit method.
73    pub has_notify_method: bool,
74}
75
76/// Extracted import info.
77#[derive(Debug, Clone)]
78pub struct ImportInfo {
79    pub source: String,
80    pub line: usize,
81}
82
83/// A comment extracted from source code by the language parser.
84#[derive(Debug, Clone)]
85pub struct CommentInfo {
86    pub text: String,
87    pub line: usize,
88}
89
90/// Unified source model produced by parsing.
91#[derive(Debug, Clone)]
92pub struct SourceModel {
93    pub language: String,
94    pub total_lines: usize,
95    pub functions: Vec<FunctionInfo>,
96    pub classes: Vec<ClassInfo>,
97    pub imports: Vec<ImportInfo>,
98    pub comments: Vec<CommentInfo>,
99    /// Type aliases: (alias, original). e.g. typedef, using, type =
100    pub type_aliases: Vec<(String, String)>,
101}