Code repairing method and device, electronic equipment and readable storage medium

By obtaining the code syntax tree and calling the preset repair component to automatically repair problems in the code, the problem of inefficient code repair is solved, and comprehensive automatic repair of different types of code is achieved, which improves the repair efficiency.

CN119149411APending Publication Date: 2024-12-17CHINA MERCHANTS BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411176384.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-26
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

In the prior art, code repair is inefficient, manual repair work is large and easy to miss, resulting in inefficient code repair.

Method used

By obtaining the code syntax tree, traverse the tree structure to find problem code that does not comply with the preset code quality rules, and call preset repair components (including code parsing components and large language models) to automatically repair different types of problem code, including simple types , comment defect types, variable naming types, and complex types.

Benefits of technology

It realizes automatic repair of codes of different problem types, reduces manual repair workload, improves code repair efficiency, and reduces omissions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149411A_ABST
    Figure CN119149411A_ABST
Patent Text Reader

Abstract

The invention discloses a code repairing method and device, electronic equipment and a readable storage medium, and relates to the technical field of software maintenance, and the code repairing method comprises the following steps: obtaining a code syntax tree of a to-be-repaired code, traversing the code syntax tree, and searching a problem code which does not accord with a preset code quality rule from the code syntax tree; according to the question type of the question code, a preset repair component of the question type is called, the question code is repaired, and the question type comprises at least one of a simple type, an annotation defect type, a variable naming type and a complex type. The preset repair component comprises at least one of a preset code analysis component and a preset large language model. The technical problem of low code repair efficiency is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software maintenance technology, and in particular to a code repair method, device, electronic device, and readable storage medium. Background Art

[0002] In the process of software development and maintenance, ensuring the quality of the code is the key to ensuring the normal operation of the software. Currently, various code quality issues found during code quality scanning are mainly repaired by manual modification or global search and replacement, but the workload of manual repair is large and it is easy to miss something, resulting in low code repair efficiency.

[0003] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention

[0004] The main purpose of this application is to provide a code repair method, device, electronic device and readable storage medium, aiming to solve the technical problem of low code repair efficiency.

[0005] To achieve the above purpose, the present application provides a code repair method, the method comprising:

[0006] Obtain a code syntax tree of the code to be repaired, traverse the code syntax tree, and search the code syntax tree for problematic code that does not meet preset code quality rules;

[0007] According to the problem type of the problem code, a preset repair component of the problem type is called to repair the problem code, wherein the problem type includes at least one of the following: a simple type, an annotation defect type, a variable naming type, and a complex type, and the preset repair component includes at least one of a preset code parsing component and a preset large language model.

[0008] In one embodiment, the preset repair component includes a preset code parsing component; the step of calling the preset repair component of the problem type according to the problem type of the problem code and repairing the problem code includes:

[0009] In the case where the problem type of the problem code is a simple type, calling the preset code parsing component to find the code position of the problem code in the code syntax tree, wherein the simple type includes a useless subtype and a position abnormal subtype;

[0010] If the problem code belongs to the useless subtype, calling the preset code parsing component to delete the problem code at the code position;

[0011] If the problem code belongs to the position abnormality subtype, the standard position of the problem code is found in the preset code logic sequence rule, the code parsing component is called, and the code position of the problem code is adjusted to the standard position to repair the problem code.

[0012] In one embodiment, the step of calling a preset repair component of the problem type according to the problem type of the problem code to repair the problem code includes:

[0013] In the case where the problem type of the problem code is an annotation defect type, generating an annotation repair statement according to the problem code and a preset annotation prompt;

[0014] Inputting the comment repair statement into the preset large language model to generate comment supplementary information of the problem code;

[0015] According to the preset code parsing component, searching for the code position of the problem code in the code syntax tree;

[0016] The comment supplementary information is added at the code location to fix the problematic code.

[0017] In one embodiment, the step of calling a preset repair component of the problem type according to the problem type of the problem code to repair the problem code includes:

[0018] In the case where the problem type of the problem code is a variable naming type, generating a variable repair statement according to a preset variable prompt and the problem code;

[0019] Inputting the variable repair statement into the preset large language model to generate a standard repair variable for the problem code;

[0020] According to the preset code parsing component, searching for the code position of the problem code in the code syntax tree;

[0021] According to the code position, the problem code is replaced with the standard repair variable to repair the problem code.

[0022] In one embodiment, the problem code includes a target repair code; the step of calling a preset repair component of the problem type according to the problem type of the problem code to repair the problem code includes:

[0023] When the problem type of the problem code is a complex type, obtaining a code call relationship graph of the code to be repaired;

[0024] Receiving an external problem repair instruction input based on the problem code, and searching a preset code vector database for a target repair code corresponding to the problem repair instruction;

[0025] Calling the preset large language model, repairing the code to be repaired according to the target repair code, the code call relationship graph and the problem repair indication, to obtain a first code to be tested;

[0026] Testing the first code to be tested to obtain a first test result;

[0027] If the first test result indicates that the test passed, it is determined that the repair of the code to be repaired is completed.

[0028] In one embodiment, the step of calling the preset large language model, repairing the code to be repaired according to the target repair code, the code call relationship and the problem repair indication, and obtaining the first code to be tested further includes:

[0029] Calling the preset large language model, searching the code associated with the target repair code in the code call relationship graph;

[0030] Calling the preset large language model, determining a first repair operation for the target repair code in the problem repair instruction, and determining a second repair operation for the associated code according to a calling relationship between the associated code and the target repair code;

[0031] The first repair operation is performed on the target repair code, and the second repair operation is performed on the associated code, so as to repair the code to be repaired to obtain a first code to be tested.

[0032] In one embodiment, after the step of testing the first code to be tested to obtain a first test result, the method further includes:

[0033] If the first test result indicates that the test fails, calling a preset test analysis model to determine an exception code and a corresponding exception cause from the first test result;

[0034] Inputting the exception code and the exception cause into a preset large language model, repairing the code to be repaired according to the exception code and the exception cause, and obtaining a second code to be tested;

[0035] Testing the second code to be tested to obtain a second test result;

[0036] If the second test result meets the preset exception condition, the first test result is updated to the second test result, and the step of calling the preset test analysis model to determine the exception code and the corresponding exception cause from the first test result is returned until the second test result does not meet the preset exception condition.

