5std::vector<std::string> CounterDuplicationCode::common_folders(
8 std::vector<std::string> tokens_relative_1;
9 std::vector<std::string> tokens_relative_2;
11 for (
const auto& part : path1.
value())
12 tokens_relative_1.push_back(part.string());
13 for (
const auto& part : path2.
value())
14 tokens_relative_2.push_back(part.string());
16 size_t minimum_size_tokens = std::min(tokens_relative_1.size(), tokens_relative_2.size());
17 std::vector<std::string> common_folders;
18 for (
size_t i = 0; i < minimum_size_tokens; i++) {
19 auto token_1 = tokens_relative_1[i];
20 auto token_2 = tokens_relative_2[i];
21 if (token_1 == token_2)
22 common_folders.push_back(token_1);
26 return common_folders;
29void CounterDuplicationCode::mark_path_as_processed(
Path path) {
30 processed_paths.insert(path);
33bool CounterDuplicationCode::is_path_processed_path(
Path path) {
34 return processed_paths.find(path) != processed_paths.end();
37int CounterDuplicationCode::get_number_of_lines_in_path(
const Path& path) {
43void CounterDuplicationCode::register_code_duplication(
const Path& path1,
const Path& path2,
int number_of_lines) {
44 std::vector<std::string> common_folder_path = common_folders(path1, path2);
48void CounterDuplicationCode::process_path(
const Path& path) {
49 if (is_path_processed_path(path)) {
52 uint32_t number_of_lines = get_number_of_lines_in_path(path);
53 mark_path_as_processed(path);
55 for (
const auto& similar_path : similar_paths) {
56 mark_path_as_processed(similar_path);
57 register_code_duplication(path, similar_path, number_of_lines);
61void CounterDuplicationCode::process_every_path_in_similarity_table() {
63 for (
const auto& path : paths) {
68CounterDuplicationCode::CounterDuplicationCode(
Similarity_Table* _similarity_table) {
69 similarity_table = _similarity_table;
74 throw CLIError(
"--json is not supported in this command.");
80 process_every_path_in_similarity_table();
Base class for CLI-related errors.
const CliOption * options() const final
void add_folder_duplication_code(const std::vector< std::string > &folder_path, int number_of_duplication_lines)
Adds duplication count for a folder path.
void print_duplication_code_trie()
Prints the trie structure with duplication counts.
bool validate(const ParsedOptions &options) override
Validate the arguments already analyzed.
bool run(const ParsedOptions &options) override
Handles duplication analysis command.
Function load_metadata(const Path &path)
Loads function metadata from a path.
const FunctionLocation & scope_location() const
Gets the function location inside the source file.
Represents a logical path to a function in the codebase.
const fs::path & value() const
Gets the underlying filesystem path.
Represents a similarity graph between functions (paths).
const std::vector< Path > & get_path_list() const
Gets list of all known paths.
std::vector< Path > get_similar_path_to_the_reference(const Path &reference)
Gets paths similar to reference path.
Code duplication reporting system.
Provides functionality to load Function objects from external sources.
constexpr uint32_t size() const noexcept