Method for determining influenced function of system based on change code and related device

By comparing code versions, generating abstract syntax trees and extracting routing information, the impact of changing code on system functions is automatically determined, and the problem of manual analysis of changing codes in the existing technology is solved, and an efficient and automated analysis process is achieved.

CN120045440AActive Publication Date: 2025-05-27ABC FINANCIAL TECH CO LTD

Patent Information

Application Number
CN202510241778.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-03
Publication Date
2025-05-27
Estimated Expiration
2045-03-03

AI Technical Summary

Technical Problem

When code version updates, fixes vulnerabilities or adds new functions, it is time-consuming and labor-intensive to analyze the impact of changing code on system functions manually or automatically, and it is very labor-intensive, making it difficult to achieve automated and efficient analysis.

Method used

By comparing the new version code file collection and the old version code file collection, the changing code file and the changing row are determined, and an abstract syntax tree is generated, and the first and second level routing information corresponding to the changing rows is extracted from it. Combined with the correspondence between the routing information of the interface and the system functional points, the target functional points affected by the changing rows in the system to be evaluated are automatically determined.

Benefits of technology

It realizes the automated accurate determination of the system's affected functions based on changing codes, which reduces manual participation, improves analysis efficiency, and reduces labor costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120045440A_ABST
    Figure CN120045440A_ABST
Patent Text Reader

Abstract

The invention discloses a method for determining an affected function of a system based on a variable code and a related device, and relates to the technical field of computers, and the method comprises the following steps: comparing a new version code file set with an old version code file set of a to-be-evaluated system, determining a variable code file and a variable row in the variable code file from the new version code file set, obtaining a file package where the variable code file is located, generating an abstract syntax tree based on the file package, extracting first-level routing information and second-level routing information corresponding to the variable row from the abstract syntax tree, and sending the first-level routing information and the second-level routing information to the new version code file set; and according to the first-level routing information and the second-level routing information, determining a target function point influenced by the change line in the to-be-evaluated system. According to the method, the two-stage routing information is extracted based on the abstract syntax tree, so that the target function point influenced by the variable row is accurately determined, manual participation is not needed in the whole process, more time and labor are saved, and the labor cost is saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular, to a method and related device for determining system-affected functions based on changed code. Background Art

[0002] In scenarios such as code version updates, vulnerability fixes, or new feature additions, existing code needs to be modified. Code changes may affect the original functions and performance of the system. Therefore, it is crucial to master the specific impact of changed code on system functions.

[0003] Currently, the method for determining system-affected functions based on changed code is as follows: Manually or using automated analysis tools (such as SonarQube tools, a combination of Code Review tools and static analysis tools, continuous integration and continuous delivery toolchains, etc.) to analyze the changed code, and then manually analyze the system functions affected by the changed code.

[0004] However, the manual analysis method has the disadvantages of being time-consuming, laborious, and having a high human cost, which urgently needs to be solved. Summary of the Invention

[0005] In view of the above problems, this application provides a method and related device for determining system-affected functions based on changed code to achieve the purpose of automatically and accurately determining system-affected functions based on changed code. The specific solutions are as follows:

[0006] The first aspect of this application provides a method for determining system-affected functions based on changed code, including:

[0007] Comparing the new version code file set and the old version code file set of the system to be evaluated to determine the changed code files and the changed lines in the changed code files from the new version code file set;

[0008] Obtaining the file package where the changed code file is located, and generating an abstract syntax tree based on the file package, where the file package is composed of all or part of the files in the new version code file set;

[0009] Extracting the first-level routing information and the second-level routing information corresponding to the changed lines from the abstract syntax tree, where the first-level routing information and the second-level routing information form the complete routing information of the interface corresponding to the changed lines;

[0010] Determining the target function points affected by the changed lines in the system to be evaluated according to the first-level routing information and the second-level routing information.

[0011] In a possible implementation, comparing the new version code file set and the old version code file set of the system to be evaluated includes:

[0012] Compare the new version code file set and the old version code file set using Git Diff.

[0013] In a possible implementation, generate an abstract syntax tree based on a file package, including:

[0014] Use Java Parser to perform syntax parsing on the code in the file package to generate an abstract syntax tree.

[0015] In a possible implementation, extract the first-level routing information and second-level routing information corresponding to the changed lines from the abstract syntax tree, including:

[0016] Determine the method tree corresponding to the changed code file from the abstract syntax tree as the target method tree;

[0017] Filter a set of candidate methods from the target method tree, and each candidate method in the set of candidate methods contains a request path processing annotation;

[0018] Determine the candidate method closest to the root node in the target method tree from the set of candidate methods as the first target method;

[0019] Extract the first-level routing information from the request path processing annotation contained in the first target method;

[0020] Obtain the method corresponding to the changed line, and determine whether the method corresponding to the changed line contains a request path processing annotation;

[0021] If so, use the method corresponding to the changed line as the second target method, and extract the second-level routing information from the request path processing annotation contained in the second target method;

[0022] If not, starting from the method corresponding to the changed line in the target method tree, recursively search for the first method containing a request path processing annotation level by level as the third target method, and extract the second-level routing information from the request path processing annotation contained in the third target method.

[0023] In a possible implementation, determine the target function points affected by the changed lines in the system to be evaluated according to the first-level routing information and the second-level routing information, including:

[0024] Concatenate the first-level routing information and the second-level routing information together to obtain concatenated routing information;

[0025] Query the function points corresponding to the concatenated routing information from a pre-built database, and determine the queried function points as the target function points, where the pre-built database contains the correspondence between the routing information of the interface and the function points.

