Code modification content analysis method, device and storage medium

CN123011312APending Publication Date: 2026-10-30CHINA MERCHANTS BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611206577.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-10
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0004]本申请的主要目的在于提供一种代码修改内容分析方法、设备及存储介质,旨在解决现有代码变更分析中代码修改内容切分不准确的技术问题

Benefits of technology

本申请通过以方法为最小单元对代码差异信息进行切分,使每个修改点精确对应单个方法的代码变更,避免不同方法的修改被错误合并,提升了代码修改内容分析的精准度;通过将各修改点对应的差异代码及所属方法的完整代码共同输入大模型,使大模型能够获得完整的代码上下文进行语义理解,避免因缺失方法上下文导致的总结信息不完整,提升了修改内容总结的准确性;进一步地,通过根据类内调用关系和类间调用关系对各修改点进行调用链路分析,能够从修改点所属方法出发逐层向上追溯所有层级的调用关系,直至确定所影响的顶层方法,克服了传统调用链路分析仅能识别直接调用关系的局限性,实现了跨层级的全链路影响追踪;此外,基于所述修改内容总结和所述调用链路分析文档生成代码变更影响分析结果,将大模型的语义理解能力与结构化的调用链路分析深度融合,使开发人员能够以顶层方法为维度快速定位受影响的改动范围,提升了代码评审和变更影响分析的效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123011312A_ABST
    Figure CN123011312A_ABST
Patent Text Reader

Abstract

The application discloses a code modification content analysis method and device and a storage medium, relates to the technical field of software code analysis, and comprises the following steps: obtaining difference information before and after target project code modification; analyzing the difference information based on an abstract syntax tree, cutting the difference information into multiple modification points as the minimum unit; inputting the difference code of each modification point and the complete code of the method to which the modification point belongs into a large model to obtain a modification content summary; performing calling link analysis on each modification point according to intra-class calling relationship and inter-class calling relationship to obtain a calling link analysis document; and generating a code change analysis result based on the modification content summary and the calling link analysis document. The application cuts the difference information into fine-grained units as the minimum unit, improves the accuracy of code modification content analysis, and traces the top-level interface influenced by each modification point by summarizing the modification content through the large model and fusing the calling link analysis, thereby improving the completeness and efficiency of code change influence analysis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software code analysis technology, and in particular to a method, device and storage medium for analyzing code modification content. Background Technology

[0002] In Git-based software development, code change impact analysis is a crucial step in version review and defect localization. Existing analysis tools primarily rely on native Git commands to extract code differences, but they typically use file or line distance as the dividing line, lacking an understanding of the code's semantic structure. This can easily lead to merging modifications from different methods into the same change unit, resulting in coarse and inaccurate change unit segmentation. This segmentation method affects the reliability of change impact analysis and fails to meet the needs of fine-grained code modification evaluation.

[0003] The above content is only used to help understand the technical solution of this application and does not represent an admission that the above content is prior art. Summary of the Invention

[0004] The main purpose of this application is to provide a method, device and storage medium for analyzing code modification content, which aims to solve the technical problem of inaccurate segmentation of code modification content in existing code change analysis.

[0005] To achieve the above objectives, embodiments of this application provide a method for analyzing code modification content, the method comprising: Obtain information on the code differences before and after modifications to the target project; The code difference information is parsed based on the abstract syntax tree, and the code difference information is divided into multiple modification points with the method as the smallest unit. Each modification point corresponds to the code change of a single method. Input the difference code and the complete code of the method corresponding to each modification point into the large model to obtain a summary of the modifications; Based on the intra-class and inter-class call relationships of the methods to which each modification point belongs, a call chain analysis is performed to obtain a call chain analysis document; Based on the summary of the modifications and the call chain analysis document, code change analysis results are generated.

[0006] In one embodiment, the step of obtaining the code difference information before and after the target project code modification includes: Obtain the hash values ​​of the target project code before and after modification, as input by the user; Based on the hash value, the `git diff` command is executed in the command-line terminal to obtain the code difference information.

[0007] In one embodiment, the step of parsing the code difference information based on an abstract syntax tree, segmenting the code difference information by method as the smallest unit to obtain multiple modification points, each modification point corresponding to a code change of a single method, includes: Based on the code difference information, determine the files where code changes occurred and the range of changed code lines; The file is parsed using an abstract syntax tree to obtain the name, start line, and end line of all methods in the file. The range of changed code lines is compared with the start and end lines of each method. When the range of changed code lines spans the start and end lines of at least two methods, the code difference information is split into multiple modification points according to the method boundaries, with each modification point corresponding to the code change of a single method.

[0008] In one embodiment, after the step of determining the file and the range of changed lines of code based on the code difference information, the code modification analysis method further includes: Get the type of the file that has undergone code changes; When the type is a preset configuration file type, the file whose code has changed is marked as a configuration modification, and the modification point corresponding to the configuration modification is recorded.

[0009] In one embodiment, the step of inputting the difference code corresponding to each modification point and the complete code of the method to which they belong into the large model to obtain a summary of the modifications includes: Obtain the difference code corresponding to the modified point and the complete code of the method to which it belongs; The difference code and the complete code are filled into the preset prompt word template, and the filled prompt words are input into the large model to obtain the code change summary of the modification points output by the large model; After traversing all the modification points, summarize the code changes at each modification point to obtain the summary of the modifications.

