Fixed tests after refactoring namespace handling

This commit is contained in:
Bartek Kryza
2022-03-05 18:46:29 +01:00
parent a67b459437
commit f84e86ca6d
6 changed files with 14 additions and 39 deletions

View File

@@ -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>
*
@@ -115,15 +115,14 @@ std::string class_::full_name(bool relative) const
using clanguml::common::model::namespace_;
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);
return ostr.str();
if (relative)
return using_namespace().relative(ostr.str());
else
return ostr.str();
}
std::ostringstream &class_::render_template_params(
std::ostringstream &ostr) const

View File

@@ -66,7 +66,8 @@ void diagram::add_package(std::unique_ptr<common::model::package> &&p)
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(), "::"))
throw std::runtime_error("Name cannot contain namespace: " + c->name());

View File

@@ -62,7 +62,7 @@ void element::set_using_namespaces(const 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_; }

View File

@@ -1,5 +1,5 @@
/**
* src/common/model/namespace.h
* src/common/model/namespace.cc
*
* 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::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())
return name;

View File

@@ -153,7 +153,7 @@ bool diagram::should_include(const std::string &name_) const
auto name = clanguml::util::unqualify(name_);
for (const auto &ex : exclude().namespaces) {
if (ex.starts_with(name)) {
if (name.find(ex.to_string()) == 0) {
LOG_DBG("Skipping from diagram: {}", name);
return false;
}

View File

@@ -93,15 +93,14 @@ void translation_unit_visitor::operator()(const cppast::cpp_entity &file)
auto package_parent = ctx.get_namespace();
auto package_path = package_parent | e.name();
auto usn = common::model::namespace_{
ctx.config().using_namespace()};
auto usn = 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);
package_path = package_path.relative_to(usn);
p->set_name(e.name());
p->set_namespace(package_path);
p->set_namespace(package_parent);
if (ns_declaration.comment().has_value())
p->add_decorators(decorators::parse(