Added comment() function support in package diagrams
This commit is contained in:
@@ -37,19 +37,6 @@ std::string package::full_name(bool relative) const
|
|||||||
|
|
||||||
return (get_namespace().relative_to(using_namespace()) | name())
|
return (get_namespace().relative_to(using_namespace()) | name())
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
// auto fn = get_namespace();
|
|
||||||
// auto ns = using_namespace();
|
|
||||||
//
|
|
||||||
// if (relative && (fn.size() >= ns.size())) {
|
|
||||||
// if (fn.starts_with(using_namespace())
|
|
||||||
// fn = std::vector<std::string>(fn.begin() + ns.size(),
|
|
||||||
// fn.end());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fn.push_back(name());
|
|
||||||
//
|
|
||||||
// return fmt::format("{}", fmt::join(fn, "::"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool package::is_deprecated() const { return is_deprecated_; }
|
bool package::is_deprecated() const { return is_deprecated_; }
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ public:
|
|||||||
|
|
||||||
void set_deprecated(bool deprecated);
|
void set_deprecated(bool deprecated);
|
||||||
|
|
||||||
|
void add_package(std::unique_ptr<common::model::package> &&p);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool is_deprecated_{false};
|
bool is_deprecated_{false};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,10 +28,33 @@ common::model::diagram_t diagram::type() const
|
|||||||
return common::model::diagram_t::kPackage;
|
return common::model::diagram_t::kPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void diagram::add_package(std::unique_ptr<common::model::package> &&p)
|
||||||
|
{
|
||||||
|
LOG_DBG("Adding package: {}, {}", p->name(), p->full_name(true));
|
||||||
|
|
||||||
|
auto ns = p->get_relative_namespace();
|
||||||
|
|
||||||
|
packages_.emplace_back(*p);
|
||||||
|
|
||||||
|
add_element(ns, std::move(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
type_safe::optional_ref<const common::model::package> diagram::get_package(
|
||||||
|
const std::string &name) const
|
||||||
|
{
|
||||||
|
for (const auto &p : packages_) {
|
||||||
|
if (p.get().full_name(false) == name) {
|
||||||
|
return {p};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return type_safe::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
type_safe::optional_ref<const clanguml::common::model::element> diagram::get(
|
type_safe::optional_ref<const clanguml::common::model::element> diagram::get(
|
||||||
const std::string &full_name) const
|
const std::string &full_name) const
|
||||||
{
|
{
|
||||||
return {};
|
return get_package(full_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string diagram::to_alias(const std::string &full_name) const
|
std::string diagram::to_alias(const std::string &full_name) const
|
||||||
|
|||||||
@@ -40,9 +40,18 @@ public:
|
|||||||
|
|
||||||
common::model::diagram_t type() const override;
|
common::model::diagram_t type() const override;
|
||||||
|
|
||||||
type_safe::optional_ref<const clanguml::common::model::element> get(
|
type_safe::optional_ref<const common::model::element> get(
|
||||||
const std::string &full_name) const;
|
const std::string &full_name) const;
|
||||||
|
|
||||||
|
void add_package(std::unique_ptr<common::model::package> &&p);
|
||||||
|
|
||||||
|
type_safe::optional_ref<const common::model::package> get_package(
|
||||||
|
const std::string &name) const;
|
||||||
|
|
||||||
std::string to_alias(const std::string &full_name) const;
|
std::string to_alias(const std::string &full_name) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<type_safe::object_ref<const common::model::package, false>>
|
||||||
|
packages_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,9 +106,12 @@ void translation_unit_visitor::operator()(const cppast::cpp_entity &file)
|
|||||||
p->set_namespace(package_parent);
|
p->set_namespace(package_parent);
|
||||||
|
|
||||||
if (ctx.diagram().should_include(*p)) {
|
if (ctx.diagram().should_include(*p)) {
|
||||||
if (ns_declaration.comment().has_value())
|
if (ns_declaration.comment().has_value()) {
|
||||||
|
p->set_comment(
|
||||||
|
ns_declaration.comment().value());
|
||||||
p->add_decorators(decorators::parse(
|
p->add_decorators(decorators::parse(
|
||||||
ns_declaration.comment().value()));
|
ns_declaration.comment().value()));
|
||||||
|
}
|
||||||
|
|
||||||
p->set_style(p->style_spec());
|
p->set_style(p->style_spec());
|
||||||
|
|
||||||
@@ -123,7 +126,7 @@ void translation_unit_visitor::operator()(const cppast::cpp_entity &file)
|
|||||||
|
|
||||||
if (!p->skip()) {
|
if (!p->skip()) {
|
||||||
auto rns = p->get_relative_namespace();
|
auto rns = p->get_relative_namespace();
|
||||||
ctx.diagram().add_element(rns, std::move(p));
|
ctx.diagram().add_package(std::move(p));
|
||||||
ctx.set_current_package(
|
ctx.set_current_package(
|
||||||
ctx.diagram().get_element<package>(
|
ctx.diagram().get_element<package>(
|
||||||
package_path));
|
package_path));
|
||||||
|
|||||||
@@ -18,3 +18,5 @@ diagrams:
|
|||||||
- "' t30001 test package diagram"
|
- "' t30001 test package diagram"
|
||||||
after:
|
after:
|
||||||
- 'note right of {{ alias("A::AA::AAA") }}: A AAA note...'
|
- 'note right of {{ alias("A::AA::AAA") }}: A AAA note...'
|
||||||
|
- 'note top of {{ alias("A::AA") }} : {{ comment("A::AA") }}'
|
||||||
|
- 'note top of {{ alias("B::AA") }} : {{ comment("B::AA") }}'
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
namespace clanguml {
|
namespace clanguml {
|
||||||
namespace t30001 {
|
namespace t30001 {
|
||||||
namespace A {
|
namespace A {
|
||||||
|
/// This is namespace AA in namespace A
|
||||||
namespace AA {
|
namespace AA {
|
||||||
namespace AAA {
|
namespace AAA {
|
||||||
} // namespace AAA
|
} // namespace AAA
|
||||||
@@ -11,6 +12,7 @@ namespace BB {
|
|||||||
} // namespace BB
|
} // namespace BB
|
||||||
} // namespace A
|
} // namespace A
|
||||||
namespace B {
|
namespace B {
|
||||||
|
/// This is namespace AA in namespace B
|
||||||
namespace AA {
|
namespace AA {
|
||||||
namespace AAA {
|
namespace AAA {
|
||||||
} // namespace AAA
|
} // namespace AAA
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ TEST_CASE("t30001", "[test-case][package]")
|
|||||||
REQUIRE_THAT(puml, IsPackage("AAA"));
|
REQUIRE_THAT(puml, IsPackage("AAA"));
|
||||||
REQUIRE_THAT(puml, IsPackage("AAA"));
|
REQUIRE_THAT(puml, IsPackage("AAA"));
|
||||||
|
|
||||||
|
// TODO: Fix _A() to handle fully qualified names, right
|
||||||
|
// now it only finds the first element with unqalified
|
||||||
|
// name match
|
||||||
|
REQUIRE_THAT(
|
||||||
|
puml, HasNote(_A("AA"), "top", "This is namespace AA in namespace A"));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user