Refactored method_parameter

This commit is contained in:
Bartek Kryza
2021-09-27 22:11:02 +02:00
parent a1d96dfeeb
commit e119baee5b
3 changed files with 41 additions and 16 deletions

View File

@@ -208,16 +208,30 @@ const std::vector<class_relationship> &element::relationships() const
// //
// method_parameter // method_parameter
// //
void method_parameter::set_type(const std::string &type) { type_ = type; }
std::string method_parameter::type() const { return type_; }
void method_parameter::set_name(const std::string &name) { name_ = name; }
std::string method_parameter::name() const { return name_; }
void method_parameter::set_default_value(const std::string &value)
{
default_value_ = value;
}
std::string method_parameter::default_value() const { return default_value_; }
std::string method_parameter::to_string( std::string method_parameter::to_string(
const std::vector<std::string> &using_namespaces) const const std::vector<std::string> &using_namespaces) const
{ {
using namespace clanguml::util; using namespace clanguml::util;
auto t = ns_relative(using_namespaces, type); auto t = ns_relative(using_namespaces, type());
if (default_value.empty()) if (default_value().empty())
return fmt::format("{} {}", t, name); return fmt::format("{} {}", t, name());
return fmt::format("{} {} = {}", t, name, default_value); return fmt::format("{} {} = {}", t, name(), default_value());
} }
// //

View File

@@ -114,13 +114,24 @@ private:
bool is_static_{false}; bool is_static_{false};
}; };
struct method_parameter : public decorated_element { class method_parameter : public decorated_element {
std::string type; public:
std::string name; void set_type(const std::string &type);
std::string default_value; std::string type() const;
void set_name(const std::string &name);
std::string name() const;
void set_default_value(const std::string &value);
std::string default_value() const;
std::string to_string( std::string to_string(
const std::vector<std::string> &using_namespaces) const; const std::vector<std::string> &using_namespaces) const;
private:
std::string type_;
std::string name_;
std::string default_value_;
}; };
class class_method : public class_element { class class_method : public class_element {

View File

@@ -901,7 +901,7 @@ void tu_visitor::process_function_parameter(
const std::set<std::string> &template_parameter_names) const std::set<std::string> &template_parameter_names)
{ {
method_parameter mp; method_parameter mp;
mp.name = param.name(); mp.set_name(param.name());
if (param.comment().has_value()) if (param.comment().has_value())
m.add_decorators(decorators::parse(param.comment().value())); m.add_decorators(decorators::parse(param.comment().value()));
@@ -915,29 +915,29 @@ void tu_visitor::process_function_parameter(
// TODO: Template instantiation parameters are not fully prefixed // TODO: Template instantiation parameters are not fully prefixed
// so we have to deduce the correct namespace prefix of the // so we have to deduce the correct namespace prefix of the
// template which is being instantiated // template which is being instantiated
mp.type = cppast::to_string(param.type()); mp.set_type(cppast::to_string(param.type()));
} }
else { else {
mp.type = cppast::to_string(param.type()); mp.set_type(cppast::to_string(param.type()));
} }
auto dv = param.default_value(); auto dv = param.default_value();
if (dv) { if (dv) {
switch (dv.value().kind()) { switch (dv.value().kind()) {
case cppast::cpp_expression_kind::literal_t: case cppast::cpp_expression_kind::literal_t:
mp.default_value = mp.set_default_value(
static_cast<const cppast::cpp_literal_expression &>(dv.value()) static_cast<const cppast::cpp_literal_expression &>(dv.value())
.value(); .value());
break; break;
case cppast::cpp_expression_kind::unexposed_t: case cppast::cpp_expression_kind::unexposed_t:
mp.default_value = mp.set_default_value(
static_cast<const cppast::cpp_unexposed_expression &>( static_cast<const cppast::cpp_unexposed_expression &>(
dv.value()) dv.value())
.expression() .expression()
.as_string(); .as_string());
break; break;
default: default:
mp.default_value = "{}"; mp.set_default_value("{}");
} }
} }