[0037] In addition, to achieve the above-mentioned purpose, the present application also provides a code repair device, the device comprising:

[0038] An acquisition module is used to acquire a code syntax tree of the code to be repaired, traverse the code syntax tree, and search for problematic codes that do not meet preset code quality rules from the code syntax tree;

[0039] An automatic repair module is used to call a preset repair component of the problem type according to the problem type of the problem code to repair the problem code, wherein the problem type includes at least one of the following: a simple type, an annotation defect type, a variable naming type, and a complex type, and the preset repair component includes at least one of a preset code parsing component and a preset large language model.

[0040] In addition, to achieve the above-mentioned purpose, the present application also provides an electronic device, which includes: a memory, a processor, and a program of the code repair method stored in the memory and executable on the processor. When the program of the code repair method is executed by the processor, the steps of the code repair method as described above can be implemented.

[0041] In addition, to achieve the above-mentioned purpose, the present application also provides a computer-readable storage medium, on which is stored a program for implementing the code repair method, and when the program of the code repair method is executed by a processor, the steps of the code repair method as described above are implemented.

[0042] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned code repair method when executed by a processor.

[0043] One or more technical solutions proposed in the present application have at least the following technical effects: since the present application can obtain the code syntax tree of the code to be repaired, traverse the code syntax tree, and search the code syntax tree for the problem code that does not meet the preset code quality rules, then the preset repair component corresponding to the problem type of the problem code can be called, for example, the problem code can be repaired in a targeted manner using a preset code parsing component and / or a preset large language model, thereby achieving automatic repair of the problem code. Since the problem type includes at least a simple type, a complex type, an annotation defect type, and a variable naming type, it is convenient to achieve comprehensive and automatic repair of problem codes of different problem types, without the need for manual repair of each problem code, thereby reducing the workload of manual repair and reducing the occurrence of omissions, thereby improving the efficiency of code repair. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] The accompanying drawings herein are incorporated in and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the description, are used to explain the principles of the present application.

[0045] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0046] Figure 1 This is a flow chart of an embodiment of a code repair method of the present application;

[0047] Figure 2 This is a flowchart of another embodiment of the code repair method of the present application;

[0048] Figure 3 This is a flowchart of an example of a code repair method for this application;

[0049] Figure 4 This is a schematic diagram of the system structure of the code repair device according to the embodiment of the present application;

[0050] Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the code repair method in the embodiment of the present application.

[0051] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0052] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0053] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0054] The problems found in the code quality scanning process can be divided into two categories, simple problems and complex problems. Simple problems account for a small proportion but their corresponding repair time accounts for a relatively large proportion, while complex problems account for a small proportion but their corresponding repair time accounts for a relatively small proportion. Regardless of whether it is a simple problem or a complex problem, most of them need to be repaired. For simple problems, repair is boring, the workload is large, and there is easy to be repetitive work (for example, when there are multiple identical simple problems in the code, it is necessary to repeatedly repair multiple identical problems). If some variables in the code are replaced in batches manually, replacement errors are also prone to occur, resulting in low accuracy of code repair and more time spent. For complex problems, when manually repairing complex problems, new problems are easily introduced, making it impossible to successfully complete the repair of complex problems. It can be seen that there are currently technical problems with low code repair efficiency and poor results.

[0055] In this regard, an embodiment of the present application provides a code repair method that can automatically repair problematic code in the code to be repaired, so that whether it is a simple problem or a complex problem, it can be repaired using the technical solution of the embodiment of the present application, thereby improving the efficiency of code repair.

[0056] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device that can realize the above functions.

[0057] Based on this, the embodiment of the present application provides a code repair method, referring to Figure 1 , Figure 1 This is a flowchart of an embodiment of the code repair method of the present application.

[0058] In this embodiment, the code repair method includes steps S10 to S20:

[0059] Step S10, obtaining a code syntax tree of the code to be repaired, traversing the code syntax tree, and searching the code syntax tree for problematic codes that do not comply with preset code quality rules;

[0060] It should be noted that the code syntax tree is a form of representation of the code to be repaired. The code syntax tree is AST (Abstract Syntax Tree), which is a tree representation of the structure and syntax information of the code to be repaired. The code syntax tree consists of multiple nodes, and the nodes can be connected through parent-child relationships, so as to reflect the relationship between the codes in the code to be repaired, and the nodes can also include the code location where the corresponding code is located.

[0061] Based on the language type of the code to be repaired, the preset code parsing component of the code to be repaired can be determined, and the code to be repaired can be converted into a code syntax tree through the code parsing component; code languages ​​can be divided into Java (an object-oriented programming language), python (an interpreted, high-level programming, general-purpose programming language), JS (JavaScript, a lightweight interpreted or just-in-time compiled programming language with function priority), etc. Different code languages ​​have their own corresponding preset code parsing components. For example, for Java, its corresponding preset code parsing component is javaParser (java parser). When the code language of the code to be repaired is Java, javaParser can be used to convert the code to be repaired into a code syntax tree.

[0062] The code to be repaired is the code that needs to be inspected for code quality. There may be one or more problem codes in the code to be repaired, or there may be no problem code. Problem code refers to the code in the code to be repaired that does not meet the preset code quality rules. Problem code can be variables with irregular naming, code with inaccurate code location, etc. The preset code quality rules can be determined in advance based on actual conditions. The preset code quality rules can be displayed in the form of a table. The preset code quality rules can be divided into simple quality rules, comment quality rules, variable naming rules, and complex quality rules. For example, simple quality rules include: the position of the code segment should comply with the preset code logic sequence rules, the imported code segment in the code module should be called by the code module, and the variables in the code to be repaired should be called, etc.; the code that does not meet the simple quality rules is a simple type of problem code; the code to be repaired can be composed of multiple code modules, and each code module can import code segments from other code modules for the code module to call the imported code segments. If the code module imports the code segment but does not actually call the code segment, the code segment can be considered as an invalid imported code segment, and the invalid imported code segment can be regarded as a problem code, and the invalid imported code segment belongs to the useless subtype; when a variable is defined in the code to be repaired, but the variable is not called by other codes in the code to be repaired, the uncalled variable is also considered to be a problem code, and the uncalled variable belongs to the useless subtype; when the position of the code segment does not comply with the preset code logic sequence rules, the position of the code segment is considered to be inaccurate, and the inaccurate position of the code segment belongs to the position abnormal subtype. The code segment refers to one or more lines of code in the code to be repaired. By traversing the code syntax tree, the problematic code that does not meet the simple quality rules can be identified from the code syntax tree.

