Code analysis method and device, equipment and medium

By parsing the change lines and files of front-end applications, determining the change object and analyzing the influencing code call chain, the problem of inaccurate evaluation of the impact of code changes is solved, automated impact analysis is realized, and testing costs are reduced.

CN120491970APending Publication Date: 2025-08-15BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510571881.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-30
Publication Date
2025-08-15

AI Technical Summary

Technical Problem

The impact assessment of the code change of front-end applications is not comprehensive and accurate enough, resulting in increased risks and increased testing costs.

Method used

By obtaining the change code lines and change files, syntax parsing determines the change object, and performing call analysis based on the change object, determining the influencing code call chain, and finally determining the influencing code lines and affecting files.

Benefits of technology

It realizes automated code change impact analysis, accurately and comprehensively determines the scope of code change, and reduces the quality problems and testing costs caused by manual judgment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120491970A_ABST
    Figure CN120491970A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to a code analysis method and device, equipment and a medium. The method comprises the steps that a change code line and a change file of a front-end application program are obtained; performing grammar analysis on the change code line and the change file to determine a change object; and performing call analysis based on the change object to determine an influence code call chain. An impact code line and an impact file are determined based on the impact code call chain. By the adoption of the technical scheme, the change object is obtained by analyzing the change code line and the change file of the front-end application program, the influence code calling chain is called, analyzed and determined on the basis of the change object, then the influence code line and the influence file are determined, automatic influence analysis of code change of the front-end application program is achieved, and the user experience is improved. According to the method, the influence range of code change is accurately and comprehensively determined, the quality problem caused by manual judgment is effectively reduced, the test cost is further reduced, and the test sufficiency of changed codes and influence codes is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a code analysis method, apparatus, device, and medium. Background Art

[0002] Changes can drive the evolution of software systems, but they also carry risks. The impact of code changes in front-end applications is often assessed manually, which is incomplete and inaccurate, introducing unknown risks. Furthermore, as code complexity increases, the risks of changes are magnified, leading to more serious quality issues and increasing testing costs. Summary of the Invention

[0003] In order to solve the above technical problems, the present disclosure provides a code analysis method, apparatus, device and medium.

[0004] The present disclosure provides a code analysis method, the method comprising:

[0005] Get the changed code lines and changed files of the front-end application;

[0006] Performing syntax analysis on the changed code lines and the changed files to determine the changed objects;

[0007] Perform call analysis based on the changed object to determine the affected code call chain;

[0008] An affected code line and an affected file are determined based on the affected code call chain.

[0009] The present disclosure also provides a code analysis device, comprising:

[0010] The acquisition module is used to obtain the changed code lines and changed files of the front-end application;

[0011] A parsing module, configured to perform syntax analysis on the changed code lines and the changed files to determine the changed objects;

[0012] An analysis module, configured to perform call analysis based on the changed object to determine an affected code call chain;

[0013] An impact determination module is used to determine the impacted code lines and impacted files based on the impacted code call chain.

[0014] An embodiment of the present disclosure also provides an electronic device, comprising: a processor; a memory for storing instructions executable by the processor; the processor for reading the executable instructions from the memory and executing the executable instructions to implement the code analysis method provided in the embodiment of the present disclosure.

[0015] An embodiment of the present disclosure further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to execute the code analysis method provided by the embodiment of the present disclosure.

[0016] The technical solution provided by the embodiment of the present disclosure has the following advantages over the prior art: the code analysis solution provided by the embodiment of the present disclosure obtains the changed code lines and changed files of the front-end application; performs syntax parsing on the changed code lines and changed files to determine the changed objects; performs call analysis based on the changed objects to determine the affected code call chain. Determine the affected code lines and affected files based on the affected code call chain. With the above technical solution, the changed objects are obtained by parsing the changed code lines and changed files of the front-end application, and the affected code call chain is determined by call analysis based on the changed objects, and then the affected code lines and affected files are determined, thereby realizing automated impact analysis of code changes of the front-end application, accurately and comprehensively determining the scope affected by the code changes, effectively reducing quality problems caused by manual judgment, thereby reducing testing costs, and improving the testing adequacy of changed codes and affected codes. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that the originals and elements are not necessarily drawn to scale.

[0018] Figure 1 A flowchart of a code analysis method provided in some embodiments of the present disclosure;

[0019] Figure 2 A flowchart of another code analysis method provided in some embodiments of the present disclosure;

[0020] Figure 3 A schematic diagram of an impact result page provided for some embodiments of the present disclosure;