[0010] In one embodiment, the step of performing call chain analysis based on the intra-class and inter-class call relationships of the methods to which each modification point belongs, and obtaining a call chain analysis document, includes: Based on the abstract syntax tree, all class files in the target project are parsed. The inter-class call relationship is constructed according to the dependency injection markup in each class file. The method body of each class file is parsed through the abstract syntax tree to identify the same type of methods called in each method body and construct the intra-class call relationship. Based on the intra-class call relationship, determine all intra-class methods that directly or indirectly call the method to which the modification point belongs, and combine the method to which the modification point belongs and all intra-class methods into an initial method set; Based on the inter-class call relationships, identify all methods that have cross-class upper-level calls from the initial method set to form a set of methods to be analyzed; For each method in the set of methods to be analyzed, the cross-class upper-level calling method is traced upwards by combining the intra-class calling relationship and the inter-class calling relationship. If the traced cross-class upper-level calling method has further cross-class upper-level calls, the tracing continues until the traced cross-class upper-level calling method does not have cross-class upper-level calls in the inter-class calling relationship. The finally traced cross-class upper-level calling method is recorded as the top-level method. The call chain analysis document is generated based on each modification point and the top-level method traced back to each modification point.

[0011] In one embodiment, the step of generating the call chain analysis document based on each modification point and the top-level method traced back to each modification point includes: Each modification point is grouped based on the top-level method, with each group containing the same top-level method and all modification points affected by the top-level method. For each group, based on the intra-class call relationship and the inter-class call relationship, a call chain is constructed from each modification point within the group to the corresponding top-level method, and the call chains of all groups are integrated into a directed acyclic graph, where each node of the directed acyclic graph represents a method call; Based on the directed acyclic graph and the grouping information of each group, the call chain analysis document is generated. The call chain analysis document records each top-level method and the affected modification points corresponding to the top-level method, as well as the complete call path from each modification point to the corresponding top-level method.

[0012] In one embodiment, the step of generating code change analysis results based on the summary of modifications and the call chain analysis document includes: Based on the call chain information, the summary of modifications is associated with each method call node in the call chain information to generate a mapping relationship between the method call nodes and the summary of modifications; Based on the mapping relationship and the call chain analysis document, code change analysis results are generated.

[0013] This application embodiment also provides a code modification content analysis device, the code modification content analysis device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the code modification content analysis method described above.

[0014] This application embodiment also provides a storage medium, which is a computer-readable storage medium, and stores a computer program on the storage medium. When the computer program is executed by a processor, it implements the steps of the code modification content analysis method described above.

[0015] One or more technical solutions proposed in this application have at least the following technical effects: This application segments code difference information by using methods as the smallest unit, ensuring that each modification point precisely corresponds to the code change of a single method. This avoids the erroneous merging of modifications from different methods, improving the accuracy of code modification analysis. By inputting the difference code corresponding to each modification point and the complete code of the method to which it belongs into a large model, the large model can obtain a complete code context for semantic understanding, avoiding incomplete summary information due to missing method context and improving the accuracy of modification summary. Furthermore, by performing call chain analysis on each modification point based on intra-class and inter-class call relationships, it can trace the call relationships at all levels from the method to which the modification point belongs, until the top-level method affected is identified. This overcomes the limitation of traditional call chain analysis, which can only identify direct call relationships, and achieves cross-level full-link impact tracing. In addition, based on the modification summary and the call chain analysis document, code change impact analysis results are generated, deeply integrating the semantic understanding capability of the large model with structured call chain analysis. This allows developers to quickly locate the scope of affected changes by using the top-level method as the dimension, improving the efficiency of code review and change impact analysis. Attached Figure Description

[0016] Figure 1 A flowchart illustrating the method for analyzing code modifications in this application, provided in Embodiment 1. Figure 2 A schematic diagram of the prompt word template structure based on a large model provided in Embodiment 1 of the code modification content analysis method of this application; Figure 3 This is a schematic diagram of the process for generating a summary of modifications based on a large model, provided in Embodiment 1 of the code modification content analysis method for this application. Figure 4 A complete flowchart example of call chain analysis is provided in Embodiment 1 of the method for analyzing code modifications in this application. Figure 5 This is a schematic diagram of the overall process of analyzing code modifications provided in Embodiment 1 of the code modification analysis method of this application; Figure 6 This is a schematic diagram of the hardware operating environment for analyzing code modifications in the embodiments of this application.

[0017] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0018] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit this application.

[0019] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.

[0020] In Git-based software development, code change impact analysis is a crucial step in version review and defect localization. Existing analysis tools primarily rely on native Git commands to extract code differences, but they typically use file or line distance as the dividing line, lacking an understanding of the code's semantic structure. This can easily lead to merging modifications from different methods into the same change unit, resulting in coarse and inaccurate change unit segmentation. This segmentation method affects the reliability of change impact analysis and fails to meet the needs of fine-grained code modification evaluation.