[0026] In a possible implementation, before querying the function points corresponding to the spliced routing information from the pre-built database, it further includes:

[0027] Deduplicate the spliced routing information to obtain the deduplicated spliced routing information.

[0028] The second aspect of the present application provides a device for determining the functions affected by the system based on the changed code, including:

[0029] A code comparison module for comparing the new version code file set and the old version code file set of the system to be evaluated, so as to determine the changed code files and the changed lines in the changed code files from the new version code file set;

[0030] A syntax parsing module for obtaining the file package where the changed code file is located and generating an abstract syntax tree based on the file package, where the file package is composed of all or part of the files in the new version code file set;

[0031] A routing extraction module for extracting the first-level routing information and the second-level routing information corresponding to the changed lines from the abstract syntax tree, where the first-level routing information and the second-level routing information form the complete routing information of the interface corresponding to the changed lines;

[0032] A function determination module for determining the target function points affected by the changed lines in the system to be evaluated according to the first-level routing information and the second-level routing information.

[0033] The third aspect of the present application provides a computer program product, including computer-readable instructions, which, when running on an electronic device, enable the electronic device to implement the method for determining the functions affected by the system based on the changed code in the first aspect or any implementation manner of the first aspect.

[0034] The fourth aspect of the present application provides an electronic device, including at least one processor and a memory connected to the processor, where:

[0035] The memory is used to store a computer program;

[0036] The processor is used to execute the computer program so that the electronic device can implement the method for determining the functions affected by the system based on the changed code in the first aspect or any implementation manner of the first aspect.

[0037] The fifth aspect of the present application provides a computer storage medium, and the storage medium carries one or more computer programs, which, when executed by an electronic device, can enable the electronic device to implement the method for determining the functions affected by the system based on the changed code in the first aspect or any implementation manner of the first aspect.

[0038] With the above technical solution, the method for determining the functions affected by the system based on the changed code provided by this application compares the set of new version code files and the set of old version code files of the system to be evaluated, so as to determine the changed code files and the changed lines in the changed code files from the set of new version code files, obtain the file packages where the changed code files are located, generate abstract syntax trees based on the file packages, extract the first-level routing information and the second-level routing information corresponding to the changed lines from the abstract syntax trees, and determine the target function points affected by the changed lines in the system to be evaluated according to the first-level routing information and the second-level routing information. It can be seen that this application can generate the file packages where the changed code files are located into abstract syntax trees, so that the two-level routing information corresponding to the changed lines in the changed code files can be more accurately extracted from the abstract syntax trees. Since there is a corresponding relationship between the routing information of the interface and the system function points, the target function points affected by the changed lines can be accurately determined through the two-level routing information. The whole process does not require manual participation, which is more time-saving and labor-saving, and saves labor costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In combination with the accompanying drawings and with reference to the following specific embodiments, the above and other features, advantages and aspects of the various embodiments of the present disclosure will become more apparent. 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 the original and elements are not necessarily drawn to scale.

[0040] Figure 1 It is a schematic diagram of a system architecture provided by this application;

[0041] Figure 2 It is a schematic diagram of an optional hardware structure of the terminal 100 provided by this application;

[0042] Figure 3 It is a schematic diagram of the structure of a server 200 provided by this application;

[0043] Figure 4 It is a schematic flowchart of a method for determining the functions affected by the system based on the changed code provided by this application;

[0044] Figure 5 It is a schematic diagram of the structure of a device for determining the functions affected by the system based on the changed code provided by this application;

[0045] Figure 6 It is a schematic diagram of the structure of an electronic device provided by this application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0046] The following describes the embodiments of the present application in combination with the drawings in the embodiments of the present application. The terms used in the embodiments part of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0047] The embodiments of the present application will be described below with reference to the accompanying drawings. As can be known to those of ordinary skill in the art, with the development of technology and the emergence of new scenarios, the technical solutions provided by the embodiments of the present application are equally applicable to similar technical problems.

[0048] The terms "first", "second", etc. in the specification, claims and above-mentioned drawings of the present application are used to distinguish similar objects, and do not have to be used to describe a specific order or sequence. It should be understood that such terms can be interchanged under appropriate circumstances, which is only a way of distinguishing when describing objects with the same attributes in the embodiments of the present application. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion, so that a process, method, system, product or device comprising a series of units does not have to be limited to those units, but may include other units not clearly listed or inherent to these processes, methods, products or devices.

[0049] See Figure 1 , Figure 1 which shows a schematic diagram of a system architecture. The system may include a terminal 100 and a server 200. Among them, the server 200 may include one or more servers ( Figure 1 taking including one server as an example for illustration), and the server 200 may provide the method provided by the embodiments of the present application for one or more terminals.

[0050] Among them, an application program may be installed on the terminal 100, and the above application program and web page may provide an interface. The terminal 100 may receive relevant parameters input by the user on the interface and send the above parameters to the server 200. The server 200 may obtain a processing result based on the received parameters and return the processing result to the terminal 100.

[0051] It should be understood that in some alternative implementations, the terminal 100 may also complete the action of obtaining the processing result based on the received parameters by itself, without the need for the cooperation of the server, which is not limited in the embodiments of the present application.

[0052] Next, describe Figure 1 the product form of the terminal 100 in

[0053] The terminal 100 in the embodiments of the present application may be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an Augmented Reality (AR) / Virtual Reality (VR) device, a laptop computer, an Ultra-mobile Personal Computer (UMPC), a netbook, a Personal Digital Assistant (PDA), etc., and the embodiments of the present application do not make any restrictions on this.