[0021] Figure 4 A schematic diagram of another impact result page provided in some embodiments of the present disclosure;

[0022] Figure 5 A schematic diagram of a code analysis process provided for some embodiments of the present disclosure;

[0023] Figure 6 A schematic diagram of the structure of a code analysis device provided in some embodiments of the present disclosure;

[0024] Figure 7 A schematic structural diagram of an electronic device provided in some embodiments of the present disclosure. DETAILED DESCRIPTION

[0025] The following describes embodiments of the present disclosure in more detail with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments described herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are for illustrative purposes only and are not intended to limit the scope of protection of the present disclosure.

[0026] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.

[0027] As used herein, the term "including" and its variations are open-ended, i.e., "including but not limited to." The term "based on" means "based, at least in part, on." The term "one embodiment" means "at least one embodiment," the term "another embodiment" means "at least one additional embodiment," and the term "some embodiments" means "at least some embodiments." Other terms are defined in the following description.

[0028] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0029] It should be noted that the modifications of "one" and "multiple" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, they should be understood as "one or more".

[0030] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.

[0031] In order to solve the problem that the impact assessment of the above-mentioned code changes is not comprehensive and accurate, the embodiments of the present disclosure provide a code analysis method, which is introduced below in conjunction with specific embodiments.

[0032] Figure 1 This is a flow chart of a code analysis method provided by some embodiments of the present disclosure. The method can be executed by a code analysis device, wherein the device can be implemented using software and / or hardware and can generally be integrated into an electronic device. Figure 1 As shown, the method includes:

[0033] Step 101: Obtain the changed code lines and changed files of the front-end application.

[0034] The code analysis method of the embodiment of the present disclosure can be performed by a code analysis tool, which can be used to perform change code analysis and impact code analysis, and can communicate with the coverage plug-in to obtain the code test results of the front-end application. The front-end application can be an application running on the client (such as a browser, mobile device, etc.), which is directly responsible for processing the user interface, interactive logic and data display to the user, and communicates with the back-end service to complete the function. The changed code line can be the specific code line in the front-end application where the code is changed, and the number of changed code lines can be multiple. The change file can be the code file where the changed code line is located. In addition to the changed code line, the change file can also include multiple unchanged code lines. The unchanged code line can be the code line whose code has not been changed.

[0035] Specifically, the code analysis device can obtain the changed code text information of the front-end application in response to the code modification operation of the front-end application; identify the changed code text information to obtain the changed code lines of the front-end application and the changed files where the changed code lines are located.

[0036] The changed code text information can be a text description that details the specific changes that have occurred in the code, obtained by using a code change management tool to compare the differences in code quality inspection before and after the code change operation for the code repository of the front-end application. It can be specifically determined by using a static analysis method through the code change instruction in the code change management tool. When the front-end application is subjected to a code change operation, code analysis can be triggered. The code analysis device can obtain the changed code text information of the front-end application and use a format conversion tool to convert the changed code text information into changed code data. The changed code data can be a readable data structure, such as JSON data. The changed code data is then identified, and the code behavior of the data change type is extracted as the changed code line, and the code file where the changed code line is located is determined as the changed file. By performing a change code analysis on the front-end application, the specific changed code line and changed file can be located, the scope of the change can be determined, and preparations can be made for subsequent impact analysis.

[0037] Step 102: Parse the changed code lines and the changed files to determine the changed objects.

[0038] Among them, the change object can be a specific object involved in the code change operation determined according to the code syntax rules, can be an object directly affected by the code change operation, can include the characteristic value corresponding to the code line used for definition and the parent characteristic value of the executable code line, and the change object can include characteristic values such as changed functions and / or changed variables.

[0039] Specifically, the code analysis device may perform syntax analysis on the changed code lines and changed files using code syntax rules to determine the changed objects therein. The code syntax rules may be, for example, Abstract Syntax Tree (AST) technology.

[0040] For example, Figure 2 A flowchart of another code analysis method provided in some embodiments of the present disclosure is shown as follows: Figure 2 As shown, in a feasible implementation, parsing the changed code lines and the changed files to determine the changed objects may include:

[0041] Step 201: Obtain a code compilation configuration file corresponding to the affected module based on the change file.

[0042] The affected module can be a functional module or page directly affected by the code modification in the front-end application. In this case, it can be the affected module corresponding to the changed file. The code compilation configuration file can be a file used to set and control various parameters and options during the code compilation process of the affected module. It can include configuration files for compilers, linkers, and other build tools.

