Added support for styling static methods in sequence diagrams
This commit is contained in:
@@ -249,12 +249,15 @@ std::string method::full_name(bool /*relative*/) const
|
||||
|
||||
std::string method::message_name(message_render_mode mode) const
|
||||
{
|
||||
const std::string style = is_static() ? "__" : "";
|
||||
|
||||
if (mode == message_render_mode::no_arguments) {
|
||||
return fmt::format("{}(){}", method_name(), is_const() ? " const" : "");
|
||||
return fmt::format("{}{}(){}{}", style, method_name(),
|
||||
is_const() ? " const" : "", style);
|
||||
}
|
||||
|
||||
return fmt::format("{}({}){}", method_name(), fmt::join(parameters(), ","),
|
||||
is_const() ? " const" : "");
|
||||
return fmt::format("{}{}({}){}{}", style, method_name(),
|
||||
fmt::join(parameters(), ","), is_const() ? " const" : "", style);
|
||||
}
|
||||
|
||||
class_::diagram_element::id_t method::class_id() const { return class_id_; }
|
||||
@@ -265,6 +268,10 @@ std::string method::to_string() const
|
||||
type_name(), id(), full_name(false), class_id());
|
||||
}
|
||||
|
||||
bool method::is_static() const { return is_static_; }
|
||||
|
||||
void method::is_static(bool s) { is_static_ = s; }
|
||||
|
||||
function_template::function_template(
|
||||
const common::model::namespace_ &using_namespace)
|
||||
: function{using_namespace}
|
||||
|
||||
@@ -200,10 +200,15 @@ struct method : public function {
|
||||
|
||||
std::string to_string() const override;
|
||||
|
||||
bool is_static() const;
|
||||
|
||||
void is_static(bool s);
|
||||
|
||||
private:
|
||||
diagram_element::id_t class_id_;
|
||||
std::string method_name_;
|
||||
std::string class_full_name_;
|
||||
bool is_static_{false};
|
||||
};
|
||||
|
||||
struct function_template : public function, public template_trait {
|
||||
|
||||
@@ -314,6 +314,7 @@ bool translation_unit_visitor::VisitCXXMethodDecl(clang::CXXMethodDecl *m)
|
||||
m_ptr->set_name(
|
||||
get_participant(m_ptr->class_id()).value().full_name_no_ns() +
|
||||
"::" + m->getNameAsString());
|
||||
m_ptr->is_static(m->isStatic());
|
||||
|
||||
for (const auto *param : m->parameters()) {
|
||||
m_ptr->add_parameter(simplify_system_template(
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
return res;
|
||||
}
|
||||
|
||||
void log_result(int r) { }
|
||||
static void log_result(int r) { }
|
||||
|
||||
private:
|
||||
detail::C m_c{};
|
||||
|
||||
@@ -38,8 +38,8 @@ TEST_CASE("t20001", "[test-case][sequence]")
|
||||
REQUIRE_THAT(puml, StartsWith("@startuml"));
|
||||
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
|
||||
|
||||
REQUIRE_THAT(puml, HasCall(_A("A"), "log_result(int)"));
|
||||
REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "log_result(int)"));
|
||||
REQUIRE_THAT(puml, HasCall(_A("A"), "__log_result(int)__"));
|
||||
REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "__log_result(int)__"));
|
||||
REQUIRE_THAT(
|
||||
puml, HasCallWithResponse(_A("B"), _A("A"), "add3(int,int,int)"));
|
||||
REQUIRE_THAT(puml, HasCall(_A("A"), "add(int,int)"));
|
||||
|
||||
Reference in New Issue
Block a user