[0054] Figure 2 Fig. shows an optional schematic diagram of the hardware structure of the terminal 100.

[0055] Referring to Figure 2 As shown, the terminal 100 may include a radio frequency unit 110, a memory 120, an input unit 130, a display unit 140, a camera 150 (optional), an audio circuit 160 (optional), a speaker 161 (optional), a microphone 162 (optional), a headphone jack 163 (optional), a processor 170, an external interface 180, a power supply 190, and other components. Those skilled in the art can understand that Figure 2 This is only an example of a terminal or a multifunctional device, and does not constitute a limitation on the terminal or the multifunctional device. It may include more or fewer components than shown in the figure, or combine some components, or different components.

[0056] The input unit 130 can be used to receive input digital or character information, and generate key signal inputs related to the user settings and function controls of the portable multifunctional device. Specifically, the input unit 130 may include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can collect touch operations of the user on or near it (such as operations of the user using a finger, a joint, a stylus, or any suitable object on or near the touch screen), and drive the corresponding connection device according to a pre-set program. The touch screen can detect the touch action of the user on the touch screen, convert the touch action into a touch signal and send it to the processor 170, and can receive and execute the commands sent by the processor 170; the touch signal at least includes contact coordinate information. The touch screen 131 can provide an input interface and an output interface between the terminal 100 and the user. In addition, various types such as resistive, capacitive, infrared, and surface acoustic wave can be used to implement the touch screen. In addition to the touch screen 131, the input unit 130 may further include other input devices. Specifically, the other input devices 132 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, and the like.

[0057] Among them, the input device 132 can receive input data and so on.

[0058] The display unit 140 can be used to display information input by the user or information provided to the user, various menus of the terminal 100, an interactive interface, file display, and / or play any kind of multimedia file.

[0059] The memory 120 can be used to store instructions and data. The memory 120 mainly includes a storage instruction area and a storage data area. The storage data area can store various data, such as multimedia files, texts, etc.; the storage instruction area can store software units such as an operating system, applications, instructions required for at least one function, or their subsets or extended sets. It can also include a non-volatile random access memory; it provides the processor 170 with functions including managing hardware, software, and data resources in the computing processing device, supporting control software and applications. It is also used for storing multimedia files and storing and running programs and applications.

[0060] The processor 170 is the control center of the terminal 100. It uses various interfaces and lines to connect all parts of the entire terminal 100. By running or executing instructions stored in the memory 120 and calling data stored in the memory 120, it executes various functions of the terminal 100 and processes data, thereby performing overall control of the terminal device. Optionally, the processor 170 may include one or more processing units; preferably, the processor 170 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor may not be integrated into the processor 170. In some embodiments, the processor and the memory can be implemented on a single chip. In some embodiments, they can also be separately implemented on independent chips. The processor 170 can also be used to generate corresponding operation control signals, send them to corresponding components of the computing processing device, read and process data in the software, especially read and process data and programs in the memory 120, so that each functional module therein executes corresponding functions, thereby controlling the corresponding components to act according to the requirements of the instructions.

[0061] Among them, the memory 120 can be used to store software codes related to the method for determining system-affected functions based on change codes. The processor 170 can execute the steps of the method for determining system-affected functions based on change codes, or can also schedule other units (such as the above-mentioned input unit 130 and display unit 140) to implement corresponding functions.

[0062] The radio frequency unit 110 (optional) can be used for receiving and transmitting information or signals during a call. For example, after receiving the downlink information from the base station, it is sent to the processor 170 for processing; in addition, the uplink data designed is sent to the base station. Generally, the RF circuit includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (LNA), a duplexer, etc. In addition, the radio frequency unit 110 can also communicate with network devices and other devices through wireless communication. This wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile Communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.

[0063] Among them, in the embodiment of this application, the radio frequency unit 110 can send data to the server 200 and receive the processing result sent by the server 200.

[0064] It should be understood that the radio frequency unit 110 is optional and can be replaced by other communication interfaces, such as a network interface.

[0065] The terminal 100 also includes a power supply 190 (such as a battery) for powering each component. Preferably, the power supply can be logically connected to the processor 170 through a power management system, so as to realize functions such as management of charging, discharging, and power consumption management through the power management system.

[0066] The terminal 100 also includes an external interface 180. This external interface can be a standard Micro USB interface or a multi-pin connector, which can be used to connect the terminal 100 to other devices for communication and can also be used to connect a charger to charge the terminal 100.

[0067] Although not shown, the terminal 100 may also include a flash, a Wireless Fidelity (WiFi) module, a Bluetooth module, sensors with different functions, etc., which will not be elaborated here. Some or all of the methods described below can be applied to the terminal 100 as Figure 2 shown.

[0068] The following describes Figure 1 the product form of the server 200 in

[0069] Figure 3 A schematic structural diagram of a server 200 is provided, as shown in Figure 3 The server 200 includes a bus 201, a processor 202, a communication interface 203, and a memory 204. The processor 202, the memory 204, and the communication interface 203 communicate with each other through the bus 201.

[0070] The bus 201 can be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of simplicity of representation, Figure 3 only a thick line is used to represent it in , but it does not mean that there is only one bus or one type of bus.

[0071] The processor 202 can be any one or more of a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a Micro Processor (MP), or a Digital Signal Processor (DSP).

[0072] The memory 204 can include a volatile memory, such as a Random Access Memory (RAM). The memory 204 can also include a non-volatile memory, such as a Read-Only Memory (ROM), a flash memory, a Hard Disk Drive (HDD), or a Solid State Drive (SSD).

