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