[0043] Specifically, the code analysis device can determine the affected module directory where the change file is located, and extract the code compilation configuration file of the affected module corresponding to the change file in the affected module directory. The affected module directory can be the code directory of the affected module, and the affected module directory can include multiple code files, and the change file is one of the code files. If the affected module directory includes the code compilation configuration file, subsequent analysis can be performed; otherwise, the analysis is stopped. Here, the code compilation configuration file is obtained from the directory where the change file is located to prepare for subsequent syntax analysis.

[0044] Step 202: Parse the changed file based on the code compilation configuration file to determine a changed syntax tree.

[0045] Among them, the change syntax tree can be a syntax tree obtained by abstractly representing the code syntax structure of the change file in a tree form. Each node in the change syntax tree represents a structure in the code. In the embodiment of the present disclosure, the change syntax tree is an abstract syntax tree as an example for explanation.

[0046] In some embodiments, performing syntax parsing on the change file based on the code compilation configuration file to determine the change syntax tree may include: extracting syntax units of the declared types in the change file based on the code compilation configuration file to construct multiple nodes; and constructing the change syntax tree according to the calling relationship between the multiple nodes.

[0047] Among them, the syntax unit (token) of the declared type can be a keyword or symbol that clearly specifies the data type of a variable, function return type, function parameter, class member variable, data structure field, etc. For example, if a code line in the change file is "function test(){}", the code line is a change function named test. Specifically, the code analysis device can decompose the change file into multiple lexical units based on the lexical analysis rules in the code compilation configuration file, and then use the parsing strategy to parse the multiple lexical units and organize them into corresponding change syntax trees. The parsing strategy here can be, for example, a recursive descent parsing strategy. Taking AST technology as an example, the syntax unit of the declared type is extracted according to the parsing result to construct the corresponding node, that is, the feature value corresponding to the code line defined below and the parent feature value of the code line used for execution are constructed. The parent-child relationship and sibling relationship between the nodes are established according to the call relationship. By recursively creating nodes and establishing relationships, a complete abstract syntax tree is finally formed. The abstract syntax tree is the change syntax tree; if there are multiple change files, multiple change syntax trees can be constructed. In the above scheme, the corresponding change syntax tree can be quickly constructed by parsing the change file, preparing for the subsequent search of the change object.

[0048] Step 203: Determine the node corresponding to the changed code line in the changed syntax tree as the changed object.

[0049] After constructing the change syntax tree, the code analysis device can search in the change syntax tree to determine that the node corresponding to the changed code line is the change object.

[0050] In the above solution, parsing the changed file based on the code compilation configuration file can quickly and accurately determine the changed object corresponding to the changed code line, and by constructing a syntax tree, it helps to quickly determine the impact scope of the changed object.

[0051] Step 103: Perform call analysis based on the changed object to determine the affected code call chain.

[0052] Among them, the affected code call chain can be the link in which the change object corresponding to the code modification operation is called. The change object can affect the end node of the code call chain. Other nodes directly or indirectly call the change object. Other objects in the affected code call chain except the change object are affected objects.

[0053] In some embodiments, a call analysis is performed based on the changed object to determine the affected code call chain, including: searching the changed object step by step upward according to the call relationship based on the changed syntax tree until the entry object is found; and determining the call chain between the changed object and the entry object as the affected code call chain.

[0054] Among them, the entry object can be an object that has not been called by other objects, and can be the starting point for the compiler to start compiling. Specifically, the code analysis device can use the call relationship analysis function to search the call relationship starting from the change object on the basis of the above-mentioned change syntax tree, find the node that calls the change object, and search upward step by step until a node is found that has not been called. The node is the entry object; the call chain between the change object and the entry object is determined as the affected code call chain, and the other objects in the affected code call chain except the change object are affected objects. Since the number of change objects is multiple, the number of affected code call chains is also multiple. The above-mentioned call relationship analysis function has different implementation methods for different code languages, which are not specifically limited. In the above scheme, the call chain where the change object is located can be quickly determined through call analysis on the basis of the change syntax tree, and then the affected code call chain can be quickly determined.

[0055] Step 104: Determine the affected code lines and affected files based on the affected code call chain.

[0056] An affected code line can be a code line indirectly affected by a code modification operation. This means that the affected code line may not change directly, but may change at a specific moment due to the code modification operation. The object corresponding to the affected code line is the affected object. An affected file can be the code file where the affected code line is located.