[0073] Among them, the memory 204 can be used to store software code related to the method of determining the system-affected functions based on the changed code, and the processor 202 can execute the steps of the method of determining the system-affected functions of the chip based on the changed code, or can also schedule other units to implement the corresponding functions.

[0074] It should be understood that the above terminal 100 and server 200 can be centralized or distributed devices, and the processors in the above terminal 100 and server 200 (such as processor 170 and processor 202) can be hardware circuits (such as Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA), general-purpose processor, DSP, microprocessor or microcontroller, etc.), or a combination of these hardware circuits. For example, the processor can be a hardware system with the function of executing instructions, such as CPU, DSP, etc., or a hardware system without the function of executing instructions, such as ASIC, FPGA, etc., or a combination of the above hardware system without the function of executing instructions and the hardware system with the function of executing instructions.

[0075] This application provides a method for determining affected functions of a system based on changed codes. The method for determining affected functions of a system based on changed codes in the embodiments of this application will be introduced in detail below with reference to the accompanying drawings.

[0076] Refer to Figure 4 , Figure 4 which is a schematic flowchart of a method for determining affected functions of a system based on changed codes provided by an embodiment of this application. The method may include:

[0077] Step S401: Compare the new version code file set and the old version code file set of the system to be evaluated, so as to determine the changed code files and the changed lines in the changed code files from the new version code file set.

[0078] In this application, the system that needs to be evaluated for the impact of code changes is defined as the system to be evaluated. It can be understood that code changes may occur in the system to be evaluated, such as fixing system vulnerabilities, version updates, etc. For the convenience of introducing this application, the set composed of the files where the old code is located before the change is called the old version code file set, and the set composed of the files where the new code is located after the change is called the new version code file set. That is, the old version code file set is composed of at least one old version code file, and each old version code file contains at least one line of old version code. Similarly, the new version code file set is composed of at least one new version code file, and each new version code file contains at least one line of new version code (in this embodiment, both the new version code file and the old version code file are backend files).

[0079] In order to determine which files have code changes, in this embodiment, the set of new-version code files and the set of old-version code files can be compared to obtain, compared with the set of old-version code files, the files with code changes in the set of new-version code files and the changed code in the files. For the convenience of the following description, the files with code changes are denoted as changed code files, and each line of changed code in the file is denoted as a changed line.

[0080] It should be noted that the set of new-version code files may contain multiple changed code files (each changed code file is a new-version code file). Then, in this embodiment, multiple changed code files can be determined through comparison. Optionally, the multiple changed code files can be stored in a changed file list. At the same time, there may be multiple lines of code changes in each changed code file. Then, for each changed code file, this embodiment can determine at least one changed line.

[0081] Optionally, Git Diff can be used to compare the set of new-version code files and the set of old-version code files to obtain code change information, and then the changed code files and changed lines can be determined according to the code change information.

[0082] Optionally, the code change information includes: the path of the changed code file and the line number information of the changed line. Here, the path of the changed code file points to the changed code file, so that the changed code file can be found through this path.

[0083] Of course, the code change information can also be other, for example, the name of the changed code file, etc. The present application does not make specific limitations.

[0084] In a possible implementation, considering that the above comparison process may be incorrect and result in non-existent changed code files, based on this, this embodiment can also traverse the changed file list to check whether each traversed changed code file exists. If it exists, the changed code file is processed according to the following steps. If it does not exist, the next changed code file is traversed until all the changed code files in the changed file list are traversed.

[0085] Optionally, the process of "checking whether each traversed changed code file exists" can include: obtaining the path of the changed code file output by GitDiff, and searching for the changed code file at the position indicated by this path. If it can be found, it is determined that the changed code file exists; otherwise, it is determined that the changed code file does not exist.

[0086] Step S402: Obtain the file package where the changed code file is located, and generate an abstract syntax tree based on the file package.

[0087] Those skilled in the art should understand that the set of new version code files for implementing the system to be evaluated may be packaged into one file package or multiple file packages. Therefore, the file package where the changed code file is located consists of all or part of the files within the set of new version code files.

[0088] In this embodiment, an abstract syntax tree can be generated based on the file package where the changed code file is located. More specifically, an abstract syntax tree is generated based on the code within the file package where the changed code file is located.

[0089] It should be noted that if multiple changed code files are determined in the foregoing, this application can obtain the file packages where the multiple changed code files are located respectively. After deduplicating the file packages, an abstract syntax tree is generated based on each file package.

[0090] Optionally, Java Parser can be used to perform syntax parsing on the code within the file package to generate an Abstract Syntax Tree (AST).

[0091] Step S403: Extract the first-level routing information and the second-level routing information corresponding to the changed line from the abstract syntax tree.

[0092] As introduced above, for each changed code file, embodiments of this application can determine at least one changed line. If multiple changed lines are determined, this application can extract the first-level routing information and the second-level routing information corresponding to each changed line from the corresponding abstract syntax tree respectively.

[0093] Here, the first-level routing information refers to the common part in the routing information of the class defined by the changed line, and the second-level routing information refers to the specific path of the interface implemented by the class defined by the changed line (hereinafter referred to as the interface corresponding to the changed line). The first-level routing information and the second-level routing information constitute the complete routing information of the interface corresponding to the changed line.

[0094] For example, if the first-level routing information is " / api / user" and the second-level routing information is " / create", then the complete routing information of the interface corresponding to the changed line is " / api / user / create".

[0095] Step S404: Determine the target function points in the system to be evaluated affected by the changed line according to the first-level routing information and the second-level routing information.