[0063] For example, the comment quality rules include: the class in the code to be repaired should have comments, and the method code segment of the class should have comments; the code that does not meet the comment quality rules belongs to the problem code of the comment defect type; class (Class) is a core concept in object-oriented programming (OOP), which allows programmers to define the properties and behaviors of objects. A class is an instance of a group of objects with the same properties (properties are used to define the state or data of the object) and the same methods or functions. The method of a class refers to the function defined in the class. When there is no comment on the class in the code to be repaired, it means that the class belongs to the problem code, and when there is no comment on the method in the class, it means that the method of the class belongs to the problem code. The problem code that does not meet the comment quality rules can be determined from the code syntax tree by traversing the code syntax tree.

[0064] For example, the variable naming rules include: the length of the variable should be greater than the preset character threshold, and the format of the variable should comply with the preset variable format; the code that does not comply with the variable naming rules belongs to the problem code of the variable naming type; for example, when the length of the variable is less than the preset character threshold, the variable is determined to be a problem code, the preset character threshold can be 2 characters, and when the format of the variable does not comply with the preset variable format, the variable is determined to be a problem code. For example, the preset variable format can be: variables should not be named using spaces, special characters, etc. The problem code that does not comply with the variable naming rules can be determined from the code syntax tree by traversing the code syntax tree.

[0065] For example, the complex quality rules include: the number of parameters of the class in the code to be repaired should be less than the preset first quantity threshold, and the parameter may refer to the parameters of the variables in the class, etc.; the length of the function body in the code to be repaired should be less than the preset function length threshold, and the total number of code lines of the code module should be less than the preset second quantity threshold. Code that does not meet the complex quality rules belongs to complex type problem code, wherein the function body length is the total number of code lines corresponding to the function. For example, when the length of the function is greater than the preset function length threshold, it is determined that the function belongs to the problem code; when the number of parameters in the class is greater than the preset first quantity threshold, it is determined that the class belongs to the problem code; when the total number of code lines in the class or the total number of code lines in the code module is greater than the preset second quantity threshold, it is determined that the class is the problem code. For example, the preset quantity threshold is 10,000 lines, etc. The problem code that does not meet the complex quality rules can be determined from the code syntax tree by traversing the code syntax tree. Further, the code syntax tree can be traversed through the Visitor (visitor mode) to find the problem code in the code to be repaired.

[0066] Step S20: According to the problem type of the problem code, a preset repair component of the problem type is called to repair the problem code.

[0067] It should be noted that the problem types can be divided into simple types, annotation defect types, variable naming types, and complex types, etc. The problem type of the problem code can be determined based on preset quality rules. When the problem code does not meet the simple quality rules, the problem code is determined to be a simple type. When the problem code does not meet the annotation quality rules, the problem code is determined to be an annotation defect type. When the problem code does not meet the variable naming rules, the problem code is determined to be a variable naming type. When the problem code does not meet the complex quality rules, the problem code is determined to be a complex type.

[0068] Different problem types can correspond to different preset repair components, so the preset repair component corresponding to the problem type can be called to repair the problem code, thereby repairing the code to be repaired. Problem codes belonging to the same problem type can be stored in the same list, so as to facilitate fast batch repair of problem codes in the same list. For example, complex types, simple types, variable naming types, and comment defect types can each correspond to a list, and each list stores the corresponding problem code.

[0069] For example, there may be one or more problem codes in the code to be repaired, or there may be no problem code. When there is no problem code in the code to be repaired, there is no need to repair the code to be repaired, and the repair of the code to be repaired can be ended. When there are one or more problem codes in the code to be repaired, the corresponding problem codes are repaired according to the preset repair components corresponding to each problem code to complete the repair of the code to be repaired. The problem code can be repaired in the code syntax tree. After all the problem repair codes are repaired, the repaired code syntax tree can be restored to obtain the repaired code.

[0070] Since the embodiments of the present application can traverse the code syntax tree based on preset code quality rules, problem codes with quality problems can be found from the code syntax tree. Furthermore, the embodiments of the present application can call the preset repair component corresponding to the problem type of the problem code, and repair the problem code in a targeted manner, thereby realizing automatic repair of the problem code, and then facilitating the comprehensive and automatic repair of problem codes of different problem types, without the need for manual repair of each problem code, reducing the workload of manual repair, and reducing the occurrence of omissions, thereby improving the efficiency of code repair.

[0071] In a feasible embodiment, step S20 includes steps S21 to S23:

[0072] Step S21, when the problem type of the problem code is a simple type, calling the preset code parsing component to find the code position of the problem code in the code syntax tree, wherein the simple type includes a useless subtype and a position abnormal subtype;

[0073] It should be noted that the preset code parsing component is used to find the code location of the problem code in the code syntax tree, and the preset code parsing component can also be used to convert the code to be repaired into a code syntax tree. The code location can refer to the node location of the problem code in the code syntax tree, etc. Simple types can be divided into useless subtypes and position abnormal subtypes. The useless subtype refers to the code that has not been called, and the position abnormal subtype refers to the code with abnormal position.

[0074] Step S22, if the problem code belongs to the useless subtype, calling the preset code parsing component to delete the problem code at the code position;

[0075] It should be noted that when the problem code belongs to the useless subtype, it means that the problem code has not been called. If it has not been called, the problem code can be deleted to reduce the content of the code to be repaired, and it will not affect the operation of the code to be repaired. The problem code belonging to the useless subtype can be divided into the useless variable class and the useless import class. The useless variable class refers to the variables that have not been called, and the useless import class refers to the code segment in the imported code module that has not been called by the code module.

[0076] Step S23, if the problem code belongs to the position abnormality subtype, then find the standard position of the problem code in the preset code logic sequence rule, call the code parsing component, adjust the code position of the problem code to the standard position, so as to repair the problem code.

[0077] It should be noted that the preset code logical order rules can be pre-defined, and the preset code logical order can include the order in which each function appears, etc. When there is a code that does not conform to the preset code logical order, the code position of the problem code belonging to the position abnormality subtype can be adjusted to the standard position according to the preset code logical order.