[0021] In view of the above problems, this application proposes a code modification analysis method to obtain code difference information before and after the modification of the target project code; based on the abstract syntax tree, the code difference information is parsed and segmented into multiple modification points, with each modification point corresponding to the code change of a single method; the difference code corresponding to each modification point and the complete code of the method to which it belongs are input into a large model to obtain a summary of the modification content; based on the intra-class call relationship and inter-class call relationship of the method to which each modification point belongs, a call chain analysis is performed to obtain a call chain analysis document; based on the summary of the modification content and the call chain analysis document, code change analysis results are generated.

[0022] This application provides a solution that segments code difference information by method as the smallest unit, ensuring that each modification point precisely corresponds to the code change of a single method. This avoids the erroneous merging of modifications from different methods, improving the accuracy of code modification analysis. By inputting the difference code corresponding to each modification point and the complete code of the method to which it belongs into a large model, the large model can obtain a complete code context for semantic understanding, avoiding incomplete summary information due to missing method context and improving the accuracy of modification summary. Furthermore, by performing call chain analysis on each modification point based on intra-class and inter-class call relationships, it is possible to trace the call relationships at all levels from the method to which the modification point belongs, until the top-level method affected is identified. This overcomes the limitation of traditional call chain analysis, which can only identify direct call relationships, and achieves cross-level full-link impact tracing. In addition, code change impact analysis results are generated based on the modification summary and the call chain analysis document, deeply integrating the semantic understanding capability of the large model with structured call chain analysis. This allows developers to quickly locate the scope of affected changes at the top-level method, improving the efficiency of code review and change impact analysis.

[0023] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or server, or an electronic device, code modification content analysis device, or system capable of performing the above functions. The following description uses a code modification content analysis system as an example to illustrate this embodiment and the subsequent embodiments.

[0024] Please refer to the code modification content analysis method of the first embodiment proposed in this application. Figure 1 The method includes steps S10 to S50: Step S10: Obtain the code difference information before and after the target project code is modified.

[0025] In software version control scenarios, after developers modify code, they typically need to understand which files and lines of code have been changed. Code difference information is the data used to describe these changes. In this embodiment, code difference information is the difference data generated by version control tools by comparing the code versions before and after the modification. It specifically records the names of the changed files, the line number range of the changed code, the deleted lines of code, and the newly added lines of code.

[0026] In Git-based version control software projects, each code commit by developers generates a unique hash value. This hash value acts as a unique identifier for the code version on the timeline, used to accurately pinpoint the snapshot state before and after a specific code change. Existing analysis tools typically rely directly on native Git commands to obtain differences, but due to the lack of subsequent structured processing, the extracted information is coarse-grained and difficult to support refined impact analysis.

[0027] As an optional implementation, this embodiment provides an interactive interface. After reading the target project code, it obtains two hash values ​​of the target project code before and after modification via Git commands, input by the user. Then, based on these hash values, the system calls the command-line terminal to execute a difference comparison command (e.g., `git diff`), thereby extracting code difference information including filename changes and added / deleted lines of code. This code difference information is temporarily stored in a temporary file for later parsing. Considering that developers may work in different environments, the execution environment is compatible with multiple operating systems such as Windows and Linux to ensure the tool's universality. Through the above steps, this embodiment can obtain raw data on code changes in a standardized manner, providing a reliable data foundation for subsequent fine-grained segmentation.

[0028] Step S20: Based on the abstract syntax tree, the code difference information is parsed and segmented into multiple modification points, with each modification point corresponding to the code change of a single method.

[0029] After obtaining the code difference information, this embodiment introduces Abstract Syntax Tree (AST) parsing technology to process the code. An AST is a tree-like data structure that transforms source code according to its syntactic structure. It clearly displays the hierarchical relationships and physical locations of program elements such as classes, methods, and variables. Traditional Git difference analysis determines whether changes are the same by measuring the distance between lines of code. This method is prone to misclassifying changes across different methods as the same change. To overcome this deficiency, this embodiment uses an AST to perform a deep scan of the changed file, extracting the names, starting lines, and ending lines of all methods within the file.

[0030] Specifically, step S20 includes steps S21 to S23: Step S21: Based on the code difference information, determine the file where the code change occurred and the range of changed code lines; Step S22: Parse the file using an abstract syntax tree to obtain the name, start line, and end line of all methods in the file; Step S23: Compare the range of changed code lines with the start and end code lines of each method. When the range of changed code lines spans the start and end code lines of at least two methods, the code difference information is split into multiple modification points according to the method boundaries, and each modification point corresponds to the code change of a single method.

[0031] In this embodiment, the target file where the code change occurred and the specific range of changed lines of code are first extracted from the code difference information. The range of changed lines of code refers to the specific range of line numbers in the code where addition, deletion, or modification operations occurred. This range provides key coordinates for subsequent precise location of the modification. Optionally, the system can read the code difference information line by line, filter out line numbers marked with addition, deletion, or modification, thereby determining the affected code range.

[0032] Next, the target file is parsed using an abstract syntax tree to obtain the names, starting lines, and ending lines of all methods in the target file, thus clarifying the physical boundaries of each method in the code. Then, the range of changed lines in the code difference information is compared with the starting and ending lines of each method in the target file. When it is detected that the range of changed lines spans the starting and ending lines of a method, it indicates that the modification actually involves changes to two or more methods. In this case, this embodiment will perform fine-grained segmentation using the method dimension as the smallest unit, that is, splitting the current change location into multiple independent modification points, ensuring that each modification point contains only a single method's code change.

