From 92ed559baf01166f36d0a64909f328b59e195416 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sun, 28 Feb 2021 10:46:44 +0800 Subject: [PATCH] feat(uml): add support for array --- .../src/plantuml_render.rs | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/plugins/coco_struct_analysis/src/plantuml_render.rs b/plugins/coco_struct_analysis/src/plantuml_render.rs index 47295343..a31a8baa 100644 --- a/plugins/coco_struct_analysis/src/plantuml_render.rs +++ b/plugins/coco_struct_analysis/src/plantuml_render.rs @@ -62,7 +62,11 @@ impl PlantUmlRender { method.access, method.return_type, method.name )); - dep_map.insert(method.return_type.clone(), clazz.name.clone()); + if method.pure_return_type.len() > 0 { + dep_map.insert(method.pure_return_type.clone(), clazz.name.clone()); + } else { + dep_map.insert(method.return_type.clone(), clazz.name.clone()); + } } } methods @@ -79,7 +83,11 @@ impl PlantUmlRender { member.access, member.data_type, member.name )); - dep_map.insert(member.data_type.clone(), clazz.name.clone()); + if member.data_type.len() > 0 { + dep_map.insert(member.data_type.clone(), clazz.name.clone()); + } else { + dep_map.insert(member.data_type.clone(), clazz.name.clone()); + } } } members @@ -165,4 +173,22 @@ mod tests { str ); } + + #[test] + fn should_render_array() { + let mut classes = vec![]; + let mut demo = ClassInfo::new("Demo"); + let demo2 = ClassInfo::new("Demo2"); + + let mut method = MethodInfo::new("method", "-", "[]Demo2".to_string()); + method.pure_return_type = "Demo2".to_string(); + demo.methods.push(method); + + classes.push(demo); + classes.push(demo2); + + let str = PlantUmlRender::render(&classes); + assert_eq!(true, str.contains("Demo -- Demo2")); + assert_eq!(false, str.contains("Demo -- String")); + } }