[0057] The code analysis device can determine the code lines corresponding to the affected objects other than the changed objects in the affected code call chain as the affected code lines, and determine the code file where the affected code lines are located as the affected file. The affected object can be an object indirectly affected by the code change operation, and the affected object directly or indirectly calls the changed object. Each object in the affected code call chain carries a corresponding code line. After obtaining the affected code call chain, the code behavior of each affected object can be determined to affect the code line, and then the affected file can be obtained, effectively determining the scope of influence of the code change.

[0058] The code analysis solution provided by the embodiment of the present disclosure obtains the changed code lines and changed files of the front-end application; performs syntax analysis on the changed code lines and changed files to determine the changed objects; and performs call analysis based on the changed objects to determine the affected code call chain. The affected code lines and affected files are determined based on the affected code call chain. By adopting the above technical solution, the changed objects are obtained by parsing the changed code lines and changed files of the front-end application, and the affected code call chain is determined by call analysis based on the changed objects, and then the affected code lines and affected files are determined, thereby realizing automated impact analysis of code changes of the front-end application, accurately and comprehensively determining the scope affected by the code changes, effectively reducing quality problems caused by manual judgment, thereby reducing testing costs, and improving the testing adequacy of changed codes and affected codes.

[0059] In some embodiments, the code analysis method may further include: obtaining code test results, and extracting a first number of execution-affected code lines and a second number of execution-changed code lines in the code test results; determining the impact test coverage based on the first number of execution-affected code lines and the third number of affected code lines; determining the change test coverage based on the second number of execution-changed code lines and the fourth number of executable change code lines in the changed code lines.

[0060] The code test results can be code execution results obtained by functionally testing the front-end application in a test environment after code modification operations. These can be obtained using a coverage plug-in. The coverage plug-in can be a plug-in connected to the code repository of the front-end application to record and report code execution information in real time during the user's testing of the front-end application. The code test results can include information about the code executed during the test process. The code test results can include execution-affected code lines, execution-changed code lines, and specific numbers. The execution-affected code lines can be the affected code lines executed or covered during the test process. The first number can be the specific number of execution-affected code lines. The execution-changed code lines can be the changed code lines executed or covered during the test process. The second number can be the specific number of execution-changed code lines. The third number can be the specific number of the aforementioned affected code lines, and the third number is greater than the first number. The fourth number can be the specific number of executable changed code lines among the changed code lines. The executable changed code lines can be the code lines that can be executed among the changed code lines, or can be the code lines that have been instrumented. The changed code lines also include the following defined code lines that cannot be executed.

[0061] Impact test coverage is a metric that measures the extent to which impact code is tested and executed. It indicates the specific proportion of impact code that is actually executed during the testing process, usually expressed as a percentage. Change test coverage is a metric that measures the extent to which change code is tested and executed. It indicates the specific proportion of executable code in the change code that is actually executed during the testing process, usually expressed as a percentage. Change test coverage can be an important metric for evaluating test effectiveness, helping to identify untested changes and improve code quality.

[0062] Specifically, the code analysis device can obtain the code test results reported by the coverage plug-in after the user finishes testing the front-end application, extract the first number of executed affected code lines and the second number of executed changed code lines in the code test results; calculate the ratio of the first number divided by the third number of affected code lines, and determine the ratio as the impact test coverage; and calculate the ratio of the second number divided by the fourth number of executable changed code lines in the changed code lines, and determine the ratio as the change test coverage.

[0063] In the above solution, expanding code impact test coverage beyond code change test coverage ensures not only comprehensive testing of the changed code but also comprehensive testing of the impacted code. Combining these two approaches significantly improves the quality and confidence of test activities.

[0064] In some embodiments, the code analysis method may further include: displaying code test results, test coverage results, changed code lines, and affected code lines on the impact result page, wherein the test coverage results include impact test coverage and change test coverage.

[0065] Among them, the impact result page can be used to display the code test results of the front-end application for the code modification operation and the calculated test coverage result page, and the test coverage result can include the above-mentioned impact test coverage and change test coverage. After obtaining the code test results, the code analysis device can display the impact result page, display the code test results, test coverage results, changed code lines and affected code lines in the impact result page, and highlight the execution impact code lines and execution change code lines. The specific highlighting method is not limited, as long as it can be distinguished from other code lines. For example, the execution impact code lines can be highlighted with a first color, and the execution change code lines can be highlighted with a second color. The first color and the second color are different, such as the first color is green and the second color is purple.

