ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
similar_function_finder.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include <string>
15#include <vector>
16
18#include <arkanjo/base/path.hpp>
20
23
30class SimilarFunctionFinder : public CommandBase<SimilarFunctionFinder> {
31 static constexpr const char* TEMPLATE_EMPTY_FUNCTION =
32 "There is no functions that resembles the "
33 "name: {pattern:function}\n"
34 "Value incorrected passed or there is no "
35 "duplication code with this function";
36 static constexpr const char* TEMPLATE_COUNT =
37 "The total number of functions that are "
38 "similar to the found one is {count}. "
39 "More info about them are listed below.";
40 static constexpr const char* REFERENCE_PATH_MESSAGE = "The following function was found:";
41
42 Similarity_Table* similarity_table;
43 std::string function_pattern;
44 bool open_folder;
45 bool show_mode;
46 bool no_numbers;
47 Path path;
48
52 void find_path_that_meets_pattern();
53
57 void print_empty_path_message() const;
58
63 Function get_reference_function(const Path& path) const;
64
68 void print_reference_path();
69
74 void print_similar_functions(const std::vector<Path>& similar_paths);
75
79 void print_similar_functions();
80
81 void handle_show_mode();
82
83 public:
84 static constexpr CliOption options_[] = {
85 {"function_name", 0, PositionalArgument, "The tool will match the parameter with any function that has the `FUNCTION_NAME` as a substring."},
86 {"open", 'o', NoArgument, "Open the folder where the function is located."},
87 {"show", 's', NoArgument, "Show detailed information and the full source code of the function."},
88 {"no-numbers", 0, NoArgument, "Hide line numbers in the displayed source code."},
90 };
91 COMMAND_DESCRIPTION("Search for functions using a substring match.")
92
93
98 explicit SimilarFunctionFinder(Similarity_Table* _similarity_table);
99
100 bool validate(const ParsedOptions& options) override;
101
105 bool run(const ParsedOptions& options) override;
106};
const CliOption * options() const final
Represents a function extracted from a codebase.
Definition: function.hpp:45
Represents a logical path to a function in the codebase.
Definition: path.hpp:26
Similar function locator and reporter.
static constexpr CliOption options_[]
bool validate(const ParsedOptions &options) override
Validate the arguments already analyzed.
bool run(const ParsedOptions &options) override
Handles similar function finding command.
Represents a similarity graph between functions (paths).
#define COMMAND_DESCRIPTION(str)
Definition: command_base.hpp:9
Function representation for a codebase.
#define OPTION_END
This marks the end of a long array of options.
@ NoArgument
@ PositionalArgument
Logical path abstraction for source code elements.
Similarity relationships storage and analysis.