1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use analysis::{Description, Enum, Function};
use synthesis::{TestClass, TestFunction};
macro_rules! implement_conversion {
($t:ident) => {
impl EntityConversion for $t {
fn convert(entity_type: &mut EntityType) -> Option<&mut $t> {
match entity_type {
EntityType::$t(entity) => Some(entity),
_ => None,
}
}
}
};
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum EntityType {
Entity(Entity),
Enum(Enum),
Function(Function),
TestClass(TestClass),
TestFunction(TestFunction),
}
pub trait EntityConversion {
fn convert(entity_type: &mut EntityType) -> Option<&mut Self>;
}
implement_conversion!(Entity);
implement_conversion!(Enum);
implement_conversion!(Function);
implement_conversion!(TestClass);
implement_conversion!(TestFunction);
fn convert<T>(entity_type: &mut EntityType) -> Option<&mut T>
where
T: EntityConversion,
{
T::convert(entity_type)
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Entity {
pub name: String,
pub entities: Vec<EntityType>,
pub description: Option<Description>,
}
impl Entity {
pub fn new<S: Into<String>>(name: S) -> Self {
Self {
name: name.into(),
entities: Vec::new(),
description: None,
}
}
pub fn add_entity<T>(&mut self, entity: EntityType) -> Option<&mut T>
where
T: EntityConversion,
{
self.entities.push(entity);
if let Some(entity) = self.entities.last_mut() {
return convert(entity);
}
None
}
pub fn functions(&self) -> Vec<&Function> {
let mut entity_vec: Vec<&Function> = Vec::new();
for entity in &self.entities {
if let EntityType::Function(fct) = entity {
entity_vec.push(&fct);
}
}
return entity_vec;
}
pub fn set_description(&mut self, description: &str) {
if self.description.is_none() {
self.description = Some(Description::new());
}
if let Some(desc) = &mut self.description {
desc.set(description);
}
}
}