[0066] For example, Figure 3 A schematic diagram of an impact result page provided by some embodiments of the present disclosure, such as Figure 3 As shown in the figure, an impact result page 300 is shown, and the top of the impact result page 300 shows the identification of the code repository, the changed execution code lines, the executable changed code lines, the executed change code lines, the affected code lines, the specific number of the executed affected code lines in the code test results, and the impact test coverage and the change test coverage in the test coverage results; the lower left side of the impact result page 300 shows the directory, which includes the changed files and the affected files, and the lower right side of the impact result page 300 shows the changed code lines, affected code lines, executed change code lines and executed affected code lines in the selected changed file or affected file. Different code lines can be distinguished by different colors (colors are not shown in the figure), and the executed change code lines and the executed affected code lines can be highlighted. For example, the code line 301 selected by the box in the figure is the execution affected code line.

[0067] In the above solution, after testing the front-end application, the code test results and test coverage results can be displayed, and different types of code lines, such as execution change code lines and execution impact code lines, can be displayed separately, so that users can quickly know the change test coverage and impact test coverage, as well as the specific code lines. The scope of code changes and the scope of change impact are presented in a visual way, effectively improving the efficiency of test coverage display.

[0068] In some embodiments, the code analysis method may further include: in response to an invalid marking operation on a target impact code line in the impact result page, adding an invalid impact tag to the target impact code line, wherein the invalid impact tag indicates that it does not belong to an impact code line.

[0069] An invalid marking operation can trigger the addition of an invalid impact label to an affected code line, such as by clicking or double-clicking the invalid impact label control. The target affected code line can be the currently selected affected code line or the code line targeted by the invalid marking operation. An invalid impact label can be a label that modifies the properties of an affected code line. Manually adding this label to an affected code line indicates that the code line is not an affected code line.

[0070] Specifically, after displaying the above-mentioned impact result page, the code analysis device receives the user's invalid marking operation on the target impact code line, and can add an invalid impact label to the target impact code line, indicating that the target impact code line is an invalid impact code line, and the target impact code line can be deleted when calculating the impact test coverage.

[0071] Optionally, the code analysis device can also add corresponding labels in response to marking operations on other code lines. The marking operations may include redundant code marking operations, no-test coverage required marking operations, etc., without limitation. Different marking operations correspond to different labels. For example, a code line is subjected to a redundant code marking operation. The code line is marked or a redundant code label is added, and it will not be counted in the denominator when calculating the above-mentioned change test coverage and impact test coverage.

[0072] In the above solution, by supporting the tagging operation of code lines and adding different tags, it is convenient for users to modify the properties of the code and the test coverage results, effectively improving the accuracy of the code line attribute display and the accuracy of the test coverage result determination.

[0073] In some embodiments, the code analysis method may further include: in response to a trigger operation for displaying an impact link in an impact result page, displaying a call relationship graph of the impact code call chain.

[0074] The trigger operation that affects the display of the link can be a trigger operation that affects the code call chain, for example, Figure 3 The code call chain control 302 is affected by single-clicking or double-clicking. The call relationship graph can be a graph obtained by visualizing the code call chain. The specific visualization method can be a relationship graph or a Sankey diagram. The embodiment of the present disclosure uses the relationship graph as an example. The call relationship graph can display each object included in the code call chain and the call relationship between different objects.

[0075] For example, Figure 4 Another schematic diagram of an impact result page provided in some embodiments of the present disclosure is as follows: Figure 4 As shown in the figure, the impact result page 400 is shown, and the impact result page 400 can be Figure 3 The impact code call chain control 302 is displayed after the trigger operation. The impact result page 400 may include multiple impact code call chains. Each circle in the figure represents an object in an impact code call chain. Different objects are connected by lines, indicating that they have a call relationship or a reference relationship. Each object can represent the test coverage of the object by its circle color. The test coverage of the object represents the proportion of multiple objects connected to the object that are actually executed during the test process. Different test coverages have different colors (not shown in the figure); each object represents its impact range by the size of its circle, that is, the number of connected objects. The larger the size, the more connected objects. In the figure, A, B, C, D, and E are 5 objects with larger impact ranges.

[0076] Optionally, multiple filter item controls can also be displayed in the impact result page 400 to support filtering of filter items such as node type, node name search, whether the node has been tested and covered, and display the impact code call chain under the corresponding filter item. For example, for the node type, only the changed objects in the impact code call chain can be displayed.

[0077] In the above solution, the affected code call chain can be visualized to visualize the scope of code change impact, allowing users to quickly understand the scope of impact and improving the efficiency and flexibility of the scope of impact display.

