Improved skipping of empty packages in class diagrams

This commit is contained in:
Bartek Kryza
2023-05-28 18:09:01 +02:00
parent 5c4a98ba79
commit 81c7ce71df
15 changed files with 121 additions and 53 deletions

View File

@@ -721,9 +721,14 @@ void generator::generate_relationships(
{
for (const auto &subpackage : p) {
if (dynamic_cast<package *>(subpackage.get()) != nullptr) {
// TODO: add option - generate_empty_packages
// TODO: add option - generate_empty_packages, currently
// packages which do not contain anything but other packages
// are skipped
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 !m_model.should_include(e);
}))
generate_relationships(sp, ostr);
}
else if (dynamic_cast<class_ *>(subpackage.get()) != nullptr) {
@@ -774,7 +779,10 @@ void generator::generate_top_level_elements(std::ostream &ostr) const
{
for (const auto &p : m_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 !m_model.should_include(e);
}))
generate(*pkg, ostr);
}
else if (auto *cls = dynamic_cast<class_ *>(p.get()); cls) {

View File

@@ -187,7 +187,6 @@ bool diagram::add_with_filesystem_path(
const auto base_name = e->name();
const auto full_name = e->full_name(false);
const auto id = e->id();
auto &e_ref = *e;
if (add_element(parent_path, std::move(e))) {
@@ -195,9 +194,6 @@ bool diagram::add_with_filesystem_path(
return true;
}
LOG_WARN(
"Cannot add {} {} with id {} due to: {}", element_type, base_name, id);
return false;
}

View File

@@ -1044,6 +1044,8 @@ template_builder::try_as_template_specialization_type(
}
if (diagram().should_include(nested_template_instantiation_full_name)) {
visitor_.set_source_location(
*template_decl, *nested_template_instantiation);
visitor_.add_class(std::move(nested_template_instantiation));
}
@@ -1155,7 +1157,7 @@ std::optional<template_parameter> template_builder::try_as_record_type(
if (parent.has_value())
parent.value()->add_relationship(
{relationship_t::kDependency, tag_argument->id()});
visitor_.set_source_location(*template_decl, *tag_argument);
visitor_.add_class(std::move(tag_argument));
}
}