@@ -6,7 +6,7 @@ use tucana::shared::definition_data_type_rule::Config;
66use code0_definition_reader:: parser:: Parser ;
77use code0_definition_reader:: reader:: { MetaType , ParsableDefinition , Reader } ;
88use crate :: analyser:: diagnostics:: { Diagnose , DiagnosticKind , Reporter } ;
9- use crate :: analyser:: diagnostics:: DiagnosticKind :: { DuplicateDataTypeIdentifier , NullField , UndefinedDataTypeIdentifier , UndefinedGenericKey , UndefinedTranslation , UnusedGenericKey } ;
9+ use crate :: analyser:: diagnostics:: DiagnosticKind :: { DuplicateDataTypeIdentifier , DuplicateFlowTypeIdentifier , NullField , UndefinedDataTypeIdentifier , UndefinedGenericKey , UndefinedTranslation , UnusedGenericKey } ;
1010
1111#[ derive( Clone ) ]
1212pub struct AnalysableDataType {
@@ -15,6 +15,7 @@ pub struct AnalysableDataType {
1515 pub id : i16
1616}
1717
18+ #[ derive( Clone ) ]
1819pub struct AnalysableFlowType {
1920 pub original_definition : ParsableDefinition ,
2021 pub flow_type : FlowType ,
@@ -329,6 +330,76 @@ impl Analyser {
329330 }
330331 }
331332
333+ pub fn analyse_flow_type ( & mut self , analysable_flow_type : AnalysableFlowType ) {
334+ let flow= analysable_flow_type. flow_type . clone ( ) ;
335+ let original_definition = analysable_flow_type. original_definition ;
336+ let name = flow. identifier ;
337+
338+ // Check if at least one Translation is present
339+ if flow. name . is_empty ( ) {
340+ self . reporter . add_report ( Diagnose :: new (
341+ name. clone ( ) ,
342+ original_definition. clone ( ) ,
343+ UndefinedTranslation { translation_field : String :: from ( "name" ) }
344+ ) ) ;
345+ }
346+
347+ if flow. description . is_empty ( ) {
348+ self . reporter . add_report ( Diagnose :: new (
349+ name. clone ( ) ,
350+ original_definition. clone ( ) ,
351+ UndefinedTranslation { translation_field : String :: from ( "description" ) }
352+ ) ) ;
353+ }
354+
355+ if flow. documentation . is_empty ( ) {
356+ self . reporter . add_report ( Diagnose :: new (
357+ name. clone ( ) ,
358+ original_definition. clone ( ) ,
359+ UndefinedTranslation { translation_field : String :: from ( "documentation" ) }
360+ ) ) ;
361+ }
362+
363+ // Check if input identifier exists
364+ if let Some ( identifier) = flow. input_type_identifier {
365+ if !self . data_type_identifier_exists ( identifier. clone ( ) , -1 ) {
366+ self . reporter . add_report ( Diagnose :: new (
367+ name. clone ( ) ,
368+ original_definition. clone ( ) ,
369+ UndefinedDataTypeIdentifier { identifier}
370+ ) ) ;
371+ }
372+ }
373+
374+ // Check if return identifier exists
375+ if let Some ( identifier) = flow. return_type_identifier {
376+ if !self . data_type_identifier_exists ( identifier. clone ( ) , -1 ) {
377+ self . reporter . add_report ( Diagnose :: new (
378+ name. clone ( ) ,
379+ original_definition. clone ( ) ,
380+ UndefinedDataTypeIdentifier { identifier}
381+ ) ) ;
382+ }
383+ }
384+
385+ // Check if flow type identifier already exists
386+ for flow_type in & self . flow_types {
387+ if analysable_flow_type. id == flow_type. id {
388+ continue
389+ }
390+
391+ if flow_type. flow_type . identifier . to_lowercase ( ) == name. clone ( ) . to_lowercase ( ) {
392+ self . reporter . add_report ( Diagnose :: new (
393+ name. clone ( ) ,
394+ original_definition. clone ( ) ,
395+ DuplicateFlowTypeIdentifier { identifier : name }
396+ ) ) ;
397+ break ;
398+ }
399+ }
400+
401+ }
402+
332403 pub fn report ( & self ) {
333404 self . reporter . run_report ( )
334405 }
0 commit comments