Added generate_method_arguments handling in class diagram generator
This commit is contained in:
@@ -150,13 +150,19 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
|
||||
ostr << to_string(m.scope()) << m.name();
|
||||
|
||||
ostr << "(";
|
||||
if (true) { // TODO: add option to disable parameter generation
|
||||
if (m_config.generate_method_arguments() !=
|
||||
config::method_arguments::none) {
|
||||
std::vector<std::string> params;
|
||||
std::transform(m.parameters().cbegin(), m.parameters().cend(),
|
||||
std::back_inserter(params), [this](const auto &mp) {
|
||||
return mp.to_string(m_config.using_namespace());
|
||||
});
|
||||
ostr << fmt::format("{}", fmt::join(params, ", "));
|
||||
auto args_string = fmt::format("{}", fmt::join(params, ", "));
|
||||
if (m_config.generate_method_arguments() !=
|
||||
config::method_arguments::abbreviated) {
|
||||
args_string = clanguml::util::abbreviate(args_string, 10);
|
||||
}
|
||||
ostr << args_string;
|
||||
}
|
||||
ostr << ")";
|
||||
|
||||
|
||||
@@ -109,6 +109,22 @@ std::string unqualify(const std::string &s)
|
||||
return fmt::format("{}", fmt::join(toks, " "));
|
||||
}
|
||||
|
||||
std::string abbreviate(const std::string &s, const unsigned int max_length)
|
||||
{
|
||||
if (s.size() <= max_length)
|
||||
return s;
|
||||
|
||||
auto res = s;
|
||||
|
||||
res.resize(max_length);
|
||||
|
||||
if (res.size() > 3) {
|
||||
res.replace(res.size() - 3, 3, 3, '.');
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool find_element_alias(
|
||||
const std::string &input, std::tuple<std::string, size_t, size_t> &result)
|
||||
{
|
||||
|
||||
@@ -94,6 +94,16 @@ std::string ns_relative(
|
||||
*/
|
||||
std::string unqualify(const std::string &s);
|
||||
|
||||
/**
|
||||
* @brief Abbreviate string to max_length, and replace last 3 characters
|
||||
* with ellipsis.
|
||||
*
|
||||
* @param s Input string
|
||||
* @param max_length Maximum length
|
||||
* @return Abbreviated string
|
||||
*/
|
||||
std::string abbreviate(const std::string &s, const unsigned int max_length);
|
||||
|
||||
/**
|
||||
* @brief Find element alias in Puml note
|
||||
*
|
||||
|
||||
@@ -47,6 +47,16 @@ TEST_CASE("Test ns_relative", "[unit-test]")
|
||||
CHECK(ns_relative({"clanguml::t0"}, "clanguml::t0") == "t0");
|
||||
}
|
||||
|
||||
TEST_CASE("Test abbreviate", "[unit-test]")
|
||||
{
|
||||
using namespace clanguml::util;
|
||||
|
||||
CHECK(abbreviate("", 10) == "");
|
||||
CHECK(abbreviate("abcd", 10) == "abcd");
|
||||
CHECK(abbreviate("abcd", 2) == "ab");
|
||||
CHECK(abbreviate("abcdefg", 5) == "ab...");
|
||||
}
|
||||
|
||||
TEST_CASE("Test replace_all", "[unit-test]")
|
||||
{
|
||||
using namespace clanguml::util;
|
||||
|
||||
Reference in New Issue
Block a user