[0033] As an example, suppose the `git diff` command reveals that the changed code lines in file A.java are from line 100 to line 120. Abstract syntax tree (API) parsing shows that A.java contains three methods: `funcA`, `funcB`, and `funcC`. `funcA` is located at lines 70 to 90, `funcB` at lines 95 to 110, and `funcC` at lines 115 to 180. This embodiment, when traversing the code difference information, compares each method in the order they appear in the code. It will identify that `funcA` (lines 70-90) has no overlap with the changed code lines (lines 100-120), `funcB` (lines 95-110) overlaps with the changed code lines (lines 100-110), and `funcC` (lines 115-180) overlaps with the changed code lines (lines 115-120). Ultimately, this embodiment precisely divides the aforementioned changes into two method-level modification points, each corresponding to a single method's code change. For each modification point, the system saves it as a separate temporary file. This temporary file records information including the class name, the starting line of the changed code, the fine-grained splitting result from `git diff`, the name of the changed method, and the complete code of the changed method. This information will be read and used in subsequent code change summaries and call chain analysis steps. Through this method, this embodiment achieves code change identification from the file level to the method level, effectively avoiding inaccurate splitting caused by incorrect merging of different method modifications.

[0034] For the various change scenarios involved in the code difference information, not all changes involve method code modifications; they may also include non-method type changes such as constant modifications, configuration modifications, or class import modifications. To accurately identify these special scenarios, steps S211~S212 are included after step S21: Step S211: Obtain the type of the file whose code has been changed; Step S212: When the type is a preset configuration file type, mark the file with code changes as a configuration modification and record the modification point corresponding to the configuration modification.

[0035] Specifically, this embodiment distinguishes whether a file is a configuration modification by reading the configuration file extension of the file whose code has been changed. When the file extension of the changed file is a preset configuration file type (e.g., .xml, .yaml, or .yml), the changed file is marked as a configuration modification, and its corresponding modification point is recorded in a temporary file so as to distinguish it from method-level modifications in subsequent processing.

[0036] Through the above methods, this embodiment can separately identify and process special types of code changes such as configuration files, ensuring that non-method type changes are not mistakenly included in the method-level splitting process, thereby improving the adaptability of the solution to different types of code changes.

[0037] Step S30: Input the difference code corresponding to each modification point and the complete code of the method to which they belong into the large model to obtain a summary of the modifications.

[0038] After obtaining the fine-grained modification points at the method level, this embodiment leverages the powerful semantic understanding capabilities of a large language model to generate a summary of the modifications. In this process, this embodiment specifically designs a context enhancement mechanism. Since large models often lack a global perspective when understanding code snippets, inputting only a few lines of modified code can easily lead to misunderstandings or omissions. Therefore, this embodiment not only extracts the difference code at the modification point itself but also obtains the complete code of the class containing the method to which the modification point belongs through an abstract syntax tree, inputting it along with the context information.

[0039] Specifically, step S30 includes steps S31 to S33: Step S31: Obtain the difference code corresponding to the modification point and the complete code of the method to which it belongs; Step S32: Fill the difference code and the complete code into the preset prompt word template, and input the filled prompt word into the large model to obtain the code change summary of the modification point output by the large model; Step S33: After traversing all modification points, summarize the code changes at each modification point to obtain the summary of the modification content.

[0040] By segmenting at the method level, this embodiment obtains modification points with methods as the smallest unit. Then, it can extract the complete code of the method to which each modification point belongs using an abstract syntax tree, and input this as contextual information into the larger model to enhance the model's global understanding of the modifications. Based on this, this embodiment traverses all fine-grained modification points, structurally assembling the difference code and complete context code corresponding to each modification point according to a preset prompt template. Then, it calls the large model interface to summarize the modifications. The aforementioned prompt template is designed around the core requirements of the code change summary task. Through structured input parsing, task constraint definition, output logic decomposition, and scenario adaptation mechanisms, it achieves accurate extraction and formatted output of code change information, ensuring that the large model generates accurate and structured summary results with sufficient contextual support.

[0041] As an example, this prompt template first parses the fine-grained git diff splitting result output in step S20 at the input level, extracting file paths, starting line numbers of changed code, code block addition / deletion markers, and differing code snippets. Simultaneously, it extracts contextual data such as method names, annotations, class references, and interface references for each modification point after fine-grained splitting through an abstract syntax tree, providing a complete technical context for subsequent summarization. For instruction design, please refer to... Figure 2 The prompt explicitly limits the large model to acting as a code change summary assistant, requiring it to focus only on code logic changes, ignoring irrelevant information such as formatting adjustments, and mandating JSON output with fields including method name, method change type, and a code change summary text. For example, Figure 2 The prompts require three fields: methodName, methodChgType, and codeChgSummary. The prompts also provide typical examples to guide the model in learning the field generation rules. For instance, methodChgType (method change type) needs to be determined based on the addition / deletion markers in the code block and the completeness of the method body (e.g., addition, modification, or deletion). codeChgSummary (code change summary) needs to be broken down step-by-step, combining annotation descriptions, code comments, and implementation logic to break down the functional purpose and technical details. For special scenarios where the change content does not involve method modification (e.g., class variable modification), the prompts also have a default value mechanism, outputting both the method name and method change type as "none". Through a placeholder mechanism, the prompts can dynamically inject information such as filename, starting line of code, git diff details, and method context into the preset prompt template. This ensures that each time the large model is called, customized prompts are provided for the current modification point, thus ensuring the accuracy and consistency of the output results. Through this context enhancement mechanism, the large model is no longer analyzed based solely on isolated, fragmented lines of difference, but can instead reason within the complete code context, thereby generating a more accurate and detailed summary of the modifications.

