Dependency Tree Generation Method and Apparatus
By querying the component information library in the target project to obtain or generate the component's declaration table and call table, the problem of relying on third-party files in the existing technology is solved, and the applicability and efficiency of dependency tree generation is improved.
Patent Information
- Application Number
- CN202211572177.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-08
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2042-12-08
AI Technical Summary
When generating dependency trees, the existing technology needs to rely on third-party files, resulting in low applicability and accuracy, and each time it is necessary to generate a declaration table and a call table of components, affecting efficiency.
A dependency tree generation method is proposed. By obtaining the component name and version of the component in the target project, querying the component information library to obtain or generate the component's declaration table and call table, and then generating the dependency tree without relying on third-party files.
Improve the applicability and accuracy of dependency tree generation, reduce the frequency of generating component declaration tables and call tables, and improve the efficiency of dependency tree generation.
Smart Images

Figure CN116028019B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for generating a dependency tree. Background Art
[0002] In a computer project, there are usually multiple third-party components. A tree structure generated based on the call relationships between the third-party components is called a dependency tree. In related technologies, computer projects often change or upgrade third-party components due to function changes, vulnerability repairs, etc. Since the number of third-party components referenced in current computer projects is huge, a project may reference hundreds or even thousands of third-party components. Individually changing or upgrading a certain component may affect the usability of other components that have call relationships with this component. Therefore, when making changes or upgrades to third-party components, if the call relationships before and after each component can be understood based on the dependency tree, the impact caused by changing or upgrading components can be better analyzed and evaluated, and it is also helpful to analyze and locate the component call chains affected by vulnerabilities. Summary of the Invention
[0003] The present invention aims to at least solve one of the technical problems in the related technologies to some extent.
[0004] To this end, a first object of the present invention is to propose a method for generating a dependency tree to generate a dependency tree based on a component declaration table and a call table, without relying on third-party files, and improve the applicability of the method.
[0005] A second object of the present invention is to propose an apparatus for generating a dependency tree.
[0006] A third object of the present invention is to propose an electronic device.
[0007] A fourth object of the present invention is to propose a computer-readable storage medium.
[0008] A fifth object of the present invention is to propose a computer program product.
[0009] To achieve the above object, an embodiment of the first aspect of the present invention proposes a method for generating a dependency tree, including:
[0010] Obtaining the component names and component versions of at least two components in a target project;
[0011] For any one of the components, querying whether component information of the component exists in a component information library based on the component name and component version of the component;
[0012] In response to the existence of the component information of the component in the component information library, obtaining the declaration table and call table of the component from the component information library;
[0013] In response to the non - existence of component information of the component in the component information library, obtain the method information of at least one declared method and the method information of at least one called method in the component, generate a declaration table of the component based on the method information of each declared method, and generate a call table of the component based on the method information of each called method;
[0014] Generate a dependency tree corresponding to the target project according to the declaration tables and call tables of the components in the target project.
[0015] Optionally, as the first possible implementation manner of the first aspect, the method information includes class name, method name, number of parameters, and parameter types; the generating a declaration table of the component based on the method information of each declared method and generating a call table of the component based on the method information of each called method includes:
[0016] For any one of the declared methods or called methods in the component, determine a class - name feature value, a method - name feature value, and a parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type and a preset position coefficient;
[0017] Generate a method - characterized numerical value according to the length of the class name, the class - name feature value, the length of the method name, the method - name feature value, the number of parameters, the parameter feature value, and a preset character;
[0018] Generate a declaration table of the component based on the method - characterized numerical values of each declared method, and generate a call table of the component based on the method - characterized numerical values of each called method.
[0019] Optionally, as the second possible implementation manner of the first aspect, the determining a class - name feature value, a method - name feature value, and a parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type and a preset position coefficient includes:
[0020] Sort each position character in the class name, method name, and parameter type to determine the order of each position character; among them, the position characters with adjacent order have an adjacent relationship, and there is an adjacent relationship between the first and last position characters;
[0021] For any one of the position characters, determine the ASCII code ratio between the position characters with an adjacent relationship as the ASCII code ratio of the position character;
[0022] Multiply the ASCII code ratio of the position character by the preset position coefficient corresponding to the position character to obtain the feature value of the position character;
[0023] Add the characteristic values of each of the position characters in the class name, method name, and parameter types to obtain a class name characteristic value, a method name characteristic value, and a parameter characteristic value.
[0024] Optionally, as a third possible implementation manner of the first aspect, the generating a method characterization value according to the length of the class name, the class name characteristic value, the length of the method name, the method name characteristic value, the number of parameters, the parameter characteristic value, and a preset character includes:
[0025] Concatenate the length of the class name, the class name characteristic value, the length of the method name, the method name characteristic value, the number of parameters, and the parameter characteristic value with a preset character to generate a method characterization value.
[0026] Optionally, as a fourth possible implementation manner of the first aspect, the method characterization value includes at least one numerical data, and the generating the declaration table of the component based on the method characterization values of each of the declared methods, and generating the call table of the component based on the method characterization values of each of the called methods includes:
[0027] For each of the declared methods, compare each of the numerical data in the method characterization value of each of the declared methods based on the order of at least one numerical data in the method characterization value;
[0028] Generate the declaration table of the component according to the first comparison result;
[0029] For each of the called methods, compare each of the numerical data in the method characterization value of each of the called methods based on the order of at least one numerical data in the method characterization value;
[0030] Generate the call table of the component according to the second comparison result.
[0031] Optionally, as a fifth possible implementation manner of the first aspect, the generating the dependency tree corresponding to the target project according to the declaration table and the call table of each of the components in the target project includes:
[0032] For any one of the components in the target project, obtain the method characterization value of at least one called method from the call table of the component;
[0033] Match the method characterization value with the method characterization values of each of the declared methods in the declaration tables of other components in the target project except the component to determine the call relationship between each of the components;
[0034] Generate the dependency tree corresponding to the target project based on the call relationship between each of the components.
[0035] Optionally, as a sixth possible implementation manner of the first aspect, the statement table stores the method characterization values of the respective statement methods in sequence, the call table stores the method characterization values of the respective call methods in sequence, the method characterization values include at least one numerical data, and the matching of the method characterization values with the method characterization values of the respective statement methods in the statement tables of other components in the target project except the component to determine the call relationship between the respective components includes:
[0036] Based on the order of at least one numerical data in the method characterization values, the binary search method is used to respectively match the respective numerical data in the method characterization values with the corresponding numerical data in the method characterization values of the respective statement methods in the statement tables of other components in the target project except the component;
[0037] When all the numerical data in the method characterization values are matched and consistent, it is determined that there is a call relationship between the component and the other components.
[0038] Optionally, as a seventh possible implementation manner of the first aspect, the component information library is used to store the component information of at least one component, and the component information includes the component name, component version, statement table, and call table.
[0039] The method further includes:
[0040] When the component information of the component does not exist in the component information library, the generated statement table and call table of the component, as well as the component name and component version of the component are added to the component information library.
[0041] To achieve the above object, an embodiment of the second aspect of the present invention provides a dependency tree generation device, including:
[0042] A first acquisition module, configured to acquire the component names and component versions of at least two components in a target project;
[0043] A query module, configured to query, for any one of the components, whether the component information of the component exists in a component information library based on the component name and component version of the component;
[0044] A second acquisition module, configured to, in response to the existence of the component information of the component in the component information library, acquire the statement table and call table of the component from the component information library;
[0045] A processing module, configured to, in response to the absence of component information of the component in the component information library, obtain the method information of at least one declared method and the method information of at least one invoked method in the component, generate a declaration table of the component based on the method information of each of the declared methods, and generate an invocation table of the component based on the method information of each of the invoked methods;
[0046] A generation module, configured to generate a dependency tree corresponding to the target project according to the declaration tables and invocation tables of the components in the target project.
[0047] Optionally, as a first possible implementation manner of the second aspect, the method information includes a class name, a method name, the number of parameters, and parameter types; the processing module includes:
[0048] A determination unit, configured to, for any one of the declared methods or the invoked methods in the component, determine a class name feature value, a method name feature value, and a parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type and a preset position coefficient;
[0049] A first generation unit, configured to generate a method characterization value according to the length of the class name, the class name feature value, the length of the method name, the method name feature value, the number of parameters, the parameter feature value, and a preset character;
[0050] A second generation unit, configured to generate a declaration table of the component based on the method characterization values of each of the declared methods, and generate an invocation table of the component based on the method characterization values of each of the invoked methods.
[0051] Optionally, as a second possible implementation manner of the second aspect, the determination unit is further configured to:
[0052] Sort each position character in the class name, method name, and parameter type to determine the order of each position character; wherein, adjacent position characters, and the first and last position characters have an adjacent relationship;
[0053] For any one of the position characters, determine the ASCII code ratio between the adjacent position characters as the ASCII code ratio of the position character;
[0054] Multiply the ASCII code ratio of the position character by the preset position coefficient corresponding to the position character to obtain the feature value of the position character;
[0055] Add the feature values of each of the position characters in the class name, method name, and parameter type to obtain a class name feature value, a method name feature value, and a parameter feature value.
[0056] Optionally, as a third possible implementation manner of the second aspect, the first generating unit is further configured to:
[0057] Concatenate the length of the class name, the class name feature value, the length of the method name, the method name feature value, the number of parameters, and the parameter feature value with a preset character to generate a method-characterized value.
[0058] Optionally, as a fourth possible implementation manner of the second aspect, the method-characterized value includes at least one numerical data, and the second generating unit is further configured to:
[0059] For each of the declared methods, compare each of the numerical data in the method-characterized value of each of the declared methods based on the order of at least one numerical data in the method-characterized value;
[0060] Generate a declaration table of the component according to the first comparison result;
[0061] For each of the called methods, compare each of the numerical data in the method-characterized value of each of the called methods based on the order of at least one numerical data in the method-characterized value;
[0062] Generate a call table of the component according to the second comparison result.
[0063] Optionally, as a fifth possible implementation manner of the second aspect, the generating module includes:
[0064] An obtaining unit, configured to obtain the method-characterized value of at least one called method from the call table of the component for any component in the target project;
[0065] A matching unit, configured to match the method-characterized value with the method-characterized values of each of the declared methods in the declaration tables of other components except the component in the target project to determine the call relationship between each of the components;
[0066] A third generating unit, configured to generate a dependency tree corresponding to the target project based on the call relationship between each of the components.
[0067] Optionally, as a sixth possible implementation manner of the second aspect, the declaration table stores the method-characterized values of each of the declared methods in sequence, the call table stores the method-characterized values of each of the called methods in sequence, the method-characterized value includes at least one numerical data, and the matching unit is further configured to:
[0068] Characterize the order of at least one numerical data among the method-characterizing numerical values, and use the binary search method to match each of the numerical data among the method-characterizing numerical values with the corresponding numerical data among the method-characterizing numerical values of each of the declared methods in the declaration table of other components except the component in the target item;
[0069] When all of the numerical data among the method-characterizing numerical values match, it is determined that there is a call relationship between the component and the other components.
[0070] Optionally, as the seventh possible implementation manner of the second aspect, the component information library is used to store the component information of at least one component, and the component information includes a component name, a component version, a declaration table, and a call table.
[0071] The device further includes:
[0072] An adding module, configured to add the generated declaration table and call table of the component, as well as the component name and component version of the component, to the component information library when the component information of the component does not exist in the component information library.
[0073] To achieve the above object, an embodiment of the third aspect of the present invention provides an electronic device, including:
[0074] At least one processor; and
[0075] A memory communicatively connected to the at least one processor; wherein,
[0076] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the dependency tree generation method of the foregoing first aspect.
[0077] To achieve the above object, an embodiment of the fourth aspect of the present invention provides a computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to execute the dependency tree generation method of the foregoing first aspect.
[0078] To achieve the above object, an embodiment of the fifth aspect of the present invention provides a computer program product, including a computer program, and the computer program implements the dependency tree generation method of the foregoing first aspect when executed by a processor.
[0079] The technical solutions provided by the embodiments of the present invention have the following beneficial effects:
[0080] By obtaining the component names and component versions of at least two components in a target project, for any component, based on the component name and component version of the component, query whether there is component information of the component in the component information library. Thus, in response to the existence of component information of the component in the component information library, obtain the declaration table and call table of the component from the component information library; or, in response to the non-existence of component information of the component in the component information library, obtain the method information of at least one declaration method and the method information of at least one call method in the component, generate the declaration table of the component based on the method information of each declaration method, and generate the call table of the component based on the method information of each call method. Furthermore, generate a dependency tree corresponding to the target project according to the declaration tables and call tables of each component in the target project. Thus, it is possible to generate a dependency tree based on the declaration table and call table of the component, without relying on a third-party file, improving the applicability and accuracy of generating the dependency tree. At the same time, since the declaration table and call table of the component can be stored in the component information library, when there is component information of the component in the component information library, directly obtain the declaration table and call table of the component from the component information library, so that it is not necessary to generate the declaration table and call table of the component every time, improving the generation efficiency of the dependency tree.
[0081] Additional aspects and advantages of the present invention will be given in part in the following description, become apparent in part from the following description, or be learned through the practice of the present invention. Description of the Drawings
[0082] The above-mentioned and / or additional aspects and advantages of the present invention will become apparent and be readily understood from the following description of the embodiments in conjunction with the drawings, where:
[0083] Figure 1 is a schematic flowchart of a method for generating a dependency tree provided by an embodiment of the present invention;
[0084] Figure 2 is a schematic flowchart of another method for generating a dependency tree provided by an embodiment of the present invention;
[0085] Figure 3 is a schematic diagram of the method-characteristic numerical format in a scenario provided by an embodiment of the present invention;
[0086] Figure 4 is a schematic flowchart of another method for generating a dependency tree provided by an embodiment of the present invention;
[0087] Figure 5 is a schematic flowchart of another method for generating a dependency tree provided by an embodiment of the present invention;
[0088] Figure 6 is a schematic flowchart of another method for generating a dependency tree provided by an embodiment of the present invention;
[0089] Figure 7 A schematic diagram of a flow chart of another dependency tree generation method provided by an embodiment of the present invention;
[0090] Figure 8 A schematic diagram of the principle of a dependency tree generation method in a scenario provided by an embodiment of the present invention;
[0091] Figure 9 A schematic diagram of the structure of a dependency tree generating device provided by an embodiment of the present invention;
[0092] Figure 10 A schematic diagram of the structure of another dependency tree generating device provided by an embodiment of the present invention;
[0093] Figure 11 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0094] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present invention, and should not be construed as limiting the present invention.
[0095] In the related art, for Maven Java projects, the GAV coordinates of the pom file can be used to determine the calling relationship between components and generate a dependency tree. However, this method can only be used for Maven-built projects. Non-Maven-built projects cannot generate dependency trees through this method because they do not contain pom files, so the applicability is low. In addition, the accuracy of this method depends on the standardization of pom files developed by third-party component developers. If the pom files are not written in a standardized manner, the generated dependency tree will be biased and the accuracy will be low.
[0096] In addition, you can also statically parse the calling relationships of methods in each class through Java bytecode to generate a dependency tree. This method is accurate to the calling of specific methods and has high accuracy, but because all bytecode (.class) files need to be parsed each time and all methods need to be compared, the entire parsing and dependency judgment process takes a long time, affecting the efficiency of dependency tree generation.
[0097] In view of the above problems, an embodiment of the present invention provides a method for generating a dependency tree, which can generate a dependency tree based on a component declaration table and a call table without relying on a third-party file, improving the applicability and accuracy of generating the dependency tree. At the same time, since the component declaration table and the call table can be stored in a component information library, when there is component information of a component in the component information library, the component declaration table and the call table can be directly obtained from the component information library, thus eliminating the need to generate the component declaration table and the call table each time and improving the generation efficiency of the dependency tree.
[0098] The following describes the method and apparatus for generating a dependency tree according to an embodiment of the present invention with reference to the accompanying drawings.
[0099] Figure 1 It is a flowchart of a method for generating a dependency tree provided by an embodiment of the present invention.
[0100] It should be noted that the method for generating a dependency tree according to an embodiment of the present invention can be executed by the apparatus for generating a dependency tree provided by an embodiment of the present invention. The apparatus for generating a dependency tree can be an electronic device or can be configured in an electronic device. Among them, the electronic device can be any stationary or mobile computing device capable of data processing, such as mobile computing devices such as laptops, smartphones, wearable devices, etc., or stationary computing devices such as desktop computers, or servers, or other types of computing devices, etc., and this is not limited in this embodiment.
[0101] As Figure 1 shown, the method for generating a dependency tree includes the following steps:
[0102] Step 101: Obtain the component names and component versions of at least two components in the target project.
[0103] In this embodiment, the target project can be understood as any computer project, such as a Java project. A component can be understood as a third-party component referenced by the target project. It can be understood that there are at least two third-party components in the target project to determine the call relationship between components and generate a dependency tree.
[0104] In this embodiment, the apparatus for generating a dependency tree can obtain the component names and component versions of at least two components in the target project through various public, legal, and compliant methods. For example, the apparatus for generating a dependency tree can collect the component names and component versions of at least two components in the target project in real time, or can also obtain the component names and component versions of at least two components in the target project from other devices through network transmission or physical copying, or can also obtain the component names and component versions of at least two components in the target project through other public, legal, and compliant methods, and this is not limited in this embodiment.
[0105] Step 102: For any component, query whether there is component information of the component in the component information library based on the component name and component version of the component.
[0106] In this embodiment, the component information library is used to store component information of at least one component. Optionally, the component information may include a component name, a component version, a declaration table, and a call table. It can be understood that for any one component, the component name and component version of this component cannot be the same as those of other components at the same time. Therefore, the component name and component version of the component can be used as the unique identifier of the component in the component information library. Thus, in this embodiment, for any component obtained, it is possible to query whether there is component information of this component in the component information library according to the component name and component version of this component.
[0107] In a possible implementation manner of this embodiment, for any component obtained, the component name and component version of this component can be respectively matched with the component names and component versions in the component information of at least one component stored in the component information library. Thus, when both the component name and the component version match, it is determined that there is component information of this component in the component information library; when either the component name or the component version does not match, it is determined that there is no component information of this component in the component information library. Among them, regarding the matching order of the component name and component version of this component with the component names and component versions in the component information of at least one component stored in the component information library, the embodiments of the present invention do not make any limitations. Optionally, the component name of this component can be first matched with the component names in the component information of at least one component stored in the component information library, and then the component version of this component can be matched with the component versions in the component information of at least one component whose component name matches in the component information library. Or, the component version of this component can be first matched with the component versions in the component information of at least one component stored in the component information library, and then the component name of this component can be matched with the component names in the component information of at least one component whose component version matches in the component information library. Or, when the component name of this component is matched with the component names in the component information of at least one component stored in the component information library, and then the component version of this component is matched with the component versions in the component information of at least one component whose component name matches in the component information library, the component version of this component can also be matched with the component versions in the component information of at least one component stored in the component information library at the same time. This embodiment does not make any limitations in this regard.
[0108] Step 103: In response to the existence of component information of the component in the component information library, obtain the declaration table and call table of the component from the component information library.
[0109] In this embodiment, when there is component information of a component in the component information library, the declaration table and call table of the component can be directly obtained from the component information library, so that it is not necessary to generate the declaration table and call table of the component each time, improving the generation efficiency of the dependency tree.
[0110] Similarly, in this embodiment, when there is component information of a component in the component information library, the dependency tree generation device can obtain the declaration table and call table of the component from the component information library through various public, legal, and compliant ways.
[0111] Step 104, in response to the absence of component information of a component in the component information library, obtain the method information of at least one declaration method and the method information of at least one call method in the component, generate a declaration table of the component based on the method information of each declaration method, and generate a call table of the component based on the method information of each call method.
[0112] In this embodiment, when there is no component information of a component in the component information library, the method information of the declaration method and call method of the component can be obtained, so as to generate the declaration table and call table of the component based on the method information of the declaration method and call method of the component.
[0113] It should be noted that for any component, there is at least one declaration method and at least one call method in the component. Therefore, by obtaining the method information of at least one declaration method and at least one call method in the component, it is possible to generate a declaration table of the component based on the method information of each declaration method, and generate a call table of the component based on the method information of each call method.
[0114] In a possible implementation manner of this embodiment, the method information of at least one declaration method and the method information of at least one call method in the component can be obtained by parsing the bytecode file of the component. Thus, corresponding method characterization values can be generated based on the method information of each declaration method and the method information of each call method. Furthermore, the declaration table of the component can be obtained by sequentially storing the method characterization values of each declaration method in the component, and the call table of the component can be obtained by sequentially storing the method characterization values of each call method in the component.
[0115] Step 105, generate a dependency tree corresponding to the target project according to the declaration tables and call tables of the components in the target project.
[0116] In this embodiment, after obtaining the declaration table and call table of each component in the target project, a dependency tree corresponding to the target project can be generated based on the declaration table and call table of each component in the target project. Optionally, for any component in the target project, at least one call method can be obtained from the call table of the component first, and then the obtained call method can be matched with the declared methods in the declaration tables of other components in the target project except this component, so as to determine the sequential call relationship between each component based on the matching result and generate a dependency tree corresponding to the target project.
[0117] The dependency tree generation method provided in this embodiment realizes, for any component, querying whether there is component information of the component in the component information library based on the component name and component version of the component by obtaining the component names and component versions of at least two components in the target project. Thus, in response to the existence of the component information of the component in the component information library, the declaration table and call table of the component are obtained from the component information library; or, in response to the non-existence of the component information of the component in the component information library, the method information of at least one declared method and the method information of at least one call method in the component are obtained, and the declaration table of the component is generated based on the method information of each declared method, and the call table of the component is generated based on the method information of each call method. Furthermore, a dependency tree corresponding to the target project is generated according to the declaration table and call table of each component in the target project. Thereby, it is possible to generate a dependency tree based on the declaration table and call table of the component without relying on a third-party file, improving the applicability and accuracy of generating the dependency tree. At the same time, since the declaration table and call table of the component can be stored in the component information library, when there is component information of the component in the component information library, the declaration table and call table of the component can be directly obtained from the component information library, thus eliminating the need to generate the declaration table and call table of the component each time and improving the generation efficiency of the dependency tree.
[0118] Through the above analysis, it can be seen that in the embodiment of the present invention, the declaration table of the component can be generated based on the method information of each declared method, and the call table of the component can be generated based on the method information of each call method. To clearly illustrate how the declaration table and call table of the component are generated in the present invention, this embodiment provides a possible implementation manner of the dependency tree generation method. Figure 2 It is a schematic flowchart of another dependency tree generation method provided in the embodiment of the present invention.
[0119] As Figure 2 shown, the dependency tree generation method may include the following steps:
[0120] Step 201, obtain the component names and component versions of at least two components in the target project.
[0121] Step 202, for any component, query whether there is component information of the component in the component information library based on the component name and component version of the component.
[0122] Step 203: In response to the existence of component information of a component in the component information library, obtain the declaration table and call table of the component from the component information library.
[0123] It should be noted that the execution processes of Steps 201-203 can refer to the execution processes of Steps 101-103 in the previous embodiment. The principles are the same and will not be elaborated here.
[0124] Step 204: In response to the non-existence of component information of a component in the component information library, obtain the method information of at least one declaration method and the method information of at least one call method in the component.
[0125] In this embodiment, the method information includes the class name, method name, number of parameters, and parameter types. Among them, the number of parameters is used to indicate how many parameters the method has in total.
[0126] It should be noted that the execution process of this step can refer to the execution process of Step 104 in the previous embodiment. The principles are the same and will not be elaborated here.
[0127] Step 205: For any declaration method or call method in the component, determine the class name feature value, method name feature value, and parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type and the preset position coefficient.
[0128] In this embodiment, the ASCII code ratio of the position characters in the class name, method name, and parameter type of a method can be understood as the ratio of the ASCII code of this position character to the ASCII code of the adjacent position character. For example, assuming the class name is com.test.open, for the second position character 0, since it is adjacent to both the first position character c and the third position character m, that is, the adjacent position characters of the second position character 0 include c and m. Thus, the ASCII code ratio of the second position character 0 can be either ASCII(o) / ASCII(c) or ASCII(o) / ASCII(m). This embodiment does not limit this.
[0129] It should be noted that, in order to ensure the consistency of the ASCII code ratio of characters at each position, for the characters at each position, the direction of determining adjacent characters should be kept consistent. For example, for the above example with the class name com.test.open, if it is determined that the adjacent character of the second-position character 0 is m, then for the characters at each position, the direction of determining adjacent characters should be to the right; if it is determined that the adjacent character of the second-position character 0 is c, then for the characters at each position, the direction of determining adjacent characters should be to the left. It can be understood that when the direction of determining adjacent characters is to the right, the last-position character has no adjacent character. At this time, the first-position character can be determined as the adjacent character of the last-position character. For example, for the above example with the class name com.test.open, the adjacent character of the last-position character n is the first-position character c, so the ASCII code ratio of the last-position character n is ASCII(n) / ASCII(c); when the direction of determining adjacent characters is to the left, the first-position character has no adjacent character. At this time, the last-position character can be determined as the adjacent character of the first-position character. For example, for the above example with the class name com.test.open, the adjacent character of the first-position character c is the last-position character n, so the ASCII code ratio of the first-position character c is ASCII(c) / ASCII(n).
[0130] In this embodiment, for any declared method or any called method in the component, the class name feature value, method name feature value, and parameter feature value can be determined according to the ASCII code ratio of characters at each position in the class name, method name, and parameter type of the method and the preset position coefficient. That is to say, for any declared method or any called method in the component, the class name feature value can be determined according to the ASCII code ratio of characters at each position in the class name of the method and the preset position coefficient, the method name feature value can be determined according to the ASCII code ratio of characters at each position in the method name of the method and the preset position coefficient, and the parameter feature value can be determined according to the ASCII code ratio of characters at each position in the parameter type of the method and the preset position coefficient. Among them, the present invention embodiment does not limit the setting of the preset position coefficient. Optionally, it can be set according to manual experience. For example, the preset position coefficient can be set to 1, 2, 3, 4,... or it can be set to 1, -2, 3, -4,... and so on. Or, it can also be dynamically adjusted according to actual application requirements, and this is not limited in this embodiment.
[0131] In a possible implementation of this embodiment, for any declared method or any invoked method in a component, the class name feature value, method name feature value, and parameter feature value can be obtained by accumulating the values obtained by multiplying the ASCII code ratio of each position character in the class name, method name, and parameter type by the corresponding preset position coefficient. For example, assume that the length of a certain class name or method name or the number of parameters is n, the preset position coefficient is C, and the ASCII code ratio is T. Then the calculation formula for the class name feature value or method name feature value or parameter feature value is where C n represents the preset position coefficient corresponding to the nth position character, and T n represents the ASCII code ratio of the nth position character.
[0132] It can be understood that the class name feature value, method name feature value, and parameter feature value determined in this step are all numerical data, that is, numerical data composed of numbers (0-9).
[0133] Step 206: Generate a method characterization value based on the length of the class name, class name feature value, length of the method name, method name feature value, number of parameters, parameter feature value, and preset character.
[0134] In this embodiment, the length of the class name can be understood as the number of characters included in the class name. For example, for the above example where the class name is com.test.open, the length of the class name is 11. Similarly, the length of the method name can be understood as the number of characters included in the method name.
[0135] In this embodiment, for any declared method or any invoked method in a component, a corresponding method characterization value can be generated based on the length of the class name, class name feature value, length of the method name, method name feature value, number of parameters, parameter feature value, and preset character. Thus, the method characterization values of each declared method and each invoked method in the component can be obtained. Among them, the present invention embodiment does not limit the setting of the preset character. Optionally, it can be set according to manual experience. For example, the preset character can be set to -, or the preset position coefficient can be set to &, etc. Or, it can also be dynamically adjusted according to actual application requirements. This embodiment does not limit this. It should be noted that since the length of the class name, class name feature value, length of the method name, method name feature value, number of parameters, and parameter feature value are all numerical data, the preset character cannot be a number from 0 to 9.
[0136] In a possible implementation of this embodiment, for any declared method or any called method in a component, the length of the class name, the class name feature value, the length of the method name, the method name feature value, the number of parameters, and the parameter feature value can be concatenated with a preset character to generate a corresponding method characterization value. For example, for any declared method or any called method in a component, assuming the preset character is '-', the length of the class name is represented by A, the class name feature value is represented by a, the length of the method name is represented by B, the method name feature value is represented by b, the number of parameters is represented by C, and the parameter feature value is represented by c, then the generated corresponding method characterization value can be as Figure 3 shown as A-a-B-b-C-c.
[0137] Thus, by representing the declared methods and called methods of each component with the corresponding method characterization values, it is convenient to directly perform numerical matching when determining the call relationships between components in subsequent steps, without having to compare the strings contained in the declared methods and called methods of each component, reducing the matching overhead.
[0138] Step 207, generate a declaration table for the component based on the method characterization values of each declared method, and generate a call table for the component based on the method characterization values of each called method.
[0139] In this embodiment, a declaration table for the component can be generated based on the method characterization values of each declared method, and a call table for the component can be generated based on the method characterization values of each called method. Optionally, the declaration table for the component can be obtained by sequentially storing the method characterization values of each declared method in the component, and the call table for the component can be obtained by sequentially storing the method characterization values of each called method in the component. At this time, since the declaration table of the component sequentially stores the method characterization values of each declared method, and the call table sequentially stores the method characterization values of each called method, a binary search method can be used for numerical matching when determining the call relationships between components in subsequent steps, effectively improving the matching efficiency.
[0140] Step 208, generate a dependency tree corresponding to the target project according to the declaration table and call table of each component in the target project.
[0141] It should be noted that the execution process of step 208 can refer to the execution process of step 105 in the previous embodiment, with the same principle, which will not be elaborated here.
[0142] The dependency tree generation method provided in this embodiment determines the class name feature value, method name feature value, and parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type and the preset position coefficient for any declared method or called method in the component, and realizes generating the method characterization value according to the length of the class name, class name feature value, length of the method name, method name feature value, number of parameters, parameter feature value, and preset characters, so as to generate the declaration table of the component based on the method characterization values of each declared method, and generate the call table of the component based on the method characterization values of each called method. Thus, in the case where the component information of the component does not exist in the component information library, by obtaining the method information of at least one declared method and the method information of at least one called method in the component, it is possible to generate the declaration table of the component based on the method information of each declared method, and generate the call table of the component based on the method information of each called method, and generate a dependency tree based on the declaration table and call table of the component, without relying on a third-party file, improving the applicability and accuracy of generating the dependency tree.
[0143] As can be seen from the above analysis, in the embodiment of the present invention, the class name feature value, method name feature value, and parameter feature value can be determined according to the ASCII code ratio of each character in the class name, method name, and parameter type and the preset position coefficient. To more clearly illustrate how the class name feature value, method name feature value, and parameter feature value are determined in the present invention, this embodiment provides another possible implementation manner of the dependency tree generation method. Figure 4 It is a schematic flowchart of another dependency tree generation method provided in the embodiment of the present invention.
[0144] As Figure 4 shown, the dependency tree generation method may include the following steps:
[0145] Step 401, obtain the component names and component versions of at least two components in the target project.
[0146] Step 402, for any component, query whether there is component information of the component in the component information library based on the component name and component version of the component.
[0147] Step 403, in response to the existence of component information of the component in the component information library, obtain the declaration table and call table of the component from the component information library.
[0148] Step 404, in response to the non-existence of component information of the component in the component information library, obtain the method information of at least one declared method and the method information of at least one called method in the component.
[0149] It should be noted that the execution process of steps 401-404 can refer to the execution process of steps 201-204 in the previous embodiment, with the same principle and will not be elaborated here.
[0150] Step 405: For any declared method or invoked method in the component, sort the characters at each position in the class name, method name, and parameter types to determine the order of the characters at each position.
[0151] In this embodiment, for any declared method or any invoked method in the component, the characters at each position in the class name, method name, and parameter types can be sorted to determine the order of the characters at each position. Among them, the characters at adjacent positions, as well as the characters at the first and last positions, have an adjacent relationship.
[0152] For example, assume the class name is com.test.open. Sorting the characters at each position in this class name from left to right, it can be determined that the order of the character c is 1, the order of the first o is 2, the order of the character m is 3, the order of the first t is 4, the order of the first e is 5, the order of the character s is 6, the order of the second t is 7, the order of the second o is 8, the order of the character p is 9, the order of the second e is 10, the order of the character n is 11. And the characters at adjacent positions, for example, the character with order 1 and the character with order 2, the character with order 2 and the character with order 3, etc., as well as the first and last characters (the character c and the character n) have an adjacent relationship.
[0153] Step 406: For any character at a position, determine the ASCII code ratio between the characters at adjacent positions as the ASCII code ratio of the character at the position.
[0154] In this embodiment, after determining the order of the characters at each position, for any character at a position, the ASCII code ratio between the characters at adjacent positions can be determined as the ASCII code ratio of the character at the position, that is, for any character at a position, the ratio of the ASCII code of this character to the ASCII code of a character at an adjacent position with an adjacent relationship to it is determined as the ASCII code ratio of this character at the position. It can be understood that since the characters at adjacent positions, as well as the characters at the first and last positions, all have an adjacent relationship, for any character at a position, there are two characters at adjacent positions with an adjacent relationship to it. Therefore, in this embodiment, for any character at a position, one of the two characters at adjacent positions with an adjacent relationship to it needs to be selected to determine the ASCII code ratio.
[0155] It should be noted that in this embodiment, in order to ensure the consistency of the ASCII code ratios of the characters at each determined position, for any position character, the direction of selecting one of the two position characters adjacent to it should be kept consistent. For example, for the above example with the class name com.test.open, if for any position character, the direction of selecting one of the two position characters adjacent to it is sequential selection, then for the first position character (the position character with order 1), although the position characters adjacent to it are the position character with order 2 and the last position character (the position character with order 11), due to sequential selection, the ASCII code ratio of this first position character is the ratio of the ASCII code of this first position character to the ASCII code of the position character with order 2, that is, the ratio of the ASCII code of position character c to the ASCII code of position character o, i.e., ASCII(c) / ASCII(o). For the position character with order 2, although the position characters adjacent to it are the first position character (the position character with order 1) and the position character with order 3, due to sequential selection, the ASCII code ratio of this position character with order 2 is the ratio of the ASCII code of this position character with order 2 to the ASCII code of the position character with order 3, that is, the ratio of the ASCII code of position character o to the ASCII code of position character m, i.e., ASCII(o) / ASCII(m). And so on. For the last position character (the position character with order 11), although the position characters adjacent to it are the position character with order 10 and the first position character (the position character with order 1), due to sequential selection, and there is no subsequent position character in order after the last position character, the ratio of the ASCII code of the last position character to the ASCII code of the first position character can be determined as the ASCII code ratio of this last position character. That is to say, the ASCII code ratio of this last position character is the ratio of the ASCII code of position character n to the ASCII code of position character c, i.e., ASCII(n) / ASCII(c).
[0156] Similarly, for the above example with the class name com.test.open, if for any position character, the direction of selecting one of the two position characters adjacent to it is: reverse selection, then for the first position character (the position character with order 1), although the position characters adjacent to it are the position character with order 2 and the last position character (the position character with order 11), due to reverse selection and there being no reverse position character in front of the first position character, the ratio of the ASCII code of the first position character to the ASCII code of the last position character can be determined as the ASCII code ratio of the first position character. That is to say, the ASCII code ratio of this first position character is the ratio of the ASCII code of position character c to the ASCII code of position character n, i.e., ASCII(c) / ASCII(n). For the position character with order 2, although the position characters adjacent to it are the first position character (the position character with order 1) and the position character with order 3, due to reverse selection, the ASCII code ratio of this position character with order 2 is the ratio of the ASCII code of this position character with order 2 to the ASCII code of the first position character, i.e., the ratio of the ASCII code of position character o to the ASCII code of position character c, i.e., ASCII(o) / ASCII(c). And so on, for the last position character (the position character with order 11), although the position characters adjacent to it are the position character with order 10 and the first position character (the position character with order 1), due to reverse selection, the ASCII code ratio of this last position character is the ratio of the ASCII code of this last position character to the ASCII code of the position character with order 10, i.e., the ratio of the ASCII code of position character n to the ASCII code of position character e, i.e., ASCII(n) / ASCII(e).
[0157] Step 407: Multiply the ASCII code ratio of the position character by the preset position coefficient corresponding to the position character to obtain the characteristic value of the position character.
[0158] In this embodiment, in order to reduce the collision of characteristic values, a preset position coefficient is introduced, so that for any position character, there can be a preset position coefficient corresponding to it by setting the preset position coefficient. Among them, the present invention embodiment does not limit the setting of the preset position coefficient. Optionally, it can be set according to manual experience. For example, the preset position coefficient can be set to 1, 2, 3, 4,... or can be set to 1, -2, 3, -4,... and so on. Or, it can also be dynamically adjusted according to actual application requirements, and this is not limited in this embodiment.
[0159] In this embodiment, after obtaining the ASCII code ratios of the characters at each position, for any character at a position, the ASCII code ratio of the character at that position can be multiplied by the preset position coefficient corresponding to the character at that position to obtain the characteristic value of the character at that position. For example, assume that the preset position coefficient corresponding to the nth character in a certain class name, method name, or parameter type is C n , and the ASCII code ratio is T n . Then the calculation formula for the characteristic value of the nth character is C n *T n .
[0160] Step 408: Add up the characteristic values of the characters at each position in the class name, method name, and parameter type to obtain the class name characteristic value, method name characteristic value, and parameter characteristic value.
[0161] In this embodiment, after obtaining the characteristic values of the characters at each position in the class name, method name, and parameter type, the class name characteristic value, method name characteristic value, and parameter characteristic value can be obtained by adding up the characteristic values of the characters at each position in the class name, method name, and parameter type. That is to say, the characteristic values of the characters at each position in the class name can be added up to obtain the class name characteristic value, the characteristic values of the characters at each position in the method name can be added up to obtain the method name characteristic value, and the characteristic values of the characters at each position in the parameter type can be added up to obtain the parameter characteristic value. For example, assume that the length of a certain class name, method name, or the number of parameters is n, and the preset position coefficient corresponding to the nth character is C n , and the ASCII code ratio is T n . Then the calculation formula for the class name characteristic value, method name characteristic value, or parameter characteristic value is
[0162] It can be understood that the class name characteristic value, method name characteristic value, and parameter characteristic value determined in this step are all numerical data, that is, numerical data composed of numbers (0-9).
[0163] Step 409: Generate a method characteristic value based on the length of the class name, class name characteristic value, length of the method name, method name characteristic value, number of parameters, parameter characteristic value, and preset characters.
[0164] Step 410: Generate a declaration table of the component based on the method characteristic values of each declared method, and generate a call table of the component based on the method characteristic values of each called method.
[0165] Step 411: Generate a dependency tree corresponding to the target project according to the declaration table and call table of each component in the target project.
[0166] It should be noted that the execution processes of steps 409 - 411 can refer to the execution processes of steps 206 - 208 in the previous embodiment. Since the principles are the same, they will not be elaborated here.
[0167] In the dependency tree generation method provided in this embodiment, for any declared method or called method in a component, the characters at each position in the class name, method name, and parameter type are sorted to determine the order of the characters at each position. Thus, for any character at a position, the ASCII code ratio between the characters at adjacent positions is determined as the ASCII code ratio of the character at that position. Furthermore, the ASCII code ratio of the character at the position is multiplied by the preset position coefficient corresponding to the character at that position to obtain the characteristic value of the character at that position, and the characteristic values of the characters at each position in the class name, method name, and parameter type are added together to obtain the class name characteristic value, method name characteristic value, and parameter characteristic value. Thus, based on the ASCII code ratio of each character in the class name, method name, and parameter type and the preset position coefficient, the class name characteristic value, method name characteristic value, and parameter characteristic value can be determined.
[0168] From the above analysis, it can be seen that in the embodiments of the present invention, the declaration table of a component can be obtained by sequentially storing the method characterization values of each declared method in the component, and the call table of the component can be obtained by sequentially storing the method characterization values of each called method in the component. To more clearly illustrate how the declaration table of a component is obtained by sequentially storing the method characterization values of each declared method in the component and how the call table of the component is obtained by sequentially storing the method characterization values of each called method in the component in the present invention, this embodiment provides another possible implementation manner of the dependency tree generation method. Figure 5 It is a schematic flowchart of another dependency tree generation method provided in the embodiments of the present invention.
[0169] As Figure 5 shown, the dependency tree generation method may include the following steps:
[0170] Step 501, obtain the component names and component versions of at least two components in the target project.
[0171] Step 502, for any component, query whether there is component information of the component in the component information library based on the component name and component version of the component.
[0172] Step 503, in response to the existence of the component information of the component in the component information library, obtain the declaration table and call table of the component from the component information library.
[0173] Step 504, in response to the non - existence of the component information of the component in the component information library, obtain the method information of at least one declared method and the method information of at least one called method in the component.
[0174] Step 505: For any declared method or called method in the component, determine the class name feature value, method name feature value, and parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type and the preset position coefficient.
[0175] It should be noted that the execution processes of Steps 501 - 505 can refer to the execution processes of Steps 201 - 205 in the above embodiments. The principles are the same and will not be elaborated here.
[0176] Step 506: Generate a method characterization value according to the length of the class name, class name feature value, length of the method name, method name feature value, number of parameters, parameter feature value, and preset characters.
[0177] In this embodiment, the generated method characterization value can include at least one numerical data.
[0178] It should be noted that the execution process of this step can refer to the execution process of Step 206 in the above embodiments. The principles are the same and will not be elaborated here.
[0179] Step 507: For each declared method, compare each numerical data in the method characterization value of each declared method based on the order of at least one numerical data in the method characterization value.
[0180] In this embodiment, since the generated method characterization value can include at least one numerical data, after obtaining the method characterization values of each declared method, for each declared method, each numerical data in the method characterization value of each declared method can be compared based on the order of at least one numerical data in the method characterization value. For example, assume that the generated method characterization values of each declared method are as Figure 3As shown, it is A-a-B-b-C-c, where A represents the length of the class name of each declared method, a represents the class name characteristic value of each declared method, B represents the length of the method name of each declared method, b represents the method name characteristic value of each declared method, C represents the number of parameters of each declared method, c represents the parameter characteristic value of each declared method, and A, a, B, b, C, and c are all numerical data. Since the order of at least one numerical data in the method characteristic numerical values at this time is A, a, B, b, C, c, it is possible to first compare the numerical data A in the method characteristic numerical values of each declared method, and then, based on the comparison result obtained after comparing A, compare the numerical data a in the method characteristic numerical values of each declared method. Then, based on the comparison result obtained after comparing a, compare the numerical data B, and so on, until all the numerical data in the method characteristic numerical values of each declared method are compared to obtain a first comparison result. It can be understood that the obtained first comparison result is the result of sorting the sizes of the numerical data in the method characteristic numerical values of each declared method in the order of the numerical data in the method characteristic numerical values.
[0181] Step 508: Generate a declaration table for the component according to the first comparison result.
[0182] Since it is possible to compare the numerical data in the method characteristic numerical values of each declared method based on the order of at least one numerical data in the method characteristic numerical values to obtain a first comparison result, and this first comparison result is the result of sorting the sizes of the numerical data in the method characteristic numerical values of each declared method in the order of the numerical data in the method characteristic numerical values, it is possible to sequentially store the method characteristic numerical values of each declared method in the component based on the first comparison result, thereby generating a declaration table for the component and realizing sequential numerical storage.
[0183] Step 509: For each called method, compare the numerical data in the method characteristic numerical values of each called method based on the order of at least one numerical data in the method characteristic numerical values.
[0184] In this embodiment, since the generated method characteristic numerical values may include at least one numerical data, after obtaining the method characteristic numerical values of each called method, it is possible to compare the numerical data in the method characteristic numerical values of each called method based on the order of at least one numerical data in the method characteristic numerical values. For example, assume that the method characteristic numerical values of each called method generated are as Figure 3As shown, it is A-a-B-b-C-c. Among them, A represents the length of the class name of each calling method, a represents the class name characteristic value of each calling method, B represents the length of the method name of each calling method, b represents the method name characteristic value of each calling method, C represents the number of parameters of each calling method, and c represents the parameter characteristic value of each calling method. Moreover, A, a, B, b, C, and c are all numerical data. Since at this time the order of at least one numerical data in the method characteristic numerical values is A, a, B, b, C, c, it is possible to first compare the numerical data A in the method characteristic numerical values of each calling method, and then, based on the comparison result obtained after comparing A, compare the numerical data a in the method characteristic numerical values of each calling method. Then, based on the comparison result obtained after comparing a, compare the numerical data B. And so on, until all the numerical data in the method characteristic numerical values of each calling method are compared to obtain the first comparison result. It can be understood that the obtained first comparison result is the result of sorting the sizes of the numerical data in the method characteristic numerical values of each calling method in order according to the order of each numerical data in the method characteristic numerical values.
[0185] Step 510, generate a call table of the component according to the second comparison result.
[0186] Since it is possible to compare each numerical data in the method characteristic numerical values of each calling method based on the order of at least one numerical data in the method characteristic numerical values to obtain the second comparison result, and this second comparison result is the result of sorting the sizes of the numerical data in the method characteristic numerical values of each calling method in order according to the order of each numerical data in the method characteristic numerical values, it is possible to sequentially store the method characteristic numerical values of each calling method in the component based on the second comparison result, thereby generating a call table of the component and realizing numerical sequential storage.
[0187] Step 511, generate a dependency tree corresponding to the target project according to the declaration table and call table of each component in the target project.
[0188] It should be noted that the execution process of step 511 can refer to the execution process of step 208 in the above embodiment. The principle is the same and will not be elaborated here.
[0189] The dependency tree generation method provided in this embodiment compares each numerical data in the method characterization values of each declared method based on the order of at least one numerical data in the method characterization values, and generates a declaration table of the component according to the first comparison result. And for each calling method, based on the order of at least one numerical data in the method characterization values, compare each numerical data in the method characterization values of each calling method, and generate a call table of the component according to the second comparison result. Thus, it can be realized that the declaration table of the component is obtained by sequentially storing the method characterization values of each declared method in the component, and the call table of the component is obtained by sequentially storing the method characterization values of each calling method in the component.
[0190] As can be seen from the above analysis, in the embodiment of the present invention, the dependency tree corresponding to the target project can be generated according to the declaration table and call table of each component in the target project. In order to more clearly illustrate how the dependency tree corresponding to the target project is generated in the present invention, this embodiment provides another possible implementation manner of the dependency tree generation method. Figure 6 It is a schematic flowchart of another dependency tree generation method provided in the embodiment of the present invention.
[0191] As Figure 6 shown, the dependency tree generation method may include the following steps:
[0192] Step 601, obtain the component names and component versions of at least two components in the target project.
[0193] Step 602, for any component, query whether there is component information of the component in the component information library based on the component name and component version of the component.
[0194] Step 603, in response to the existence of the component information of the component in the component information library, obtain the declaration table and call table of the component from the component information library.
[0195] Step 604, in response to the non-existence of the component information of the component in the component information library, obtain the method information of at least one declared method and the method information of at least one calling method in the component.
[0196] Step 605, for any declared method or calling method in the component, determine the class name feature value, method name feature value, and parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type and the preset position coefficient.
[0197] Step 606, generate a method characterization value according to the length of the class name, class name feature value, length of the method name, method name feature value, number of parameters, parameter feature value, and preset character.
[0198] Step 607: Generate a declaration table for the component based on the method-characterized values of each declaration method, and generate a call table for the component based on the method-characterized values of each call method.
[0199] It should be noted that the execution processes of Steps 601-607 can refer to the execution processes of Steps 201-207 in the above embodiments. The principles are the same and will not be elaborated here.
[0200] Step 608: For any component in the target project, obtain the method-characterized values of at least one call method from the call table of the component.
[0201] In this embodiment, after obtaining the declaration tables and call tables of each component, for any component in the target project, the method-characterized values of at least one call method can be obtained from the call table of the component, so as to determine the call relationships between the components in the target project based on the method-characterized values of at least one call method.
[0202] Step 609: Match the method-characterized values with the method-characterized values of each declaration method in the declaration tables of other components in the target project except the component, so as to determine the call relationships between the components.
[0203] In this embodiment, the method-characterized values of at least one obtained call method can be matched with the method-characterized values of each declaration method in the declaration tables of other components in the target project except the component, so as to determine the call relationships between the components. Optionally, for the method-characterized value of any one call method, the method-characterized value can be matched with the method-characterized values of each declaration method in the declaration tables of other components in the target project except the component, so as to determine the call relationships between the components.
[0204] In a possible implementation manner of this embodiment, when the method-characterized values of each declaration method in the component are sequentially stored in the declaration table of each component in the target project, the method-characterized values of each call method in the component are sequentially stored in the call table of each component, and the method-characterized value includes at least one numerical data, for the method-characterized value of any one call method of any one component obtained in the target project, the binary search method can be used to respectively match each numerical data in the method-characterized value with the corresponding numerical data in the method-characterized values of each declaration method in the declaration tables of other components in the target project except this component, and when each numerical data in the method-characterized value is matched and consistent, it is determined that there is a call relationship between this component and other components. For example, assume that the method-characterized value is as Figure 3As shown, it is A-a-B-b-C-c, where A represents the length of the class name, a represents the class name characteristic value, B represents the length of the method name, b represents the method name characteristic value, C represents the number of parameters, and c represents the parameter characteristic value. Moreover, A, a, B, b, C, and c are all numerical data. Since the order of at least one numerical data in the method-characterized numerical values at this time is A, a, B, b, C, c, for the method-characterized numerical value of any call method of any component in the obtained target project, the binary search method can be used to first match the numerical data A in the obtained method-characterized numerical value with the A in the method-characterized numerical values of each declared method in the declaration table of other components in the target project except this component. Then, when A matches, continue to use the binary search method to match the numerical data a in the obtained method-characterized numerical value with the a in the method-characterized numerical values of each declared method in the declaration table of other components in the target project except this component. Next, when a also matches, continue to use the binary search method to match the numerical data B in the obtained method-characterized numerical value with the B in the method-characterized numerical values of each declared method in the declaration table of other components in the target project except this component, and so on, until all the numerical data in the obtained method-characterized numerical value are matched. And when all the numerical data match, it is determined that there is a call relationship between this component and the other component corresponding to the method-characterized numerical value with which it matches. Thus, the original string matching (to determine the call relationship between components, it is necessary to match the strings included in the declared methods and call methods of each component) can be improved to store the declared methods and call methods of each component in numerical order and use the binary search method for matching, thereby reducing the matching overhead, effectively improving the matching efficiency, and further improving the generation efficiency of the dependency tree.
[0205] Step 610, generate a dependency tree corresponding to the target project based on the call relationships between the components.
[0206] In this embodiment, a dependency tree corresponding to the target project can be generated based on the call relationships between the components in the target project. Optionally, a component in the target project that is not called by other components can be determined as the root node of the dependency tree corresponding to the target project, at least one component in the target project that is both called by other components and calls other components can be determined as the child nodes of the dependency tree corresponding to the target project, and at least one component in the target project that is only called by other components and does not call other components can be determined as the leaf nodes of the dependency tree corresponding to the target project.
[0207] The dependency tree generation method provided in this embodiment obtains the method characterization values of at least one calling method from the call table of a component for any component in the target project, and realizes matching the method characterization values of the calling methods with the method characterization values of each declared method in the declaration tables of other components except the component in the target project, so as to determine the call relationships between components. Then, based on the call relationships between components, a dependency tree corresponding to the target project is generated. Since the call relationships between components can be determined by matching the method characterization values of the declared methods and calling methods of each component in the target project, without having to match the strings included in the declared methods and calling methods of each component, the matching overhead is reduced, and the matching efficiency is also improved, thereby improving the efficiency of generating the dependency tree.
[0208] To more clearly illustrate the above embodiment, this embodiment also provides a possible implementation manner of the dependency tree generation method. Figure 7 It is a schematic flowchart of another dependency tree generation method provided in the embodiments of the present invention.
[0209] As Figure 7 shown, the dependency tree generation method may include the following steps:
[0210] Step 701, obtain the component names and component versions of at least two components in the target project.
[0211] Step 702, for any component, query whether there is component information of the component in the component information library based on the component name and component version of the component.
[0212] Step 703, in response to the existence of component information of the component in the component information library, obtain the declaration table and call table of the component from the component information library.
[0213] Step 704, in response to the non-existence of component information of the component in the component information library, obtain the method information of at least one declared method and the method information of at least one calling method in the component, and generate a declaration table of the component based on the method information of each declared method, and generate a call table of the component based on the method information of each calling method.
[0214] Step 705, generate a dependency tree corresponding to the target project according to the declaration tables and call tables of each component in the target project.
[0215] It should be noted that the execution processes of steps 701-705 can refer to the execution processes of steps 101-105 in the above embodiment, with the same principle and will not be elaborated here.
[0216] Step 706, in the case where there is no component information of the component in the component information library, add the generated declaration table and call table of the component, as well as the component name and component version of the component to the component information library.
[0217] In this embodiment, in the case where component information does not exist in the component information library, the generated declaration table and call table of the component, as well as the component name and component version of the component, can be added to the component information library to increase the component information of the components in the component information library and improve the efficiency of generating the dependency tree.
[0218] The dependency tree generation method provided in this embodiment can add the generated declaration table and call table of the component, as well as the component name and component version of the component, to the component information library in the case where component information does not exist in the component information library. Thus, by adding and storing the component information of components that do not exist in the component information library, the number of times of generating the declaration table and call table of the component can be reduced, and with the increase of the component information of the components in the component information library, the efficiency of generating the dependency tree can be effectively improved.
[0219] To illustrate the above embodiments more clearly, examples are given below for illustration.
[0220] For example Figure 8As shown in the figure, first, obtain the component names and component versions of all components in the target project, so as to query whether there is component information of a component in the component information library for any component in the target project. The component information library is used to store component information of at least one component, and the component information may include a component name, a component version, a declaration table, and a call table. Furthermore, in the case where there is component information of the component in the component information library, directly obtain the declaration table and call table of the component, or, in the case where there is no component information of the component in the component information library, generate the declaration table of the component based on the method information of all declared methods and the method information of all called methods in the component, and generate the call table of the component based on the method information of all called methods, where the method information may include a class name, a method name, the number of parameters, and parameter types. Optionally, the process of generating the declaration table of the component based on the method information of all declared methods and generating the call table of the component based on the method information of all called methods may be: for any declared method or called method in the component, determine the class name feature value, method name feature value, and parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type of the method and a preset position coefficient, where the ASCII code ratio of the position characters in the class name, method name, and parameter type of the method can be understood as the ratio of the ASCII code of this position character to the ASCII code of the adjacent position character, and the preset position coefficient may be 1, 2, 3, 4,..., or 1, -2, 3, -4,..., and so on. Thus, the corresponding method characteristic value can be generated by concatenating the length of the class name, class name feature value, length of the method name, method name feature value, number of parameters, and parameter feature value of any declared method or called method with a preset character. For example, for any declared method or called method in the component, assuming the preset character is -, the length of the class name is represented by A, the class name feature value is represented by a, the length of the method name is represented by B, the method name feature value is represented by b, the number of parameters is represented by C, and the parameter feature value is represented by c, then the corresponding method characteristic value generated can be as Figure 3 shown, which is A-a-B-b-C-c. Furthermore, the declaration table of the component can be generated based on the method characteristic values of all declared methods in the component, and the call table of the component can be generated based on the method characteristic values of all called methods in the component. For example, the declaration table of the component can be obtained by sequentially storing the method characteristic values of all declared methods in the component, and the call table of the component can be obtained by sequentially storing the method characteristic values of all called methods in the component.
[0221] After obtaining the declaration table and call table of each component in the target project, the dependency tree corresponding to the target project can be generated by matching the declaration table and call table of each component in the target project. Optionally, for any component in the target project, the method characteristic value of at least one call method can be obtained from the call table of the component, so as to match the method characteristic value with the method characteristic values of each declared method in the declaration tables of other components in the target project except the component, so as to determine the call relationship between the components, and then generate the dependency tree corresponding to the target project based on the call relationship between the components. Since the call relationship between the components can be determined by matching the method characteristic values of the declared methods and call methods of each component in the target project, without having to match the strings included in the declared methods and call methods of each component, the matching overhead is reduced, and the matching efficiency is also improved, thereby improving the efficiency of generating the dependency tree.
[0222] After generating the dependency tree corresponding to the target project, when the component information of the component does not exist in the component information library, the generated declaration table and call table of the component, as well as the component name and component version of the component can be added to the component information library. Thus, by adding and storing the component information of the components that do not exist in the component information library, the number of times of generating the declaration table and call table of the components can be reduced, and the efficiency of generating the dependency tree can be effectively improved as the component information of the components in the component information library increases.
[0223] To implement the above embodiments, the present invention also proposes a dependency tree generation device.
[0224] Figure 9 It is a schematic structural diagram of a dependency tree generation device provided by an embodiment of the present invention.
[0225] As Figure 9 shown, the dependency tree generation device includes: a first acquisition module 91, a query module 92, a second acquisition module 93, a processing module 94, and a generation module 95.
[0226] The first acquisition module 91 is used to acquire the component names and component versions of at least two components in the target project;
[0227] The query module 92 is used to query whether a component exists in the component information library for any component based on the component name and component version of the component;
[0228] The second acquisition module 93 is used to, in response to the existence of the component information of the component in the component information library, acquire the declaration table and call table of the component from the component information library;
[0229] A processing module 94, configured to, in response to the non-existence of component information of a component in a component information library, obtain method information of at least one declared method and method information of at least one invoked method in the component, generate a declaration table of the component based on the method information of each declared method, and generate an invocation table of the component based on the method information of each invoked method;
[0230] A generation module 95, configured to generate a dependency tree corresponding to a target project according to the declaration tables and invocation tables of the components in the target project.
[0231] Further, in a possible implementation manner of the embodiment of the present invention, the method information includes a class name, a method name, the number of parameters, and parameter types; the processing module 94 includes:
[0232] A determination unit, configured to, for any declared method or invoked method in the component, determine a class name feature value, a method name feature value, and a parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type and a preset position coefficient;
[0233] A first generation unit, configured to generate a method characterization value according to the length of the class name, the class name feature value, the length of the method name, the method name feature value, the number of parameters, the parameter feature value, and a preset character;
[0234] A second generation unit, configured to generate a declaration table of the component based on the method characterization values of each declared method, and generate an invocation table of the component based on the method characterization values of each invoked method.
[0235] Further, in a possible implementation manner of the embodiment of the present invention, the determination unit is further configured to:
[0236] Sort each position character in the class name, method name, and parameter type to determine the order of each position character; wherein, adjacent position characters and the first and last position characters have an adjacent relationship;
[0237] For any position character, determine the ASCII code ratio between the position characters with an adjacent relationship as the ASCII code ratio of the position character;
[0238] Multiply the ASCII code ratio of the position character by the preset position coefficient corresponding to the position character to obtain the feature value of the position character;
[0239] Add the feature values of each position character in the class name, method name, and parameter type to obtain the class name feature value, the method name feature value, and the parameter feature value.
[0240] Further, in a possible implementation manner of the embodiment of the present invention, the first generation unit is further configured to:
[0241] Concatenate the length of the class name, the class name feature value, the length of the method name, the method name feature value, the number of parameters, and the parameter feature value with a preset character to generate a method-characterized value.
[0242] Further, in a possible implementation manner of the embodiment of the present invention, the method-characterized value includes at least one numerical data, and the second generation unit is further configured to:
[0243] For each declared method, compare each numerical data in the method-characterized value of each declared method based on the order of at least one numerical data in the method-characterized value;
[0244] Generate a declaration table of the component according to the first comparison result;
[0245] For each called method, compare each numerical data in the method-characterized value of each called method based on the order of at least one numerical data in the method-characterized value;
[0246] Generate a call table of the component according to the second comparison result.
[0247] Further, in a possible implementation manner of the embodiment of the present invention, the generation module 95 includes:
[0248] An acquisition unit, configured to, for any component in the target project, acquire the method-characterized value of at least one called method from the call table of the component;
[0249] A matching unit, configured to match the method-characterized value with the method-characterized values of each declared method in the declaration tables of other components except the component in the target project to determine the call relationship between each component;
[0250] A third generation unit, configured to generate a dependency tree corresponding to the target project based on the call relationship between each component.
[0251] Further, in a possible implementation manner of the embodiment of the present invention, the declaration table stores the method-characterized values of each declared method in sequence, the call table stores the method-characterized values of each called method in sequence, and the matching unit is further configured to:
[0252] Use the binary search method to match at least one numerical data in the method-characterized value with the corresponding numerical data in the method-characterized values of each declared method in the declaration tables of other components except the component in the target project;
[0253] When at least one numerical data in the method-characterized value all match, determine that there is a call relationship between the component and other components.
[0254] Further, in a possible implementation manner of the embodiment of the present invention, the component information library is used to store component information of at least one component, and the component information includes a component name, a component version, a declaration table, and a call table.
[0255] It should be noted that the foregoing explanation of the embodiment of the dependency tree generation method is also applicable to the dependency tree generation device of this embodiment, and will not be elaborated here.
[0256] Based on the above embodiment, the embodiment of the present invention also provides a possible implementation manner of a dependency tree generation device. Figure 10 FIG. is a schematic structural diagram of a dependency tree generation device provided by an embodiment of the present invention. On the basis of the previous embodiment, the dependency tree generation device further includes: an adding module 96.
[0257] The adding module 96 is configured to add the generated declaration table and call table of the component, as well as the component name and component version of the component, to the component information library when the component information of the component does not exist in the component information library.
[0258] The dependency tree generation device provided in this embodiment realizes, for any component, querying whether the component information of the component exists in the component information library based on the component name and component version of the component by obtaining the component names and component versions of at least two components in the target project. Thus, in response to the existence of the component information of the component in the component information library, the declaration table and call table of the component are obtained from the component information library; or, in response to the non-existence of the component information of the component in the component information library, the method information of at least one declaration method and the method information of at least one call method in the component are obtained, and the declaration table of the component is generated based on the method information of each declaration method, and the call table of the component is generated based on the method information of each call method. Furthermore, according to the declaration tables and call tables of each component in the target project, a dependency tree corresponding to the target project is generated. Therefore, it is possible to generate a dependency tree based on the declaration table and call table of the component without relying on a third-party file, improving the applicability and accuracy of generating the dependency tree. At the same time, since the declaration table and call table of the component can be stored in the component information library, when the component information of the component exists in the component information library, the declaration table and call table of the component can be directly obtained from the component information library, thus eliminating the need to generate the declaration table and call table of the component each time and improving the generation efficiency of the dependency tree.
[0259] To implement the above embodiment, the present invention also proposes an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the dependency tree generation method proposed in any one of the above embodiments of the present invention.
[0260] Figure 11The figure is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. It should be noted that Figure 11 The electronic device shown is merely an example and should not impose any limitations on the functions and usage scope of the embodiments of the present invention.
[0261] As Figure 11 shown, the electronic device may include: a housing 11, a processor 12, a memory 13, a circuit board 14, and a power supply circuit 15. Among them, the circuit board 14 is arranged inside the space enclosed by the housing 11, and the processor 12 and the memory 13 are arranged on the circuit board 14; the power supply circuit 15 is used to supply power to each circuit or device of the above-mentioned electronic device; the memory 13 is used to store executable program codes; the processor 12 runs a program corresponding to the executable program code by reading the executable program code stored in the memory 13, and is used to execute the dependency tree generation method proposed in any one of the above embodiments of the present invention.
[0262] For the specific execution process of the above steps by the processor 12 and the further steps executed by the processor 12 by running the executable program code, reference may be made to the description of the embodiments Figure 1-8 shown in the present invention, which will not be elaborated here.
[0263] To implement the above embodiments, the present invention also proposes a computer-readable storage medium storing computer instructions, where the computer instructions are used to cause a computer to execute the dependency tree generation method proposed in any one of the above embodiments of the present invention.
[0264] To implement the above embodiments, the present invention also proposes a computer program product, including a computer program, which implements the dependency tree generation method proposed in any one of the above embodiments of the present invention when executed by a processor.
[0265] In the description of this specification, the descriptions with reference to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0266] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the quantity of the technical features indicated. Thus, features defined with "first" and "second" may explicitly or implicitly include at least one such feature. In the description of the present invention, the meaning of "a plurality of" is at least two, such as two, three, etc., unless otherwise specifically defined.
[0267] Any process or method description represented in a flowchart or otherwise described herein can be understood to represent a module, segment, or portion of code including one or more executable instructions for implementing a customized logical function or process. The scope of the preferred embodiments of the present invention includes additional implementations where functions may be executed in a manner not shown or discussed, including in a substantially simultaneous manner according to the functions involved or in a reverse order, which should be understood by those skilled in the art to which the embodiments of the present invention pertain.
[0268] The logic and / or steps represented in a flowchart or otherwise described herein, for example, can be considered a sequenced list of executable instructions for implementing a logical function and can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, a system including a processor, or other systems that can fetch and execute instructions from the instruction execution system, apparatus, or device. As used in this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of the computer-readable medium include the following: an electrical connection portion having one or more wirings (electronic device), a portable computer diskette (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium can even be paper or other suitable media on which the program can be printed, as the program can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpretation, or otherwise appropriate processing as necessary, and then stored in a computer memory.
[0269] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, any one or a combination of the following techniques well known in the art can be used: discrete logic circuits with logic gate circuits for implementing logical functions on data signals, application specific integrated circuits with appropriate combinational logic gate circuits, programmable gate arrays (PGAs), field programmable gate arrays (FPGAs), etc.
[0270] Those of ordinary skill in the art can understand that all or part of the steps carried by the method of the above embodiments can be completed by instructing relevant hardware through a program, and the said program can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiments.
[0271] In addition, each functional unit in various embodiments of the present invention can be integrated into a processing module, or each unit can exist physically alone, or two or more units can be integrated into one module. The above integrated module can be implemented in the form of hardware or in the form of a software functional module. When the above integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0272] The above-mentioned storage medium can be a read-only memory, a magnetic disk or an optical disc, etc. Although the embodiments of the present invention have been shown and described above, it can be understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those of ordinary skill in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.
Claims
1. A method for generating a dependency tree, characterized in that, Including the following steps: Obtain the component names and component versions of at least two components in the target project; For any one of the components, query whether there is component information of the component in the component information library based on the component name and component version of the component; In response to the existence of the component information of the component in the component information library, obtain the declaration table and call table of the component from the component information library; In response to the non-existence of the component information of the component in the component information library, obtain the method information of at least one declaration method and the method information of at least one call method in the component, and generate the declaration table of the component based on the method information of each declaration method, and generate the call table of the component based on the method information of each call method; Generate a dependency tree corresponding to the target project according to the declaration tables and call tables of the components in the target project; Wherein, the method information includes class name, method name, number of parameters, and parameter type; generating the declaration table of the component based on the method information of each declaration method, and generating the call table of the component based on the method information of each call method, includes: For any one of the declaration methods or call methods in the component, determine the class name feature value, method name feature value, and parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type and the preset position coefficient; Generate a method characteristic value according to the length of the class name, the class name feature value, the length of the method name, the method name feature value, the number of parameters, the parameter feature value, and the preset character; Generate the declaration table of the component based on the method characteristic values of each declaration method, and generate the call table of the component based on the method characteristic values of each call method.
2. The method according to claim 1, characterized in that, The determining the class name feature value, method name feature value, and parameter feature value according to the ASCII code ratio of each position character in the class name, method name, and parameter type and the preset position coefficient includes: Sort each position character in the class name, method name, and parameter type to determine the order of each position character; wherein, the position characters with adjacent order have an adjacent relationship, and there is an adjacent relationship between the first and last position characters; For any one of the position characters, determine the ASCII code ratio between the position characters with an adjacent relationship as the ASCII code ratio of the position character; Multiply the ASCII code ratio of the position character by the preset position coefficient corresponding to the position character to obtain the feature value of the position character; Add the feature values of each position character in the class name, method name, and parameter type to obtain the class name feature value, method name feature value, and parameter feature value.
3. The method according to claim 1, characterized in that The generating a method characteristic value according to the length of the class name, the class name feature value, the length of the method name, the method name feature value, the number of parameters, the parameter feature value, and the preset character includes: Concatenate the length of the class name, the class name feature value, the length of the method name, the method name feature value, the number of parameters, and the parameter feature value with the preset character to generate a method characteristic value.
4. The method according to claim 1, wherein The method characterization value includes at least one numerical data. Based on the method characterization values of each of the declared methods, a declaration table of the component is generated, and based on the method characterization values of each of the called methods, a call table of the component is generated, including: For each of the declared methods, compare each of the numerical data in the method characterization value of each of the declared methods based on the order of at least one numerical data in the method characterization value; Generate a declaration table of the component according to the first comparison result; For each of the called methods, compare each of the numerical data in the method characterization value of each of the called methods based on the order of at least one numerical data in the method characterization value; Generate a call table of the component according to the second comparison result.
5. The method according to claim 1, characterized in that, The generating a dependency tree corresponding to the target project according to the declaration table and call table of each component in the target project includes: For any one component in the target project, obtain the method characterization value of at least one called method from the call table of the component; Match the method characterization value with the method characterization values of each of the declared methods in the declaration tables of other components in the target project except the component to determine the call relationship between each component; Generate a dependency tree corresponding to the target project based on the call relationship between each component.
6. The method according to claim 5, wherein The declaration table stores the method characterization values of each of the declared methods in sequence, and the call table stores the method characterization values of each of the called methods in sequence. The method characterization value includes at least one numerical data. The matching the method characterization value with the method characterization values of each of the declared methods in the declaration tables of other components in the target project except the component to determine the call relationship between each component includes: Based on the order of at least one numerical data in the method characterization value, use the binary search method to match each of the numerical data in the method characterization value with the corresponding numerical data in the method characterization values of each of the declared methods in the declaration tables of other components in the target project except the component; When each of the numerical data in the method characterization value is matched and consistent, determine that there is a call relationship between the component and the other component.
7. The method according to any one of claims 1-6, characterized in that The component information library is used to store the component information of at least one component. The component information includes component name, component version, declaration table and call table. The method further includes: When the component information of the component does not exist in the component information library, add the generated declaration table and call table of the component, as well as the component name and component version of the component to the component information library.
8. A dependency tree generation device, characterized in that Including: A first acquisition module for acquiring the component names and component versions of at least two components in the target project; A query module for querying whether the component information of any one component exists in the component information library based on the component name and component version of the component. A second acquisition module, configured to, in response to the presence of component information of the component in the component information library, acquire a declaration table and an invocation table of the component from the component information library; A processing module, configured to, in response to the absence of component information of the component in the component information library, acquire method information of at least one declaration method and method information of at least one invocation method in the component, generate a declaration table of the component based on the method information of each declaration method, and generate an invocation table of the component based on the method information of each invocation method; A generation module, configured to generate a dependency tree corresponding to the target project according to the declaration tables and invocation tables of the components in the target project; Wherein, the method information includes a class name, a method name, the number of parameters, and parameter types; the processing module includes: A determination unit, configured to, for any one of the declaration methods or the invocation methods in the component, determine a class name feature value, a method name feature value, and a parameter feature value according to the ASCII code ratio of each position character in the class name, the method name, and the parameter type and a preset position coefficient; A first generation unit, configured to generate a method characterization value according to the length of the class name, the class name feature value, the length of the method name, the method name feature value, the number of parameters, the parameter feature value, and a preset character; A second generation unit, configured to generate a declaration table of the component based on the method characterization values of each declaration method, and generate an invocation table of the component based on the method characterization values of each invocation method; 9. The device according to claim 8, characterized in that, The determination unit is further configured to: Sort each position character in the class name, the method name, and the parameter type to determine the order of each position character; wherein, adjacent position characters, and the first and last position characters have an adjacent relationship; For any one of the position characters, determine the ASCII code ratio between the position characters with an adjacent relationship as the ASCII code ratio of the position character; Multiply the ASCII code ratio of the position character by the preset position coefficient corresponding to the position character to obtain the feature value of the position character; Add the feature values of each position character in the class name, the method name, and the parameter type to obtain the class name feature value, the method name feature value, and the parameter feature value.
10. The device according to claim 8, characterized in that, The first generation unit is further configured to: Concatenate the length of the class name, the class name feature value, the length of the method name, the method name feature value, the number of parameters, and the parameter feature value with a preset character to generate a method characterization value.
11. The device according to claim 8, characterized in that, The method characterization value includes at least one numerical data, and the second generation unit is further configured to: For each declaration method, compare each numerical data in the method characterization value of each declaration method based on the order of at least one numerical data in the method characterization value; Generate a declaration table of the component according to a first comparison result; For each invocation method, compare each numerical data in the method characterization value of each invocation method based on the order of at least one numerical data in the method characterization value; Generate an invocation table of the component according to a second comparison result.
12. The device according to claim 8, wherein The generation module includes: An acquisition unit configured to obtain, for any one of the components in the target project, the method characterization values of at least one call method from the call table of the component; A matching unit configured to match the method characterization values with the method characterization values of each of the declared methods in the declaration tables of other components in the target project except the component, so as to determine the call relationships between the components; A third generation unit configured to generate a dependency tree corresponding to the target project based on the call relationships between the components.
13. The device according to claim 12, characterized in that, The declaration tables sequentially store the method characterization values of the declared methods, the call tables sequentially store the method characterization values of the call methods, the method characterization values include at least one numerical data, and the matching unit is further configured to: Based on the order of at least one numerical data in the method characterization values, use the binary search method to respectively match each of the numerical data in the method characterization values with the corresponding numerical data in the method characterization values of each of the declared methods in the declaration tables of other components in the target project except the component; When all the numerical data in the method characterization values are matched and consistent, determine that there is a call relationship between the component and the other components.
14. The device according to any one of claims 8 - 13, characterized in that, The component information library is used to store the component information of at least one component, and the component information includes the component name, component version, declaration table, and call table. The device further includes: An adding module configured to, when the component information of the component does not exist in the component information library, add the generated declaration table and call table of the component, as well as the component name and component version of the component to the component information library.
15. An electronic device, characterized in that, Comprising: At least one processor; And A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method according to any one of claims 1-7.
16. A computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to execute the method according to any one of claims 1-7.
17. A computer program product, characterized in that, Including a computer program which, when executed by a processor, implements the method according to any one of claims 1-7.
Citation Information
Patent Citations
Dependent component information extraction method and device and computer readable storage medium
CN112711438A
Component dependency relationship generation method and device, equipment and storage medium
CN114816413A