[0078] Exemplarily, when the problem type of the problem code is a simple type, the preset code parsing component is called to find the code position of the problem code in the code syntax tree; if the problem code belongs to a useless variable class or a useless import class, the preset code parsing component can be called to delete the problem code at the code position; if the problem code belongs to a position abnormality subtype, the standard position of the problem code is found in the preset code logical sequence rules, and the code parsing component is called to adjust the code position of the problem code to the standard position to repair the problem code.

[0079] This embodiment repairs simple types of problem codes, thereby eliminating the need for manual search and repair by humans, reducing manual workload and improving the efficiency of repairing simple types of problem codes.

[0080] Furthermore, in a feasible embodiment, step S20 further includes steps A10 to A40:

[0081] Step A10, when the problem type of the problem code is a comment defect type, generating a comment repair statement according to the problem code and a preset comment prompt;

[0082] Step A20, inputting the comment repair statement into the preset large language model to generate comment supplementary information of the problem code;

[0083] Step A30, searching for the code position of the problem code in the code syntax tree according to the preset code parsing component;

[0084] Step A40, adding the annotation supplementary information at the code location to repair the problematic code.

[0085] It should be noted that when the problem code belongs to the comment defect type, it means that the problem code lacks comments and needs to add comments to the problem code, so the preset large language model can be called to generate comment supplementary information for the problem code to add the comment supplementary information to the code position.

[0086] The comment repair statement is a prompt for prompting the preset large language model to generate the comment supplementary information of the problem code; the preset comment prompt can be a prompt language template for prompting the preset large language model to generate the comment supplementary information of the problem code, the problem code can be substituted into the preset code position of the preset comment prompt to generate the comment repair statement, the preset comment prompt can be a natural language, the preset code position is the position where the problem code should be placed in the preset comment prompt, the preset comment prompt can be determined based on the preset large language model, and the preset comment prompts corresponding to different preset large language models may be different. For example, the preset large language model may be an LLM model (Large Language Model), and the preset comment prompt may be: Please add a comment to "A". Where A is the position of the problem code. The above example is one example, and this embodiment does not make specific restrictions on this.

[0087] The annotation supplementary information refers to the annotation of the problem code, which can be used to describe the function implemented by the problem code, etc. The annotation supplementary information can be added at the beginning or end of the problem code, etc., which is not specifically limited in this embodiment.

[0088] Exemplarily, when the problem type of the problem code is a comment defect type, a comment repair statement is generated according to a preset comment prompt and the problem code, the comment repair statement is input into a preset large language model, the comment supplementary information of the problem code is generated, and the comment supplementary information is added to the problem code according to the code position of the problem code to repair the problem code. Among them, when there are multiple lines of code in the problem code, the code position may include the starting position and the ending position of the problem code, for example, the starting position is the starting line of the problem code, and the ending position is the ending line of the problem code. When the problem code is a line of code, the code position is the line where the problem code is located. Specifically, the code position may refer to the node position of the problem code in the code syntax tree, etc. The node of the problem code in the code syntax tree can be determined based on the node position, and the starting position and the ending position of the problem code in the source code to be repaired can be determined based on the node, etc., and then the comment supplementary information can be added to the starting position or the ending position of the problem code represented by the node.

[0089] This embodiment adds annotation supplementary information to the problematic code with annotation defects, so that the classes and methods in the code to be repaired can have their own corresponding annotations, thereby making the code to be repaired more complete and clearer.

[0090] In a feasible embodiment, step S20 further includes steps B10 to B40:

[0091] Step B10, when the problem type of the problem code is a variable naming type, generating a variable repair statement according to a preset variable prompt and the problem code;

[0092] Step B20, inputting the variable repair statement into the preset large language model to generate a standard repair variable for the problem code;

[0093] Step B30, searching for the code position of the problem code in the code syntax tree according to the preset code parsing component;

[0094] Step B40, according to the code position, replace the problem code with the standard repair variable to repair the problem code.

[0095] It should be noted that when the problem code belongs to the variable naming type, it means that the problem code has the problem of non-standard variable naming, for example, the variable name length is less than the preset character threshold, such as the name length is less than 2 characters, etc., or there are spaces, special characters, etc. in the variable name.

[0096] The preset variable prompt is a prompt template for prompting the preset large language model to modify the name of the variable corresponding to the problem code. The preset variable prompt can be a natural language, and the variable repair statement is used to prompt the preset large language model to generate a standard repair variable for the variable corresponding to the problem code. The standard repair variable refers to a variable that complies with the variable naming rules corresponding to the problem code.

[0097] Exemplarily, when the problem type of the problem code is a variable naming type, the problem code is substituted into a preset variable prompt to generate a variable repair statement; the variable repair statement is input into a preset large language model to generate a standard repair variable for the problem code, and a preset code parsing component is called to find the code position of the problem code in the code syntax tree, and according to the code position, the problem code in the code syntax tree is replaced with the standard repair variable to repair the problem code. Since the code syntax tree is determined by the preset code parsing component and the code to be repaired, the code position of the problem code in the code syntax tree can also be found by the preset code parsing component.

[0098] This embodiment can automatically modify the problem of simple variable naming irregularities by modifying the problem code with irregular variable naming, without manual intervention, thereby improving the efficiency of code repair. In addition, there may be multiple problem codes with irregular variable naming in the code to be repaired. This embodiment automatically determines the standard repair variable through the preset large language model, and automatically replaces the problem code with the standard repair variable, thereby reducing manual repetitive work and further improving the efficiency of code repair. Since the annotation repair statement can be input into the preset large language model, the preset large language model can be instructed to generate annotation supplementary information for the problem code. When the variable repair statement is input into the preset large language model, the preset large language model can be instructed to generate the standard repair variable.

[0099] Further, see Figure 2 In a feasible embodiment, step S20 further includes steps C10 to C50:

[0100] Step C10, when the problem type of the problem code is a complex type, obtaining a code call relationship graph of the code to be repaired;

[0101] The complex type includes that the length of the function body in the problem code is greater than a preset function length threshold, and / or the number of variables in the problem code is greater than a preset first number threshold;

