This commit is contained in:
Bartek Kryza
2024-05-13 15:51:45 +02:00
parent 235533d9fa
commit eeae5caef5
57 changed files with 2240 additions and 2480 deletions

View File

@@ -76,6 +76,8 @@ void to_json(nlohmann::json &j, const class_method &c)
j["is_move_assignment"] = c.is_move_assignment();
j["is_copy_assignment"] = c.is_copy_assignment();
j["is_operator"] = c.is_operator();
j["template_parameters"] = c.template_params();
j["display_name"] = c.display_name();
j["parameters"] = c.parameters();
}
@@ -156,7 +158,10 @@ void generator::generate_top_level_elements(nlohmann::json &parent) const
{
for (const auto &p : model()) {
if (auto *pkg = dynamic_cast<package *>(p.get()); pkg) {
if (!pkg->is_empty())
if (!pkg->is_empty() &&
!pkg->all_of([this](const common::model::element &e) {
return !model().should_include(e);
}))
generate(*pkg, parent);
}
else if (auto *cls = dynamic_cast<class_ *>(p.get()); cls) {
@@ -198,7 +203,10 @@ void generator::generate(const package &p, nlohmann::json &parent) const
for (const auto &subpackage : p) {
if (dynamic_cast<package *>(subpackage.get()) != nullptr) {
const auto &sp = dynamic_cast<package &>(*subpackage);
if (!sp.is_empty()) {
if (!sp.is_empty() &&
!sp.all_of([this](const common::model::element &e) {
return !model().should_include(e);
})) {
if (config().generate_packages())
generate(sp, package_object);
else
@@ -282,6 +290,9 @@ void generator::generate_relationships(
const class_ &c, nlohmann::json &parent) const
{
for (const auto &r : c.relationships()) {
if (!model().should_include(r))
continue;
auto target_element = model().get(r.destination());
if (!target_element.has_value()) {
LOG_DBG("Skipping {} relation from {} to {} due "
@@ -310,6 +321,9 @@ void generator::generate_relationships(
const enum_ &c, nlohmann::json &parent) const
{
for (const auto &r : c.relationships()) {
if (!model().should_include(r))
continue;
auto target_element = model().get(r.destination());
if (!target_element.has_value()) {
LOG_DBG("Skipping {} relation from {} to {} due "
@@ -328,6 +342,9 @@ void generator::generate_relationships(
const concept_ &c, nlohmann::json &parent) const
{
for (const auto &r : c.relationships()) {
if (!model().should_include(r))
continue;
auto target_element = model().get(r.destination());
if (!target_element.has_value()) {
LOG_DBG("Skipping {} relation from {} to {} due "

View File

@@ -281,8 +281,7 @@ 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";

View File

@@ -26,6 +26,26 @@ class_method::class_method(common::model::access_t access,
{
}
void class_method::update(const common::model::namespace_ &un)
{
if (template_params().empty()) {
set_display_name(name());
}
else {
std::stringstream template_params_str;
render_template_params(template_params_str, un, true);
set_display_name(
fmt::format("{}{}", name(), template_params_str.str()));
}
}
std::string class_method::display_name() const { return display_name_; }
void class_method::set_display_name(const std::string &display_name)
{
display_name_ = display_name;
}
bool class_method::is_pure_virtual() const { return is_pure_virtual_; }
void class_method::is_pure_virtual(bool is_pure_virtual)

View File

@@ -46,6 +46,17 @@ public:
~class_method() override = default;
void update(const common::model::namespace_& un);
/**
* @brief Method name including template parameters/arguments if any
*
* @return String representation of the methods display name
*/
std::string display_name() const;
void set_display_name(const std::string &display_name);
/**
* @brief Whether the method is pure virtual.
*
@@ -282,5 +293,7 @@ private:
bool is_move_assignment_{false};
bool is_copy_assignment_{false};
bool is_operator_{false};
std::string display_name_;
};
} // namespace clanguml::class_diagram::model

View File

@@ -1187,7 +1187,8 @@ void translation_unit_visitor::process_method(
}
class_method method{common::access_specifier_to_access_t(mf.getAccess()),
util::trim(method_name), method_return_type};
util::trim(method_name),
config().simplify_template_type(method_return_type)};
process_method_properties(mf, c, method_name, method);
@@ -1266,6 +1267,8 @@ void translation_unit_visitor::process_method(
process_function_parameter_find_relationships_in_autotype(c, atsp);
}
method.update(config().using_namespace());
if (diagram().should_include(method)) {
LOG_DBG("Adding method: {}", method.name());
@@ -1390,6 +1393,8 @@ void translation_unit_visitor::process_template_method(
process_function_parameter(*param, method, c);
}
method.update(config().using_namespace());
if (diagram().should_include(method)) {
LOG_DBG("Adding method: {}", method.name());
@@ -1678,7 +1683,9 @@ void translation_unit_visitor::process_static_field(
class_member field{
common::access_specifier_to_access_t(field_declaration.getAccess()),
field_declaration.getNameAsString(), type_name};
field_declaration.getNameAsString(),
config().simplify_template_type(type_name)};
field.is_static(true);
process_comment(field_declaration, field);
@@ -1769,7 +1776,7 @@ void translation_unit_visitor::process_field(
class_member field{
common::access_specifier_to_access_t(field_declaration.getAccess()),
field_name, field_type_str};
field_name, config().simplify_template_type(field_type_str)};
// Parse the field comment
process_comment(field_declaration, field);