Added package diagram test case with C++20 module partitions dependencies
This commit is contained in:
@@ -184,18 +184,7 @@ void generator::generate(const package &p, nlohmann::json &parent) const
|
||||
if (!uns.starts_with({p.full_name(false)})) {
|
||||
LOG_DBG("Generating package {}", p.name());
|
||||
|
||||
switch (config().package_type()) {
|
||||
case config::package_type_t::kDirectory:
|
||||
package_object["type"] = "directory";
|
||||
break;
|
||||
case config::package_type_t::kModule:
|
||||
package_object["type"] = "module";
|
||||
break;
|
||||
case config::package_type_t::kNamespace:
|
||||
package_object["type"] = "namespace";
|
||||
break;
|
||||
}
|
||||
|
||||
package_object["type"] = to_string(config().package_type());
|
||||
package_object["name"] = p.name();
|
||||
package_object["display_name"] = p.full_name(false);
|
||||
}
|
||||
|
||||
35
src/common/model/path.cc
Normal file
35
src/common/model/path.cc
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @file src/common/model/path.cc
|
||||
*
|
||||
* Copyright (c) 2021-2023 Bartek Kryza <bkryza@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "path.h"
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
std::string to_string(const path_type pt)
|
||||
{
|
||||
switch (pt) {
|
||||
case path_type::kModule:
|
||||
return "module";
|
||||
case path_type::kNamespace:
|
||||
return "namespace";
|
||||
case path_type::kFilesystem:
|
||||
return "directory";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace clanguml::common::model
|
||||
@@ -37,6 +37,8 @@ enum class path_type {
|
||||
kModule /*!< Module path */
|
||||
};
|
||||
|
||||
std::string to_string(path_type pt);
|
||||
|
||||
/**
|
||||
* @brief Diagram path
|
||||
*
|
||||
@@ -135,7 +137,8 @@ public:
|
||||
return *this;
|
||||
|
||||
if (path_type_ != right.path_type_)
|
||||
throw std::runtime_error("");
|
||||
throw std::runtime_error(
|
||||
"Cannot assign a path to a path with another path type.");
|
||||
|
||||
path_type_ = right.path_type_;
|
||||
path_ = right.path_;
|
||||
@@ -225,6 +228,7 @@ public:
|
||||
path operator|(const path &right) const
|
||||
{
|
||||
path res{*this};
|
||||
res.path_type_ = right.path_type_;
|
||||
res.append(right);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -147,6 +147,8 @@ std::string to_string(package_type_t pt)
|
||||
return "namespace";
|
||||
case package_type_t::kDirectory:
|
||||
return "directory";
|
||||
case package_type_t::kModule:
|
||||
return "module";
|
||||
default:
|
||||
assert(false);
|
||||
return "";
|
||||
|
||||
@@ -58,12 +58,12 @@ void generator::generate_relationships(
|
||||
|
||||
void generator::generate(const package &p, nlohmann::json &parent) const
|
||||
{
|
||||
LOG_DBG("Generating package {}", p.name());
|
||||
LOG_DBG("Generating package {}", p.full_name(false));
|
||||
|
||||
nlohmann::json j;
|
||||
j["id"] = std::to_string(p.id());
|
||||
j["name"] = p.name();
|
||||
j["type"] = "namespace";
|
||||
j["type"] = to_string(config().package_type());
|
||||
j["display_name"] = p.full_name(false);
|
||||
j["is_deprecated"] = p.is_deprecated();
|
||||
if (!p.file().empty())
|
||||
@@ -86,10 +86,12 @@ void generator::generate_diagram(nlohmann::json &parent) const
|
||||
{
|
||||
if (config().using_namespace)
|
||||
parent["using_namespace"] = config().using_namespace().to_string();
|
||||
if (config().using_module)
|
||||
parent["using_module"] = config().using_module();
|
||||
|
||||
parent["name"] = model().name();
|
||||
parent["diagram_type"] = "package";
|
||||
|
||||
parent["package_type"] = to_string(config().package_type());
|
||||
parent["elements"] = std::vector<nlohmann::json>{};
|
||||
parent["relationships"] = std::vector<nlohmann::json>{};
|
||||
|
||||
|
||||
@@ -260,35 +260,29 @@ bool diagram::add_with_module_path(
|
||||
|
||||
// Make sure all parent modules are already packages in the
|
||||
// model
|
||||
std::string module_path = p->using_namespace().to_string();
|
||||
auto module_relative_to = path{p->using_namespace()};
|
||||
|
||||
for (auto it = parent_path.begin(); it != parent_path.end(); it++) {
|
||||
auto pkg = std::make_unique<common::model::package>(
|
||||
p->using_namespace(), common::model::path_type::kModule);
|
||||
pkg->set_name(*it);
|
||||
|
||||
auto ns = common::model::path(
|
||||
auto module_relative_part = common::model::path(
|
||||
parent_path.begin(), it, common::model::path_type::kModule);
|
||||
pkg->set_module(module_path);
|
||||
pkg->set_namespace(ns);
|
||||
|
||||
std::string package_id_path;
|
||||
if (module_path.empty())
|
||||
package_id_path = pkg->name();
|
||||
else
|
||||
package_id_path = module_path + "." + pkg->name();
|
||||
auto module_absolute_path = module_relative_to | module_relative_part;
|
||||
pkg->set_module(module_absolute_path.to_string());
|
||||
pkg->set_namespace(module_absolute_path);
|
||||
|
||||
pkg->set_id(common::to_id(package_id_path));
|
||||
auto package_absolute_path = module_absolute_path | pkg->name();
|
||||
|
||||
pkg->set_id(common::to_id(package_absolute_path.to_string()));
|
||||
|
||||
auto p_ref = std::ref(*pkg);
|
||||
|
||||
auto res = add_element(ns, std::move(pkg));
|
||||
auto res = add_element(module_relative_part, std::move(pkg));
|
||||
if (res)
|
||||
element_view<ElementT>::add(p_ref);
|
||||
|
||||
if (module_path.empty())
|
||||
module_path = *it;
|
||||
else
|
||||
module_path += fmt::format(".{}", *it);
|
||||
}
|
||||
|
||||
auto p_ref = std::ref(*p);
|
||||
|
||||
@@ -270,7 +270,7 @@ void translation_unit_visitor::add_relationships(
|
||||
// This is for diagram filters
|
||||
pkg->set_module(module_path.to_string());
|
||||
// This is for rendering nested package structure
|
||||
pkg->set_namespace(parent_path);
|
||||
pkg->set_namespace(module_path);
|
||||
set_source_location(*cls, *pkg);
|
||||
|
||||
if (diagram().should_include(*pkg))
|
||||
|
||||
Reference in New Issue
Block a user