Refactored method_parameter
This commit is contained in:
@@ -208,16 +208,30 @@ const std::vector<class_relationship> &element::relationships() const
|
||||
//
|
||||
// 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(
|
||||
const std::vector<std::string> &using_namespaces) const
|
||||
{
|
||||
using namespace clanguml::util;
|
||||
auto t = ns_relative(using_namespaces, type);
|
||||
if (default_value.empty())
|
||||
return fmt::format("{} {}", t, name);
|
||||
auto t = ns_relative(using_namespaces, type());
|
||||
if (default_value().empty())
|
||||
return fmt::format("{} {}", t, name());
|
||||
|
||||
return fmt::format("{} {} = {}", t, name, default_value);
|
||||
return fmt::format("{} {} = {}", t, name(), default_value());
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -114,13 +114,24 @@ private:
|
||||
bool is_static_{false};
|
||||
};
|
||||
|
||||
struct method_parameter : public decorated_element {
|
||||
std::string type;
|
||||
std::string name;
|
||||
std::string default_value;
|
||||
class method_parameter : public decorated_element {
|
||||
public:
|
||||
void set_type(const std::string &type);
|
||||
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(
|
||||
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 {
|
||||
|
||||
@@ -901,7 +901,7 @@ void tu_visitor::process_function_parameter(
|
||||
const std::set<std::string> &template_parameter_names)
|
||||
{
|
||||
method_parameter mp;
|
||||
mp.name = param.name();
|
||||
mp.set_name(param.name());
|
||||
|
||||
if (param.comment().has_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
|
||||
// so we have to deduce the correct namespace prefix of the
|
||||
// template which is being instantiated
|
||||
mp.type = cppast::to_string(param.type());
|
||||
mp.set_type(cppast::to_string(param.type()));
|
||||
}
|
||||
else {
|
||||
mp.type = cppast::to_string(param.type());
|
||||
mp.set_type(cppast::to_string(param.type()));
|
||||
}
|
||||
|
||||
auto dv = param.default_value();
|
||||
if (dv) {
|
||||
switch (dv.value().kind()) {
|
||||
case cppast::cpp_expression_kind::literal_t:
|
||||
mp.default_value =
|
||||
mp.set_default_value(
|
||||
static_cast<const cppast::cpp_literal_expression &>(dv.value())
|
||||
.value();
|
||||
.value());
|
||||
break;
|
||||
case cppast::cpp_expression_kind::unexposed_t:
|
||||
mp.default_value =
|
||||
mp.set_default_value(
|
||||
static_cast<const cppast::cpp_unexposed_expression &>(
|
||||
dv.value())
|
||||
.expression()
|
||||
.as_string();
|
||||
.as_string());
|
||||
break;
|
||||
default:
|
||||
mp.default_value = "{}";
|
||||
mp.set_default_value("{}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user