codegraph_parser_api/entities/
class.rs1use super::function::FunctionEntity;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
6pub struct Field {
7 pub name: String,
9
10 pub type_annotation: Option<String>,
12
13 pub visibility: String,
15
16 pub is_static: bool,
18
19 pub is_constant: bool,
21
22 pub default_value: Option<String>,
24}
25
26impl Field {
27 pub fn new(name: impl Into<String>) -> Self {
28 Self {
29 name: name.into(),
30 type_annotation: None,
31 visibility: "public".to_string(),
32 is_static: false,
33 is_constant: false,
34 default_value: None,
35 }
36 }
37
38 pub fn with_type(mut self, type_ann: impl Into<String>) -> Self {
39 self.type_annotation = Some(type_ann.into());
40 self
41 }
42
43 pub fn with_visibility(mut self, vis: impl Into<String>) -> Self {
44 self.visibility = vis.into();
45 self
46 }
47
48 pub fn static_field(mut self) -> Self {
49 self.is_static = true;
50 self
51 }
52
53 pub fn constant(mut self) -> Self {
54 self.is_constant = true;
55 self
56 }
57
58 pub fn with_default(mut self, default: impl Into<String>) -> Self {
59 self.default_value = Some(default.into());
60 self
61 }
62}
63
64#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
66pub struct ClassEntity {
67 pub name: String,
69
70 pub visibility: String,
72
73 pub line_start: usize,
75
76 pub line_end: usize,
78
79 pub is_abstract: bool,
81
82 pub is_interface: bool,
84
85 pub base_classes: Vec<String>,
87
88 pub implemented_traits: Vec<String>,
90
91 pub methods: Vec<FunctionEntity>,
93
94 pub fields: Vec<Field>,
96
97 pub doc_comment: Option<String>,
99
100 pub attributes: Vec<String>,
102
103 pub type_parameters: Vec<String>,
105}
106
107impl ClassEntity {
108 pub fn new(name: impl Into<String>, line_start: usize, line_end: usize) -> Self {
109 Self {
110 name: name.into(),
111 visibility: "public".to_string(),
112 line_start,
113 line_end,
114 is_abstract: false,
115 is_interface: false,
116 base_classes: Vec::new(),
117 implemented_traits: Vec::new(),
118 methods: Vec::new(),
119 fields: Vec::new(),
120 doc_comment: None,
121 attributes: Vec::new(),
122 type_parameters: Vec::new(),
123 }
124 }
125
126 pub fn with_visibility(mut self, vis: impl Into<String>) -> Self {
127 self.visibility = vis.into();
128 self
129 }
130
131 pub fn abstract_class(mut self) -> Self {
132 self.is_abstract = true;
133 self
134 }
135
136 pub fn interface(mut self) -> Self {
137 self.is_interface = true;
138 self
139 }
140
141 pub fn with_bases(mut self, bases: Vec<String>) -> Self {
142 self.base_classes = bases;
143 self
144 }
145
146 pub fn with_traits(mut self, traits: Vec<String>) -> Self {
147 self.implemented_traits = traits;
148 self
149 }
150
151 pub fn with_methods(mut self, methods: Vec<FunctionEntity>) -> Self {
152 self.methods = methods;
153 self
154 }
155
156 pub fn with_fields(mut self, fields: Vec<Field>) -> Self {
157 self.fields = fields;
158 self
159 }
160
161 pub fn with_doc(mut self, doc: impl Into<String>) -> Self {
162 self.doc_comment = Some(doc.into());
163 self
164 }
165
166 pub fn with_attributes(mut self, attrs: Vec<String>) -> Self {
167 self.attributes = attrs;
168 self
169 }
170
171 pub fn with_type_parameters(mut self, type_params: Vec<String>) -> Self {
172 self.type_parameters = type_params;
173 self
174 }
175}