[0078] The following is a further explanation of the code analysis solution of the embodiment of the present disclosure through a specific example. The complete process of analyzing and testing the front-end application after the code modification operation of the embodiment of the present disclosure may include:

[0079] 1. Access code coverage, enter information such as code repository and identification information, and check the Code Impact Analysis switch to turn it on.

[0080] 2. The code repository integrates the coverage plug-in, mainly by integrating the coverage plug-in in the build configuration.

[0081] 3. After the integration step is completed, submit the code changes and create a code merge request. At this time, a code analysis task will be initiated, which can include the following two analysis tasks:

[0082] a. Change code analysis to obtain changed code lines and changed files;

[0083] b. Impact code analysis to obtain the affected code lines and affected files, see Figure 5 .

[0084] 4. Build the source code product of the code repository. During the build process, since the coverage plug-in is connected in step 2, the coverage plug-in can perform code instrumentation, full stub reporting, and reporting function injection during this period.

[0085] Code instrumentation can obtain executable code lines through static analysis and add a marker function to each line of code to record the code lines executed by the user during testing. The key logic of the implementation is to use a compilation tool to convert the code into an abstract syntax tree, and then insert the abstract syntax tree data structure related to the marker function for each executable code line.

[0086] Full stub reporting can report all stub information collected during the code instrumentation process to the backend, where stubs refer to executable code lines.

[0087] Reporting function injection can be to insert template code into the source code product to report the executed code line information to the backend during the user's test.

[0088] 5. Deploy the source code product from step 4 to a low-traffic environment. Users can test page functions in this environment. Due to code instrumentation, it can record the code information executed by users during the test in real time. Due to the injection of reporting functions, it monitors the execution status of the code through polling and reports the information to the backend.

[0089] 6. Display the impact result page, through which you can see the detailed changed code lines, affected code lines and code test results.

[0090] 7. Display the influencing code call chain through relationship diagram or Sankey diagram, and support filtering items such as node type, node name search, and whether the node has test coverage.

[0091] For example, Figure 5 A schematic diagram of a code analysis process provided by some embodiments of the present disclosure, such as Figure 5 As shown in the figure, the code analysis process may include:

[0092] 1. Pull the code repository to local.

[0093] 2. Preliminary environment preparation.

[0094] a. Identify the repository type. If it is a single-module repository, go directly to the next step. If it is a multi-module repository, identify the package manager type.

[0095] b. Depending on the repository type, use the appropriate terminal command to download the tool packages that the repository depends on.

[0096] 3. Impact code analysis.

[0097] a. After the pre-environment is prepared, perform the same steps as "Change Code Analysis" to obtain the changed code lines and changed files.

[0098] b. Analyze the affected module directory based on the changed file, and determine whether the directory contains configuration files.

[0099] c. Get the code compilation configuration file. Get the code compilation configuration file that affects the module directory, such as the compiler configuration file.

[0100] d. Identify the changed objects. Based on the abstract syntax tree technology, the changed functions / variables and other feature values are identified as the changed objects according to the changed files and changed code lines. The key logic is to parse the code lines included in the changed files, extract the syntax units of the declaration type, and construct nodes. Then, a change syntax tree is constructed, and the nodes corresponding to the changed code lines in the change syntax tree are identified as the changed objects.

[0101] e. Determine the affected code chain. Continuing with the abstract syntax tree, analyze the affected code call chain based on the changed object. The key logic is to find the object called by the changed object and search upwards until no object is called, thus forming a complete affected code call chain. This is implemented differently for different languages.

[0102] 4. Report the impact code call chain obtained from the impact code analysis to the backend.

[0103] This solution uses code analysis capabilities to implement change impact analysis for front-end applications. It analyzes the affected code lines and files in advance and presents them to users, reducing the impact of manual judgment. It also combines code coverage with change impact analysis. Based on code coverage, it expands code impact coverage to help improve the test adequacy of the tested functions and affected functions during testing.

[0104] Figure 6This is a schematic diagram of the structure of a code analysis device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware and can generally be integrated into an electronic device. Figure 6 As shown, the device includes:

[0105] The acquisition module 601 is used to acquire the changed code lines and changed files of the front-end application;

[0106] Parsing module 602, used for parsing the changed code line and the changed file to determine the changed object;

[0107] An analysis module 603 is configured to perform call analysis based on the changed object to determine an affected code call chain;

[0108] The impact determination module 604 is configured to determine the impacted code lines and impacted files based on the impacted code call chain.

[0109] Optionally, the acquisition module 601 is used to:

[0110] In response to a code modification operation of the front-end application, obtaining text information of the changed code of the front-end application;

