|
15 | 15 |
|
16 | 16 | use std::collections::BTreeSet; |
17 | 17 |
|
18 | | -use super::Errors; |
19 | | - |
20 | | -/// A single class-diagram entity such as a class, struct, enum, or interface. |
21 | | -#[derive(Debug, Clone, PartialEq)] |
22 | | -pub struct ClassDiagramEntityInput { |
23 | | - pub id: String, |
24 | | - pub name: Option<String>, |
25 | | - pub alias: Option<String>, |
26 | | - pub parent_id: Option<String>, |
27 | | - pub entity_type: String, |
28 | | - pub stereotypes: Vec<String>, |
29 | | - pub template_params: Vec<String>, |
30 | | - pub source_file: Option<String>, |
31 | | - pub source_line: u32, |
32 | | -} |
| 18 | +use class_diagram::ClassDiagram as ClassDiagramInput; |
33 | 19 |
|
34 | | -/// A relationship edge between two class-diagram entities. |
35 | | -#[derive(Debug, Clone, PartialEq)] |
36 | | -pub struct ClassDiagramRelationshipInput { |
37 | | - pub source: String, |
38 | | - pub target: String, |
39 | | - pub relation_type: String, |
40 | | - pub label: Option<String>, |
41 | | - pub stereotype: Option<String>, |
42 | | - pub source_multiplicity: Option<String>, |
43 | | - pub target_multiplicity: Option<String>, |
44 | | - pub source_role: Option<String>, |
45 | | - pub target_role: Option<String>, |
46 | | -} |
47 | | - |
48 | | -/// One parsed class diagram, including entities, containers, and |
49 | | -/// relationships. |
50 | | -#[derive(Debug, Clone, PartialEq)] |
51 | | -pub struct ClassDiagramInput { |
52 | | - pub name: String, |
53 | | - pub entities: Vec<ClassDiagramEntityInput>, |
54 | | - pub relationships: Vec<ClassDiagramRelationshipInput>, |
55 | | - pub source_files: Vec<String>, |
56 | | - pub version: Option<String>, |
57 | | -} |
| 20 | +use super::Errors; |
58 | 21 |
|
59 | 22 | /// Collection of class diagrams loaded from one or more FlatBuffer files. |
60 | | -#[derive(Debug, Clone, PartialEq)] |
61 | | -pub struct ClassDiagramInputs { |
62 | | - pub diagrams: Vec<ClassDiagramInput>, |
| 23 | +pub type ClassDiagramInputs = Vec<ClassDiagramInput>; |
| 24 | + |
| 25 | +/// Indexed class-diagram data prepared for validators. |
| 26 | +pub struct ClassDiagramIndex { |
| 27 | + observed_enclosing_namespace_ids: BTreeSet<String>, |
63 | 28 | } |
64 | 29 |
|
65 | | -impl ClassDiagramInputs { |
| 30 | +impl ClassDiagramIndex { |
66 | 31 | /// Build a [`ClassDiagramIndex`] from class diagram inputs. |
67 | | - pub fn to_class_diagram_index(&self, _errors: &mut Errors) -> ClassDiagramIndex { |
68 | | - let observed_namespace_names = self |
69 | | - .diagrams |
| 32 | + pub fn build_index(diagrams: &[ClassDiagramInput], _errors: &mut Errors) -> Self { |
| 33 | + let observed_enclosing_namespace_ids = diagrams |
70 | 34 | .iter() |
71 | 35 | .flat_map(|diagram| diagram.entities.iter()) |
72 | | - .filter_map(|entity| entity.parent_id.clone()) |
73 | | - .filter(|parent_id| !parent_id.is_empty()) |
| 36 | + .filter_map(|entity| entity.enclosing_namespace_id.clone()) |
| 37 | + .filter(|namespace_id| !namespace_id.is_empty()) |
74 | 38 | .collect(); |
75 | 39 |
|
76 | | - ClassDiagramIndex { |
77 | | - observed_namespace_names, |
| 40 | + Self { |
| 41 | + observed_enclosing_namespace_ids, |
78 | 42 | } |
79 | 43 | } |
80 | | -} |
81 | 44 |
|
82 | | -/// Indexed names derived from class-diagram entities. |
83 | | -#[derive(Clone)] |
84 | | -pub struct ClassDiagramIndex { |
85 | | - pub observed_namespace_names: BTreeSet<String>, |
| 45 | + pub fn enclosing_namespace_ids(&self) -> &BTreeSet<String> { |
| 46 | + &self.observed_enclosing_namespace_ids |
| 47 | + } |
86 | 48 | } |
0 commit comments