[0042] After traversing all fine-grained modification points, this embodiment will obtain a summary of code changes for each modification point based on the output of the large model. Finally, this embodiment will generate a structured analysis document, which can be organized in tabular form (e.g., an Excel file). Each row records complete analysis information for a modification point, specifically including the following fields: the modified file name, the starting line number of the changed code, the method name (if the modification involves a method change), the method change type (including addition, modification, deletion, or none), and the code change summary output by the large model. Except for the code change summary, which comes from the semantic analysis output of the large model, the other fields are directly obtained from the static parsing results of the abstract syntax tree. Through this structured document, developers can clearly and intuitively understand the changes and semantic summary of each code modification, providing a traceable and searchable data foundation for subsequent code review and impact analysis.

[0043] For example, refer to Figure 3 To aid in understanding the flowchart of the modification summary generation process based on the large model in this embodiment, specifically: when generating the modification summary, it is necessary to traverse each modification point obtained in the previous step, and determine one by one whether all modification points have been processed. If not, the difference code and the complete context code of the method to which the current modification point belongs are obtained, and this information is filled into the prompt word template and input into the large model. The large model then summarizes the modification content of the modification point and generates a code change summary for that modification point. Then, the judgment step is returned, and the next modification point is traversed until all modification points are processed. At this point, the loop is exited, the code change summaries of each modification point are summarized, and the final modification summary document is generated.

[0044] Step S40: Perform call chain analysis based on the intra-class and inter-class call relationships of the methods to which each modification point belongs, and obtain a call chain analysis document.

[0045] The impact of code modifications often extends beyond the point of change itself. In complex software systems, a change to a low-level method can propagate upwards along the call chain, affecting multiple upper-level callers and even the highest-level interface exposed to the outside world. To comprehensively assess the potential impact of modifications, this embodiment achieves full-chain tracing by constructing inter-class and intra-class call relationships. Specifically, inter-class call relationships refer to cross-class method call associations established between different classes through dependency injection mechanisms (such as the @Component and @Autowired annotations in the Spring framework). These relationships reveal the vertical collaboration paths between different business layers of the system (such as the controller layer, service layer, and data access layer). Intra-class call relationships, on the other hand, refer to direct call associations between different methods within the same class. This application identifies these internal references by parsing the syntax structure of the method bodies, thereby constructing a directed acyclic graph that reflects the flow of inter-method calls.

[0046] Specifically, step S40 includes steps S41 to S45: Step S41: Based on the abstract syntax tree, parse all class files in the target project, construct the inter-class call relationship according to the dependency injection mark in each class file, and parse each method body in each class file through the abstract syntax tree to identify the same type of methods called in each method body and construct the intra-class call relationship. When constructing call relationships, this embodiment first uses an abstract syntax tree to parse all class files in the target project. Taking a Java project based on the Spring framework as an example, the construction of inter-class call relationships typically involves a layered architecture, including Controller, Service, and Dao layers, with dependencies between layers implemented through dependency injection. This embodiment identifies all inter-class call relationships by examining dependency injection markers (such as the `@Autowired` keyword) in each class file and stores these relationships in a call relationship mapping table (such as a HashMap) for quick retrieval of cross-class call information later.

[0047] To construct intra-class call relationships, this embodiment utilizes an abstract syntax tree to parse each method body in each class file, identifying other methods within the same class called by each method body, thereby constructing a call relationship graph between methods within the same class. It should be noted that intra-class call relationships include not only calls between public methods but also calls from public methods to private methods and mutual calls between private methods. This embodiment constructs a complete intra-class call relationship by fully parsing all method references within the method body.

[0048] Step S42: Based on the intra-class call relationship, determine all intra-class methods that directly or indirectly call the method to which the modification point belongs, and combine the method to which the modification point belongs and all intra-class methods into an initial method set; Of all the modification points obtained in step S20, some modifications may not involve method changes, such as constant modifications, package import modifications, or configuration file modifications. These modifications cannot be analyzed using call chain analysis, so they need to be filtered, retaining only the modification points involving method code changes for subsequent analysis. For each modification point to be analyzed, this embodiment first traces upwards within the class to which the modification point belongs, based on the pre-built intra-class call relationship, to find all methods that directly call the method to which the modification point belongs, as well as methods that indirectly call the method to which the modification point belongs through multi-level call chains. These intra-class methods, together with the method to which the modification point belongs itself, are then combined to form an initial method set.

[0049] Step S43: Based on the inter-class call relationship, identify all methods with cross-class upper-level calls from the initial method set to form a set of methods to be analyzed; After obtaining the initial method set, this embodiment queries the pre-built inter-class call relationship mapping table to identify all methods that have cross-class upper-level calls from the initial method set, that is, methods called by methods in other classes. These methods are then grouped into a set of methods to be analyzed, which serves as the starting point for the next step of cross-level tracing.