[0111] The change code text information is identified to obtain the change code line of the front-end application and the change file where the change code line is located.

[0112] Optionally, the parsing module 602 includes:

[0113] The first unit is configured to obtain a code compilation configuration file corresponding to the affected module based on the change file;

[0114] The second unit is configured to perform syntax analysis on the change file based on the code compilation configuration file to determine a change syntax tree;

[0115] The third unit is configured to determine a node corresponding to the changed code line in the changed syntax tree as a changed object.

[0116] Optionally, the first unit is used to:

[0117] Determine the module directory affected by the change file, and extract the code compilation configuration file of the module affected by the change file corresponding to the module directory affected.

[0118] Optionally, the second unit is used to:

[0119] Extracting grammatical units of the declared types in the change file based on the code compilation configuration file to construct multiple nodes;

[0120] The change syntax tree is constructed according to the calling relationship between the multiple nodes.

[0121] Optionally, the analysis module 603 is used to:

[0122] Based on the change syntax tree, the change object is searched upward step by step according to the call relationship until the entry object is found;

[0123] The call chain between the changed object and the entry object is determined as the impact code call chain.

[0124] Optionally, the impact determination module 604 is configured to:

[0125] The code lines corresponding to the affected objects other than the changed object in the affected code call chain are determined as affected code lines, and the code file where the affected code lines are located is determined as the affected file.

[0126] Optionally, the device further includes a coverage rate module, configured to:

[0127] Obtaining a code test result, and extracting a first number of execution-affected code lines and a second number of execution-changed code lines from the code test result;

[0128] determining an impact test coverage based on the first number of the execution-impacted code lines and the third number of the impacted code lines;

[0129] The change test coverage is determined based on the second number of the executed changed code lines and a fourth number of executable changed code lines among the changed code lines.

[0130] Optionally, the device further includes a display module, configured to:

[0131] The code test results, test coverage results, the changed code lines, and the affected code lines are displayed on the impact result page, wherein the test coverage results include the impact test coverage and the change test coverage.

[0132] Optionally, the device further includes a marking module, configured to:

[0133] In response to the invalidation marking operation on the target impact code line in the impact result page, an invalid impact label is added to the target impact code line, wherein the invalid impact label indicates that it does not belong to the impact code line.

[0134] Optionally, the device further includes a link module, configured to:

[0135] In response to a triggering operation on displaying an impact link in the impact result page, a call relationship graph of the impact code call chain is displayed.

[0136] The code analysis device provided in the embodiments of the present disclosure can execute the code analysis method provided in any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.

[0137] An embodiment of the present disclosure further provides a computer program product, including a computer program / instruction, which implements the code analysis method provided by any embodiment of the present disclosure when executed by a processor.

[0138] Figure 7 A schematic structural diagram of an electronic device provided in an embodiment of the present disclosure.

[0139] The following specific reference Figure 7 , which shows a schematic structural diagram of an electronic device 700 suitable for implementing the embodiments of the present disclosure. The electronic device 700 in the embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (PADs), portable media players (PMPs), vehicle-mounted terminals (e.g., vehicle-mounted navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 7 The electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present disclosure.

[0140] like Figure 7 As shown, the electronic device 700 may include a processing device 701 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage device 708 into a random access memory (RAM) 703. Various programs and data required for the operation of the electronic device 700 are also stored in the RAM 703. The processing device 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0141] Typically, the following devices may be connected to the I / O interface 705: an input device 706 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 708 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 709. The communication device 709 may allow the electronic device 700 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 7 The electronic device 700 is shown with various devices, but it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed instead.

[0142] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 709, or installed from the storage device 708, or installed from the ROM 702. When the computer program is executed by the processing device 701, the above-mentioned functions defined in the code analysis method of the embodiment of the present disclosure are performed.

[0143] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory (EPROM), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, radio frequency (RF), etc., or any suitable combination thereof.

[0144] In some embodiments, the client and server can communicate using any currently known or future developed network protocol, such as the HyperText Transfer Protocol (HTTP), and can be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), internets (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed networks.

[0145] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0146] The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device: obtains the changed code lines and changed files of the front-end application; performs syntax parsing on the changed code lines and the changed files to determine the changed objects; performs call analysis based on the changed objects to determine the affected code call chain; and determines the affected code lines and affected files based on the affected code call chain.

[0147] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including, but not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network or a wide area network, or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0148] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0149] The units involved in the embodiments described in this disclosure may be implemented in software or hardware, wherein the name of a unit does not necessarily limit the unit itself.

