Skip dependencies between parent and child packages in package diagrams (Fixes #186)
This commit is contained in:
@@ -30,6 +30,16 @@ diagram_element::id_t diagram_element::id() const { return id_; }
|
||||
|
||||
void diagram_element::set_id(diagram_element::id_t id) { id_ = id; }
|
||||
|
||||
std::optional<id_t> diagram_element::parent_element_id() const
|
||||
{
|
||||
return parent_element_id_;
|
||||
}
|
||||
|
||||
void diagram_element::set_parent_element_id(diagram_element::id_t id)
|
||||
{
|
||||
parent_element_id_ = id;
|
||||
}
|
||||
|
||||
std::string diagram_element::alias() const
|
||||
{
|
||||
assert(id_ >= 0);
|
||||
|
||||
@@ -64,6 +64,20 @@ public:
|
||||
*/
|
||||
void set_id(id_t id);
|
||||
|
||||
/**
|
||||
* Get elements parent package id.
|
||||
*
|
||||
* @return Parent package id if element is nested.
|
||||
*/
|
||||
std::optional<id_t> parent_element_id() const;
|
||||
|
||||
/**
|
||||
* Set elements parent package id.
|
||||
*
|
||||
* @param id Id of parent package.
|
||||
*/
|
||||
void set_parent_element_id(diagram_element::id_t id);
|
||||
|
||||
/**
|
||||
* @brief Return elements' diagram alias.
|
||||
*
|
||||
@@ -174,6 +188,7 @@ public:
|
||||
|
||||
private:
|
||||
id_t id_{0};
|
||||
std::optional<id_t> parent_element_id_{0};
|
||||
std::string name_;
|
||||
std::vector<relationship> relationships_;
|
||||
bool nested_{false};
|
||||
|
||||
@@ -248,10 +248,6 @@ tvl::value_t namespace_filter::match(const diagram &d, const element &e) const
|
||||
e.full_name(false);
|
||||
});
|
||||
|
||||
if (tvl::is_false(result))
|
||||
LOG_DBG("Element {} rejected by namespace_filter 1",
|
||||
e.full_name(false));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -273,10 +269,6 @@ tvl::value_t namespace_filter::match(const diagram &d, const element &e) const
|
||||
e.full_name(false);
|
||||
});
|
||||
|
||||
if (tvl::is_false(result))
|
||||
LOG_DBG("Element {} rejected by namespace_filter (package diagram)",
|
||||
e.full_name(false));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -290,9 +282,6 @@ tvl::value_t namespace_filter::match(const diagram &d, const element &e) const
|
||||
return std::get<common::regex>(nsit.value()) %= e.full_name(false);
|
||||
});
|
||||
|
||||
if (tvl::is_false(result))
|
||||
LOG_DBG("Element {} rejected by namespace_filter", e.full_name(false));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,9 +94,11 @@ public:
|
||||
|
||||
auto parent = get_element(path);
|
||||
|
||||
if (parent && dynamic_cast<nested_trait<T, Path> *>(&parent.value()))
|
||||
if (parent && dynamic_cast<nested_trait<T, Path> *>(&parent.value())) {
|
||||
p->set_parent_element_id(parent.value().id());
|
||||
return dynamic_cast<nested_trait<T, Path> &>(parent.value())
|
||||
.template add_element<V>(std::move(p));
|
||||
}
|
||||
|
||||
LOG_INFO("No parent element found at: {}", path.to_string());
|
||||
|
||||
|
||||
@@ -62,8 +62,9 @@ void generator::generate_relationships(
|
||||
|
||||
// Process it's subpackages relationships
|
||||
for (const auto &subpackage : p) {
|
||||
generate_relationships(
|
||||
dynamic_cast<const package &>(*subpackage), ostr);
|
||||
if (model().should_include(dynamic_cast<const package &>(*subpackage)))
|
||||
generate_relationships(
|
||||
dynamic_cast<const package &>(*subpackage), ostr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,12 +76,12 @@ bool translation_unit_visitor::VisitNamespaceDecl(clang::NamespaceDecl *ns)
|
||||
p->set_name(name);
|
||||
p->set_namespace(package_parent);
|
||||
p->set_id(common::to_id(*ns));
|
||||
set_source_location(*ns, *p);
|
||||
|
||||
assert(p->id() > 0);
|
||||
|
||||
if (diagram().should_include(*p) && !diagram().get(p->id())) {
|
||||
process_comment(*ns, *p);
|
||||
set_source_location(*ns, *p);
|
||||
|
||||
p->set_style(p->style_spec());
|
||||
|
||||
@@ -232,8 +232,10 @@ void translation_unit_visitor::add_relationships(
|
||||
|
||||
pkg->set_name(pkg_name);
|
||||
pkg->set_id(get_package_id(cls));
|
||||
set_source_location(*cls, *pkg);
|
||||
|
||||
diagram().add(parent_path, std::move(pkg));
|
||||
if (diagram().should_include(*pkg))
|
||||
diagram().add(parent_path, std::move(pkg));
|
||||
}
|
||||
|
||||
auto current_package_id = get_package_id(cls);
|
||||
@@ -246,8 +248,21 @@ void translation_unit_visitor::add_relationships(
|
||||
auto current_package = diagram().get(current_package_id);
|
||||
|
||||
if (current_package) {
|
||||
std::vector<common::model::diagram_element::id_t> parent_ids =
|
||||
get_parent_package_ids(current_package_id);
|
||||
|
||||
for (const auto &dependency : relationships) {
|
||||
const auto destination_id = std::get<0>(dependency);
|
||||
|
||||
// Skip dependency relationships to parent packages
|
||||
if (util::contains(parent_ids, destination_id))
|
||||
continue;
|
||||
|
||||
// Skip dependency relationship to child packages
|
||||
if (util::contains(
|
||||
get_parent_package_ids(destination_id), current_package_id))
|
||||
continue;
|
||||
|
||||
relationship r{relationship_t::kDependency, destination_id,
|
||||
common::model::access_t::kNone};
|
||||
if (destination_id != current_package_id)
|
||||
@@ -605,4 +620,23 @@ translation_unit_visitor::config() const
|
||||
|
||||
void translation_unit_visitor::finalize() { }
|
||||
|
||||
std::vector<common::model::diagram_element::id_t>
|
||||
translation_unit_visitor::get_parent_package_ids(
|
||||
common::model::diagram_element::id_t id)
|
||||
{
|
||||
std::vector<common::model::diagram_element::id_t> parent_ids;
|
||||
std::optional<common::model::diagram_element::id_t> parent_id = id;
|
||||
|
||||
while (parent_id.has_value()) {
|
||||
parent_ids.push_back(parent_id.value());
|
||||
auto parent = this->diagram().get(parent_id.value());
|
||||
if (parent)
|
||||
parent_id = parent.value().parent_element_id();
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return parent_ids;
|
||||
}
|
||||
|
||||
} // namespace clanguml::package_diagram::visitor
|
||||
|
||||
@@ -214,6 +214,9 @@ private:
|
||||
void add_relationships(
|
||||
clang::Decl *cls, found_relationships_t &relationships);
|
||||
|
||||
std::vector<common::model::diagram_element::id_t> get_parent_package_ids(
|
||||
common::model::diagram_element::id_t id);
|
||||
|
||||
// Reference to the output diagram model
|
||||
clanguml::package_diagram::model::diagram &diagram_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user