Improved skipping of empty packages in class diagrams
This commit is contained in:
@@ -736,4 +736,19 @@ std::vector<std::string> tokenize_unexposed_template_parameter(
|
||||
return result;
|
||||
}
|
||||
|
||||
bool parse_source_location(const std::string &location_str, std::string &file,
|
||||
unsigned &line, unsigned &column)
|
||||
{
|
||||
auto tokens = util::split(location_str, ":");
|
||||
|
||||
if (tokens.size() < 3)
|
||||
return false;
|
||||
|
||||
file = tokens.at(0);
|
||||
line = std::stoi(tokens.at(1));
|
||||
column = std::stoi(tokens.at(2));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace clanguml::common
|
||||
|
||||
@@ -170,6 +170,9 @@ void if_dyn_cast(P pointer, F &&func)
|
||||
}
|
||||
}
|
||||
|
||||
bool parse_source_location(const std::string &location_str, std::string &file,
|
||||
unsigned &line, unsigned &column);
|
||||
|
||||
bool is_type_parameter(const std::string &t);
|
||||
|
||||
bool is_qualifier(const std::string &q);
|
||||
|
||||
@@ -70,7 +70,9 @@ public:
|
||||
if (parent && dynamic_cast<nested_trait<T, Path> *>(&parent.value()))
|
||||
return dynamic_cast<nested_trait<T, Path> &>(parent.value())
|
||||
.template add_element<V>(std::move(p));
|
||||
spdlog::info("No parent element found at: {}", path.to_string());
|
||||
|
||||
LOG_INFO("No parent element found at: {}", path.to_string());
|
||||
|
||||
throw std::runtime_error(
|
||||
"No parent element found for " + path.to_string());
|
||||
}
|
||||
@@ -135,7 +137,29 @@ public:
|
||||
elements_.end();
|
||||
}
|
||||
|
||||
bool is_empty() const { return elements_.empty(); }
|
||||
template <typename F> bool all_of(F &&f) const
|
||||
{
|
||||
return std::all_of(
|
||||
elements_.cbegin(), elements_.cend(), [f](const auto &e) {
|
||||
const auto *package_ptr =
|
||||
dynamic_cast<nested_trait<T, Path> *>(e.get());
|
||||
|
||||
if (package_ptr != nullptr)
|
||||
return package_ptr->all_of(f);
|
||||
|
||||
return f(*e);
|
||||
});
|
||||
}
|
||||
|
||||
bool is_empty() const
|
||||
{
|
||||
return elements_.empty() ||
|
||||
std::all_of(elements_.cbegin(), elements_.cend(), [](auto &e) {
|
||||
const auto *package_ptr =
|
||||
dynamic_cast<nested_trait<T, Path> *>(e.get());
|
||||
return package_ptr != nullptr && package_ptr->is_empty();
|
||||
});
|
||||
}
|
||||
|
||||
auto begin() { return elements_.begin(); }
|
||||
auto end() { return elements_.end(); }
|
||||
|
||||
@@ -85,14 +85,36 @@ void translation_unit_visitor::set_source_location(
|
||||
const clang::SourceLocation &location,
|
||||
clanguml::common::model::source_location &element)
|
||||
{
|
||||
std::string file;
|
||||
unsigned line{};
|
||||
[[maybe_unused]] unsigned column{};
|
||||
|
||||
if (location.isValid()) {
|
||||
element.set_file(source_manager_.getFilename(location).str());
|
||||
element.set_file_relative(util::path_to_url(
|
||||
std::filesystem::relative(element.file(), relative_to_path_)
|
||||
.string()));
|
||||
element.set_line(source_manager_.getSpellingLineNumber(location));
|
||||
element.set_location_id(location.getHashValue());
|
||||
file = source_manager_.getFilename(location).str();
|
||||
line = source_manager_.getSpellingLineNumber(location);
|
||||
column = source_manager_.getSpellingColumnNumber(location);
|
||||
|
||||
if (file.empty()) {
|
||||
// Why do I have to do this?
|
||||
parse_source_location(
|
||||
location.printToString(source_manager()), file, line, column);
|
||||
}
|
||||
}
|
||||
else {
|
||||
auto success = parse_source_location(
|
||||
location.printToString(source_manager()), file, line, column);
|
||||
if (!success) {
|
||||
LOG_DBG("Failed to extract source location for element from {}",
|
||||
location.printToString(source_manager_));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
element.set_file(file);
|
||||
element.set_file_relative(util::path_to_url(
|
||||
std::filesystem::relative(element.file(), relative_to_path_).string()));
|
||||
element.set_line(line);
|
||||
element.set_location_id(location.getHashValue());
|
||||
}
|
||||
|
||||
} // namespace clanguml::common::visitor
|
||||
Reference in New Issue
Block a user