Refactored class, package and include diagram test cases (#266)

This commit is contained in:
Bartek Kryza
2024-05-14 11:39:07 +02:00
parent eeae5caef5
commit 27eaea5bbe
105 changed files with 660 additions and 4427 deletions

View File

@@ -247,18 +247,33 @@ void generator::generate(const package &p, nlohmann::json &parent) const
void generator::generate(const class_ &c, nlohmann::json &parent) const
{
nlohmann::json object = c;
if (!config().generate_fully_qualified_name())
object["display_name"] =
common::generators::json::render_name(c.full_name_no_ns());
parent["elements"].push_back(std::move(object));
}
void generator::generate(const enum_ &e, nlohmann::json &parent) const
{
nlohmann::json object = e;
if (!config().generate_fully_qualified_name())
object["display_name"] =
common::generators::json::render_name(e.full_name_no_ns());
parent["elements"].push_back(std::move(object));
}
void generator::generate(const concept_ &c, nlohmann::json &parent) const
{
nlohmann::json object = c;
if (!config().generate_fully_qualified_name())
object["display_name"] =
common::generators::json::render_name(c.full_name_no_ns());
parent["elements"].push_back(std::move(object));
}

View File

@@ -281,7 +281,8 @@ void generator::generate_member(
void generator::generate(const concept_ &c, std::ostream &ostr) const
{
ostr << indent(1) << "class" << " " << c.alias();
ostr << indent(1) << "class"
<< " " << c.alias();
ostr << " {" << '\n';
ostr << indent(2) << "<<concept>>\n";
@@ -299,7 +300,8 @@ void generator::generate(const concept_ &c, std::ostream &ostr) const
<< fmt::format("\"({})\"\n", fmt::join(parameters, ","));
for (const auto &req : c.requires_statements()) {
ostr << indent(2) << fmt::format("\"{}\"\n", render_name(req));
ostr << indent(2)
<< fmt::format("\"{}\"\n", render_name(req, false));
}
}

View File

@@ -67,7 +67,7 @@ void generator::generate_alias(const class_ &c, std::ostream &ostr) const
class_type = "abstract";
std::string full_name;
if (config().generate_fully_qualified_name())
if (!config().generate_fully_qualified_name())
full_name = c.full_name_no_ns();
else
full_name = c.full_name();
@@ -89,7 +89,7 @@ void generator::generate_alias(const enum_ &e, std::ostream &ostr) const
{
print_debug(e, ostr);
if (config().generate_fully_qualified_name())
if (!config().generate_fully_qualified_name())
ostr << "enum"
<< " \"" << e.name();
else
@@ -106,7 +106,7 @@ void generator::generate_alias(const concept_ &c, std::ostream &ostr) const
{
print_debug(c, ostr);
if (config().generate_fully_qualified_name())
if (!config().generate_fully_qualified_name())
ostr << "class"
<< " \"" << c.full_name_no_ns();
else

View File

@@ -46,7 +46,7 @@ public:
~class_method() override = default;
void update(const common::model::namespace_& un);
void update(const common::model::namespace_ &un);
/**
* @brief Method name including template parameters/arguments if any

View File

@@ -18,18 +18,10 @@
#include "generator.h"
namespace clanguml::common::model {
namespace clanguml::common {
namespace model {
using nlohmann::json;
namespace detail {
std::string render_name(std::string name)
{
util::replace_all(name, "##", "::");
return name;
}
} // namespace detail
void to_json(nlohmann::json &j, const source_location &sl)
{
j = json{{"file", sl.file_relative()},
@@ -40,9 +32,10 @@ void to_json(nlohmann::json &j, const source_location &sl)
void to_json(nlohmann::json &j, const element &c)
{
j = json{{"id", std::to_string(c.id())},
{"name", detail::render_name(c.name())},
{"name", common::generators::json::render_name(c.name())},
{"namespace", c.get_namespace().to_string()}, {"type", c.type_name()},
{"display_name", detail::render_name(c.full_name(true))}};
{"display_name",
common::generators::json::render_name(c.full_name(true))}};
if (const auto &comment = c.comment(); comment)
j["comment"] = comment.value();
@@ -81,4 +74,16 @@ void to_json(nlohmann::json &j, const relationship &c)
if (const auto &comment = c.comment(); comment)
j["comment"] = comment.value();
}
} // namespace model
namespace generators::json {
std::string render_name(std::string name)
{
util::replace_all(name, "##", "::");
return name;
}
} // namespace generators::json
} // namespace clanguml::common::model

View File

@@ -51,6 +51,8 @@ using clanguml::common::model::element;
using clanguml::common::model::message_t;
using clanguml::common::model::relationship_t;
std::string render_name(std::string name);
/**
* @brief Base class for diagram generators
*

View File

@@ -78,12 +78,14 @@ std::string indent(const unsigned level)
return std::string(level * kIndentWidth, ' '); // NOLINT
}
std::string render_name(std::string name)
std::string render_name(std::string name, bool round_brackets)
{
util::replace_all(name, "<", "&lt;");
util::replace_all(name, ">", "&gt;");
util::replace_all(name, "(", "&lpar;");
util::replace_all(name, ")", "&rpar;");
if (round_brackets) {
util::replace_all(name, "(", "&lpar;");
util::replace_all(name, ")", "&rpar;");
}
util::replace_all(name, "##", "::");
util::replace_all(name, "{", "&lbrace;");
util::replace_all(name, "}", "&rbrace;");

View File

@@ -44,7 +44,7 @@ std::string to_mermaid(message_t r);
std::string indent(unsigned level);
std::string render_name(std::string name);
std::string render_name(std::string name, bool round_brackets = true);
/**
* @brief Base class for diagram generators

View File

@@ -268,8 +268,8 @@ std::string inheritable_diagram_options::simplify_template_type(
bool inheritable_diagram_options::generate_fully_qualified_name() const
{
return generate_packages() &&
(package_type() == package_type_t::kNamespace);
return (package_type() == package_type_t::kNamespace) &&
!generate_packages();
}
std::vector<std::string> diagram::get_translation_units() const

View File

@@ -89,7 +89,7 @@ void generator::generate(const package &p, std::ostream &ostr) const
<< "]\n";
if (p.is_deprecated())
ostr << indent(1) << "%% <<deprecated>>";
ostr << indent(1) << "%% <<deprecated>>\n";
}
for (const auto &subpackage : p) {