[0150] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: Field-Programmable Gate Array (FPGA), Application Specific Integrated Circuit (ASIC), Application Specific Standard Parts (ASSP), System on Chip (SOC), Complex Programmable Logic Device (CPLD), and the like.

[0151] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or apparatus. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, a flash memory, an optical fiber, a portable compact disk read-only memory, an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0152] It is understandable that before using the technical solutions disclosed in the embodiments of this disclosure, the type, scope of use, usage scenarios, etc. of the information involved in this disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0153] The above description is merely a preferred embodiment of the present disclosure and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also includes other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the above-mentioned disclosed concepts. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this disclosure.

[0154] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details have been included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.

[0155] Although the subject matter has been described in language specific to structural features and / or methodological logical acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are merely example forms of implementing the claims.

Claims

1. A code analysis method, characterized in that: include: Get the changed code lines and changed files of the front-end application; Performing syntax analysis on the changed code lines and the changed files to determine the changed objects; Perform call analysis based on the changed object to determine the affected code call chain; An affected code line and an affected file are determined based on the affected code call chain.

2. The method according to claim 1, characterized in that The obtaining of the changed code lines and changed files of the front-end application includes: In response to a code modification operation of the front-end application, obtaining text information of the changed code of the front-end application; The change code text information is identified to obtain the change code line of the front-end application and the change file where the change code line is located.

3. The method according to claim 1, characterized in that Performing syntax analysis on the changed code line and the changed file to determine the changed object includes: Obtaining a code compilation configuration file corresponding to the affected module based on the change file; Performing syntax analysis on the change file based on the code compilation configuration file to determine a change syntax tree; A node corresponding to the changed code line in the changed syntax tree is determined as a changed object.

4. The method according to claim 3, characterized in that Obtaining a code compilation configuration file corresponding to the affected module based on the change file includes: Determine the module directory affected by the change file, and extract the code compilation configuration file of the module affected by the change file corresponding to the module directory affected.

5. The method according to claim 3, characterized in that Performing syntax analysis on the change file based on the code compilation configuration file to determine a change syntax tree includes: Extracting grammatical units of the declared types in the change file based on the code compilation configuration file to construct multiple nodes; The change syntax tree is constructed according to the calling relationship between the multiple nodes.

6. The method according to claim 3, characterized in that Performing call analysis based on the changed object to determine the affected code call chain includes: Based on the change syntax tree, the change object is searched upward step by step according to the call relationship until the entry object is found; The call chain between the changed object and the entry object is determined as the impact code call chain.

7. The method according to claim 1, characterized in that Determining the affected code line and affected file based on the affected code call chain includes: The code lines corresponding to the affected objects other than the changed object in the affected code call chain are determined as affected code lines, and the code file where the affected code lines are located is determined as the affected file.

8. The method according to claim 1, characterized in that The method further comprises: Obtaining a code test result, and extracting a first number of execution-affected code lines and a second number of execution-changed code lines from the code test result; determining an impact test coverage based on the first number of the execution-impacted code lines and the third number of the impacted code lines; The change test coverage is determined based on the second number of the executed changed code lines and a fourth number of executable changed code lines among the changed code lines.

9. The method according to claim 8, characterized in that The method further comprises: The code test results, test coverage results, the changed code lines, and the affected code lines are displayed on the impact result page, wherein the test coverage results include the impact test coverage and the change test coverage.

10. The method according to claim 9, characterized in that The method further comprises: In response to the invalidation marking operation on the target impact code line in the impact result page, an invalid impact label is added to the target impact code line, wherein the invalid impact label indicates that it does not belong to the impact code line.

11. The method according to claim 9, characterized in that The method further comprises: In response to a triggering operation on displaying an impact link in the impact result page, a call relationship graph of the impact code call chain is displayed.

12. A code analysis device, characterized in that: include: The acquisition module is used to obtain the changed code lines and changed files of the front-end application; A parsing module, configured to parse the changed code lines and the changed files to determine the changed objects; An analysis module, configured to perform call analysis based on the changed object to determine an affected code call chain; An impact determination module is used to determine the impacted code lines and impacted files based on the impacted code call chain.

13. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing instructions executable by the processor; The processor is configured to read the executable instructions from the memory and execute the executable instructions to implement the code analysis method described in any one of claims 1-11.

14. A computer-readable storage medium, characterized in that The storage medium stores a computer program, and the computer program is used to execute the code analysis method according to any one of claims 1 to 11.