[0102] It should be noted that when the problem code is of a complex type, the problem with the problem code may be too many parameters, too long functions, too high complexity, etc., and too high complexity can be manifested as the number of code lines of the class being greater than a preset number threshold, for example, the number of code lines of the class being greater than 10,000 lines, etc., indicating that the complexity of the class is too high, and the class can be determined as a problem code. Complex types can also include the total number of code lines of a code module being greater than a preset second number threshold.

[0103] The code call relationship graph can be obtained from the preset graph database. When it is necessary to find the calling or called relationship of a function in the code to be repaired, the code call relationship graph can be viewed in the preset graph database, and the calling or called relationship of the function can be found in the code call relationship graph, thereby improving the efficiency of finding the calling or called relationship. The code call relationship graph is used to represent the relationship between various classes, methods corresponding to each class, interfaces, and properties of each class in the code to be repaired. For example, the inclusion relationship: represents the relationship between the class containing the method or property, and another example is the inheritance relationship: represents the inheritance relationship between classes, etc. This embodiment does not make specific limitations on this. The corresponding identifiers of various classes, methods corresponding to each class, interfaces, and functions existing in the code to be repaired can be determined, and the relationship between each identifier can be determined. According to the relationship between each identifier, the code call relationship graph of the code to be repaired stored in the preset graph database is determined. The preset graph database can be Neo4j (graph database).

[0104] Step C20, receiving a problem repair instruction inputted externally based on the problem code, and searching a preset code vector database for a target repair code corresponding to the problem repair instruction;

[0105] It should be noted that the problem repair instruction can be initiated by the maintenance personnel of the code to be repaired, and the external person can be the maintenance personnel. When the problem code belonging to a complex relationship is found by traversing the code syntax tree, the relevant maintenance personnel can be prompted to check the problem code and determine the cause of the problem that the problem code belongs to a complex type, so as to input the problem repair instruction to the device where the code to be repaired is located. Since traversing the code syntax tree can find the problem code belonging to a complex type, but cannot traverse the reason why the problem code belongs to a complex type, and thus it is difficult to directly repair the problem code, it is necessary to obtain the problem repair instruction to instruct the preset large language model to repair the problem code.

[0106] The problem repair instruction is used to instruct the preset large language model to repair the problem code. The problem repair text can be determined from the problem repair instruction, and the problem repair text can be a natural language. For example, when the maintenance personnel determine that the problem code belongs to a complex type, it is because the problem code is mixed with multiple business logics. For example, the problem code may be a class L, and the total number of lines of code of class L may be more than 10,000 lines. The reason why the code has more than 10,000 lines is that class L includes multiple business logics such as business logic A, business logic B, and business logic C. Then the problem repair instruction given by the maintenance personnel may be: extract the functions related to business logic A from class L, and classify the extracted functions into a new class. Thereby, the complexity of class L can be reduced.

[0107] Since the problem repair instruction is expressed in the form of natural language, after being directly input into the preset large language model, the preset large language model may not know what the code content referred to by the problem repair instruction is. In this embodiment, the target repair code corresponding to the problem repair instruction is searched in the preset code vector database, so that the preset large language model can know that the target repair code is to be repaired. The target repair code is the code in the problem code corresponding to the problem repair instruction. Using the previous example, the target repair code is all functions related to business logic A in class L, including functions 1, 2, 3, etc. The above is only an example, and this embodiment does not make specific restrictions on this.

[0108] The preset code vector database stores the mapping relationship between natural language and code, so that the target repair code corresponding to the problem repair indication can be found in the code vector database.

[0109] Step C30, calling the preset large language model, repairing the code to be repaired according to the target repair code, the code call relationship diagram and the problem repair indication, and obtaining a first code to be tested;

[0110] Step C40, testing the first code to be tested to obtain a first test result;

[0111] Step C50: If the first test result indicates that the test is passed, it is determined that the repair of the code to be repaired is completed.

[0112] It should be noted that the preset large language model can repair the problem code based on the target repair code, the problem repair indication and the code call relationship diagram, that is, repair the code to be repaired, so as to get the first code to be tested. The first code to be tested refers to the code to be repaired that has repaired a complex type. Since the repair of complex types of problem codes is more complicated, in order to ensure the accuracy of the repair, it is necessary to call the preset test component to test the first code to be tested and obtain the first test result. The first test result can be used to describe whether the first code to be tested passes the test. For example, when the code to be tested is Java, the preset test component can be JUnit (unit testing framework) or the like.

[0113] The preset exception condition indicates that the first test result fails the test. When the first test result does not meet the preset exception condition, it means that the first test result passes the test, which means that the preset large language model accurately repairs the problem code belonging to the complex type, and the repair of the code to be repaired can be completed.

[0114] The preset test component is used to perform automated testing on the first code to be tested. When the first test code fails the test, it means that the code to be repaired has not been repaired successfully, and the code to be repaired needs to be repaired again.

[0115] Exemplarily, when the problem type of the problem code is a complex type, the code to be repaired is imported into the preset graph database, the code call relationship graph of the code to be repaired is obtained, and saved in the preset graph database, so that it is convenient to view the code call relationship graph directly in the preset graph database later, and the code viewing efficiency is improved. The prompt information that there is a complex type of problem code in the code to be repaired can be sent to the relevant maintenance personnel to prompt the maintenance personnel that there is a complex type of problem code in the code to be repaired, so that the maintenance personnel can view the problem code in the code to be repaired, and input the problem repair instruction to the device where the code to be repaired is located, so that the device where the code to be repaired is located can receive the problem repair instruction, and the device will search for the target repair code corresponding to the problem repair instruction in the preset code vector database, and will call the preset large language model to repair the code to be repaired according to the target repair code, the code call relationship and the problem repair instruction to obtain the first test code. Call the preset test component to test the first code to be tested to obtain a first test result. When the first test result does not meet the preset abnormal condition, the repair of the code to be repaired is completed. Since the problem repair instruction can be input to the preset large language model, it can refer to that the preset large language model repairs the problem code according to the problem repair instruction. Since the problem repair instructions, comment repair statements, and variable repair statements are all different, and the preset large language model can output content corresponding to the data based on the input data, the preset large language model can generate comment supplementary information based on the input comment repair statements, and can also generate standard repair variables based on the input variable repair statements, and can also repair complex types of problem codes based on the input problem repair instructions.