[0096] Those skilled in the art should understand that there is a corresponding relationship between the interfaces in the system to be evaluated and the function points of the system. Consequently, there is also a corresponding relationship between the routing information of the interfaces and the function points. Based on this, in this embodiment, the corresponding relationship between the routing information of the interfaces and the function points of the system can be pre-constructed, and then the corresponding relationship can be queried according to the first-level routing information and the second-level routing information to obtain the target function points affected by the changed lines in the system to be evaluated.

[0097] Optionally, the above function points may be function modules, function components, services, etc., and the present application does not make specific limitations.

[0098] The method for determining the functions affected by changes in the system provided by the present application compares the new version code file set and the old version code file set of the system to be evaluated to determine the changed code files and the changed lines in the changed code files from the new version code file set, obtain the file package where the changed code file is located, generate an abstract syntax tree based on the file package, extract the first-level routing information and the second-level routing information corresponding to the changed lines from the abstract syntax tree, and determine the target function points affected by the changed lines in the system to be evaluated according to the first-level routing information and the second-level routing information. It can be seen that the present application can generate an abstract syntax tree from the file package where the changed code file is located, so that the two-level routing information corresponding to the changed lines in the changed code file can be more accurately extracted from the abstract syntax tree. Since there is a corresponding relationship between the routing information of the interfaces and the system function points, the target function points affected by the changed lines can be accurately determined through the two-level routing information. The whole process does not require manual participation, which is more time-saving and labor-saving, and saves labor costs.

[0099] In some embodiments of the present application, the process of "extracting the first-level routing information and the second-level routing information corresponding to the changed lines from the abstract syntax tree" in step S403 above is introduced.

[0100] As introduced above, the abstract syntax tree is generated based on the file package, and the file package contains at least one file, and at least one file includes the changed code file. Therefore, the abstract syntax tree includes method trees corresponding to at least one file respectively, that is, the abstract syntax tree includes the method tree corresponding to the changed code file. Based on this, in this embodiment, the method tree corresponding to the changed code file can be determined from the abstract syntax tree. For the convenience of the following introduction, the method tree corresponding to the changed code file is denoted as the target method tree.

[0101] The following introduces an example with any changed line.

[0102] Considering that the change line may be in the interface layer or not, if the change line is in the interface layer, the method corresponding to the change line (in this case, the method corresponding to the change line is the method in the interface corresponding to the change line) contains the request path processing annotation, and the second-level routing information can be directly extracted from the request path processing annotation contained in the method corresponding to the change line. If the change line is not in the interface layer, the method corresponding to the change line does not contain the request path processing annotation, then it is also necessary to find the method in the interface corresponding to the change line from the target method tree, and then extract the second-level routing information from the request path processing annotation contained in the method.

[0103] Based on this, this embodiment can obtain the method corresponding to the change line, and determine whether the method corresponding to the change line contains a request path processing annotation, that is, determine whether the method corresponding to the change line contains a request path processing annotation; if so, that is, the method corresponding to the change line contains a request path processing annotation, it means that the change line is in the interface layer, then, the method corresponding to the change line can be used as the second target method, and the second-level routing information is extracted from the request path processing annotation contained in the second target method; on the contrary, if not, that is, the method corresponding to the change line does not contain a request path processing annotation, that is, the change line is not in the interface layer, then starting from the method corresponding to the change line in the target method tree, recursively search upward step by step for the first method containing the request path processing annotation, and use the found method as the third target method, and extract the second-level routing information from the request path processing annotation contained in the third target method.

[0104] It should be noted that in the method declaration of the target method tree, the changed lines are usually marked with line numbers. Based on this, optionally, this embodiment can extract the line number information of the changed lines from the code change information output by Git Diff in the previous text, and then query the method declaration from the target method tree according to the line number information to obtain the method declaration containing the line number information, and then obtain the method corresponding to the changed line, and then extract the second-level routing information according to the above steps.

[0105] It should also be noted that the process of "starting from the method corresponding to the changed line in the target method tree, recursively searching upward step by step for the first method containing the request path processing annotation" can be understood as: determining the method call chain where the changed line is located according to the target method tree, recursively searching for the upper method in the method call chain until the first method containing the request path processing annotation is found.

[0106] The above method call chain is explained by taking an example. Assuming that method A calls method B, and method B calls method C, the changed code of method C affects both the interface for calling method B and the interface for calling method A. Therefore, CB and CBA are both method call chains of this changed code, and method B and method A are upper-level methods of method C.

[0107] Taking the C method corresponding to the changed line as an example, first find the upper method of the C method, that is, the B method. If the B method includes a request path processing annotation, then the B method is used as the third target method; if the B method does not include a request path processing annotation, then continue to recursively find the upper method of the B method, that is, the A method, and so on.

[0108] Optionally, the above request path processing annotation is the @RequestMapping annotation, which is used to process the request path. For example, in @RequestMapping(value = " / list", method = RequestMethod.GET), / list is the end part of the routing information of the interface corresponding to the changed line, that is, the above second-level routing information.

[0109] Those skilled in the art should understand that in addition to the end part specifying the specific interface path in the routing information of an interface, it also includes the routing information of the class implementing the interface, that is, the first-level routing information. The node of this first-level routing information in the target method tree is closer to the root node.

[0110] Based on this, optionally, this embodiment can screen candidate methods including request path processing annotations from the target method tree. For the convenience of introduction, the screened candidate methods are denoted as the candidate method set.

