Fixed rendering of methods in template class specializations

This commit is contained in:
Bartek Kryza
2023-05-14 18:57:40 +02:00
parent 0fbf491dfe
commit 02f470e563
4 changed files with 24 additions and 10 deletions

View File

@@ -1269,8 +1269,16 @@ void translation_unit_visitor::process_method(
ensure_lambda_type_is_relative(method_return_type); ensure_lambda_type_is_relative(method_return_type);
auto method_name = mf.getNameAsString();
if (mf.isTemplated()) {
// Sometimes in template specializations method names contain the
// template parameters for some reason - drop them
// Is there a better way to do this?
method_name = method_name.substr(0, method_name.find('<'));
}
class_method method{common::access_specifier_to_access_t(mf.getAccess()), class_method method{common::access_specifier_to_access_t(mf.getAccess()),
util::trim(mf.getNameAsString()), method_return_type}; util::trim(method_name), method_return_type};
method.is_pure_virtual(mf.isPure()); method.is_pure_virtual(mf.isPure());
method.is_virtual(mf.isVirtual()); method.is_virtual(mf.isVirtual());
@@ -1302,16 +1310,18 @@ void translation_unit_visitor::process_method(
unaliased_type = unaliased_type->getAliasedType() unaliased_type = unaliased_type->getAliasedType()
->getAs<clang::TemplateSpecializationType>(); ->getAs<clang::TemplateSpecializationType>();
auto template_specialization_ptr = tbuilder().build( if (unaliased_type != nullptr) {
unaliased_type->getTemplateName().getAsTemplateDecl(), auto template_specialization_ptr = tbuilder().build(
*unaliased_type, &c); unaliased_type->getTemplateName().getAsTemplateDecl(),
*unaliased_type, &c);
if (diagram().should_include( if (diagram().should_include(
template_specialization_ptr->full_name(false))) { template_specialization_ptr->full_name(false))) {
relationships.emplace_back( relationships.emplace_back(template_specialization_ptr->id(),
template_specialization_ptr->id(), relationship_t::kDependency); relationship_t::kDependency);
diagram().add_class(std::move(template_specialization_ptr)); diagram().add_class(std::move(template_specialization_ptr));
}
} }
} }

View File

@@ -161,7 +161,7 @@ std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx,
clanguml::util::replace_all(result, ", ", ","); clanguml::util::replace_all(result, ", ", ",");
clanguml::util::replace_all(result, "> >", ">>"); clanguml::util::replace_all(result, "> >", ">>");
// Get rid of 'type-parameter-X-Y' ugliness // Try to get rid of 'type-parameter-X-Y' ugliness
if (result.find("type-parameter-") != std::string::npos) { if (result.find("type-parameter-") != std::string::npos) {
util::apply_if_not_null( util::apply_if_not_null(
common::dereference(type)->getAs<clang::TypedefType>(), common::dereference(type)->getAs<clang::TypedefType>(),

View File

@@ -15,6 +15,8 @@ public:
{ {
} }
template <typename CastTo> CastTo *get_signal() { return (CastTo *)signal; }
private: private:
signal_t *signal; signal_t *signal;
}; };

View File

@@ -35,6 +35,8 @@ TEST_CASE("t00044", "[test-case][class]")
REQUIRE_THAT(puml, StartsWith("@startuml")); REQUIRE_THAT(puml, StartsWith("@startuml"));
REQUIRE_THAT(puml, EndsWith("@enduml\n")); REQUIRE_THAT(puml, EndsWith("@enduml\n"));
REQUIRE_THAT(puml, !Contains("type-parameter-"));
REQUIRE_THAT(puml, IsClassTemplate("sink", "T")); REQUIRE_THAT(puml, IsClassTemplate("sink", "T"));
REQUIRE_THAT(puml, IsClassTemplate("signal_handler", "T,A")); REQUIRE_THAT(puml, IsClassTemplate("signal_handler", "T,A"));