[0050] Step S44: For each method in the set of methods to be analyzed, trace upwards the cross-class upper-level calling method by combining the intra-class calling relationship and the inter-class calling relationship. If the traced cross-class upper-level calling method has further cross-class upper-level calls, continue tracing until the traced cross-class upper-level calling method does not have cross-class upper-level calls in the inter-class calling relationship. Record the finally traced cross-class upper-level calling method as the top-level method. This embodiment employs a recursive tracing strategy. For each method in the set of methods to be analyzed, it traces upwards layer by layer, combining intra-class call relationships and inter-class call relationships. For the currently analyzed method, it first checks the inter-class call relationship mapping table to see if there are any methods from other classes that call this method. If so, these cross-class upper-level call methods are used as new starting points to continue checking if there are any higher-level cross-class calls to these methods. This process is repeated until the currently traced cross-class upper-level call method has no higher-level cross-class calls in the inter-class call relationship. When the recursion terminates, the method reached is the top-level method of this call chain. These top-level methods are usually interfaces or entry points exposed to external calls.

[0051] Step S45: Generate the call chain analysis document based on each modification point and the top-level method traced back to each modification point.

[0052] Once the call chain for all modification points has been traced, this embodiment summarizes each modification point and its corresponding top-level method, and generates a call chain analysis document based on this. This document records all the underlying modification points affected by each top-level method, as well as the complete call path from each modification point to the top-level method.

[0053] As an example, this embodiment can employ a depth-first search algorithm. Starting from a low-level modification point, it searches upwards within the class along the intra-class call relationships to find all methods that directly or indirectly call it, forming an initial method set. Then, combining inter-class call relationships, it traces upwards across class boundaries to higher-level callers, repeating this process until there are no higher-level cross-class calls, ultimately reaching the top-level interface of the system. Through this cross-level recursive tracing, this embodiment can clearly reveal the complete call path between low-level modifications and the top-level interface, allowing developers to accurately assess the scope of impact.

[0054] For example, refer to Figure 4 To aid in understanding the complete flowchart of call chain analysis in this embodiment, specifically: First, the inter-class call relationships of the target project code are constructed as the basis for subsequent cross-class tracing; then, each modification point is traversed, and it is determined one by one whether there are any unprocessed modification points. If there are still untraversed modification points, the intra-class call relationship of the class where the modification point is located is obtained, and recursively traced in conjunction with the constructed inter-class call relationships to find all top-level methods affected by the modification point; the judgment step is returned again until all modification points have been processed. At this point, the loop is exited, the call chain information of all modification points is summarized, and a call chain analysis document is generated.

[0055] Furthermore, step S45 further includes steps S451 to S453: Step S451: Group each modification point by the top-level method, with each group containing the same top-level method and all modification points affected by the top-level method; Step S452: For each group, based on the intra-class call relationship and the inter-class call relationship, construct a call chain from each modification point within the group to the corresponding top-level method, and integrate the call chains of all groups into a directed acyclic graph, where each node of the directed acyclic graph represents a method call; Step S453: Based on the directed acyclic graph and the grouping information of each group, generate the call chain analysis document. The call chain analysis document records each top-level method and the affected modification points corresponding to the top-level method, as well as the complete call path from each modification point to the corresponding top-level method.

[0056] In this embodiment, the above-described tracing process can obtain all top-level methods affected by each modification point. Each top-level method may also correspond to multiple bottom-level modification points, creating a complex many-to-many mapping relationship. To organize this information in a way that better suits developers' analytical habits, this embodiment aggregates each modification point on a top-level method basis.

[0057] For each top-level method, all modification points corresponding to that top-level method are grouped into the same group, allowing developers to intuitively understand which underlying modifications affect a particular top-level interface. Based on this, for each group, a complete call chain is constructed from each modification point within the group to the corresponding top-level method according to intra-class and inter-class call relationships. The call chains of all groups are then integrated into a Directed Acyclic Graph (DAG), where each node represents a method call and edges represent the call directions between methods. Based on the aforementioned DAG and the grouping information, a call chain analysis document is generated. This document records each top-level method and its corresponding affected modification points, as well as the complete call path from each modification point to the corresponding top-level method. Through this aggregation presentation centered on top-level methods, this embodiment deeply integrates the structured information of the call chain with the modification summary generated by the large model, providing a clear and complete basis for impact scope analysis for subsequent code reviews and release decisions.

[0058] Step S50: Based on the summary of the modifications and the call chain analysis document, generate code change analysis results.

[0059] After obtaining precise summaries of code modifications and comprehensive call chain analysis documents, this embodiment requires deep integration of these two pieces of information to generate the final code change impact analysis results for developers. Presenting only the modification summary or only displaying the call chain structure is insufficient to intuitively reflect the actual impact of code changes within the entire call system. Developers, during code reviews or troubleshooting, require a comprehensive analytical view that can correlate and integrate semantic-level modification descriptions with structural-level call chain impacts.

[0060] Specifically, step S50 includes steps S51 to S52: Step S51: Based on the call chain information, associate the summary of modified content with each method call node in the call chain information to generate a mapping relationship between the method call nodes and the summary of modified content; Step S52: Generate code change analysis results based on the mapping relationship and the call chain analysis document.