[0116] This embodiment improves the degree of automated repair of problem codes by performing repairs using a preset large language model. Problem codes can be automatically repaired by only giving problem repair instructions, thereby reducing the manual repair process and improving the efficiency of code repair. Furthermore, since the first code to be tested is also tested, it is easy to ensure the accuracy of the repair of the code to be repaired.

[0117] In a feasible embodiment, step C30 further includes steps C31 to C33:

[0118] Step C31, calling the preset large language model, and searching the associated code with which the target repair code has a calling relationship in the code calling relationship graph;

[0119] Step C32, calling the preset large language model, determining a first repair operation for the target repair code in the problem repair instruction, and determining a second repair operation for the associated code according to a calling relationship between the associated code and the target repair code;

[0120] Step C33: performing a repair operation on the target repair code and the associated code to repair the code to be repaired to obtain a first code to be tested.

[0121] It should be noted that the code call relationship diagram represents the calling relationship and called relationship between each code segment in the code to be repaired, and the code segment refers to the class, method, function, variable, etc. in the code to be repaired. The first repair operation refers to the behavior of repairing the target repair code, for example, the repair operation can be an extraction operation, a call path adjustment operation, etc. The second repair operation is the behavior of repairing the associated code, and the second repair operation can also be an extraction operation, a call path operation, etc. The first repair operations can be the same or different.

[0122] Since the problem repair instruction can be used to instruct the preset large language model to repair the target repair code, the first repair operation for the target repair code can be determined from the problem repair instruction. For example, the problem repair instruction includes extracting functions related to business logic A to obtain a new class, then the target repair code can be function K related to business logic A, and the first repair operation can be extracting function K and placing the function K in the new class. The above is just one example, and this embodiment does not specifically limit this.

[0123] When the first repair operation is performed on the target repair code, since there is a calling relationship between the associated code and the target repair code (for example, it may be a calling relationship in which the associated code calls the target repair code, or the target repair code calls the associated code, etc.), when the first repair operation is performed on the target repair code, it may affect the associated code. If the associated code is not adjusted, then the associated code may be abnormal. Therefore, this embodiment determines the second repair operation of the associated code by presetting a large language model, a calling relationship between the associated code and the target repair code, thereby facilitating the guarantee that the associated code will not be abnormal after the target repair code is repaired. For example, when the target repair code is extracted into a new class, the second repair operation may be: adjusting the calling path between the associated code and the target repair code, thereby ensuring that the associated code and the target repair code can be called normally.

[0124] Exemplarily, a preset large language model is called, and associated code that has a calling relationship with the target repair code is searched in the code call relationship graph, a first repair operation for the target repair code is determined in the problem repair indication, and a second repair operation for the associated code is determined, and the first repair operation is performed on the target repair code and the second repair operation is performed on the associated code to obtain a first code to be tested.

[0125] This embodiment performs the second repair operation on the associated code, thereby ensuring that the associated code related to the target repair code will not be abnormal due to the adjustment of the target repair code, thereby ensuring the accuracy of the repair of the code to be repaired.

[0126] In a feasible embodiment, after step C40, steps C41 to C44 are further included:

[0127] Step C41, if the first test result indicates that the test fails, calling a preset test analysis model to determine an abnormality code and a corresponding abnormality cause from the first test result;

[0128] Step C42, inputting the exception code and the exception cause into a preset large language model, repairing the code to be repaired according to the exception code and the exception cause, and obtaining a second code to be tested;

[0129] Step C43, testing the second code to be tested to obtain a second test result;

[0130] Step C44, if the second test result meets the preset exception condition, the first test result is updated to the second test result, and the process returns to the step of calling the preset test analysis model to determine the exception code and the corresponding exception cause from the first test result until the second test result does not meet the preset exception condition.

[0131] It should be noted that when the first test result meets the preset abnormal condition, it means that the first test result indicates that the first code to be tested fails the test. In order to successfully repair the code to be repaired, the preset test analysis model can be called to determine the abnormal code and the corresponding abnormal cause from the first test result. The preset test analysis model can be obtained based on the training of the neural network model. The abnormal code is the code that failed the test in the first code to be tested, and the abnormal cause refers to the reason why the abnormal code failed the test. When the first code to be tested is automatically tested, it may be performed in modules. For example, the first module to be tested is divided into several modules, and these modules are tested separately to see whether they can pass the test. When any module fails the test, the module can be considered as an abnormal code. The abnormal code can be a target repair code, an associated code, or neither a target repair code nor an associated code.

[0132] Then, the abnormal code and the abnormal reason are input into the preset large language model, and the abnormal code is repaired by the preset large language model to repair the code to be repaired, thereby obtaining the second code to be tested. The second code to be tested refers to the code to be repaired with the abnormal code.

[0133] After obtaining the second code to be tested, it is still necessary to test the second code to be tested to obtain a second test result, so as to determine whether the second code to be tested can pass the test, so as to ensure the accuracy of repairing the code to be repaired.

[0134] Exemplarily, if the first test result meets the preset abnormal condition, the preset test analysis model is called to determine the abnormal code and the corresponding abnormal cause from the first test result; the abnormal code and the abnormal cause are input into the preset large language model, and the preset large language model can generate an abnormal repair operation of the abnormal code based on the abnormal cause, and the abnormal code is repaired through the abnormal repair operation to obtain the second code to be tested. The preset test component is called to perform an automated test on the second code to be tested to obtain the second test result. If the second test result does not meet the preset abnormal condition, it is determined that the repair of the code to be repaired is successful, and the repair of the code to be repaired can be ended. If the second test result meets the preset abnormal condition, the first test result is updated to the second test result, and the call to the preset test analysis model is returned to determine the abnormal code and the corresponding abnormal cause from the first test result until the second test result does not meet the preset abnormal condition. Thereby, it is easy to successfully implement the successful test of the code to be repaired. The accuracy of the repair of the code to be repaired is guaranteed.

[0135] Furthermore, the step of obtaining a preset test analysis model may include: determining the model to be trained, obtaining training samples, the training samples including test result samples, abnormal labels, the abnormal labels including abnormal code labels and corresponding abnormal cause labels; inputting the test result samples into the model to be trained, obtaining abnormal features, calculating the distance between the abnormal labels and the abnormal features, obtaining the training loss of the model to be trained, when the training loss is less than a preset loss threshold, using the model to be trained as the preset test analysis model, if the training loss is greater than or equal to the preset loss threshold, re-obtaining the training samples, and returning to the step: inputting the test result samples into the model to be trained to iteratively train the model to be trained until the training loss is less than the preset loss threshold.

