11use crate :: analyser:: core:: { AnalysableDataType , Analyser } ;
22use crate :: diagnostics:: diagnose:: Diagnose ;
33use crate :: diagnostics:: kinds:: DiagnosticKind ;
4- use tucana:: shared:: DataTypeIdentifier ;
5- use tucana:: shared:: data_type_identifier:: Type ;
64use tucana:: shared:: definition_data_type_rule:: Config ;
75
86impl Analyser {
@@ -17,13 +15,16 @@ impl Analyser {
1715 } ,
1816 ) ) ;
1917 }
20-
21- if dt. variant == 0 {
22- self . reporter . add ( Diagnose :: new (
23- dt. identifier . clone ( ) ,
24- adt. original_definition . clone ( ) ,
25- DiagnosticKind :: ForbiddenVariant ,
26- ) ) ;
18+ for linked in dt. linked_data_type_identifiers . clone ( ) {
19+ if !self . data_type_identifier_exists ( linked. as_str ( ) , None ) {
20+ self . reporter . add ( Diagnose :: new (
21+ dt. identifier . clone ( ) ,
22+ adt. original_definition . clone ( ) ,
23+ DiagnosticKind :: UndefinedDataTypeIdentifier {
24+ identifier : linked. clone ( ) ,
25+ } ,
26+ ) ) ;
27+ }
2728 }
2829
2930 if dt. alias . is_empty ( ) {
@@ -45,89 +46,27 @@ impl Analyser {
4546 } ,
4647 ) ) ;
4748 }
48- let mut detected: Vec < String > = vec ! [ ] ;
49+
50+ if dt. signature == "" {
51+ self . reporter . add ( Diagnose :: new (
52+ dt. identifier . clone ( ) ,
53+ adt. original_definition . clone ( ) ,
54+ DiagnosticKind :: NullField {
55+ field_name : "signature" . into ( ) ,
56+ } ,
57+ ) ) ;
58+ }
59+
4960 for optional_rule in & dt. rules {
5061 if let Some ( config) = & optional_rule. config {
5162 match config {
52- Config :: ContainsKey ( rule) => {
53- if let Some ( dti) = & rule. data_type_identifier {
54- self . walk_data_type_identifier ( adt, dti, & mut detected) ;
55- } else {
56- self . null_field ( "definition_data_type_contains_key_rule" . into ( ) , adt) ;
57- }
58- }
59- Config :: ContainsType ( rule) => {
60- if let Some ( dti) = & rule. data_type_identifier {
61- self . walk_data_type_identifier ( adt, dti, & mut detected) ;
62- } else {
63- self . null_field ( "definition_data_type_contains_type_rule" . into ( ) , adt) ;
64- }
65- }
66- Config :: ItemOfCollection ( rule) => {
67- if rule. items . is_empty ( ) {
68- self . null_field (
69- "definition_data_type_item_of_collection_rule" . into ( ) ,
70- adt,
71- ) ;
72- }
73- }
7463 Config :: NumberRange ( _) | Config :: Regex ( _) => { }
75- Config :: InputTypes ( rule) => {
76- if rule. input_types . is_empty ( ) {
77- self . null_field ( "definition_data_type_input_types_rule" . into ( ) , adt) ;
78- }
79- for input in & rule. input_types {
80- if let Some ( dti) = & input. data_type_identifier {
81- self . walk_data_type_identifier ( adt, dti, & mut detected) ;
82- } else {
83- self . reporter . add ( Diagnose :: new (
84- dt. identifier . clone ( ) ,
85- adt. original_definition . clone ( ) ,
86- DiagnosticKind :: UndefinedDataTypeIdentifier {
87- identifier : dt. identifier . clone ( ) ,
88- } ,
89- ) ) ;
90- }
91- }
92- }
93- Config :: ReturnType ( rule) => {
94- if let Some ( dti) = & rule. data_type_identifier {
95- self . walk_data_type_identifier ( adt, dti, & mut detected) ;
96- } else {
97- self . null_field ( "definition_data_type_return_type_rule" . into ( ) , adt) ;
98- }
99- }
100- Config :: ParentType ( rule) => {
101- if let Some ( dti) = & rule. parent_type {
102- self . walk_data_type_identifier ( adt, dti, & mut detected) ;
103- } else {
104- self . null_field ( "definition_data_type_parent_type_rule" . into ( ) , adt) ;
105- }
106- }
10764 }
10865 } else {
10966 self . null_field ( "rule" . into ( ) , adt) ;
11067 }
11168 }
11269
113- for key in dt. generic_keys . iter ( ) . filter ( |k| !detected. contains ( k) ) {
114- self . reporter . add ( Diagnose :: new (
115- dt. identifier . clone ( ) ,
116- adt. original_definition . clone ( ) ,
117- DiagnosticKind :: UnusedGenericKey { key : key. clone ( ) } ,
118- ) ) ;
119- }
120- for key in detected
121- . into_iter ( )
122- . filter ( |k| !dt. generic_keys . contains ( k) )
123- {
124- self . reporter . add ( Diagnose :: new (
125- dt. identifier . clone ( ) ,
126- adt. original_definition . clone ( ) ,
127- DiagnosticKind :: UndefinedGenericKey { key } ,
128- ) ) ;
129- }
130-
13170 if dt. name . is_empty ( ) {
13271 self . reporter . add ( Diagnose :: new (
13372 dt. identifier . clone ( ) ,
@@ -138,62 +77,4 @@ impl Analyser {
13877 ) ) ;
13978 }
14079 }
141-
142- fn walk_data_type_identifier (
143- & mut self ,
144- adt : & AnalysableDataType ,
145- dti : & DataTypeIdentifier ,
146- acc : & mut Vec < String > ,
147- ) {
148- if let Some ( t) = & dti. r#type {
149- match t {
150- Type :: DataTypeIdentifier ( identifier) => {
151- if !self . data_type_identifier_exists ( identifier, Some ( adt. id ) ) {
152- self . reporter . add ( Diagnose :: new (
153- adt. definition_data_type . identifier . clone ( ) ,
154- adt. original_definition . clone ( ) ,
155- DiagnosticKind :: UndefinedDataTypeIdentifier {
156- identifier : identifier. clone ( ) ,
157- } ,
158- ) ) ;
159- }
160- }
161- Type :: GenericType ( generic) => {
162- if !self
163- . data_type_identifier_exists ( & generic. data_type_identifier , Some ( adt. id ) )
164- {
165- self . reporter . add ( Diagnose :: new (
166- adt. definition_data_type . identifier . clone ( ) ,
167- adt. original_definition . clone ( ) ,
168- DiagnosticKind :: UndefinedDataTypeIdentifier {
169- identifier : generic. data_type_identifier . clone ( ) ,
170- } ,
171- ) ) ;
172- }
173- if generic. generic_mappers . is_empty ( ) {
174- self . reporter . add ( Diagnose :: new (
175- adt. definition_data_type . identifier . clone ( ) ,
176- adt. original_definition . clone ( ) ,
177- DiagnosticKind :: EmptyGenericMapper ,
178- ) ) ;
179- }
180- for mapper in & generic. generic_mappers {
181- if adt
182- . definition_data_type
183- . generic_keys
184- . contains ( & mapper. target )
185- {
186- acc. push ( mapper. target . clone ( ) ) ;
187- }
188- for source in & mapper. source {
189- self . walk_data_type_identifier ( adt, source, acc) ;
190- }
191- }
192- }
193- Type :: GenericKey ( key) => acc. push ( key. clone ( ) ) ,
194- }
195- } else {
196- self . null_field ( "data_type" . into ( ) , adt) ;
197- }
198- }
19980}
0 commit comments