Arkanjo 0.2
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
counter_duplication_code.cpp
Go to the documentation of this file.
2
3void CounterDuplicationCode::mark_path_as_processed(Path path) {
4 processed_paths.insert(path);
5}
6
7bool CounterDuplicationCode::is_path_processed_path(Path path) {
8 return processed_paths.find(path) != processed_paths.end();
9}
10
11int CounterDuplicationCode::get_number_of_lines_in_path(const Path& path) {
12 Function function(path);
13 function.load();
14 return function.number_of_lines();
15}
16
17void CounterDuplicationCode::register_code_duplication(const Path& path1, const Path& path2, int number_of_lines) {
18 std::vector<std::string> common_folder_path = path1.get_common_folders(path2);
19 counter_duplication_code_trie.add_folder_duplication_code(common_folder_path, number_of_lines);
20}
21
22void CounterDuplicationCode::process_path(const Path& path) {
23 if (is_path_processed_path(path)) {
24 return;
25 }
26 int number_of_lines = get_number_of_lines_in_path(path);
27 mark_path_as_processed(path);
28 std::vector<Path> similar_paths = similarity_table->get_similar_path_to_the_reference(path);
29 for (const auto& similar_path : similar_paths) {
30 mark_path_as_processed(similar_path);
31 register_code_duplication(path, similar_path, number_of_lines);
32 }
33}
34
35void CounterDuplicationCode::process_every_path_in_similarity_table() {
36 std::vector<Path> paths = similarity_table->get_path_list();
37 for (const auto& path : paths) {
38 process_path(path);
39 }
40}
41
42CounterDuplicationCode::CounterDuplicationCode(Similarity_Table* _similarity_table) {
43 similarity_table = _similarity_table;
44}
45
47 auto it_json = options.args.find("json");
48 if (it_json != options.args.end()) {
49 throw CLIError("--json is not supported in this command.");
50 return false;
51 }
52 return true;
53}
54
55bool CounterDuplicationCode::run([[maybe_unused]] const ParsedOptions& options) {
56 process_every_path_in_similarity_table();
57 counter_duplication_code_trie.print_duplication_code_trie();
58
59 return true;
60}
Base class for CLI-related errors.
Definition cli_error.hpp:10
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.
Represents a code function with its content and metadata.
Definition function.hpp:30
Path manipulation class for tool-specific directory structure.
Definition path.hpp:27
std::vector< std::string > get_common_folders(const Path &path) const
Finds common folders with another path.
Definition path.cpp:119
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.