Skip to content

Commit

Permalink
feat(uml): add extends support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 28, 2021
1 parent 061b1e2 commit 673b5ba
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions plugins/coco_struct_analysis/src/plantuml_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ impl PlantUmlRender {
let methods = PlantUmlRender::render_method(&clazz, &mut dep_map);

let content = format!("{}{}", members.join(""), methods.join(""));
rendered.push(format!("class {} {{\n{}}}", clazz.name, content));
let mut class_field = clazz.name.clone();
if clazz.parents.len() > 0 {
class_field = format!("{} extends {}", clazz.name, clazz.parents.join(","));
}

rendered.push(format!("class {} {{\n{}}}", class_field, content));

for (callee, current_clz) in dep_map {
if callee == current_clz {
Expand All @@ -35,7 +40,7 @@ impl PlantUmlRender {
continue;
}

deps.push(format!("{} --> {}\n", current_clz, callee));
deps.push(format!("{} -- {}\n", current_clz, callee));
}
}

Expand Down Expand Up @@ -139,7 +144,25 @@ mod tests {
classes.push(demo2);

let str = PlantUmlRender::render(&classes);
assert_eq!(true, str.contains("Demo --> Demo2"));
assert_eq!(false, str.contains("Demo --> String"));
assert_eq!(true, str.contains("Demo -- Demo2"));
assert_eq!(false, str.contains("Demo -- String"));
}

#[test]
fn should_render_parents() {
let mut classes = vec![];
let mut demo = ClassInfo::new("Demo");
let demo2 = ClassInfo::new("Demo2");

demo.parents.push(demo2.name.clone());

classes.push(demo);
classes.push(demo2);

let str = PlantUmlRender::render(&classes);
assert_eq!(
"@startuml\n\nclass Demo extends Demo2 {\n}\n\nclass Demo2 {\n}\n\n@enduml",
str
);
}
}

0 comments on commit 673b5ba

Please sign in to comment.