[0061] Building upon the grouping of modification points and generation of call chain analysis documents using the top-level methodology, this embodiment further associates the summary of modifications output by the large model with each method call node in the call chain. Specifically, in the directed acyclic graph of the call chain, each node represents a method call. This embodiment attaches the summary of modifications corresponding to each modification point to the corresponding node in the directed acyclic graph, forming a key-value mapping relationship between method call nodes and the summary of modifications. This mapping relationship not only includes the summary text itself but also associates the contextual information upon which the summary of modifications depends, facilitating subsequent backtracking and tracing.

[0062] As an example, the final code change analysis results can be presented in a structured spreadsheet file, where each row corresponds to a specific modification point, detailing the modified file name, the starting line of the changed code, the method name, the method change type, and a summary of code changes generated by the larger model. It also displays all top-level method interfaces affected by that modification point. This presentation method allows developers to start from the highest-level interfaces and examine all relevant underlying change details from top to bottom, effectively improving the efficiency of code review and risk assessment.

[0063] For example, refer to Figure 5 To aid in understanding the overall flowchart of code modification analysis in this embodiment, the process is as follows: First, the target project code is read, and Git version control tools are used to obtain code difference information before and after the modification. Then, the code difference information is fine-grained and segmented at the method dimension, precisely locating each code change to its corresponding method, resulting in several modification points with methods as the smallest unit. Based on this, each modification point is iterated through, and the corresponding difference code and the complete context code of the method to which it belongs are input into a larger model. The larger model performs semantic summarization for each modification point, ultimately summarizing the code changes of all modification points to generate a code modification content summary, which is output as a structured document. Simultaneously, static code analysis is used to identify the intra-class and cross-class call relationships of the methods to which each modification point belongs, performing call chain analysis to trace the top-level methods affected by each modification point, generating a call chain analysis document. Finally, the above code modification content summary and call chain analysis document are deeply integrated to generate a complete code change impact analysis result.

[0064] This embodiment effectively avoids the error of traditional tools merging different method modifications into the same change unit due to a lack of semantic awareness by finely segmenting code differences using methods as the smallest unit, significantly improving the accuracy of change identification. By extracting the complete code of the class to which the modified method belongs as context input to the large model, it compensates for the lack of context in the large model when processing isolated code fragments, thus ensuring the completeness and accuracy of the code change summary. By combining intra-class and inter-class call relationships for cross-level call chain analysis, it overcomes the limitation of traditional tools that can only identify direct call relationships, realizing full-link impact tracing from the bottom-level modification point to the top-level interface. Furthermore, by deeply integrating the semantic summary of the large model with the structured call chain document, it generates intuitive and easy-to-trace comprehensive analysis results, solving the technical problems of coarse granularity of existing code modification content analysis, lack of context, and limitations in call chain tracing, providing developers with an efficient and accurate means of assessing the impact of code changes.

[0065] This application provides a code modification content analysis device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the code modification content analysis method in the first embodiment described above.

[0066] The following is for reference. Figure 6 The diagram illustrates a structural schematic of a code modification content analysis device suitable for implementing embodiments of this application. The code modification content analysis device in the embodiments of this application may include various hardware and software components for implementing code modification content analysis methods. Figure 6 The code modification analysis device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.

[0067] like Figure 6As shown, the code modification content analysis device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the code modification content analysis device. The processing unit 1001, the ROM 1002, and the RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the code modification content analysis device to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows code modification content analysis devices with various systems, it should be understood that implementing or having all of the systems shown is not required. More or fewer systems may be implemented alternatively.

[0068] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.

[0069] The code modification content analysis device provided in this application, employing the code modification content analysis method described in the above embodiments, can solve the technical problem of inaccurate code modification content segmentation in existing code change analysis. Compared with the prior art, the beneficial effects of the code modification content analysis device provided in this application are the same as those of the code modification content analysis method provided in the above embodiments, and other technical features of this code modification content analysis device are the same as those disclosed in the previous embodiment method, and will not be repeated here.

[0070] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.

[0071] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0072] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, which are used to execute the code modification content analysis method described in the above embodiments.

[0073] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or apparatus. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, radio frequency (RF), etc., or any suitable combination thereof.

[0074] The aforementioned computer-readable storage medium may be included in the code modification content analysis device; or it may exist independently and not be assembled into the code modification content analysis device.

[0075] The aforementioned computer-readable storage medium carries one or more programs. When these programs are executed by a code modification analysis device, the code modification analysis device performs the following actions: acquires code difference information before and after code modification of the target project; parses the code difference information based on an abstract syntax tree, segments the code difference information by method as the smallest unit to obtain multiple modification points, each modification point corresponding to a single method's code change; inputs the difference code corresponding to each modification point and the complete code of the method to which it belongs into a large model to obtain a summary of modification content; performs call chain analysis based on the intra-class call relationship and inter-class call relationship of the methods to which each modification point belongs to, to obtain a call chain analysis document; and generates code change analysis results based on the summary of modification content and the call chain analysis document.

[0076] Computer program code for performing the operations of this application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., using an internet connection from an internet service provider).

[0077] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation that may be implemented in systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0078] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0079] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., computer programs) for executing the above-described code modification content analysis method, thereby solving the technical problem of inaccurate code modification content segmentation in existing code change analysis. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the code modification content analysis method provided in the above embodiments, and will not be repeated here.

