Skip to content

Commit f93cbe8

Browse files
committed
Fixed handling of nested classes in relative namespaces
1 parent ae17358 commit f93cbe8

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

src/class_diagram/model/class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class class_ : public common::model::element,
7070

7171
std::string full_name(bool relative = true) const override;
7272

73-
std::string full_name_no_ns() const;
73+
std::string full_name_no_ns() const override;
7474

7575
bool is_abstract() const;
7676

src/class_diagram/visitor/translation_unit_visitor.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ bool translation_unit_visitor::VisitEnumDecl(clang::EnumDecl *enm)
176176
assert(parent_class);
177177

178178
e.set_namespace(ns);
179-
e.set_name(parent_class.value().full_name(true) + "##" +
179+
e.set_name(parent_class.value().full_name_no_ns() + "##" +
180180
enm->getNameAsString());
181181
e.set_id(common::to_id(e.full_name(false)));
182182
e.add_relationship({relationship_t::kContainment, *id_opt});
@@ -462,19 +462,19 @@ std::unique_ptr<class_> translation_unit_visitor::create_class_declaration(
462462
const auto &[label, hint, access] =
463463
anonymous_struct_relationships_[cls->getID()];
464464

465-
c.set_name(parent_class.value().full_name(true) + "##" +
465+
c.set_name(parent_class.value().full_name_no_ns() + "##" +
466466
fmt::format("({})", label));
467467

468468
parent_class.value().add_relationship(
469469
{hint, common::to_id(c.full_name(false)), access, label});
470470
}
471471
else
472-
c.set_name(parent_class.value().full_name(true) + "##" +
472+
c.set_name(parent_class.value().full_name_no_ns() + "##" +
473473
fmt::format(
474474
"(anonymous_{})", std::to_string(cls->getID())));
475475
}
476476
else {
477-
c.set_name(parent_class.value().full_name(true) + "##" +
477+
c.set_name(parent_class.value().full_name_no_ns() + "##" +
478478
cls->getNameAsString());
479479
}
480480

src/common/model/element.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class element : public diagram_element, public source_location {
6060
return name_and_ns();
6161
}
6262

63+
virtual std::string full_name_no_ns() const { return name(); }
64+
6365
void set_using_namespaces(const namespace_ &un);
6466

6567
const namespace_ &using_namespace() const;

tests/t00004/t00004.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,15 @@ template <typename T> class C {
3535
enum class CC { CC_1, CC_2 };
3636
};
3737

38+
namespace detail {
39+
class D {
40+
public:
41+
enum class AA { AA_1, AA_2, AA_3 };
42+
43+
class DD {
44+
};
45+
};
46+
}
47+
3848
}
3949
}

tests/t00004/test_case.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ TEST_CASE("t00004", "[test-case][class]")
5858
REQUIRE_THAT(puml, IsInnerClass(_A("C<T>"), _A("C<T>::CC")));
5959
REQUIRE_THAT(puml, IsInnerClass(_A("C<T>::AA"), _A("C<T>::AA::CCC")));
6060

61+
REQUIRE_THAT(puml, IsClass(_A("detail::D")));
62+
REQUIRE_THAT(puml, IsClass(_A("detail::D::DD")));
63+
REQUIRE_THAT(puml, IsEnum(_A("detail::D::AA")));
64+
6165
save_puml(
6266
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
6367
}

0 commit comments

Comments
 (0)