Fixed class and include diagrams tests in Windows

This commit is contained in:
Bartek Kryza
2023-01-12 23:31:12 +01:00
parent 3fbf3da27f
commit ada11c6047
11 changed files with 58 additions and 14 deletions

View File

@@ -763,11 +763,10 @@ void translation_unit_visitor::process_class_children(
// Static fields have to be processed by iterating over variable
// declarations
#ifndef _MSC_VER
for (const auto *decl : cls->decls()) {
if (decl->getKind() == clang::Decl::Var) {
const clang::VarDecl *variable_declaration{
dynamic_cast<const clang::VarDecl *>(decl)};
clang::dyn_cast_or_null<clang::VarDecl>(decl)};
if ((variable_declaration != nullptr) &&
variable_declaration->isStaticDataMember()) {
process_static_field(*variable_declaration, c);
@@ -789,7 +788,7 @@ void translation_unit_visitor::process_class_children(
}
}
}
#endif
if (cls->isCompleteDefinition())
for (const auto *friend_declaration : cls->friends()) {
if (friend_declaration != nullptr)

View File

@@ -569,6 +569,7 @@ template <typename C, typename D> void generator<C, D>::init_env()
auto element_opt = m_model.get_with_namespace(
args[0]->get<std::string>(), m_config.using_namespace());
if (!element_opt.has_value())
throw clanguml::error::uml_alias_missing(
args[0]->get<std::string>());

View File

@@ -47,7 +47,7 @@ public:
/// \brief Find element in diagram which can have full name or be
/// relative to ns
common::optional_ref<clanguml::common::model::diagram_element>
virtual common::optional_ref<clanguml::common::model::diagram_element>
get_with_namespace(const std::string &name, const namespace_ &ns) const;
diagram(const diagram &) = delete;

View File

@@ -374,6 +374,8 @@ paths_filter::paths_filter(filter_t type, const std::filesystem::path &root,
continue;
}
absolute_path.make_preferred();
paths_.emplace_back(std::move(absolute_path));
}
}
@@ -386,13 +388,15 @@ tvl::value_t paths_filter::match(
}
// Matching source paths doesn't make sens if they are not absolute
if (!p.is_absolute())
if (!p.is_absolute()) {
return {};
}
auto pp = p.fs_path(root_);
for (const auto &path : paths_) {
if (pp.root_name().string() == path.root_name().string() &&
util::starts_with(pp, path)) {
util::starts_with(pp.relative_path(), path.relative_path())) {
return true;
}
}

View File

@@ -56,10 +56,12 @@ public:
explicit source_file(const std::filesystem::path &p)
{
set_path({p.parent_path().string()});
set_name(p.filename().string());
is_absolute_ = p.is_absolute();
set_id(common::to_id(p));
auto preferred = p;
preferred.make_preferred();
set_path({preferred.parent_path().string()});
set_name(preferred.filename().string());
is_absolute_ = preferred.is_absolute();
set_id(common::to_id(preferred));
}
void set_path(const filesystem_path &p) { path_ = p; }
@@ -118,6 +120,17 @@ public:
return res.lexically_normal();
}
inja::json context() const override
{
inja::json ctx = diagram_element::context();
std::filesystem::path fullNamePath{ctx["full_name"].get<std::string>()};
fullNamePath.make_preferred();
ctx["full_name"] = fullNamePath.string();
return ctx;
}
private:
filesystem_path path_;
source_file_t type_{source_file_t::kDirectory};

View File

@@ -89,8 +89,12 @@ void diagram::add_file(std::unique_ptr<common::model::source_file> &&f)
common::optional_ref<common::model::source_file> diagram::get_file(
const std::string &name) const
{
// Convert the name to the OS preferred path
std::filesystem::path namePath{name};
namePath.make_preferred();
for (const auto &p : files_) {
if (p.get().full_name(false) == name) {
if (p.get().full_name(false) == namePath.string()) {
return {p};
}
}
@@ -135,6 +139,25 @@ diagram::files() const
return files_;
}
common::optional_ref<clanguml::common::model::diagram_element>
diagram::get_with_namespace(const std::string &name, const common::model::namespace_ &ns) const
{
// Convert to preferred OS path
std::filesystem::path namePath{name};
auto namePreferred = namePath.make_preferred().string();
auto element_opt = get(namePreferred);
if (!element_opt) {
// If no element matches, try to prepend the 'using_namespace'
// value to the element and search again
auto fully_qualified_name = ns | namePreferred;
element_opt = get(fully_qualified_name.to_string());
}
return element_opt;
}
inja::json diagram::context() const
{
inja::json ctx;

View File

@@ -59,6 +59,9 @@ public:
const common::reference_vector<common::model::source_file> &files() const;
common::optional_ref<clanguml::common::model::diagram_element>
get_with_namespace(const std::string &name, const common::model::namespace_ &ns) const override;
inja::json context() const override;
private:

View File

@@ -220,18 +220,16 @@ void translation_unit_visitor::process_class_children(
// Static fields have to be processed by iterating over variable
// declarations
#ifndef _MSC_VER
for (const auto *decl : cls.decls()) {
if (decl->getKind() == clang::Decl::Var) {
const clang::VarDecl *variable_declaration{
dynamic_cast<const clang::VarDecl *>(decl)};
clang::dyn_cast_or_null<clang::VarDecl>(decl)};
if ((variable_declaration != nullptr) &&
variable_declaration->isStaticDataMember()) {
process_static_field(*variable_declaration, relationships);
}
}
}
#endif
if (cls.isCompleteDefinition())
for (const auto *friend_declaration : cls.friends()) {