Added PlantUML links generation in class diagrams
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "util/error.h"
|
||||
|
||||
#include <inja/inja.hpp>
|
||||
|
||||
namespace clanguml::class_diagram::generators::plantuml {
|
||||
|
||||
generator::generator(diagram_config &config, diagram_model &model)
|
||||
@@ -27,6 +29,27 @@ generator::generator(diagram_config &config, diagram_model &model)
|
||||
{
|
||||
}
|
||||
|
||||
void generator::generate_link(
|
||||
std::ostream &ostr, const class_diagram::model::class_element &e) const
|
||||
{
|
||||
if (e.file().empty())
|
||||
return;
|
||||
|
||||
if (!m_config.generate_links().link.empty()) {
|
||||
ostr << " [[[";
|
||||
inja::render_to(
|
||||
ostr, m_config.generate_links().link, element_context(e));
|
||||
}
|
||||
|
||||
if (!m_config.generate_links().tooltip.empty()) {
|
||||
ostr << "{";
|
||||
inja::render_to(
|
||||
ostr, m_config.generate_links().tooltip, element_context(e));
|
||||
ostr << "}";
|
||||
}
|
||||
ostr << "]]]";
|
||||
}
|
||||
|
||||
void generator::generate_alias(const class_ &c, std::ostream &ostr) const
|
||||
{
|
||||
std::string class_type{"class"};
|
||||
@@ -72,6 +95,10 @@ void generator::generate(
|
||||
|
||||
ostr << class_type << " " << c.alias();
|
||||
|
||||
if (m_config.generate_links) {
|
||||
common_generator<diagram_config, diagram_model>::generate_link(ostr, c);
|
||||
}
|
||||
|
||||
if (!c.style().empty())
|
||||
ostr << " " << c.style();
|
||||
|
||||
@@ -124,6 +151,10 @@ void generator::generate(
|
||||
|
||||
ostr << " : " << uns.relative(type);
|
||||
|
||||
if (m_config.generate_links) {
|
||||
generate_link(ostr, m);
|
||||
}
|
||||
|
||||
ostr << '\n';
|
||||
}
|
||||
|
||||
@@ -201,7 +232,13 @@ void generator::generate(
|
||||
ostr << "{static} ";
|
||||
|
||||
ostr << plantuml_common::to_plantuml(m.scope()) << m.name() << " : "
|
||||
<< uns.relative(m.type()) << '\n';
|
||||
<< uns.relative(m.type());
|
||||
|
||||
if (m_config.generate_links) {
|
||||
generate_link(ostr, m);
|
||||
}
|
||||
|
||||
ostr << '\n';
|
||||
}
|
||||
|
||||
ostr << "}" << '\n';
|
||||
@@ -233,6 +270,10 @@ void generator::generate(
|
||||
{
|
||||
ostr << "enum " << e.alias();
|
||||
|
||||
if (m_config.generate_links) {
|
||||
common_generator<diagram_config, diagram_model>::generate_link(ostr, e);
|
||||
}
|
||||
|
||||
if (!e.style().empty())
|
||||
ostr << " " << e.style();
|
||||
|
||||
|
||||
@@ -59,6 +59,9 @@ class generator : public common_generator<diagram_config, diagram_model> {
|
||||
public:
|
||||
generator(diagram_config &config, diagram_model &model);
|
||||
|
||||
void generate_link(
|
||||
std::ostream &ostr, const class_diagram::model::class_element &e) const;
|
||||
|
||||
void generate_alias(const class_ &c, std::ostream &ostr) const;
|
||||
|
||||
void generate_alias(const enum_ &e, std::ostream &ostr) const;
|
||||
|
||||
@@ -34,4 +34,12 @@ std::string class_element::name() const { return name_; }
|
||||
|
||||
std::string class_element::type() const { return type_; }
|
||||
|
||||
inja::json class_element::context() const
|
||||
{
|
||||
inja::json ctx;
|
||||
ctx["name"] = name();
|
||||
ctx["type"] = type();
|
||||
ctx["scope"] = to_string(scope());
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/model/decorated_element.h"
|
||||
#include "common/model/source_location.h"
|
||||
|
||||
#include <inja/inja.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace clanguml::class_diagram::model {
|
||||
|
||||
class class_element : public common::model::decorated_element {
|
||||
class class_element : public common::model::decorated_element,
|
||||
public common::model::source_location {
|
||||
public:
|
||||
class_element(common::model::scope_t scope, const std::string &name,
|
||||
const std::string &type);
|
||||
@@ -32,6 +36,8 @@ public:
|
||||
std::string name() const;
|
||||
std::string type() const;
|
||||
|
||||
virtual inja::json context() const;
|
||||
|
||||
private:
|
||||
common::model::scope_t scope_;
|
||||
std::string name_;
|
||||
|
||||
@@ -248,6 +248,11 @@ void translation_unit_visitor::process_namespace(
|
||||
p->set_name(e.name());
|
||||
p->set_namespace(package_parent);
|
||||
|
||||
if (e.location().has_value()) {
|
||||
p->set_file(e.location().value().file);
|
||||
p->set_line(e.location().value().line);
|
||||
}
|
||||
|
||||
if (ns_declaration.comment().has_value())
|
||||
p->add_decorators(
|
||||
decorators::parse(ns_declaration.comment().value()));
|
||||
@@ -285,6 +290,11 @@ void translation_unit_visitor::process_enum_declaration(
|
||||
e.set_name(enm.name());
|
||||
e.set_namespace(ctx.get_namespace());
|
||||
|
||||
if (enm.location().has_value()) {
|
||||
e.set_file(enm.location().value().file);
|
||||
e.set_line(enm.location().value().line);
|
||||
}
|
||||
|
||||
if (enm.comment().has_value())
|
||||
e.add_decorators(decorators::parse(enm.comment().value()));
|
||||
|
||||
@@ -326,6 +336,12 @@ void translation_unit_visitor::process_class_declaration(
|
||||
{
|
||||
auto c_ptr = std::make_unique<class_>(ctx.config().using_namespace());
|
||||
auto &c = *c_ptr;
|
||||
|
||||
if (cls.location().has_value()) {
|
||||
c.set_file(cls.location().value().file);
|
||||
c.set_line(cls.location().value().line);
|
||||
}
|
||||
|
||||
c.is_struct(cls.class_kind() == cppast::cpp_class_kind::struct_t);
|
||||
|
||||
c.set_name(cls.name());
|
||||
@@ -741,6 +757,11 @@ void translation_unit_visitor::process_field(
|
||||
class_member m{
|
||||
detail::cpp_access_specifier_to_scope(as), mv.name(), type_name};
|
||||
|
||||
if (mv.location().has_value()) {
|
||||
m.set_file(mv.location().value().file);
|
||||
m.set_line(mv.location().value().line);
|
||||
}
|
||||
|
||||
if (mv.comment().has_value())
|
||||
m.add_decorators(decorators::parse(mv.comment().value()));
|
||||
|
||||
@@ -830,6 +851,11 @@ void translation_unit_visitor::process_static_field(
|
||||
class_member m{detail::cpp_access_specifier_to_scope(as), mv.name(),
|
||||
cppast::to_string(mv.type())};
|
||||
|
||||
if (mv.location().has_value()) {
|
||||
m.set_file(mv.location().value().file);
|
||||
m.set_line(mv.location().value().line);
|
||||
}
|
||||
|
||||
m.is_static(true);
|
||||
|
||||
if (mv.comment().has_value())
|
||||
@@ -853,6 +879,11 @@ void translation_unit_visitor::process_method(
|
||||
m.is_defaulted(false);
|
||||
m.is_static(false);
|
||||
|
||||
if (mf.location().has_value()) {
|
||||
m.set_file(mf.location().value().file);
|
||||
m.set_line(mf.location().value().line);
|
||||
}
|
||||
|
||||
if (mf.comment().has_value())
|
||||
m.add_decorators(decorators::parse(mf.comment().value()));
|
||||
|
||||
@@ -889,6 +920,11 @@ void translation_unit_visitor::process_template_method(
|
||||
m.is_defaulted(false);
|
||||
m.is_static(false);
|
||||
|
||||
if (mf.location().has_value()) {
|
||||
m.set_file(mf.location().value().file);
|
||||
m.set_line(mf.location().value().line);
|
||||
}
|
||||
|
||||
if (mf.comment().has_value())
|
||||
m.add_decorators(decorators::parse(mf.comment().value()));
|
||||
|
||||
@@ -920,6 +956,11 @@ void translation_unit_visitor::process_static_method(
|
||||
m.is_defaulted(false);
|
||||
m.is_static(true);
|
||||
|
||||
if (mf.location().has_value()) {
|
||||
m.set_file(mf.location().value().file);
|
||||
m.set_line(mf.location().value().line);
|
||||
}
|
||||
|
||||
if (mf.comment().has_value())
|
||||
m.add_decorators(decorators::parse(mf.comment().value()));
|
||||
|
||||
@@ -946,6 +987,11 @@ void translation_unit_visitor::process_constructor(
|
||||
m.is_defaulted(false);
|
||||
m.is_static(true);
|
||||
|
||||
if (mf.location().has_value()) {
|
||||
m.set_file(mf.location().value().file);
|
||||
m.set_line(mf.location().value().line);
|
||||
}
|
||||
|
||||
if (mf.comment().has_value())
|
||||
m.add_decorators(decorators::parse(mf.comment().value()));
|
||||
|
||||
@@ -970,6 +1016,11 @@ void translation_unit_visitor::process_destructor(
|
||||
m.is_defaulted(false);
|
||||
m.is_static(true);
|
||||
|
||||
if (mf.location().has_value()) {
|
||||
m.set_file(mf.location().value().file);
|
||||
m.set_line(mf.location().value().line);
|
||||
}
|
||||
|
||||
c.add_method(std::move(m));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user