[0111] In the candidate method set, the candidate method closest to the root node of the target method tree is the method in the interface corresponding to the changed line. For the convenience of introduction, the candidate method determined from the candidate method set and closest to the root node in the target method tree is denoted as the first target method. Then, this embodiment can extract the first-level routing information from the request path processing annotation included in the first target method.

[0112] For example, if the class is marked with @RequestMapping(" / api / user"), then the first-level routing information is " / api / user".

[0113] Since the abstract syntax tree is generated based on the code in the file package where the changed code file (changed line) is located, it can more comprehensively and accurately reflect the changed line and the methods and interfaces affected by the changed line. Therefore, extracting the first-level routing information and the second-level routing information corresponding to the changed line based on the abstract syntax tree can make the extracted routing information more accurate.

[0114] In some other embodiments of the present application, the process of "determining the target function points affected by the changed line in the system to be evaluated according to the first-level routing information and the second-level routing information" in step S404 is introduced.

[0115] In this embodiment, considering that when a code developer writes the code files of the system to be evaluated, at least the mapping relationships between the routing information of each interface and the relevant function points will be stored in the pre-built database. For example, when writing the code corresponding to interface a, the mapping relationship composed of interface a and the system function points associated with interface a will be stored in the database as a group.

[0116] Based on this, in one implementation, for the first-level routing information and the second-level routing information corresponding to each changed line in this embodiment, query from the database according to the first-level routing information or the second-level routing information corresponding to the changed line. If a unique set of mapping relationships can be queried, the function point in the queried mapping relationship is determined as the target function point.

[0117] In another possible implementation, the present application can also splice the first-level routing information and the second-level routing information corresponding to each changed line together to obtain spliced routing information, and then query the function point corresponding to the spliced routing information from the pre-built database, and determine the queried function point as the target function point.

[0118] Considering that multiple changed lines may be determined in step S401, multiple spliced routing information will be obtained. Since the interfaces corresponding to multiple changed lines may be the same, the spliced routing information is the same. Optionally, in order to avoid repeatedly querying the function point corresponding to the same spliced routing information from the database, in this embodiment, the spliced routing information can be de-duplicated before querying the function point corresponding to the spliced routing information from the pre-built database, and then the function point is queried from the database for the de-duplicated spliced routing information, which improves the query efficiency.

[0119] In addition to the above implementation, this embodiment can also adopt other implementation methods. For example, a transaction code field is added to the pre-built database, that is, the mapping relationship between the transaction code, the routing information of the interface, and the function point is established. Then, in this embodiment, the corresponding transaction code can be found first according to the first-level routing information and the second-level routing information, and then the corresponding function point is found based on the transaction code as the target function point.

[0120] In summary, this embodiment can use the existing database for query, and can quickly determine the target function point, which helps developers analyze the influence scope of code changes and improve the R & D quality, and helps testers determine the regression scope of code changes and improve the test accuracy.

[0121] To make those skilled in the art better understand the present application, the foregoing embodiments are introduced in a summary manner through the following examples.

[0122] Step 1: Obtain all changed code files and the line numbers of specific changes in the project (i.e., the system to be evaluated) by executing the Git Diff command.

[0123] Specifically, use the Git Diff command to obtain code change information, parse the code change information to extract the path of each changed code file and the line numbers of the changed lines, and store the list of changed files and the corresponding line numbers of the changed lines (hereinafter referred to as changed line numbers).

[0124] Step 2: For each changed code file, perform a file existence check to determine whether to continue processing the changed code file.

[0125] Specifically, traverse the list of changed files, check whether each changed code file exists. If it does not exist, skip the file and continue to traverse the next changed code file. If it exists, execute Step 3.

[0126] Step 3: For each existing changed code file, obtain the line numbers of the changes it contains and store them as the first list of changed line numbers.

[0127] Step 4: For each existing changed code file, obtain the file package it belongs to and generate an abstract syntax tree.

[0128] Specifically, the file packages where each changed code file is located can be obtained and duplicate file packages can be removed. Then, the code in each deduplicated file package can be parsed using the Java Parser library to generate the corresponding abstract syntax tree AST, and the AST can be stored for subsequent analysis.

[0129] Step 5: For the first list of changed line numbers corresponding to each changed code file, traverse the first list of changed line numbers to check whether each changed line number is in the interface layer, that is, whether the method corresponding to the changed line has the @RequestMapping annotation.

[0130] Specifically, determine the target method tree corresponding to each changed code file from the AST corresponding to each changed code file, traverse the method declarations in the target method tree, and check whether each method in the target method tree contains the @RequestMapping annotation. If the changed line number is in a method containing the @RequestMapping annotation, mark that the changed line number is in the interface layer and store the second list of changed line numbers in the interface layer.

[0131] Step 6: Traverse the second list of changed line numbers, extract the @RequestMapping routing information of the method corresponding to each changed line number therein, which is the above-mentioned second-level routing information. In addition, search for the class-level @RequestMapping routing information corresponding to the changed line number from the corresponding target method tree, which is the above-mentioned first-level routing information, and obtain the spliced routing information corresponding to each changed line number in the second list of changed line numbers by splicing.

[0132] Step 7: For the changed line numbers in each changed code file that are not in the interface layer, search for the method definition corresponding to the changed line number to determine its specific position and role in the code.

[0133] Specifically, search for the method declaration where the changed line number is located in the corresponding target method tree, obtain the definition information of the changed line number, and store it in the method definition information list.

