Method for determining system-affected functions based on change codes and related apparatus
By comparing the sets of code files from the old and new versions and performing abstract syntax tree analysis, the system automatically identifies the functional points affected by the changed code, solving the time-consuming and labor-intensive problem in existing technologies and achieving efficient and accurate system function impact analysis.
Patent Information
- Application Number
- CN202510241778.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-03
- Publication Date
- 2025-12-23
- Estimated Expiration
- 2045-03-03
AI Technical Summary
Existing technologies for analyzing change codes are time-consuming, labor-intensive, and costly, making it difficult to efficiently identify the affected functional points of a system.
By comparing the collection of old and new code files, an abstract syntax tree is generated, the first and second level routing information of the changed lines is extracted, and the target function points are determined using a pre-built database, thus achieving automated analysis.
Accurately identify the target functional points in the system affected by changes, reduce manual intervention, save time and labor costs, and improve analysis efficiency.
Smart Images

Figure CN120045440B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a method for determining affected functions of a system based on changed code and related apparatus. BACKGROUND
[0002] In the scenarios of code version update, bug fixing or new function adding, the existing code needs to be modified, and the code change may affect the original functions and performance of the system. Therefore, it is crucial to master the specific influence of the changed code on the system functions.
[0003] At present, the method for determining the affected functions of a system based on changed code is as follows: manually or by using automatic analysis tools (such as SonarQube tools, Code Review tools combined with static analysis tools, continuous integration and continuous delivery tool chains, etc.) to analyze the changed code, and then manually analyzing the system functions affected by the changed code.
[0004] However, the manual analysis method has the disadvantages of time-consuming and labor-intensive, and high labor cost, which need to be solved urgently. SUMMARY
[0005] In view of the above problems, the present application provides a method for determining the affected functions of a system based on changed code and related apparatus to realize the purpose of automatically and accurately determining the affected functions of a system based on changed code. The specific scheme is as follows:
[0006] The first aspect of the present application provides a method for determining the affected functions of a system based on changed code, comprising:
[0007] Comparing a new version code file set and an old version code file set of a system to be evaluated to determine changed code files and changed lines in the changed code files from the new version code file set;
[0008] Obtaining a file package in which the changed code files are 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;
[0009] Extracting first-level routing information and second-level routing information corresponding to the changed lines from the abstract syntax tree, wherein the first-level routing information and the second-level routing information constitute complete routing information of an interface corresponding to the changed lines;
[0010] Determining target function points in the system to be evaluated affected by the changed lines according to the first-level routing information and the second-level routing information.
[0011] In one possible implementation, comparing the new version code file set and the old version code file set of the system to be evaluated comprises:
[0012] The new version code file set and the old version code file set are compared using Git Diff.
[0013] In a possible implementation, the abstract syntax tree is generated based on the file package, including:
[0014] The code in the file package is parsed using the Java Parser to generate the abstract syntax tree.
[0015] In a possible implementation, the first-level routing information and the second-level routing information corresponding to the changed line are extracted from the abstract syntax tree, including:
[0016] The method tree corresponding to the changed code file is determined from the abstract syntax tree as a target method tree;
[0017] A candidate method set is screened from the target method tree, and each candidate method in the candidate method set contains a request path processing annotation;
[0018] A candidate method closest to the root node in the target method tree is determined from the candidate method set as a first target method;
[0019] The first-level routing information is extracted from the request path processing annotation contained in the first target method;
[0020] The method corresponding to the changed line is obtained, and it is determined whether the method corresponding to the changed line contains a request path processing annotation;
[0021] If yes, the method corresponding to the changed line is taken as a second target method, and the second-level routing information is extracted from the request path processing annotation contained in the second target method;
[0022] If no, a first method containing a request path processing annotation is recursively found from the target method tree starting from the method corresponding to the changed line as a third target method, and the second-level routing information is extracted from the request path processing annotation contained in the third target method.
[0023] In a possible implementation, the target function point affected by the changed line in the system to be evaluated is determined according to the first-level routing information and the second-level routing information, including:
[0024] The first-level routing information and the second-level routing information are spliced together to obtain spliced routing information;
[0025] The function point corresponding to the spliced routing information is queried from a pre-constructed database, and the queried function point is determined as the target function point, wherein the pre-constructed database contains the correspondence between the routing information of the interface and the function point.
[0026] In a possible implementation, before querying the function point corresponding to the spliced routing information from the pre-built database, the method further includes the following steps:
[0027] The spliced routing information is de-duplicated to obtain de-duplicated spliced routing information.
[0028] The second aspect of the application provides a device for determining an affected function of a system based on changed code, comprising:
[0029] a code comparison module configured to compare a new version code file set and an old version code file set of a system to be evaluated to determine a changed code file and a changed line in the changed code file from the new version code file set;
[0030] a syntax analysis module configured to obtain a file package in which 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 files in the new version code file set;
[0031] a routing extraction module configured 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 an interface corresponding to the changed line;
[0032] a function determination module 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.
[0033] The third aspect of the application provides a computer program product, comprising computer readable instructions, when the computer readable instructions run on an electronic device, the electronic device implements the method for determining an affected function of a system based on changed code of the first aspect or any implementation manner of the first aspect.
[0034] The fourth aspect of the application provides an electronic device, comprising at least one processor and a memory connected with the processor, wherein:
[0035] the memory is configured to store a computer program;
[0036] the processor is configured to execute the computer program, so that the electronic device can implement the method for determining an affected function of a system based on changed code of the first aspect or any implementation manner of the first aspect.
[0037] The fifth aspect of the application provides a computer 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 implement the method for determining an affected function of a system based on changed code of the first aspect or any implementation manner of the first aspect.
[0038] By the technical scheme, the method for determining the affected function of a system based on changed code provided in the application compares a new version code file set and an old version code file set of a system to be evaluated to determine a changed code file and a changed line in the changed code file from the new version code file set, obtains a file package in which the changed code file is located, generates an abstract syntax tree based on the file package, extracts first-level routing information and second-level routing information corresponding to the changed line from the abstract syntax tree, and determines 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. As can be seen, the application can generate the file package in which the changed code file is located into an abstract syntax tree, so that the two-level routing information corresponding to the changed line in the changed code file can be more accurately extracted from the abstract syntax tree. The routing information of an interface is in a corresponding relationship with a function point of a system, so the target function point affected by the changed line can be accurately determined through the two-level routing information, the whole process does not need manual participation, is more time-saving and labor-saving, and saves human cost. BRIEF DESCRIPTION OF DRAWINGS
[0039] The above and other features, advantages, and aspects of the present disclosure will become more apparent by describing in detail the following specific embodiments thereof with reference to the attached drawings. Throughout the drawings, the same or similar reference numerals refer to the same or similar elements. It should be understood that the drawings are schematic and elements and features are not necessarily to scale.
[0040] Figure 1 A system architecture schematic diagram provided in the application;
[0041] Figure 2 An optional hardware structure schematic diagram of a terminal 100 provided in the application;
[0042] Figure 3 A structure schematic diagram of a server 200 provided in the application;
[0043] Figure 4 A flow schematic diagram of a method for determining the affected function of a system based on changed code provided in the application;
[0044] Figure 5 A structure schematic diagram of an apparatus for determining the affected function of a system based on changed code provided in the application;
[0045] Figure 6 A structure schematic diagram of an electronic device provided in the application. DETAILED DESCRIPTION
[0046] The embodiments of the present application are described below with reference to the accompanying drawings. The terms used in the embodiment 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. The embodiments of the present application are described below with reference to the accompanying drawings. The terms used in the embodiment 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 this application will now be described with reference to the accompanying drawings. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are equally applicable to similar technical problems.
[0048] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements, but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.
[0049] See Figure 1 , Figure 1 A schematic diagram of a system architecture is shown. The system may include a terminal 100 and a server 200. The server 200 may include one or more servers (…). Figure 1 (The example includes a server), and the server 200 can provide the methods provided in the embodiments of this application to one or more terminals.
[0050] The terminal 100 may have an application installed on it. The application and webpage can provide an interface. The terminal 100 can receive relevant parameters input by the user on the interface and send the parameters to the server 200. The server 200 can obtain the processing result based on the received parameters and return the processing result to the terminal 100.
[0051] It should be understood that in some optional implementations, the terminal 100 can also complete the action of obtaining the processing result based on the received parameters on its own, without the need for the server to cooperate. This application embodiment is not limited to this.
[0052] The following description Figure 1 The product form of the mid-terminal 100;
[0053] The terminal 100 in the embodiments of the present application can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), and the like, and the embodiments of the present application do not make any limitation in this regard.
[0054] Figure 2 An optional hardware structure schematic diagram of the terminal 100 is shown.
[0055] Reference Figure 2 As shown, the terminal 100 can 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 the like. Those skilled in the art can understand that the terminal 100 can include more or less components, or combine certain components, or different components, without departing from the scope of the present application. Figure 2 The above-mentioned terminal or multi-functional device is only an example and does not constitute a limitation on the terminal or multi-functional device, which can include more or less components, or combine certain components, or different components.
[0056] The input unit 130 can be used to receive inputted digital or character information, and to generate key signal input related to user settings and function control of the portable multi-functional device. Specifically, the input unit 130 can include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can collect touch operations of a user thereon or adjacent thereto (such as operations of the user using a finger, a joint, a stylus, or any suitable object on or adjacent to the touch screen), and drive corresponding connected devices according to a pre-set program. The touch screen can detect touch actions of the user on the touch screen, convert the touch actions into touch signals and send the touch signals to the processor 170, and can receive commands from the processor 170 and execute the commands; the touch signals at least include touch point coordinate information. The touch screen 131 can provide an input interface and an output interface between the terminal 100 and the user. In addition, the touch screen can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch screen 131, the input unit 130 can also include other input devices. Specifically, the other input devices 132 can include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control keys, on-off keys, etc.), a trackball, a mouse, a joystick, and the like.
[0057] The input device 132 can receive data and the like inputted by a user.
[0058] The display unit 140 can be configured to display information inputted by a user or provided to the user, various menus of the terminal 100, an interactive interface, a file display, and / or a play of any kind of multimedia file.
[0059] The storage 120 can be configured to store instructions and data. The storage 120 can mainly include a storage instruction area and a storage data area. The storage data area can store various data such as multimedia files, texts, and the like. The storage instruction area can store software units such as an operating system, applications, instructions required for at least one function, and the like, or a subset, an extension set thereof. The storage 120 can further include a non-volatile random access memory. The storage 120 can provide the processor 170 with software and applications including managing hardware, software, and data resources in a computing processing device, supporting control software, and the like. The storage 120 can also be used for storage of multimedia files, and storage of running programs and applications.
[0060] The processor 170 is a control center of the terminal 100. The processor 170 can be connected to each part of the terminal 100 through various interfaces and lines, and can perform various functions of the terminal 100 and process data by running or executing instructions stored in the storage 120 and calling data stored in the storage 120, thereby controlling the entire terminal device. The processor 170 can include one or more processing units. The processor 170 can include an application processor and a modem processor. The application processor can mainly process an operating system, a user interface, and an application program. The modem processor can mainly process wireless communication. It can be understood that the modem processor can not be integrated into the processor 170. In some embodiments, the processor, the storage, and the like can be implemented on a single chip, and in some embodiments, they can be implemented on separate chips. The processor 170 can also be configured to generate corresponding operation control signals and send the operation control signals to corresponding components of the computing processing device, read and process data in the software, and in particular, read and process data and programs in the storage 120, so that each functional module in the storage 120 performs corresponding functions, and the corresponding components act according to the requirements of the instructions.
[0061] The storage 120 can be configured to store software codes related to the method of determining a system-affected function based on a change code. The processor 170 can execute steps of the method of determining a system-affected function based on a change code, and can also schedule other units (for example, the input unit 130 and the display unit 140) to implement corresponding functions.
[0062] The RF unit 110 (optional) can be used to receive and send signals in the process of information or communication, for example, after receiving the downlink information of the base station, the processor 170 processes it; in addition, the uplink data 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 RF unit 110 can also communicate with network devices and other devices through wireless communication. The wireless communication can use any communication standard or protocol, including but not limited to Global System for 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] In the embodiments of the present application, the RF 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 RF unit 110 is optional, which can be replaced by other communication interfaces, for example, it can be a network interface.
[0065] The terminal 100 also includes a power supply 190 (such as a battery) for supplying power to each component. Preferably, the power supply can be logically connected to the processor 170 through a power management system, so as to realize the functions of managing charging, discharging, and power consumption management through the power management system.
[0066] The terminal 100 also includes an external interface 180, which can be a standard Micro USB interface, or a multi-pin connector, and can be used to connect the terminal 100 and other devices for communication, or can be used to connect a charger to charge the terminal 100.
[0067] Although not shown, the terminal 100 can also include a flash, a wireless fidelity (WiFi) module, a Bluetooth module, different function sensors, etc., which will not be described here. Some or all of the methods described below can be applied in the terminal 100 as shown. Figure 2
[0068] Next, the product form of the server 200 is described. Figure 1 The product form of the server 200 is described.
[0069] Figure 3 A structural diagram of the server 200 is provided, as shown in the figure. 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 through the bus 201.
[0070] The bus 201 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 In the figure, only one thick line is used, 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), etc.
[0072] The memory 204 can include a volatile memory (Volatile Memory), such as a Random Access Memory (RAM). The memory 204 can also include a non-volatile memory (Non-Volatile Memory), such as a Read-Only Memory (ROM), a flash memory, a mechanical hard disk (Hard Disk Drive, HDD), or a solid state disk (Solid State Drive, SSD).
[0073] The memory 204 can be used to store software code related to the method of determining system-affected functions based on variable code, and the processor 202 can execute the steps of the method of determining system-affected functions based on variable code of the chip, or can schedule other units to implement the corresponding functions.
[0074] It should be understood that the aforementioned terminal 100 and server 200 can be centralized or distributed devices. The processors (e.g., processor 170 and processor 202) in the aforementioned terminal 100 and server 200 can be hardware circuits (such as application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), general-purpose processors, DSPs, microprocessors, or microcontrollers, etc.) or combinations of these hardware circuits. For example, the processor can be a hardware system with instruction execution capabilities, such as a CPU or DSP, or a hardware system without instruction execution capabilities, such as an ASIC or FPGA, or a combination of the aforementioned hardware systems without instruction execution capabilities and hardware systems with instruction execution capabilities.
[0075] This application provides a method for determining the affected functions of a system based on modified codes. The method for determining the affected functions of a system based on modified codes according to embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0076] Reference Figure 4 , Figure 4 A flowchart illustrating a method for determining affected system functions based on modified codes, provided in this application embodiment, includes:
[0077] Step S401: Compare the new version code file set and the old version code file set of the system to be evaluated to identify the changed code files and the changed lines in the changed code files from the new version code file set.
[0078] This application defines the system whose impact from code changes needs to be evaluated as the system to be evaluated. It is understood that the system to be evaluated may undergo code changes, such as fixing system vulnerabilities or version updates. For ease of explanation, the set of files containing the old code before the change is referred to as the old version code file set, and the set of files containing the new code after the change is referred to as the new version code file set. That is, the old version code file set consists 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 consists 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, the embodiment can compare the new version code file set and the old version code file set to obtain the files in the new version code file set that have code changes compared with the old version code file set and the changed code in the files, for ease of the following description, the files that have code changes are recorded as changed code files, and each line of code that is changed in the files is recorded as a changed line.
[0080] It should be noted that the new version code file set can include multiple changed code files (each changed code file is a new version code file), and then the embodiment can determine the multiple changed code files by comparison. Optionally, the multiple changed code files can be stored in a changed file list. Meanwhile, there can be multiple lines of code changes in each changed code file, and then the embodiment can determine at least one changed line for each changed code file.
[0081] Optionally, the new version code file set and the old version code file set can be compared by using Git Diff to obtain code change information, and then the changed code files and the changed lines are determined according to the code change information.
[0082] Optionally, the code change information includes a path of the changed code file and 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 the path.
[0083] Of course, the code change information can also be other, for example, the name of the changed code file, and the present application does not make specific limitation.
[0084] In a possible implementation, considering that the above comparison process can be wrong and obtain a changed code file that does not originally exist, based on this, the embodiment can further 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, and the changed code files in the changed file list are all 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 Git Diff, finding the changed code file at the position indicated by the 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 in which 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 new version code file set for implementing the system to be evaluated may be packaged into one file package or multiple file packages, and therefore, the file package where the changed code file is located is composed of all or part of the files in the new version code file set.
[0088] In this embodiment, the abstract syntax tree can be generated based on the file package where the changed code file is located, and more specifically, based on the code in 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, the application can obtain the file packages where the multiple changed code files are respectively located, and generate an abstract syntax tree based on each file package after deduplication of the file packages.
[0090] Optionally, the code in the file package can be parsed by using Java Parser to generate an abstract syntax tree (AST).
[0091] Step S403: Extracting the first-level routing information and the second-level routing information corresponding to the changed line from the abstract syntax tree.
[0092] As introduced in the foregoing, for each changed code file, the embodiments of the application can determine at least one changed line. If multiple changed lines are determined, the 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.
[0093] Here, the first-level routing information refers to the general part of 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 (hereinafter referred to as the interface corresponding to the changed line) implemented by the class defined by the changed line, and 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, the first-level routing information is “ / api / user”, and the second-level routing information is “ / create”, and then the complete routing information of the interface corresponding to the changed line is “ / api / user / create”.
[0095] Step S404: Determining the target function point in the system to be evaluated that is affected by the changed line according to the first-level routing information and the second-level routing information.
[0096] The skilled in the art should understand that the interface in the system to be evaluated corresponds to the function point of the system, and the routing information of the interface also corresponds to the function point. Based on this, the embodiment can pre-construct the correspondence between the routing information of the interface and the function point of the system, and then query the correspondence according to the first-level routing information and the second-level routing information to obtain the target function point affected by the changed line in the system to be evaluated.
[0097] Optionally, the function point can be a function module, a function component, or a service, etc., which is not limited in the present application.
[0098] The method for determining the affected function of the system based on the changed code provided in 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 file and the changed line in the changed code file from the new version code file set, obtains the file package where the changed code file is located, generates an abstract syntax tree based on the file package, extracts the first-level routing information and the second-level routing information corresponding to the changed line from the abstract syntax tree, and determines the 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. As can be seen, the present application can generate the file package where the changed code file is located into an abstract syntax tree, so that the two-level routing information corresponding to the changed line in the changed code file can be more accurately extracted from the abstract syntax tree. The routing information of the interface corresponds to the function point of the system, so the target function point affected by the changed line can be accurately determined through the two-level routing information, the whole process does not need human intervention, is more time-saving and labor-saving, and saves the labor cost.
[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 line from the abstract syntax tree" in the foregoing step S403 is introduced.
[0100] As introduced before, the abstract syntax tree is generated based on the file package, and the file package contains at least one file, and the at least one file includes the changed code file, so the abstract syntax tree includes the method tree corresponding to the at least one file, that is, the abstract syntax tree includes the method tree corresponding to the changed code file. Based on this, the embodiment can determine the method tree corresponding to the changed code file from the abstract syntax tree, and for the convenience of the following introduction, the method tree corresponding to the changed code file is recorded as the target method tree.
[0101] The following is introduced by taking any changed behavior as an example.
[0102] In consideration of the fact that the changed line may or may not be in the interface layer, if the changed line is in the interface layer, the method corresponding to the changed line (at this time, the method corresponding to the changed line is the method in the interface corresponding to the changed 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 changed line. If the changed line is not in the interface layer, the method corresponding to the changed line does not contain the request path processing annotation, and then the method in the interface corresponding to the changed line needs to be found from the target method tree, and the second-level routing information needs to be extracted from the request path processing annotation contained in the method.
[0103] Based on this, the embodiment can obtain the method corresponding to the changed line, judge whether the method corresponding to the changed line contains the request path processing annotation, that is, judge whether the method corresponding to the changed line contains the request path processing annotation; if yes, that is, the method corresponding to the changed line contains the request path processing annotation, it indicates that the changed line is in the interface layer, and then the method corresponding to the changed line can be taken as the second target method, and the second-level routing information can be extracted from the request path processing annotation contained in the second target method; on the contrary, if no, that is, the method corresponding to the changed line does not contain the request path processing annotation, that is, the changed line is not in the interface layer, then the method containing the request path processing annotation can be found from the target method tree starting from the method corresponding to the changed line, the found method is taken as the third target method, and the second-level routing information is extracted 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 line is usually marked by a line number, based on this, optionally, the embodiment can extract the line number information of the changed line from the code change information output by the Git Diff in the foregoing, 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 foregoing steps.
[0105] It should be further noted that the process of "finding the first method containing the request path processing annotation from the target method tree starting from the method corresponding to the changed line and recursively searching upwards" can be understood as: determining the method call chain in which the changed line is located according to the target method tree, recursively searching the upper layer method in the method call chain until the first method containing the request path processing annotation is found.
[0106] The method call chain is explained in the form of an example. Assuming that the A method calls the B method, and the B method calls the C method, the changed code of the C method affects the interface of calling the B method and the interface of calling the A method, therefore, C-B and C-B-A are both the method call chain of the changed code this time, and the B method and the A method belong to the upper layer method of the C method.
[0107] Taking the method corresponding to the C method as an example, the upper method of the C method, i.e., the B method, is found first. If the B method includes the request path processing annotation, the B method is taken as the third target method. If the B method does not include the request path processing annotation, the upper method of the B method, i.e., the A method, is recursively found, and the process is continued in this way.
[0108] Optionally, the request path processing annotation is a @RequestMapping annotation, which is used to process a request path. For example, in the @RequestMapping (value = " / list", method = RequestMethod.GET), / list is the end part of the routing information of the interface corresponding to the changed line, i.e., the second-level routing information.
[0109] Those skilled in the art should understand that, in addition to the end part of the specified interface path, the routing information of a class implementing the interface, i.e., the first-level routing information, is also included in the routing information of an interface. The first-level routing information is closer to the root node in the target method tree.
[0110] Based on this, optionally, the embodiment can filter candidate methods including the request path processing annotation from the target method tree. For ease of introduction, the filtered candidate methods are denoted as a 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 ease of introduction, the candidate method closest to the root node of the target method tree determined from the candidate method set is denoted as the first target method. Then, the first-level routing information can be extracted from the request path processing annotation included in the first target method.
[0112] For example, the class is marked with @RequestMapping (" / api / user"), and the first-level routing information is " / api / user".
[0113] Since the abstract syntax tree is generated based on the code in the file package in which the changed code file (changed line) is located, the abstract syntax tree can more comprehensively and accurately reflect the changed line and the methods and interfaces affected by the changed line. Therefore, based on the abstract syntax tree, the first-level routing information and the second-level routing information corresponding to the changed line can be extracted, so that the extracted routing information is more accurate.
[0114] In some embodiments of the present application, the process of "determining the 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" in step S404 is introduced.
[0115] In the embodiment, considering that the code developer will at least store the mapping relationship between the routing information of each interface and the related function point in the pre-built database when writing the code file of the system to be evaluated, for example, when writing the code corresponding to interface a, a set of mapping relationship between interface a and the system function point associated with interface a is stored in the database.
[0116] Based on this, in an implementation manner, the embodiment can query the first-level routing information or the second-level routing information corresponding to each change row from the database, and if only one set of mapping relationship can be queried, the function point in the queried mapping relationship is determined as the target function point.
[0117] In another possible implementation, the application can also splice the first-level routing information and the second-level routing information corresponding to each change row 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 change rows can be determined in step S401, multiple spliced routing information is obtained. Since the interfaces corresponding to multiple change rows can be the same, the spliced routing information is the same. Optionally, in order to avoid repeated querying of the function point corresponding to the same spliced routing information from the database, the embodiment can first de-duplicate the spliced routing information before querying the function point corresponding to the spliced routing information from the pre-built database, and then query the function point from the database based on the de-duplicated spliced routing information, thereby improving the query efficiency.
[0119] In addition to the above implementation manner, the embodiment can also use other implementation manners, for example, a transaction code field is added in the pre-built database, that is, a mapping relationship between the transaction code, the routing information of the interface and the function point is established, and then the embodiment can find the corresponding transaction code based on the first-level routing information and the second-level routing information, and then find the corresponding function point based on the transaction code as the target function point.
[0120] In summary, the embodiment can use the existing database for querying, can quickly determine the target function point, is helpful for the developer to analyze the code change influence range and improve the research and development quality, and is helpful for the tester to determine the code change regression range and improve the test precision.
[0121] In order to enable those skilled in the art to better understand the application, the foregoing embodiment is introduced in a summary manner through the following examples.
[0122] First step: Get all the changed code files and the specific changed line numbers 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 number of the changed line, store the list of changed files and the corresponding changed line numbers (hereinafter referred to as changed line numbers).
[0124] Second step: 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 and 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, perform the third step.
[0126] Third step: For each existing changed code file, obtain the changed line numbers it contains and store them as a first list of changed line numbers.
[0127] Fourth step: For each existing changed code file, obtain the file package it is in and generate an abstract syntax tree.
[0128] Specifically, the file packages in which each changed code file is located can be obtained and de-duplicated. Then, the code in each de-duplicated 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] Fifth step: For each first list of changed line numbers corresponding to each changed code file, traverse the first list of changed line numbers and check whether each changed line number is in the interface layer, i.e. whether the method corresponding to the changed line has a @RequestMapping annotation.
[0130] Specifically, determine the target method tree corresponding to each changed code file from the AST of each changed code file, traverse the method declarations in the target method tree, and check whether each method in the target method tree contains a @RequestMapping annotation. If the changed line number is in a method containing a @RequestMapping annotation, mark the changed line number as being in the interface layer and store the second list of changed line numbers in the interface layer.
[0131] Step 6: Traverse the second change line number list and extract the @RequestMapping route information of the method corresponding to each change line number, which is the second-level route information mentioned above. In addition, find the @RequestMapping route information of the class level corresponding to the change line number from the corresponding target method tree, which is the first-level route information mentioned above. Through splicing, obtain the spliced route information corresponding to each change line number in the second change line number list.
[0132] Step 7: For each change line number in the changed code file that is not in the interface layer, find the method definition corresponding to the change line number to determine its specific location and role in the code.
[0133] Specifically, find the method declaration in the corresponding target method tree where the change line number is located, obtain the definition information of the change 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 change line number that is not in the interface layer), recursively find 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 route information in the @RequestMapping annotation, which is the second-level route information mentioned above. In addition, find the @RequestMapping route information of the class level corresponding to the change line number from the corresponding target method tree, which is the first-level route information mentioned above. Through splicing, obtain the spliced route information corresponding to the change line number of each method in the method definition information list.
[0135] Step 9: Add all spliced route information obtained in Step 6 and Step 8 to the route list for subsequent processing.
[0136] Step 10: Remove duplicate route information in the route list to ensure that each spliced route information is unique.
[0137] Step 11: Traverse the route list after deduplication and query each spliced route information from the database according to each spliced route information in it to obtain the target feature point corresponding to each spliced route information. Add the queried target feature point to the feature point list and return the feature point list for developers to test and use.
[0138] In summary, this embodiment uses tools such as Git Diff and Java Parse to realize automatic analysis and feature point identification of code changes, improving the accuracy and comprehensiveness of analysis and reducing the workload of manual analysis. In addition, this embodiment provides context and call chain information of changed code, enabling developers and testers to clearly understand the impact of changes on the system and realize real-time analysis of change impact.
[0139] The above introduces a method for determining system affected functions based on changed codes provided by the embodiments of the present application. The following will introduce an apparatus for executing the method for determining system affected functions based on changed codes.
[0140] Please refer to Figure 5 , Figure 5 The structure diagram of an apparatus for determining system affected functions based on changed codes provided by the embodiments of the present application. As shown in the figure, Figure 5 The apparatus can include:
[0141] The code comparison module 501 is configured to compare the new version code file set and the old version code file set of the system to be evaluated, to determine the changed code file and the changed line in the changed code file from the new version code file set.
[0142] The syntax analysis module 502 is configured to obtain the file package in which 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.
[0143] The route extraction module 503 is configured to extract the first-level route information and the second-level route information corresponding to the changed line from the abstract syntax tree, wherein the first-level route information and the second-level route information constitute the complete route information of the interface corresponding to the changed line.
[0144] The function determination module 504 is configured to determine the target function point affected by the changed line in the system to be evaluated according to the first-level route information and the second-level route information.
[0145] In a possible implementation, when comparing the new version code file set and the old version code file set of the system to be evaluated, the code comparison module can be specifically configured to compare the new version code file set and the old version code file set by using Git Diff.
[0146] In a possible implementation, when generating the abstract syntax tree based on the file package, the syntax analysis module can be specifically configured to perform syntax analysis on the code in the file package by using Java Parser to generate the abstract syntax tree.
[0147] In a possible implementation, when extracting the first-level route information and the second-level route information corresponding to the changed line from the abstract syntax tree, the route extraction module can be specifically configured to:
[0148] determine the method tree corresponding to the changed code file from the abstract syntax tree as the target method tree;
[0149] screening a candidate method set from the target method tree, each candidate method in the candidate method set comprising a request path processing annotation;
[0150] determining a candidate method closest to the root node in the target method tree from the candidate method set as a first target method;
[0151] extracting first-level routing information from the request path processing annotation comprised by the first target method;
[0152] obtaining a method corresponding to the changed line, and determining whether the method corresponding to the changed line comprises a request path processing annotation;
[0153] If yes, taking the method corresponding to the changed line as a second target method, and extracting second-level routing information from the request path processing annotation comprised by the second target method;
[0154] If no, recursively searching for a first method comprising a request path processing annotation from the method corresponding to the changed line in the target method tree as a third target method, and extracting second-level routing information from the request path processing annotation comprised by the third target method.
[0155] In a possible implementation, the function determination module can be specifically used for:
[0156] concatenating the first-level routing information and the second-level routing information to obtain concatenated routing information;
[0157] querying a function point corresponding to the concatenated routing information from a pre-constructed database, and determining the queried function point as a target function point, wherein the pre-constructed database comprises a correspondence between routing information of an interface and a function point.
[0158] In a possible implementation, before the function determination module queries the function point corresponding to the concatenated routing information from the pre-constructed database, the function determination module can also be used for: performing deduplication on the concatenated routing information to obtain deduplicated concatenated routing information.
[0159] The apparatus for determining a system-affected function based on changed code provided in the embodiments of the present application corresponds to the method for determining a system-affected function based on changed code provided in the foregoing, and details can be referred to the foregoing, which will not be described herein again.
[0160] In the embodiments of the present application, an electronic device is further provided. Refer to Figure 6The diagram illustrates a structural schematic suitable for implementing the electronic device in the embodiments of this application. The electronic device in the embodiments of this application may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 6 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0161] like Figure 6 As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. When the electronic device is powered on, the RAM 603 also stores various programs and data required for the operation of the electronic device. The processing unit 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0162] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, memory cards, hard drives, etc.; and communication devices 609. Communication device 609 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have alternatively.
[0163] This application also provides a computer program product including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the methods provided in this application for determining the affected functions of a system based on modified code.
[0164] This application also provides a computer-readable storage medium that carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device is able to implement any of the methods provided in this application for determining the affected functions of a system based on modified code.
[0165] It should be noted that the apparatus embodiments described above are merely illustrative, and the units described as separate units can or can not be physically separate, and the units displayed as units can or can not be physical units, i.e., can be located in one place, or can be distributed to multiple network units. Part or all of the modules can be selected according to actual needs to achieve the purpose of the embodiment. In addition, the connection relationship between the modules in the apparatus embodiment provided in the present application indicates that there is a communication connection between them, which can be 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 the present application can be realized by means of software and the necessary general hardware, and of course can also be realized by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. Generally, functions completed by computer programs can be easily realized by corresponding hardware, and the specific hardware structure for realizing the same function can also be various, such as analog circuit, digital circuit or special circuit, etc. However, for the present application, software program implementation is a better embodiment. Based on this understanding, the technical solutions of the present application can be embodied in the form of software products, which are stored in readable storage media, such as computer floppy disks, U disks, mobile hard disks, ROM, RAM, magnetic or optical disks, etc., including a plurality of instructions for making a computer device (which can be a personal computer, a training device, or a network device, etc.) execute the methods described in various embodiments of the present application.
[0167] In the above embodiments, all or part can be realized by software, hardware, firmware or any combination thereof. When realized by software, it can be realized in the form of a computer program product in whole or in part.
[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 generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions can be transmitted from one website, computer, training device or data center to another website, computer, training device or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be stored by the computer or a data storage device such as a training device, a data center, etc. integrated with one or more available media sets. The available media can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)), etc.
Claims
1. A method for determining the affected functions of a system based on modified codes, characterized in that, include: The new version code file set and the old version code file set of the system to be evaluated are compared to determine the modified code files and the modified lines in the modified code files from the new version code file set; Obtain the file package containing the modified code file, and generate an abstract syntax tree based on the file package, wherein the file package consists of all or part of the files in the new version code file set; Extract the first-level routing information and the second-level routing information corresponding to the change line from the abstract syntax tree, wherein the first-level routing information and the second-level routing information constitute the complete routing information of the interface corresponding to the change line; Based on the first-level routing information and the second-level routing information, determine the target functional points in the system to be evaluated that are affected by the changes; The step of determining the target functional points affected by the change in the system to be evaluated based on the first-level routing information and the second-level routing information includes: The first-level routing information and the second-level routing information are concatenated together to obtain the concatenated routing information. The system queries the pre-built database to find the corresponding function points of the spliced routing information, and determines the found function points as the target function points. The pre-built database contains the correspondence between the routing information of the interfaces and the function points.
2. The method for determining the affected functions of a system based on modified codes according to claim 1, characterized in that, The comparison of the new version code file set and the old version code file set of the system to be evaluated includes: Use Git Diff to compare the new version of the code file set with the old version of the code file set.
3. The method for determining the affected functions of a system based on modified codes according to claim 1, characterized in that, The generation of an abstract syntax tree based on the file package includes: The code within the file package is parsed using a Java Parser to generate the abstract syntax tree.
4. The method for determining the affected functions of a system based on modified codes according to claim 1, characterized in that, The step of extracting the first-level routing information and second-level routing information corresponding to the modified line from the abstract syntax tree includes: The method tree corresponding to the modified code file is determined from the abstract syntax tree and used as the target method tree; A set of candidate methods is selected from the target method tree, and each candidate method in the set contains a request path processing annotation; The candidate method whose position is closest to the root node in the target method tree is determined from the candidate method set and selected as the first target method. Extract the first-level routing information from the request path processing annotation included in the first target method; Obtain the method corresponding to the changed row, and determine whether the method corresponding to the changed row contains the request path processing annotation; If so, the method corresponding to the modified line is taken 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; If not, then starting from the method corresponding to the changed row in the target method tree, recursively search for the first method containing the request path processing annotation, which is 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 change codes according to claim 1, characterized in that, Before querying the function point corresponding to the spliced routing information from the pre-built database, the method further includes: The concatenated routing information is deduplicated to obtain the deduplicated concatenated routing information.
6. An apparatus for determining the affected functions of a system based on change codes, characterized in that, include: The code comparison module is used to compare a new version code file set and an old version code file set of the system to be evaluated, in order to identify the modified code files and the modified lines in the modified code files from the new version code file set; The syntax parsing module is used to obtain the file package where the modified code file is located, and generate an abstract syntax tree based on the file package, wherein the file package consists of all or part of the files in the set of new version code files; The route extraction module is used to extract the first-level routing information and the second-level routing information corresponding to the change line from the abstract syntax tree, wherein the first-level routing information and the second-level routing information constitute the complete routing information of the interface corresponding to the change line; The function determination module is used to determine the target function points affected by the change in the system to be evaluated based on the first-level routing information and the second-level routing information. The step of determining the target functional points affected by the change in the system to be evaluated based on the first-level routing information and the second-level routing information includes: The first-level routing information and the second-level routing information are concatenated together to obtain the concatenated routing information. The system queries the pre-built database to find the corresponding function points of the spliced routing information, and determines the found function points as the target function points. The pre-built database contains the correspondence between the routing information of the interfaces and the function points.
7. A computer program product, characterized in that, Includes computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the method for determining the affected functions of a system based on change codes as described in any one of claims 1 to 5.
8. An electronic device, characterized in that, It includes at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program to enable the electronic device to implement the method for determining the affected functions of the system based on the change code as described in any one of claims 1 to 5.
9. A computer storage medium, characterized in that, The storage medium carries one or more computer programs that, when executed by an electronic device, enable the electronic device to implement the method for determining the affected functions of a system based on modified codes as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Code change analysis method
CN112379888A
Code analysis method, code analysis device, electronic equipment and storage medium
CN115292180A