1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7pub struct EventSubscription {
8 pub subscriber: String,
10 pub event_type: String,
12 pub file_path: String,
14 pub line: usize,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
20pub struct EventPublication {
21 pub publisher: String,
23 pub event_type: String,
25 pub file_path: String,
27 pub line: usize,
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct FileAnalysis {
34 pub path: String,
36 pub subscriptions: Vec<EventSubscription>,
38 pub publications: Vec<EventPublication>,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
44pub struct SystemInfo {
45 pub name: String,
47 pub module_path: String,
49 pub file_path: String,
51 pub subscribes: Vec<String>,
53 pub publishes: Vec<String>,
55 pub hooks: Vec<String>,
57 pub states: Vec<String>,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
63pub enum HookCategory {
64 Notification,
66 Validation,
68 Lifecycle,
70 Calculation,
72 Generation,
74 Other,
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct HookMethod {
81 pub name: String,
83 pub category: HookCategory,
85 pub params: Vec<String>,
87 pub return_type: String,
89 pub has_default_impl: bool,
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct HookInfo {
96 pub trait_name: String,
98 pub module_path: String,
100 pub file_path: String,
102 pub methods: Vec<HookMethod>,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct HookCall {
109 pub hook_trait: String,
111 pub method_name: String,
113 pub caller: String,
115 pub file_path: String,
117 pub line: usize,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize)]
123pub struct PluginInfo {
124 pub name: String,
126 pub path: String,
128 pub system: Option<SystemInfo>,
130 pub hooks: Vec<String>,
132 pub events: Vec<String>,
134 pub hook_details: Vec<HookInfo>,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
140pub struct AnalysisResult {
141 pub files: Vec<FileAnalysis>,
143 pub systems: Vec<SystemInfo>,
145 pub plugins: Vec<PluginInfo>,
147}
148
149impl AnalysisResult {
150 pub fn new() -> Self {
152 Self {
153 files: Vec::new(),
154 systems: Vec::new(),
155 plugins: Vec::new(),
156 }
157 }
158
159 pub fn add_file(&mut self, analysis: FileAnalysis) {
161 self.files.push(analysis);
162 }
163
164 pub fn add_system(&mut self, system: SystemInfo) {
166 self.systems.push(system);
167 }
168
169 pub fn add_plugin(&mut self, plugin: PluginInfo) {
171 self.plugins.push(plugin);
172 }
173
174 pub fn all_subscriptions(&self) -> Vec<&EventSubscription> {
176 self.files
177 .iter()
178 .flat_map(|f| f.subscriptions.iter())
179 .collect()
180 }
181
182 pub fn all_publications(&self) -> Vec<&EventPublication> {
184 self.files
185 .iter()
186 .flat_map(|f| f.publications.iter())
187 .collect()
188 }
189
190 pub fn event_types(&self) -> Vec<String> {
192 let mut types: Vec<String> = self
193 .all_subscriptions()
194 .iter()
195 .map(|s| s.event_type.clone())
196 .chain(self.all_publications().iter().map(|p| p.event_type.clone()))
197 .collect();
198
199 types.sort();
200 types.dedup();
201 types
202 }
203}
204
205impl Default for AnalysisResult {
206 fn default() -> Self {
207 Self::new()
208 }
209}