[0134] Step 8: For each method in the method definition information list (i.e., the method corresponding to the changed line number not in the interface layer), recursively search for the upper-level method or interface in the method call chain until the first method or interface with the @RequestMapping annotation is found, extract and store the routing information in the @RequestMapping annotation, which is recorded as the above-mentioned second-level routing information. In addition, search for the class-level @RequestMapping routing information corresponding to the changed line number from the corresponding target method tree, which is the above-mentioned first-level routing information, and obtain the spliced routing information corresponding to the changed line number corresponding to each method in the method definition information list by splicing.

[0135] Step 9: Add all the spliced routing information obtained in Step 6 and Step 8 to the routing list for subsequent processing.

[0136] Step 10: Remove duplicates from the routing information in the routing list to ensure that each spliced routing information is unique.

[0137] Step 11: Traverse the deduplicated routing list, query from the database according to each spliced routing information therein, obtain the target function point corresponding to each spliced routing information, add the queried target function point to the function point list, and return the function point list for developers to use in testing.

[0138] In summary, in this embodiment, by using tools such as Git Diff and Java Parse, the automatic analysis of code changes and function point identification are realized, improving the accuracy and comprehensiveness of the analysis and reducing the workload of manual analysis. In addition, this embodiment provides the context and call chain information of the changed code, enabling developers and testers to clearly understand the system impact of the changes and realizing the real-time analysis of the change impact.

[0139] The above has introduced a method for determining functions affected by a system based on changed codes provided by an embodiment of the present application. The following will introduce an apparatus for executing the above method for determining functions affected by a system based on changed codes.

[0140] Please refer to Figure 5 , Figure 5 which is a schematic structural diagram of an apparatus for determining functions affected by a system based on changed codes provided by an embodiment of the present application. As Figure 5 shown, the apparatus may include:

[0141] A code comparison module 501, configured to compare a set of new version code files and a set of old version code files of a system to be evaluated, so as to determine changed code files and changed lines in the changed code files from the set of new version code files;

[0142] A syntax parsing module 502, configured to obtain a file package where a changed code file is located, and generate an abstract syntax tree based on the file package, where the file package is composed of all or part of the files in the set of new version code files;

[0143] A routing extraction module 503, configured to extract first-level routing information and second-level routing information corresponding to a changed line from the abstract syntax tree, where the first-level routing information and the second-level routing information form complete routing information of an interface corresponding to the changed line;

[0144] A function determination module 504, configured to determine a target function point affected by the changed line in the system to be evaluated according to the first-level routing information and the second-level routing information.

[0145] In a possible implementation, when the above code comparison module compares the set of new version code files and the set of old version code files of the system to be evaluated, it may specifically be configured to: use Git Diff to compare the set of new version code files and the set of old version code files.

[0146] In a possible implementation, when the above syntax parsing module generates an abstract syntax tree based on the file package, it may specifically be configured to: use Java Parser to perform syntax parsing on the codes in the file package to generate an abstract syntax tree.

[0147] In a possible implementation, when the above routing extraction module extracts the first-level routing information and the second-level routing information corresponding to a changed line from the abstract syntax tree, it may specifically be configured to:

[0148] Determine a method tree corresponding to the changed code file from the abstract syntax tree as a target method tree;

[0149] Screen the candidate method set from the target method tree, and each candidate method in the candidate method set contains a request path processing annotation;

[0150] Determine the candidate method closest to the root node in the target method tree from the candidate method set as the first target method;

[0151] Extract the first-level routing information from the request path processing annotation included in the first target method;

[0152] Obtain the method corresponding to the changed line, and determine whether the method corresponding to the changed line contains a request path processing annotation;

[0153] If so, use the method corresponding to the changed line as the second target method, and extract the second-level routing information from the request path processing annotation included in the second target method;

[0154] If not, starting from the method corresponding to the changed line in the target method tree, recursively search for the first method containing a request path processing annotation level by level as the third target method, and extract the second-level routing information from the request path processing annotation included in the third target method.

[0155] In a possible implementation, when the above function determination module determines the target function points affected by the changed line in the system to be evaluated according to the first-level routing information and the second-level routing information, it can specifically be used for:

[0156] Concatenate the first-level routing information and the second-level routing information together to obtain the concatenated routing information;

[0157] Query the function points corresponding to the concatenated routing information from the pre-constructed database, and determine the queried function points as the target function points, where the pre-constructed database contains the corresponding relationship between the routing information of the interface and the function points.

[0158] In a possible implementation, before the above function determination module queries the function points corresponding to the concatenated routing information from the pre-constructed database, it can also be used for: removing duplicates from the concatenated routing information to obtain the deduplicated concatenated routing information.

[0159] The device for determining the functions affected by the system based on the changed code provided in the embodiments of the present application corresponds to the method for determining the functions affected by the system based on the changed code provided above. For details, refer to the above introduction and will not be elaborated here.

[0160] In the embodiments of the present application, an electronic device is also provided. Refer to Figure 6As shown, it shows a schematic structural diagram of an electronic device suitable for implementing the electronic device in the embodiments of the present application. The electronic device in the embodiments of the present application may include, but is not limited to, fixed terminals such as mobile phones, laptop computers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), desktop computers, and the like. Figure 6 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 application.

[0161] As Figure 6 shown, the electronic device may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 601, which may perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage device 608 into the random access memory (RAM) 603. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 603. The processing device 601, the ROM 602, and the RAM 603 are connected to each other through a bus 604. The input / output (I / O) interface 605 is also connected to the bus 604.

[0162] Generally, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a memory card, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 6 it shows an electronic device having various devices, it should be understood that it is not required to implement or have all the shown devices. Instead, more or fewer devices may be implemented or had.

