Fixed tests after refactoring namespace handling
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* src/class_diagram/model/class.h
|
* src/class_diagram/model/class.cc
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
|
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -115,14 +115,13 @@ std::string class_::full_name(bool relative) const
|
|||||||
using clanguml::common::model::namespace_;
|
using clanguml::common::model::namespace_;
|
||||||
|
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
// if (relative && starts_with(get_namespace(), using_namespace()))
|
|
||||||
if (relative)
|
|
||||||
ostr << namespace_{name()}.relative_to(using_namespace()).to_string();
|
|
||||||
else
|
|
||||||
ostr << name_and_ns();
|
|
||||||
|
|
||||||
|
ostr << name_and_ns();
|
||||||
render_template_params(ostr);
|
render_template_params(ostr);
|
||||||
|
|
||||||
|
if (relative)
|
||||||
|
return using_namespace().relative(ostr.str());
|
||||||
|
else
|
||||||
return ostr.str();
|
return ostr.str();
|
||||||
}
|
}
|
||||||
std::ostringstream &class_::render_template_params(
|
std::ostringstream &class_::render_template_params(
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ void diagram::add_package(std::unique_ptr<common::model::package> &&p)
|
|||||||
|
|
||||||
void diagram::add_class(std::unique_ptr<class_> &&c)
|
void diagram::add_class(std::unique_ptr<class_> &&c)
|
||||||
{
|
{
|
||||||
LOG_DBG("Adding class: {}, {}", c->name(), c->full_name());
|
LOG_DBG("Adding class: {}::{}, {}", c->get_namespace().to_string(),
|
||||||
|
c->name(), c->full_name());
|
||||||
|
|
||||||
if (util::contains(c->name(), "::"))
|
if (util::contains(c->name(), "::"))
|
||||||
throw std::runtime_error("Name cannot contain namespace: " + c->name());
|
throw std::runtime_error("Name cannot contain namespace: " + c->name());
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ void element::set_using_namespaces(const namespace_ &un)
|
|||||||
using_namespace_ = un;
|
using_namespace_ = un;
|
||||||
}
|
}
|
||||||
|
|
||||||
const namespace_ &element::using_namespace() const { return ns_; }
|
const namespace_ &element::using_namespace() const { return using_namespace_; }
|
||||||
|
|
||||||
std::vector<relationship> &element::relationships() { return relationships_; }
|
std::vector<relationship> &element::relationships() { return relationships_; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* src/common/model/namespace.h
|
* src/common/model/namespace.cc
|
||||||
*
|
*
|
||||||
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
|
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
|
||||||
*
|
*
|
||||||
@@ -156,30 +156,6 @@ namespace_ namespace_::relative_to(const namespace_ &right) const
|
|||||||
|
|
||||||
std::string namespace_::relative(const std::string &name) const
|
std::string namespace_::relative(const std::string &name) const
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
std::vector<std::string> namespaces_sorted{namespaces};
|
|
||||||
|
|
||||||
std::sort(namespaces_sorted.rbegin(), namespaces_sorted.rend());
|
|
||||||
|
|
||||||
auto res = name;
|
|
||||||
|
|
||||||
for (const auto &ns : namespaces_sorted) {
|
|
||||||
if (ns.empty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (name == ns)
|
|
||||||
return split(n, "::").back();
|
|
||||||
|
|
||||||
auto ns_prefix = ns + "::";
|
|
||||||
auto it = res.find(ns_prefix);
|
|
||||||
while (it != std::string::npos) {
|
|
||||||
res.erase(it, ns_prefix.size());
|
|
||||||
it = res.find(ns_prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
return name;
|
return name;
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ bool diagram::should_include(const std::string &name_) const
|
|||||||
auto name = clanguml::util::unqualify(name_);
|
auto name = clanguml::util::unqualify(name_);
|
||||||
|
|
||||||
for (const auto &ex : exclude().namespaces) {
|
for (const auto &ex : exclude().namespaces) {
|
||||||
if (ex.starts_with(name)) {
|
if (name.find(ex.to_string()) == 0) {
|
||||||
LOG_DBG("Skipping from diagram: {}", name);
|
LOG_DBG("Skipping from diagram: {}", name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,15 +93,14 @@ void translation_unit_visitor::operator()(const cppast::cpp_entity &file)
|
|||||||
|
|
||||||
auto package_parent = ctx.get_namespace();
|
auto package_parent = ctx.get_namespace();
|
||||||
auto package_path = package_parent | e.name();
|
auto package_path = package_parent | e.name();
|
||||||
auto usn = common::model::namespace_{
|
auto usn = ctx.config().using_namespace();
|
||||||
ctx.config().using_namespace()};
|
|
||||||
|
|
||||||
if (!usn.starts_with(package_path)) {
|
if (ctx.config().should_include_package(package_path)) {
|
||||||
auto p = std::make_unique<package>(usn);
|
auto p = std::make_unique<package>(usn);
|
||||||
package_path = package_path.relative_to(usn);
|
package_path = package_path.relative_to(usn);
|
||||||
|
|
||||||
p->set_name(e.name());
|
p->set_name(e.name());
|
||||||
p->set_namespace(package_path);
|
p->set_namespace(package_parent);
|
||||||
|
|
||||||
if (ns_declaration.comment().has_value())
|
if (ns_declaration.comment().has_value())
|
||||||
p->add_decorators(decorators::parse(
|
p->add_decorators(decorators::parse(
|
||||||
|
|||||||
Reference in New Issue
Block a user