[0136] For a better understanding of this embodiment, please refer to Figure 3 , Figure 3The overall flow chart of this embodiment is as follows: when the code to be repaired begins to be repaired, the language of the code to be repaired is first determined, and according to the language of the code to be repaired, the corresponding preset code parsing component is called to parse the code to be repaired into a code syntax tree. For example, when the code to be repaired is Java, JavaParser can be called to parse the code to be repaired into a code syntax tree. When the code to be repaired is Python, the Parser corresponding to Python can be called as the preset code parsing component of the code to be repaired to parse the code to be repaired into a code syntax tree. When the code to be repaired is Js, the Parser corresponding to Js can be called as the preset code parsing component of the code to be repaired to parse the code to be repaired into a code syntax tree. Regardless of the language of the code to be repaired, after the code to be repaired is parsed into a code syntax tree, the code syntax tree can be traversed to determine the problem code in the code to be repaired. After calling JavaParser to parse the code to be repaired into a code syntax tree, traverse the code syntax tree to find the problem code of the code to be repaired, and call the preset repair component corresponding to the problem type according to the problem type of the problem code to repair the problem code; after traversing the code syntax tree, if it is determined that there is no problem with the code to be repaired, then the repair of the code to be repaired is completed. When the problem type is a simple type, call the preset code parsing component to repair the problem code; end the repair of the simple type of problem code; when the problem type is a comment defect type, determine the comment repair statement according to the problem code and the preset comment prompt; call the preset large language The language model is used to determine the comment supplementary information of the problem code according to the comment repair statement, and the problem code is repaired according to the comment supplementary information, such as adding comment supplementary information to the code position of the problem code in the code syntax tree; the repair of the problem code of the comment defect type is ended; when the problem type is a variable naming type, the variable repair statement is determined according to the problem code and the preset variable prompt, and the preset large language model is called to determine the standard repair variable of the problem code according to the variable repair statement, and the problem code is repaired according to the standard repair variable, such as replacing the problem code with the standard repair variable, and the repair of the problem code of the variable naming type is ended.When the problem type is a complex type, the code to be repaired is saved in the Neo4j database to facilitate determining the code call relationship graph of the code to be repaired, calling the preset large language model, and repairing the problem code according to the code call relationship graph and the preset vector database. For example, an external problem repair instruction based on the problem code input is received, and a target repair code corresponding to the problem repair instruction is searched in the preset code vector database; the preset large language model is called, and the code to be repaired is repaired according to the target repair code, the code call relationship graph and the problem repair instruction; then the repaired code is automatically tested, for example, the first code to be tested is automatically tested, or the second code to be tested is automatically tested, etc. When the repaired code passes the automated test, the repair of the complex type of problem code is terminated. When the repaired code fails the automated test, the preset test analysis model is called to determine the abnormal code and the abnormal cause of the first test result, and then the preset large language model is called to repair the abnormal code based on the abnormal code and the abnormal cause, until the automated test of the repaired code passes, that is, until the second test result does not meet the preset abnormal condition, the repair of the complex type of problem code is terminated.

[0137] This application also provides a code repair device, please refer to Figure 4 , the code repair device includes:

[0138] An acquisition module 10 is used to acquire a code syntax tree of the code to be repaired, traverse the code syntax tree, and search for problematic codes that do not meet preset code quality rules from the code syntax tree;

[0139] The automatic repair module 20 is used to call a preset repair component of the problem type according to the problem type of the problem code to repair the problem code.

[0140] The code repair device provided by the present application adopts the code repair method in the above-mentioned embodiment, aiming to solve the technical problem of low code repair efficiency. Compared with the prior art, the beneficial effects of the code repair method provided by the embodiment of the present application are the same as the beneficial effects of the code repair method provided by the above-mentioned embodiment, and other technical features in the code repair device are the same as the features disclosed in the above-mentioned embodiment method, which will not be repeated here. The embodiment of the present application provides an electronic device, which can be a playback device, and the electronic device includes: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions that can be executed by at least one processor, and the instructions are executed by at least one processor so that at least one processor can execute the code repair method in the above-mentioned embodiment.

[0141] Reference below Figure 5, which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure. The electronic device in the embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0142] like Figure 5 As shown, the electronic device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which 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 to a random access memory (RAM) 1004. In RAM 1004, various programs and data required for the operation of the electronic device are also stored. The processing device 1001, ROM 1002, and RAM 1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems may be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device may allow the electronic device to communicate wirelessly or wired with other devices to exchange data. Although the electronic device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have instead.

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

[0144] The electronic device provided by the present application adopts the code repair method in the above-mentioned embodiment 1 to solve the technical problem of low code repair efficiency. Compared with the prior art, the beneficial effect of product flow data distribution provided by the embodiment of the present application is the same as the beneficial effect of the code repair method provided by the above-mentioned embodiment, and the other technical features in the code repair device are the same as the features disclosed by the above-mentioned embodiment method, which will not be repeated here. It should be understood that the various parts of the present disclosure can be implemented by hardware, software, firmware or a combination thereof. In the description of the above-mentioned embodiments, specific features, structures, materials or characteristics can be combined in a suitable manner in any one or more embodiments or examples. The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims. The present embodiment provides a computer-readable storage medium having computer-readable program instructions stored thereon, and the computer-readable program instructions are used to execute the code repair method in the above-mentioned embodiment 1. The computer-readable storage medium provided in the embodiment of the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor devices, equipment or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable EPROM (Electrical Programmable Read Only Memory) or flash memory, an optical fiber, a portable compact disk CD-ROM (compact disc read-only memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution device, device or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency, radio frequency), etc., or any suitable combination of the above. The above-mentioned computer-readable storage medium may be contained in an electronic device; it may also exist alone without being assembled into an electronic device.The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by an electronic device, the electronic device: obtains a code syntax tree of the code to be repaired, traverses the code syntax tree, and searches for problem codes that do not comply with preset code quality rules from the code syntax tree; and according to the problem type of the problem code, calls a preset repair component of the problem type to repair the problem code.

