diff --git a/bazel/rules/rules_score/examples/seooc/design/dynamic_design.puml b/bazel/rules/rules_score/examples/seooc/design/dynamic_design.puml index 5fe8e442..4d364ecd 100644 --- a/bazel/rules/rules_score/examples/seooc/design/dynamic_design.puml +++ b/bazel/rules/rules_score/examples/seooc/design/dynamic_design.puml @@ -13,8 +13,8 @@ @startuml -participant "Unit 1" as unit_1 <> -participant "Unit 2" as unit_2 <> +participant "Unit 1 : safety_software_seooc_example::component_example::unit_1" as unit_1 <> +participant "Unit 2 : safety_software_seooc_example::component_example::unit_2" as unit_2 <> unit_1 -> unit_2 : GetData() return Data* diff --git a/bazel/rules/rules_score/examples/seooc/design/public_api.puml b/bazel/rules/rules_score/examples/seooc/design/public_api.puml index 61818294..760db8e3 100644 --- a/bazel/rules/rules_score/examples/seooc/design/public_api.puml +++ b/bazel/rules/rules_score/examples/seooc/design/public_api.puml @@ -13,10 +13,8 @@ @startuml -namespace safety_software_seooc_example { - interface "SampleLibraryAPI" as SampleLibraryAPI { - + GetNumber(): int - } +interface "SampleLibraryAPI" as SampleLibraryAPI <> { + + GetNumber(): int } @enduml diff --git a/bazel/rules/rules_score/examples/seooc/design/static_design.puml b/bazel/rules/rules_score/examples/seooc/design/static_design.puml index 1bb80210..ef85542f 100644 --- a/bazel/rules/rules_score/examples/seooc/design/static_design.puml +++ b/bazel/rules/rules_score/examples/seooc/design/static_design.puml @@ -21,7 +21,7 @@ package "Safety Software SEooC Example" as safety_software_seooc_example <, + + /// Resolver root anchor for IDs emitted by this parser (internal use only) + #[arg(long, hide = true, default_value = "")] + root_anchor: String, } #[derive(Default)] @@ -210,6 +214,37 @@ fn serialize_class_diagram( Ok(()) } +fn apply_root_anchor( + entities: &mut BTreeMap, + free_functions: &mut [FreeFunctionDecl], + root_anchor: &str, +) { + if root_anchor.is_empty() { + return; + } + + let mut anchored_entities = BTreeMap::new(); + for (_, mut entity) in std::mem::take(entities) { + entity.id = format!("{root_anchor}::{}", entity.id); + entity.enclosing_namespace_id = entity + .enclosing_namespace_id + .map(|namespace| format!("{root_anchor}::{namespace}")); + for relationship in &mut entity.relationships { + relationship.source = format!("{root_anchor}::{}", relationship.source); + relationship.target = format!("{root_anchor}::{}", relationship.target); + } + anchored_entities.insert(entity.id.clone(), entity); + } + *entities = anchored_entities; + + for free_function in free_functions { + free_function.enclosing_namespace_id = Some(match &free_function.enclosing_namespace_id { + Some(namespace) if !namespace.is_empty() => format!("{root_anchor}::{namespace}"), + _ => root_anchor.to_string(), + }); + } +} + fn ensure_output_parent_exists(path: &Path) -> Result<(), std::io::Error> { if let Some(parent) = path.parent() { fs::create_dir_all(parent)?; @@ -251,6 +286,11 @@ fn main() -> Result<(), Box> { ); } + apply_root_anchor( + &mut outputs.types, + &mut outputs.free_function_declarations, + &command_line_args.root_anchor, + ); if let Some(debug_json_output) = &command_line_args.debug_json_output { write_debug_json( debug_json_output, @@ -260,7 +300,6 @@ fn main() -> Result<(), Box> { &outputs.functions, )?; } - serialize_class_diagram( &command_line_args.class_fbs_output, outputs.types, diff --git a/plantuml/parser/integration_test/class_diagram/class_diagram_file_level_constructs/output.json b/plantuml/parser/integration_test/class_diagram/class_diagram_file_level_constructs/output.json index b58281b6..3fb46826 100644 --- a/plantuml/parser/integration_test/class_diagram/class_diagram_file_level_constructs/output.json +++ b/plantuml/parser/integration_test/class_diagram/class_diagram_file_level_constructs/output.json @@ -70,7 +70,7 @@ } }, { - "id": "sample.file_level.<