[0080] This application provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the code modification content analysis method described above.

[0081] The computer program product provided in this application can solve the technical problem of inaccurate segmentation of code modification content in existing code change analysis. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as the beneficial effects of the code modification content analysis method provided in the above embodiments, and will not be repeated here.

[0082] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent scope of this application.

[0083] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.

[0084] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.

[0085] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A method for analyzing code modification content, characterized in that, The code modification analysis method includes: Obtain information on the code differences before and after modifications to the target project; The code difference information is parsed based on the abstract syntax tree, and the code difference information is divided into multiple modification points with the method as the smallest unit. Each modification point corresponds to the code change of a single method. Input the difference code and the complete code of the method corresponding to each modification point into the large model to obtain a summary of the modifications; Based on the intra-class and inter-class call relationships of the methods to which each modification point belongs, a call chain analysis is performed to obtain a call chain analysis document; Based on the summary of the modifications and the call chain analysis document, code change analysis results are generated.

2. The code modification content analysis method as described in claim 1, characterized in that, The steps for obtaining information on code differences before and after modification of the target project code include: Obtain the hash values ​​of the target project code before and after modification, as input by the user; Based on the hash value, the `git diff` command is executed in the command-line terminal to obtain the code difference information.

3. The code modification content analysis method as described in claim 1, characterized in that, The steps of parsing the code difference information based on the abstract syntax tree, segmenting the code difference information by method as the smallest unit to obtain multiple modification points, and each modification point corresponding to a code change of a single method, include: Based on the code difference information, determine the files where code changes occurred and the range of changed code lines; The file is parsed using an abstract syntax tree to obtain the name, start line, and end line of all methods in the file. The range of changed code lines is compared with the start and end lines of each method. When the range of changed code lines spans the start and end lines of at least two methods, the code difference information is split into multiple modification points according to the method boundaries, with each modification point corresponding to the code change of a single method.

4. The code modification content analysis method as described in claim 1, characterized in that, After determining the file and the range of changed lines of code based on the code difference information, the code modification analysis method further includes: Get the type of the file that has undergone code changes; When the type is a preset configuration file type, the file whose code has changed is marked as a configuration modification, and the modification point corresponding to the configuration modification is recorded.

5. The code modification content analysis method as described in claim 1, characterized in that, The step of inputting the difference code and the complete code of the method corresponding to each modification point into the large model to obtain a summary of the modifications includes: Obtain the difference code corresponding to the modified point and the complete code of the method to which it belongs; The difference code and the complete code are filled into the preset prompt word template, and the filled prompt words are input into the large model to obtain the code change summary of the modification points output by the large model; After traversing all the modification points, summarize the code changes at each modification point to obtain the summary of the modifications.

6. The code modification content analysis method as described in claim 1, characterized in that, The steps for performing call chain analysis based on the intra-class and inter-class call relationships of the methods to which each modification point belongs, and obtaining the call chain analysis document, include: Based on the abstract syntax tree, all class files in the target project are parsed. The inter-class call relationship is constructed according to the dependency injection markup in each class file. The method body of each class file is parsed through the abstract syntax tree to identify the same type of methods called in each method body and construct the intra-class call relationship. Based on the intra-class call relationship, determine all intra-class methods that directly or indirectly call the method to which the modification point belongs, and combine the method to which the modification point belongs and all intra-class methods into an initial method set; Based on the inter-class call relationships, identify all methods that have cross-class upper-level calls from the initial method set to form a set of methods to be analyzed; For each method in the set of methods to be analyzed, the cross-class upper-level calling method is traced upwards by combining the intra-class calling relationship and the inter-class calling relationship. If the traced cross-class upper-level calling method has further cross-class upper-level calls, the tracing continues until the traced cross-class upper-level calling method does not have cross-class upper-level calls in the inter-class calling relationship. The finally traced cross-class upper-level calling method is recorded as the top-level method. The call chain analysis document is generated based on each modification point and the top-level method traced back to each modification point.

7. The code modification content analysis method as described in claim 6, characterized in that, The step of generating the call chain analysis document based on each modification point and the top-level method traced back to each modification point includes: Each modification point is grouped based on the top-level method, with each group containing the same top-level method and all modification points affected by the top-level method. For each group, based on the intra-class call relationship and the inter-class call relationship, a call chain is constructed from each modification point within the group to the corresponding top-level method, and the call chains of all groups are integrated into a directed acyclic graph, where each node of the directed acyclic graph represents a method call; Based on the directed acyclic graph and the grouping information of each group, the call chain analysis document is generated. The call chain analysis document records each top-level method and the affected modification points corresponding to the top-level method, as well as the complete call path from each modification point to the corresponding top-level method.

8. The code modification content analysis method as described in claim 1, characterized in that, The steps for generating code change analysis results based on the summary of the modifications and the call chain analysis document include: Based on the call chain information, the summary of modifications is associated with each method call node in the call chain information to generate a mapping relationship between the method call nodes and the summary of modifications; Based on the mapping relationship and the call chain analysis document, code change analysis results are generated.

9. A code modification content analysis device, characterized in that, The code modification content analysis device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the code modification content analysis method as described in any one of claims 1 to 8.

10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the code modification content analysis method as described in any one of claims 1 to 8.