Skip generation of empty or invalid relationships in PlantUML output

This commit is contained in:
Bartek Kryza
2021-05-22 14:09:39 +02:00
parent 6cc49c2660
commit 08f00889e2
6 changed files with 145 additions and 63 deletions

View File

@@ -199,47 +199,68 @@ public:
if (m_config.should_include_relationship("inheritance"))
for (const auto &b : c.bases) {
ostr << m_model.to_alias(m_config.using_namespace,
ns_relative(m_config.using_namespace, b.name))
<< " <|-- "
<< m_model.to_alias(m_config.using_namespace,
ns_relative(m_config.using_namespace, c.name))
<< std::endl;
std::stringstream relstr;
try {
relstr << m_model.to_alias(m_config.using_namespace,
ns_relative(m_config.using_namespace, b.name))
<< " <|-- "
<< m_model.to_alias(m_config.using_namespace,
ns_relative(m_config.using_namespace, c.name))
<< std::endl;
ostr << relstr.str();
}
catch (error::uml_alias_missing &e) {
LOG_ERROR("Skipping inheritance relation from {} to {} due "
"to: {}",
b.name, c.name, e.what());
}
}
for (const auto &r : c.relationships) {
if (!m_config.should_include_relationship(name(r.type)))
continue;
std::string destination;
if (r.destination.find("#") != std::string::npos ||
r.destination.find("@") != std::string::npos) {
destination = m_model.usr_to_name(
m_config.using_namespace, r.destination);
std::stringstream relstr;
// If something went wrong and we have an empty destination
// generate the relationship but comment it out for
// debugging
if (destination.empty()) {
ostr << "' ";
std::string destination;
try {
if (r.destination.find("#") != std::string::npos ||
r.destination.find("@") != std::string::npos) {
destination = m_model.usr_to_name(
m_config.using_namespace, r.destination);
// If something went wrong and we have an empty destination
// generate the relationship but comment it out for
// debugging
if (destination.empty()) {
relstr << "' ";
destination = r.destination;
}
}
else {
destination = r.destination;
}
relstr << m_model.to_alias(m_config.using_namespace,
ns_relative(m_config.using_namespace,
c.full_name(m_config.using_namespace)))
<< " " << to_string(r.type) << " "
<< m_model.to_alias(m_config.using_namespace,
ns_relative(
m_config.using_namespace, destination));
if (!r.label.empty())
relstr << " : " << r.label;
relstr << std::endl;
ostr << relstr.str();
}
else {
destination = r.destination;
catch (error::uml_alias_missing &e) {
LOG_ERROR("Skipping {} relation from {} to {} due "
"to: {}",
to_string(r.type), c.full_name(m_config.using_namespace),
destination, e.what());
}
ostr << m_model.to_alias(m_config.using_namespace,
ns_relative(m_config.using_namespace,
c.full_name(m_config.using_namespace)))
<< " " << to_string(r.type) << " "
<< m_model.to_alias(m_config.using_namespace,
ns_relative(m_config.using_namespace, destination));
if (!r.label.empty())
ostr << " : " << r.label;
ostr << std::endl;
}
}
@@ -259,29 +280,39 @@ public:
continue;
std::string destination;
if (r.destination.find("#") != std::string::npos ||
r.destination.find("@") != std::string::npos) {
destination = m_model.usr_to_name(
m_config.using_namespace, r.destination);
if (destination.empty()) {
ostr << "' ";
std::stringstream relstr;
try {
if (r.destination.find("#") != std::string::npos ||
r.destination.find("@") != std::string::npos) {
destination = m_model.usr_to_name(
m_config.using_namespace, r.destination);
if (destination.empty()) {
relstr << "' ";
destination = r.destination;
}
}
else {
destination = r.destination;
}
relstr << m_model.to_alias(m_config.using_namespace,
ns_relative(m_config.using_namespace, e.name))
<< " " << to_string(r.type) << " "
<< m_model.to_alias(m_config.using_namespace,
ns_relative(
m_config.using_namespace, destination));
if (!r.label.empty())
relstr << " : " << r.label;
relstr << std::endl;
ostr << relstr.str();
}
else {
destination = r.destination;
catch (error::uml_alias_missing &ex) {
LOG_ERROR("Skipping {} relation from {} to {} due "
"to: {}",
to_string(r.type), e.name, destination, ex.what());
}
ostr << m_model.to_alias(m_config.using_namespace,
ns_relative(m_config.using_namespace, e.name))
<< " " << to_string(r.type) << " "
<< m_model.to_alias(m_config.using_namespace,
ns_relative(m_config.using_namespace, destination));
if (!r.label.empty())
ostr << " : " << r.label;
ostr << std::endl;
}
}