[0163] The embodiments of the present application also provide a computer program product including computer-readable instructions. When the computer-readable instructions run on an electronic device, the electronic device is enabled to implement any one of the methods for determining the functions affected by the system based on the changed code provided in the embodiments of the present application.

[0164] The embodiments of the present application also provide a computer-readable storage medium. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can be enabled to implement any one of the methods for determining the functions affected by the system based on the changed code provided in the embodiments of the present application.

[0165] In addition, it should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. In addition, in the accompanying drawings of the device embodiments provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be specifically implemented as one or more communication buses or signal lines.

[0166] Through the description of the above embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general hardware. Of course, it can also be implemented by dedicated hardware including application-specific integrated circuits, dedicated CPUs, dedicated memories, dedicated components, etc. Generally, functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structures for implementing the same function can also be various, such as analog circuits, digital circuits or dedicated circuits. However, for this application, in more cases, software program implementation is a better implementation method. Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disc of a computer, and includes several instructions to enable a computer device (which can be a personal computer, training device, or network device, etc.) to execute the methods described in various embodiments of this application.

[0167] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product.

[0168] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are wholly or partly generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that can be stored by a computer or a data storage device such as a training device or a data center that includes one or more integrated available media. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.

Claims

1. A method for determining the affected functions of a system based on a changed code, characterized in that: include: Comparing a new version code file set and an old version code file set of the system to be evaluated, so as to determine a changed code file and a changed line in the changed code file from the new version code file set; Obtaining a file package where the changed code file is located, and generating an abstract syntax tree based on the file package, wherein the file package is composed of all or part of the files in the new version code file set; Extracting first-level routing information and second-level routing information corresponding to the changed row from the abstract syntax tree, wherein the first-level routing information and the second-level routing information constitute complete routing information of the interface corresponding to the changed row; A target function point affected by the change in the system to be evaluated is determined according to the first-level routing information and the second-level routing information.

2. The method for determining the affected functions of a system based on the changed code according to claim 1, characterized in that: The comparing the new version code file set and the old version code file set of the system to be evaluated includes: The new version code file set and the old version code file set are compared using Git Diff.

3. The method for determining the affected functions of a system based on the changed code according to claim 1, characterized in that: The generating an abstract syntax tree based on the file package includes: The code in the file package is parsed using Java Parser to generate the abstract syntax tree.

4. The method for determining the affected functions of a system based on a changed code according to claim 1, characterized in that: The extracting the first-level routing information and the second-level routing information corresponding to the changed line from the abstract syntax tree includes: Determine a method tree corresponding to the changed code file from the abstract syntax tree as a target method tree; Filtering a candidate method set from the target method tree, each candidate method in the candidate method set including a request path processing annotation; Determine, from the candidate method set, a candidate method that is closest to a root node in the target method tree as a first target method; Extracting the first level routing information from the request path processing annotation contained in the first target method; Obtain the method corresponding to the changed line, and determine whether the method corresponding to the changed line contains the request path processing annotation; If yes, taking the method corresponding to the changed line as the second target method, and extracting the second-level routing information from the request path processing annotation contained in the second target method; If not, starting from the method corresponding to the changed row in the target method tree, recursively search level by level for the first method containing the request path processing annotation as the third target method, and extract the second-level routing information from the request path processing annotation contained in the third target method.

5. The method for determining the affected functions of a system based on a changed code according to any one of claims 1 to 4, characterized in that: The step of determining the target function point in the system to be evaluated that is affected by the change according to the first-level routing information and the second-level routing information includes: splicing the first-level routing information and the second-level routing information together to obtain spliced ​​routing information; The function point corresponding to the spliced ​​routing information is queried from a pre-built database, and the queried function point is determined as the target function point, wherein the pre-built database contains the correspondence between the routing information of the interface and the function point.

6. The method for determining the affected functions of a system based on the changed code according to claim 5, characterized in that: Before querying the function point corresponding to the splicing routing information from the pre-built database, the method further includes: Deduplication is performed on the spliced ​​routing information to obtain deduplicated spliced ​​routing information.

7. A device for determining the affected functions of a system based on a changed code, characterized in that: include: A code comparison module, used for comparing a new version code file set and an old version code file set of the system to be evaluated, so as to determine a changed code file and a changed line in the changed code file from the new version code file set; A syntax parsing module, used to obtain a file package where the changed code file is located, and generate an abstract syntax tree based on the file package, wherein the file package is composed of all or part of the files in the new version code file set; A routing extraction module, used to extract first-level routing information and second-level routing information corresponding to the changed line from the abstract syntax tree, wherein the first-level routing information and the second-level routing information constitute complete routing information of the interface corresponding to the changed line; The function determination module is used to determine the target function point affected by the change in the system to be evaluated according to the first-level routing information and the second-level routing information.

8. A computer program product, characterized in that The method comprises computer-readable instructions, which, when executed on an electronic device, enable the electronic device to implement the method for determining affected functions of a system based on a changed code as claimed in any one of claims 1 to 6.

9. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is configured to execute the computer program so that the electronic device can implement the method for determining affected functions of a system based on a changed code as described in any one of claims 1 to 6.

10. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the method for determining affected functions of a system based on changed codes as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Code change analysis method

    CN112379888A

  • Code analysis method, code analysis device, electronic equipment and storage medium

    CN115292180A

  • Swager annotation generation method and device, equipment and storage medium

    CN115878175A

  • Code version change influence determination method and device and storage medium

    CN117762470A

  • Functional language source code vulnerability scanner

    US10628584B1

Cited By

  • Vulnerability processing method, electronic equipment, program product and storage medium

    CN120277681A