Refactoring sequence diagrams test cases (#266)

This commit is contained in:
Bartek Kryza
2024-05-20 00:09:30 +02:00
parent 7c1e0420c6
commit 4b5cfa7b48
47 changed files with 300 additions and 2709 deletions

View File

@@ -40,6 +40,8 @@ void to_json(nlohmann::json &j, const participant &c)
j["name"] = dynamic_cast<const method &>(c).method_name();
}
j["full_name"] = c.full_name(false);
if (c.type_name() == "function" || c.type_name() == "function_template") {
const auto &f = dynamic_cast<const function &>(c);
if (f.is_cuda_kernel())
@@ -172,7 +174,7 @@ void generator::generate_call(const message &m, nlohmann::json &parent) const
dynamic_cast<const clanguml::common::model::source_location &>(m);
msg["scope"] = to_string(m.message_scope());
msg["return_type"] = m.return_type();
msg["return_type"] = config().simplify_template_type(m.return_type());
parent["messages"].push_back(std::move(msg));
@@ -568,6 +570,12 @@ common::id_t generator::generate_participant(
.value()
.class_id();
LOG_DBG("Generating JSON method participant: {}",
model()
.get_participant<model::method>(participant_id)
.value()
.full_name(false));
if (!is_participant_generated(class_participant_id)) {
const auto &class_participant =
model()
@@ -580,6 +588,13 @@ common::id_t generator::generate_participant(
json_["participants"].push_back(class_participant);
json_["participants"].back()["activities"].push_back(participant);
// Perform config dependent postprocessing on generated class
const auto class_participant_full_name =
class_participant.full_name(false);
json_["participants"].back().at("display_name") =
make_display_name(class_participant_full_name);
return class_participant_id;
}
@@ -807,7 +822,8 @@ void generator::generate_diagram(nlohmann::json &parent) const
if (from.value().type_name() == "method" ||
config().combine_free_functions_into_file_participants()) {
sequence["return_type"] = from.value().return_type();
sequence["return_type"] =
make_display_name(from.value().return_type());
}
parent["sequences"].push_back(std::move(sequence));
@@ -821,11 +837,21 @@ void generator::generate_diagram(nlohmann::json &parent) const
// Perform config dependent postprocessing on generated participants
for (auto &p : json_["participants"]) {
if (p.contains("display_name")) {
p["display_name"] =
config().simplify_template_type(p["display_name"]);
p["display_name"] = make_display_name(p["display_name"]);
}
}
parent["participants"] = json_["participants"];
}
std::string generator::make_display_name(const std::string &full_name) const
{
auto result = config().simplify_template_type(full_name);
result = config().using_namespace().relative(result);
common::ensure_lambda_type_is_relative(config(), result);
result = render_name(result);
return result;
}
} // namespace clanguml::sequence_diagram::generators::json

View File

@@ -111,6 +111,8 @@ public:
*/
nlohmann::json &current_block_statement() const;
std::string make_display_name(const std::string &full_name) const;
private:
/**
* @brief Check if specified participant has already been generated.

View File

@@ -388,8 +388,11 @@ void generator::generate_participant(
print_debug(class_participant, ostr);
auto participant_name =
config().using_namespace().relative(config().simplify_template_type(
class_participant.full_name(false)));
config().simplify_template_type(
class_participant.full_name(false));
participant_name =
config().using_namespace().relative(participant_name);
common::ensure_lambda_type_is_relative(config(), participant_name);
ostr << "participant \"" << render_name(participant_name) << "\" as "
@@ -531,8 +534,7 @@ void generator::generate_diagram(std::ostream &ostr) const
if (from.value().type_name() == "method" ||
config().combine_free_functions_into_file_participants()) {
generate_participant(ostr, from_activity_id);
ostr << "[->"
<< " " << generate_alias(from.value()) << " : "
ostr << "[->" << " " << generate_alias(from.value()) << " : "
<< from.value().message_name(
select_method_arguments_render_mode())
<< '\n';
@@ -571,8 +573,7 @@ void generator::generate_diagram(std::ostream &ostr) const
if (from.value().type_name() == "method" ||
config().combine_free_functions_into_file_participants()) {
generate_participant(ostr, from_activity_id);
ostr << "[->"
<< " " << generate_alias(from.value()) << " : "
ostr << "[->" << " " << generate_alias(from.value()) << " : "
<< from.value().message_name(
select_method_arguments_render_mode())
<< '\n';
@@ -636,8 +637,7 @@ void generator::generate_diagram(std::ostream &ostr) const
// first activity for this 'start_from' condition
if (from.value().type_name() == "method" ||
config().combine_free_functions_into_file_participants()) {
ostr << "[->"
<< " " << from_alias << " : "
ostr << "[->" << " " << from_alias << " : "
<< from.value().message_name(render_mode) << '\n';
}
@@ -650,8 +650,7 @@ void generator::generate_diagram(std::ostream &ostr) const
config().combine_free_functions_into_file_participants()) {
if (!from.value().is_void()) {
ostr << "[<--"
<< " " << from_alias;
ostr << "[<--" << " " << from_alias;
if (config().generate_return_types())
ostr << " : //" << from.value().return_type() << "//";