[0145] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate 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 a remote computer, the remote computer may be connected to the user's computer via any type of network, including a LAN (local area network) or WAN (Wide Area Network), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0146] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the equipment, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based device that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0147] The modules involved in the embodiments described in the present disclosure may be implemented by software or by hardware. The name of the module does not constitute a limitation on the unit itself under certain circumstances. The computer-readable storage medium provided in the present application stores computer-readable program instructions for executing the above-mentioned code repair method, aiming to solve the technical problem of low efficiency of code repair. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the embodiments of the present application are the same as the beneficial effects of the code repair method provided in the above-mentioned embodiments, which will not be repeated here.

[0148] The present application also provides a computer program product, including a computer program, which implements the steps of the code repair method as described above when the computer program is executed by a processor. The computer program product provided by the present application is intended to solve the technical problem of low code repair efficiency. Compared with the prior art, the beneficial effects of the computer program product provided by the embodiment of the present application are the same as the beneficial effects of the code repair method provided by the above embodiment, which will not be repeated here. The above is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. All equivalent structures or equivalent process transformations made using the contents of the specification and drawings of this application, or directly or indirectly used in other related technical fields, are similarly included in the patent processing scope of the present application.

Claims

1. A code repair method, characterized in that: The method includes: Obtain a code syntax tree of the code to be repaired, traverse the code syntax tree, and search the code syntax tree for problematic code that does not meet preset code quality rules; According to the problem type of the problem code, a preset repair component of the problem type is called to repair the problem code, wherein the problem type includes at least one of the following: a simple type, an annotation defect type, a variable naming type, and a complex type, and the preset repair component includes at least one of a preset code parsing component and a preset large language model.

2. The method according to claim 1, characterized in that The preset repair component includes a preset code parsing component; The step of calling a preset repair component of the problem type according to the problem type of the problem code to repair the problem code comprises: In the case where the problem type of the problem code is a simple type, calling the preset code parsing component to find the code position of the problem code in the code syntax tree, wherein the simple type includes a useless subtype and a position abnormal subtype; If the problem code belongs to the useless subtype, calling the preset code parsing component to delete the problem code at the code position; If the problem code belongs to the position abnormality subtype, the standard position of the problem code is found in the preset code logic sequence rule, the code parsing component is called, and the code position of the problem code is adjusted to the standard position to repair the problem code.

3. The method according to claim 1, characterized in that The step of calling a preset repair component of the problem type according to the problem type of the problem code to repair the problem code comprises: In the case where the problem type of the problem code is an annotation defect type, generating an annotation repair statement according to the problem code and a preset annotation prompt; Inputting the comment repair statement into the preset large language model to generate comment supplementary information of the problem code; According to the preset code parsing component, searching for the code position of the problem code in the code syntax tree; The comment supplementary information is added at the code location to fix the problematic code.

4. The method according to claim 1, characterized in that The step of calling a preset repair component of the problem type according to the problem type of the problem code to repair the problem code comprises: In the case where the problem type of the problem code is a variable naming type, generating a variable repair statement according to a preset variable prompt and the problem code; Inputting the variable repair statement into the preset large language model to generate a standard repair variable for the problem code; According to the preset code parsing component, searching for the code position of the problem code in the code syntax tree; According to the code position, the problem code is replaced with the standard repair variable to repair the problem code.

5. The method according to claim 1, characterized in that The problem code includes a target repair code; The step of calling a preset repair component of the problem type according to the problem type of the problem code to repair the problem code comprises: In the case where the problem type of the problem code is a complex type, obtaining a code call relationship graph of the code to be repaired, wherein the complex type includes that the function body length in the problem code is greater than a preset function length threshold, and / or the number of variables in the problem code is greater than a preset first number threshold; Receiving an external problem repair instruction input based on the problem code, and searching a preset code vector database for a target repair code corresponding to the problem repair instruction; Calling the preset large language model, repairing the code to be repaired according to the target repair code, the code call relationship graph and the problem repair indication, to obtain a first code to be tested; Testing the first code to be tested to obtain a first test result; If the first test result indicates that the test passed, it is determined that the repair of the code to be repaired is completed.

6. The method according to claim 5, characterized in that The step of calling the preset large language model, repairing the code to be repaired according to the target repair code, the code call relationship and the problem repair indication, and obtaining the first code to be tested also includes: Calling the preset large language model, searching the code in the code call relationship graph for associated code that has a call relationship with the target repair code; Calling the preset large language model, determining a first repair operation for the target repair code in the problem repair instruction, and determining a second repair operation for the associated code according to a calling relationship between the associated code and the target repair code; The first repair operation is performed on the target repair code, and the second repair operation is performed on the associated code, so as to repair the code to be repaired to obtain a first code to be tested.

7. The method according to claim 5, characterized in that After the step of testing the first code to be tested to obtain a first test result, the method further includes: If the first test result indicates that the test fails, calling a preset test analysis model to determine an exception code and a corresponding exception cause from the first test result; Inputting the exception code and the exception cause into a preset large language model, repairing the code to be repaired according to the exception code and the exception cause, and obtaining a second code to be tested; Testing the second code to be tested to obtain a second test result; If the second test result meets the preset exception condition, the first test result is updated to the second test result, and the step of calling the preset test analysis model to determine the exception code and the corresponding exception cause from the first test result is returned until the second test result does not meet the preset exception condition.

8. A code repair device, characterized in that: The device comprises: An acquisition module is used to acquire a code syntax tree of the code to be repaired, traverse the code syntax tree, and search for problematic codes that do not meet preset code quality rules from the code syntax tree; An automatic repair module is used to call a preset repair component of the problem type according to the problem type of the problem code to repair the problem code, wherein the problem type includes at least one of the following: a simple type, an annotation defect type, a variable naming type, and a complex type, and the preset repair component includes at least one of a preset code parsing component and a preset large language model.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively coupled to the at least one processor; The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the steps of the code repair method described in any one of claims 1 to 7.

10. A readable storage medium, characterized in that: The readable storage medium is a computer-readable storage medium, on which is stored a program for implementing the code repair method, and the program for implementing the code repair method is executed by a processor to implement the steps of the code repair method as described in any one of claims 1 to 7.