Code reconstruction method and device, equipment and storage medium

By using the refactoring configuration interface and pre-generated change information set of the code refactoring method, the code to be modified in the code file is automatically identified and refactored, which solves the problems of low efficiency and high error risk in the existing technology and realizes intelligent and efficient code refactoring.

CN121387356APending Publication Date: 2026-01-23BEIJING YOUZHUJU NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410994322.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-23
Publication Date
2026-01-23

AI Technical Summary

Technical Problem

Existing technologies for code refactoring are inefficient, consume a lot of manpower, and carry the risk of omissions or errors, especially when refactoring multiple files.

Method used

This paper provides a code refactoring method that receives configuration information by displaying a refactoring configuration interface, automatically determines and refactors the code to be modified in the code file using a pre-generated set of refactoring change information, and generates refactoring change information using a generative network model to achieve intelligent code refactoring.

Benefits of technology

It greatly improves code refactoring efficiency, reduces labor costs, lowers the risk of omissions and errors, and ensures refactoring accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121387356A_ABST
    Figure CN121387356A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a code reconstruction method and device, equipment and a storage medium, and the method comprises the steps: responding to a reconstruction configuration instruction, and displaying a reconstruction configuration interface; receiving reconstruction configuration information corresponding to the reconstruction configuration item, and determining a to-be-reconstructed first code file according to the reconstruction configuration information; according to a pre-generated reconstruction change information set, determining a first code to be changed in the first code file and reconstructing the first code into a second code to obtain a second code file; wherein the reconstruction change information set comprises at least one piece of reconstruction change information, and each piece of reconstruction change information is used for matching the to-be-changed code and performing code reconstruction on the to-be-changed code. By means of the method, intelligent rapid searching of the to-be-reconstructed code file is achieved, and the risk of missing the to-be-reconstructed code file is better avoided while the labor cost is saved; in addition, automatic matching and reconstruction of the to-be-changed code in the to-be-reconstructed code file are achieved, and the code reconstruction rate and the reconstruction accuracy are greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present disclosure relate to the technical field of computer, and particularly, to a code refactoring method, device, equipment and storage medium. BACKGROUND

[0002] In the context of continuous development and maintenance of business projects, the code segments in the code files relied on by the business projects are often replaced or refactored due to changes in infrastructure. Since the number of code files relied on by the business projects is large, there are cases where code segments in multiple code files need to be refactored, and there are also cases where the same code segments are reused in many different code files.

[0003] In view of the above, in the existing implementation of manually refactoring code, even if only one code segment needs to be refactored, the technical personnel may need to determine whether multiple code files need to be refactored, and the code files determined need to be refactored one by one. If the number of code to be refactored is large, more time and effort are needed to record the code segments to be refactored and query and implement the refactoring of the code files to be refactored.

[0004] The existing code refactoring implementation greatly affects the code refactoring efficiency, and also has the risk of missing code files to be refactored or making mistakes in code refactoring. SUMMARY

[0005] Embodiments of the present disclosure provide a code refactoring method, device, equipment and storage medium to realize intelligent refactoring of code.

[0006] In a first aspect, embodiments of the present disclosure provide a code refactoring method, which comprises:

[0007] In response to a refactoring configuration instruction, a refactoring configuration interface is displayed, and the refactoring configuration interface includes a refactoring configuration item for determining a code file to be refactored;

[0008] Refactoring configuration information corresponding to the refactoring configuration item is received, and a first code file to be refactored is determined according to the refactoring configuration information;

[0009] According to a pre-generated refactoring change information set, a first code to be changed in the first code file is determined and the first code is refactored into a second code, to obtain a second code file;

[0010] In the refactoring change information set, at least one refactoring change information is included, and each refactoring change information is used to match a code to be changed and to refactor the matched code to be changed.

[0011] In a second aspect, embodiments of the present disclosure also provide a code refactoring device, which comprises:

[0012] a response module, configured to display a refactoring configuration interface in response to the refactoring configuration instruction, the refactoring configuration interface including a refactoring configuration item for determining a code file to be refactored;

[0013] a first determination module, configured to receive refactoring configuration information corresponding to the refactoring configuration item, and determine a first code file to be refactored according to the refactoring configuration information;

[0014] a second determination module, configured to determine a first code to be changed in the first code file according to a pre-generated refactoring change information set, and refactor the first code to a second code to obtain a second code file;

[0015] wherein the refactoring change information set includes at least one refactoring change information, and each refactoring change information is used for matching a piece of code to be changed and refactoring the matched code to be changed.

[0016] In a third aspect, an embodiment of the present disclosure further provides a computer device, which comprises:

[0017] one or more processors;

[0018] a storage device configured to store one or more programs,

[0019] when the one or more programs are executed by the one or more processors, the one or more processors implement the code refactoring method provided by any of the embodiments of the present disclosure.

[0020] In a fourth aspect, an embodiment of the present disclosure further provides a computer readable storage medium having stored thereon a computer program, which is executed by a processor to implement the code refactoring method provided by any of the embodiments of the present disclosure.

[0021] The technical scheme of the embodiment of the present disclosure specifically discloses a code refactoring method, device, equipment and storage medium, the method comprises the following steps: in response to a refactoring configuration instruction, a refactoring configuration interface is displayed, the refactoring configuration interface comprises a refactoring configuration item for determining a code file to be refactored; then, refactoring configuration information of the refactoring configuration item is received, and a first code file to be refactored is determined according to the refactoring configuration information; finally, a first code to be changed in the first code file can be determined according to a pre-generated refactoring change information set, and the first code is refactored into a second code to obtain a second code file; wherein the refactoring change information set comprises at least one refactoring change information, and each refactoring change information is used for matching a code to be changed and refactoring the matched code to be changed. In the technical scheme, an execution subject executing the above method logic can be integrated as a plug-in or installation package in a programming platform corresponding to a programming development environment, and an automatic implementation function of code refactoring is provided for a refactoring demander who has a code refactoring demand. In the technical scheme, a determination channel for determining a code file to be refactored is provided for the refactoring demander through the provided refactoring configuration interface, the determination of the code file to be refactored can be simply and quickly realized through the configuration of the configuration item in the refactoring configuration interface; compared with the prior art, the code file to be refactored does not need to be determined one by one from the folders of a business project by manpower, and intelligent and rapid searching of the code file to be refactored is realized, thereby saving manpower cost and better avoiding the risk of missing the code file to be refactored. Meanwhile, the refactoring change information set is pre-generated in the technical scheme, the code segment to be changed can be effectively matched from the code file to be refactored according to the refactoring change information in the refactoring change information set, and the refactoring of the matched code to be changed can be directly realized; compared with the prior art, the technical scheme is equivalent to realizing automatic matching and refactoring of the code to be changed in the code file to be refactored, thereby avoiding the risk of refactoring error in manual refactoring of the code and greatly improving the code refactoring efficiency and refactoring accuracy. BRIEF DESCRIPTION OF DRAWINGS

[0022] In order to more clearly illustrate the technical scheme of the exemplary embodiments of the present disclosure, the drawings needed in the description of the embodiments are briefly introduced as follows. Obviously, the drawings introduced are only a part of the drawings of the present disclosure to be described, and not all the drawings. Those skilled in the art can also obtain other drawings according to these drawings without creating any creative labor.

[0023] Figure 1 A flowchart of a code refactoring method provided by the embodiment of the present disclosure is shown in the figure;

[0024] Figure 2 A structural diagram of a code refactoring device provided by the embodiment of the present disclosure is shown in the figure;

[0025] Figure 3 This is a schematic diagram of the structure of a computer device provided in an embodiment of this disclosure. Detailed Implementation

[0026] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.

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

[0028] The term "comprising" and its variations as used herein are open-ended inclusions, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below.

[0029] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules, or units, and are not used to limit the order of functions performed by these devices, modules, or units or their interdependencies. It should also be noted that the modifications of "a" and "a plurality of" mentioned in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise expressly indicated in the context, they should be understood as "one or more".

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

[0031] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.

[0032] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.

[0033] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the software or hardware, such as the electronic device, application, server, or storage medium performing the operations of this disclosed technical solution, based on the prompt message.

[0034] As an optional but non-limiting implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0035] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.

[0036] Figure 1 This is a flowchart illustrating a code refactoring method provided in an embodiment of the present disclosure. This embodiment is applicable to code refactoring situations. The method can be executed by a code refactoring device, which can be implemented by software and / or hardware and can be configured in a terminal and / or server to implement the code refactoring method in this embodiment of the present disclosure.

[0037] It should be noted that one application scenario of this embodiment can be described as follows: In the development or maintenance of code on which a business project depends, changes in business functions may necessitate the refactoring of existing code. Currently, refactoring primarily relies on manual methods, often requiring developers or code maintainers to manually locate the relevant code files within the business project's codebase and refactor the modified code within those files. This existing approach incurs manual costs, carries the risk of missing files or code to be modified, and also carries the risk of errors in the refactored code, significantly impacting refactoring efficiency.

[0038] Specifically, in actual business applications, the underlying support code is often adjusted according to changes in business function requirements. Therefore, for a business project, once the business functions that need to be improved are known, the technical staff can clearly know which functions in the underlying support code need to be modified based on the key points of the business function improvement, and also clearly know what specific changes need to be made to these modified codes.

[0039] In the above description, it's equivalent to technical personnel only knowing which code segments in the underlying supporting code of the business project need modification and what specific modifications are involved, but not knowing which specific code files contain this modified code. In the existing code refactoring implementation, the code to be modified and its corresponding modifications can be recorded in advance. Then, relying on this recorded information, technical personnel manually determine which code files contain the code to be modified from the relevant code files in the business project, and finally manually replace the modified code in those files. This entire refactoring process is very time-consuming and labor-intensive.

[0040] Based on this, this embodiment provides a code refactoring method that can effectively solve the problems existing in current code refactoring. Specifically, as shown below... Figure 1 As shown, the code refactoring method provided in this embodiment may include:

[0041] S101. In response to the refactoring configuration command, a refactoring configuration interface is displayed, which includes refactoring configuration items for querying code files to be refactored.

[0042] It should be noted that the main form of the method provided in this embodiment can be considered as a functional plugin or software package, which can be directly integrated into the platform on which the programming development environment depends. Furthermore, after being integrated into the development platform as a functional plugin or software package, the control bar of the visual interface displayed on the development platform can use icons to represent the code refactoring functions corresponding to the method provided in this embodiment. The code refactoring function can be activated by triggering the displayed icons when code refactoring is required; alternatively, it can also be activated directly by entering command lines.

[0043] In this embodiment, the code refactoring execution logic can start from the refactoring configuration, which first identifies the code files to be refactored from the numerous code files included in the business project. Compared to manually determining which code files need refactoring from numerous code files, this execution step can better save the cost of identifying the code files to be refactored.

[0044] In this embodiment, a refactoring configuration instruction can be generated by triggering the corresponding functional control of the refactoring configuration. Specifically, the refactoring configuration instruction can be considered a logical instruction used to execute the relevant configurations involved in code refactoring, and can be used to initiate the logical execution of the code file to be refactored.

[0045] In this embodiment, the refactoring configuration instruction can be generated by triggering the function icon. As one way to trigger the refactoring configuration instruction, it can be described as follows: after triggering the function icon for code refactoring presented on the programming development platform, the code refactoring interface is presented in a visual form. The code refactoring interface can include the refactoring configuration function item. By triggering the refactoring configuration function item, a refactoring configuration instruction to enter the refactoring configuration function can be generated.

[0046] This step responds to the refactoring configuration command, and its execution can also present the refactoring configuration interface in a visual format. In this visual format, the refactoring configuration interface can contain refactoring configuration items for the operator to determine the code file to be refactored. The operator can directly trigger the controls for different refactoring configuration items, thereby popping up the corresponding refactoring configuration window, where they can edit the relevant refactoring configuration information.

[0047] In this embodiment, the refactoring configuration command can also be triggered by an input command line. Specifically, as another way to trigger the refactoring configuration command, it can be described as follows: after triggering the function icon for code refactoring displayed on the programming development platform, a command prompt box for inputting code refactoring-related commands is displayed. Thus, a refactoring configuration command can be generated upon receiving a refactoring configuration command input in the command prompt box.

[0048] Similarly, this step can also respond to the refactoring configuration command. In this case, the refactoring configuration interface presented by executing this step can also be displayed as a command prompt box, which can also include refactoring configuration items triggered by commands. For example, different refactoring configuration items can be accessed through different refactoring configuration commands to enter their respective configuration windows, allowing for the editing of relevant refactoring configuration information.

[0049] S102. Receive the reconstruction configuration information corresponding to the reconstruction configuration item, and query the first code file from the code file set according to the reconstruction configuration information.

[0050] In this embodiment, the refactoring configuration interface can specifically configure the information required to determine the code file to be refactored. Specifically, this embodiment can set multiple refactoring configuration items in the refactoring configuration interface to configure different information according to different configuration requirements. For example, it can include a path configuration item for locating the storage location of the code file to be refactored, a determination condition configuration item for determining the code file to be refactored from among many code files, and a determination method configuration item for setting the logical execution method used when determining the code file to be refactored.

[0051] Based on the above description, the operator performing code refactoring can edit and configure different refactoring configuration items in the refactoring configuration interface. This step can receive the refactoring configuration information edited in the edit box corresponding to the refactoring configuration item. For example, the received refactoring configuration information may include file path information to determine the storage path of the code file to be refactored; it may also include determination conditions to filter the code file to be refactored from among many code files; and it may also include determination execution method to serve as the logical execution method used when filtering the code file to be refactored according to the determination conditions.

[0052] In this embodiment, one way to implement the determination of the first code file to be refactored based on the refactoring configuration information is as follows: the set of code files stored under the file path in the refactoring configuration information can be found; then the set of code files can be filtered according to the determination conditions in the refactoring configuration information, such as filtering out code files that meet the set file name, or filtering out code files that meet the file extension, etc.

[0053] During the filtering process, the execution method configured in the refactoring configuration information can be used as the logical execution method. For example, if the execution method is recursive, the filtering method for the code file set can be considered recursive. Since the code file set is typically stored in a folder, the execution logic can use that folder as the first filtering object. First, the code files contained in that folder are identified as needing to be refactored based on certain conditions. After filtering this batch of code files, it can be determined whether there are any subfolders within that folder. If so, the next subfolder can be accessed, and the code files stored in that subfolder can again be identified as needing to be refactored based on certain conditions, until it is determined that there are no more subfolders.

[0054] By performing this step, one or more code files that meet the conditions for refactoring can be easily and quickly identified from the numerous code files corresponding to the business project. In this embodiment, the code file to be refactored is referred to as the first code file.

[0055] S103. Based on the pre-generated set of refactoring modification information, determine the first code to be modified in the first code file and refactor the first code into the second code to obtain the second code file.

[0056] In this embodiment, the key to refactoring the first code file lies in the refactoring change information set, which can be considered pre-generated and contains at least one refactoring change information. Each refactoring change information corresponds to a piece of code to be modified, and can be used to match a piece of code to be modified and to refactor the matched code.

[0057] In this step, one or more refactoring change information can be collected from the refactoring change information set to match the first code to be modified from the first code file. The first code to be modified can be refactored by the refactoring change information and adjusted into the second code, thereby obtaining the second code file after the refactoring of the first code file.

[0058] It is understood that, in this embodiment, the number of first code files determined by the above steps can be one or more; in addition, each first code file may include one piece of code to be modified or may include multiple pieces of code to be modified, and all the included code to be modified can be recorded as the first code in the first code file.

[0059] In this embodiment, the pre-generated refactoring modification information can be generated using a generative network model. Specifically, the generative network model processes each piece of input information and outputs a corresponding piece of refactoring modification information, which can be aggregated into a set of refactoring modification information. In this generation implementation, the input information can be a known code segment to be modified, and the corresponding modified code segment. Each piece of output refactoring modification information can be used to match a piece of code to be modified from a code file, and can also be used to refactor the matched code.

[0060] As described above, once we understand which business functions in a project have changed, we can clearly identify which underlying supporting code needs modification. Furthermore, knowing the specific changes to the business functions reveals the necessary modifications to the underlying code. Therefore, before any code refactoring, we can determine exactly which code segments have changed and what those changes are.

[0061] This embodiment can take known modified code segments and the corresponding modified code segments after the modifications, and form the input content of the model in a format that the model can recognize. The generative network model can then generate matching information that can be used to match the code to be modified in the code file by analyzing the code segment to be modified and the modified code segment. It can also generate reconstruction-related information for adjusting the code to be modified to the modified code content.

[0062] This embodiment can determine the first code by matching the file content of the first code file with the refactoring change information in the refactoring change information set; it can also refactor the first code into the second code based on the refactoring-related information contained in the refactoring change information that matches the first code.

[0063] In this embodiment, each refactoring change information can be recorded in the form of a dot data structure. For example, one implementation of determining the first code to be modified in the first code file based on a pre-generated set of refactoring change information and refactoring the first code into second code to obtain a second code file can be described as follows: For each determined first code file, a corresponding abstract syntax tree can be obtained. The tree nodes in the abstract syntax tree can be compared with the refactoring change information in the dot data structure form. If a tree node is found to match the matching information in a certain refactoring change information, the code corresponding to that tree node can be considered as the first code to be modified. Then, the node content of that tree node can be adjusted using the refactoring-related information in the refactoring change information that matches that tree node, thereby forming a new tree node. The code converted from the new tree node can be recorded as the second code. After refactoring all the first code in the first code file in the above manner, a second code file refactored from the first code file can be obtained.

[0064] This embodiment provides a code refactoring method that, through a refactoring configuration interface, offers a channel for users to identify code files to be refactored. By configuring the options in the interface, users can quickly and easily identify these files. Compared to existing technologies, this eliminates the need for manual effort to manually search through project folders to find refactored code files, enabling intelligent and rapid searching. This saves labor costs and mitigates the risk of missing files. Furthermore, by pre-generating a refactoring change information set, the method effectively matches the code segments to be modified within the refactoring files and directly refactors them. Compared to existing technologies, this solution achieves automatic matching and refactoring of the code segments to be modified within the refactoring files, avoiding the risk of errors during manual code refactoring and significantly improving refactoring efficiency and accuracy.

[0065] As a first optional embodiment of this example, based on the above optimizations, the refactoring configuration items can be optimized to include: code file path configuration items, determination condition configuration items, and determination method configuration items.

[0066] It is understandable that determining the code file to be refactored requires information that may include the storage information of the code file, as well as the determination conditions needed to screen the code file to be refactored. Furthermore, to more comprehensively determine the code file to be refactored, when the code file storage chain is complex, it is also necessary to consider the execution method of the code file determination logic. Based on this, this embodiment sets at least the following configuration items in the refactoring configuration interface: code file path configuration item, determination condition configuration item, and determination method configuration item.

[0067] Based on the above optimizations, the specific optimization of receiving the reconstruction configuration information corresponding to the reconstruction configuration item and determining the first code file to be reconstructed based on the reconstruction configuration information can be as follows:

[0068] a1) Receive the source path information configured in the path configuration item, the filtering conditions configured in the determination condition configuration item, and the determination execution method configured in the determination method configuration item.

[0069] In this embodiment, this step can obtain the refactoring configuration information corresponding to different refactoring configuration items, such as the source path information configured in the path configuration item. Specifically, the source path information can be understood as the storage path information of the source code files involved in the storage business project. This source path information can be the storage path of a specific code file or the storage path of a specific folder.

[0070] In this embodiment, the refactoring configuration information can also be filtering conditions configured in the determination condition configuration item. These filtering conditions can be understood as the filtering content relied upon when filtering code files to be refactored among numerous code files involved in the business project. This filtering content can be a specific filename or a file extension, etc. The refactoring configuration information can also be the determination execution method configured in the determination method configuration item. The determination execution method can be understood as the specific logical execution method used when performing code file filtering, such as a recursive logical execution method or a non-recursive logical execution method.

[0071] b1) If the source path information points to a code file, then the code file is identified as the first code file.

[0072] In this embodiment, if the object pointed to by the source path information is directly a code file, such as if the source path information eventually locates a code file, then the object pointed to can be considered to be a code file. In this case, it is equivalent to selecting only one code file as the code file to be refactored. At this time, the code file pointed to can be directly determined as the first code file.

[0073] c1) If the source path information points to a code folder, then according to the determined execution method, search for the first code file that meets the filtering conditions in the code folder.

[0074] In this embodiment, if the object pointed to by the source path information is a code folder, such as locating a folder containing multiple code files according to the source path information, then the pointed object can be considered to be a code folder. It should be noted that the pointed-to code folder may include multiple code files, and this folder may also include a subfolder, which may also contain multiple code files; even the subfolder may contain a lower-level folder.

[0075] In one example implementation, when the execution method is determined to be recursive, and code files with the .XX extension are used as the filtering condition, the search can begin from the pointed-to code folder and proceed to find if any code files with the .XX extension exist within that folder. If the existence of such code files is confirmed, these files can be selected as the first code files. Alternatively, after determining that such files do not exist, or after completing the search at the code folder level, the search can continue to access the sub-folders within the code folder, similarly searching for the first code files. Based on the above description, this step is equivalent to recursively accessing all levels of folders contained within the code folder and filtering for the first code files from each folder.

[0076] In one example implementation, when the execution method is determined to be non-recursive, only the code files contained in the code folder can be filtered according to the filtering criteria.

[0077] The first optional embodiment described above provides a scheme for determining the first code file. This determination logic can easily and quickly identify one or more code files that need to be refactored from among many code files, greatly improving the speed of selecting code files to be refactored.

[0078] As a second optional embodiment of this example, based on the above embodiment, the method of determining the first code to be modified in the first code file according to the pre-generated refactoring modification information set and refactoring the first code into the second code to obtain the second code file is further specified as follows:

[0079] a2) In the first abstract syntax tree of the first code file, determine the first tree node that matches any refactoring change information in the refactoring change information set.

[0080] It is known that code files can be transformed into abstract syntax trees (ASTs), where a tree node in the AST corresponds to code within a data structure in the code file. In this embodiment, the AST formed by transforming the first code file can be denoted as the first AST, and the tree nodes in the first AST can be considered as nodes to be matched. The first tree node that can match any refactoring change information in the refactoring change information set is determined by the executed matching logic.

[0081] In this embodiment, the refactoring modification information in the refactoring modification information set is represented in the form of a given data structure. The data content with this data structure can be compared with the node content of the tree nodes in the abstract syntax tree. In one implementation, starting from the root node of the first abstract syntax tree as the node to be matched, the refactoring modification information in the refactoring modification information set is matched with the node to be matched in sequence. When a refactoring modification information that matches the node to be matched is determined, the node to be matched can be determined as the first tree node. After the node to be matched is determined as the first tree node, or after all the refactoring modification information has participated in the matching, new tree nodes can be traversed as nodes to be matched, and the above matching logic can be re-executed to determine the first tree node again.

[0082] This embodiment can determine at least one first tree node from the first abstract syntax tree by performing this step. The determined first tree node may match the same refactoring change information or it may match different refactoring change information.

[0083] In this second optional embodiment, for the execution of determining the first tree node in the first abstract syntax tree that matches any refactoring change information in the refactoring change information set, one implementation method is provided, which may include the following steps:

[0084] a21) Take the root node of the first abstract syntax tree as the node to be matched.

[0085] In this embodiment, the root node of the first abstract syntax tree can be used as the initial node to be matched.

[0086] a22) Select one reconstruction change information from the reconstruction change information set according to the storage order as the reconstruction change information to be matched, and extract the node matching information from the reconstruction change information to be matched.

[0087] In this embodiment, if all refactoring modification information in the refactoring modification information set has been selected, or if none of the refactoring modification information has been selected, then when the execution conditions of this step are met, the first refactoring modification information in the refactoring modification information set can be used as the initial refactoring modification information to be matched.

[0088] Furthermore, if there are some unselected refactoring changes in the refactoring change information set, then based on the previously selected refactoring change information, the next refactoring change information of that selected refactoring change information can be selected as the refactoring change information to be matched.

[0089] This step allows you to extract the node matching information contained in the selected refactoring information to be matched.

[0090] a23) Determine whether the node to be matched matches the node matching information. If yes, proceed to step a24); otherwise, proceed to step a25.

[0091] This step is a judgment logic. When matching, it can be assumed that there is reconstruction modification information in the set that matches the node to be matched, and step a24) can be executed at this time; or when there is no match, step a25) can be used to further determine which step of the execution logic needs to be executed.

[0092] (a24) Record the node to be matched as the first tree node and jump to step a26).

[0093] This step serves as the execution branch during matching, and the node to be matched can be recorded as the first tree node; then, step a26) can be used to determine whether to return to step a22) for re-execution.

[0094] a25) Determine if all the reconstruction modification information in the reconstruction modification information set has been selected. If yes, proceed to step a26); otherwise, return to step a22.

[0095] If this step determines that all refactoring changes in the set have been selected, it means that no matching refactoring changes have been found for the current node to be matched. In this case, step a26) can be used to determine whether to return to step a22) and re-execute. If this step determines that there are still unselected refactoring changes in the set, it can be considered that the matching judgment logic for the current node to be matched has not yet ended, and step a22) can be returned to and re-executed.

[0096] a26) If the node traversal termination condition is not met, select the next node to be matched from the first abstract syntax tree according to the given traversal method, and return to step a22 again.

[0097] In this step, if the node traversal termination condition of the tree node is not met, a new node to be matched can be selected from the first abstract syntax tree, and a new round of logic execution can be started.

[0098] This embodiment, through the above steps, can iteratively execute the execution logic to determine whether each tree node in the first abstract syntax tree contains matching refactoring modification information. This implementation method comprehensively identifies the code segments in the first code file that need modification.

[0099] b2) Record the code corresponding to the first tree node as the first code in the first code file, and record the refactoring modification information matched by the first tree node as the matching refactoring modification information.

[0100] In this embodiment, considering that the first abstract syntax tree is obtained through the transformation of the first code file, the code generated by the code generator for the first tree node exists in the first code file. Therefore, in this embodiment, the code corresponding to the first tree node in the first code file can be recorded as the first code. Simultaneously, considering that a first tree node matches any refactoring change information in the refactoring change information set, this step can record the refactoring change information that matches the first tree node as the matched refactoring change information, for use in the execution of subsequent logic.

[0101] c2) Based on the matching reconstruction modification information, reconstruct the first tree node into a second tree node and obtain the second code corresponding to the second tree node.

[0102] In this embodiment, based on the above description, it can be understood that the reconstruction modification information includes node matching information for tree node matching, and also includes node transformation information for reconstructing the matched tree nodes. This step can obtain the node transformation information for node content reconstruction from the matching reconstruction modification information corresponding to the first tree node, and can adjust the first tree node into the second tree node through this node transformation information. Finally, the second code corresponding to the second tree node can be obtained through the code generator.

[0103] In this second optional embodiment, one implementation method is provided for reconstructing the first tree node into a second tree node based on the matching reconstruction modification information and obtaining the second code corresponding to the second tree node. Specifically, it may include the following steps:

[0104] c21) Extract the node transformation information contained in the matching reconstruction modification information.

[0105] In this embodiment, the reconstruction modification information matching the first tree node determined above can be recorded as the matching reconstruction modification information. This step can extract the node transformation information contained in the matching reconstruction modification information. The node transformation information can be used to control the reconstruction transformation of the first tree node.

[0106] c22) Based on the node transformation information, reconstruct the first tree node into a second tree node.

[0107] In this embodiment, the node transformation information may include control information for reconstructing the first tree node, as well as information about the specific type of node to be reconstructed from the first tree node. In one implementation, the node transformation information may specifically be a node transformation function with node transformation capabilities. This step can obtain the transformed tree node by executing this node transformation function, and the reconstructed node from the first tree node can be recorded as the second tree node.

[0108] c23) Convert the second tree node into second code according to the code generator.

[0109] d2) In the first code file, the second code is used to replace the first code to form a second code file.

[0110] In this embodiment, the first code exists in the first code file. After the first tree node corresponding to the first code is converted to the second tree node, the resulting second code can be used to replace the first code in the first code file, thereby forming a replacement file for the first code file. In this embodiment, this can be referred to as the second code file.

[0111] The above-described second optional embodiment provides the implementation logic for refactoring a first code file to obtain a second code file. This implementation logic enables automatic refactoring of the first code file based on the generated set of refactoring changes. Compared to existing technologies, this technical solution significantly improves the execution efficiency of code refactoring and also ensures the accuracy of code refactoring.

[0112] As a third optional embodiment of this embodiment, based on the above embodiments, the optimization and reconstruction modification information can be generated through a generative network model.

[0113] In this embodiment, a large-scale artificial intelligence model can be used to automatically generate refactoring change information for code file refactoring, and this information can form a refactoring change information set containing multiple refactoring change pieces. The large-scale artificial intelligence model used in this embodiment can be a generative network model. A generative network model can be understood as being able to output corresponding response content based on input information such as images or text. For example, given the input code to be modified and the modified code, it can output matching information on how to match the code to be modified in the code file and transformation information on how to adjust the code to be modified.

[0114] Specifically, the steps for generating reconstruction change information through generative network models can be further optimized as follows:

[0115] a3) Receive at least one modification description message edited in a format readable by the given model. Each modification description message corresponds to a piece of code to be modified, including the original code content description and the modified code content description.

[0116] In this embodiment, the execution subject of this step can be considered as a generative network model. The generative network model can receive at least one modification description as input information. The modification description includes a description of the original code content corresponding to the code to be modified and a description of the modified code content to be modified.

[0117] It's important to note that the input information required for generative network models to execute their processing logic often needs to be formatted in a specific way to ensure readability. Therefore, the modification descriptions used as input information must be edited in a format readable by the model. Furthermore, generative network models can read modification descriptions in batches or one at a time.

[0118] b3) Process each received modification description information according to the pre-given modification constraint information, and generate a reconstruction modification information for each modification description information.

[0119] In this embodiment, the generative network model with code refactoring capabilities can be considered to have been pre-trained using code refactoring-related information. To help the generative network model better understand what processing logic needs to be executed, modification constraint information can be provided to output refactoring change information. During the actual execution process, the modification description information can be processed based on the constraint rules or processing directions in the modification constraint information.

[0120] The modified constraint information can be suggestive descriptive information used by the generative network model for information output. Taking code refactoring in this embodiment as an example, the content of the modified constraint information can preferably include: functional execution descriptions that inform the generative network model what functions it should have, such as informing the generative network model that it is an expert in refactoring code by modifying the abstract syntax tree, and is good at generating transformation functions that transform the node content of tree nodes in the abstract syntax tree, so as to convert the existing code into a more efficient new version of code.

[0121] The modification constraint information may also include: informing the generative network model what skills it should possess to achieve code refactoring, such as node matching skills and node transformation skills. Furthermore, the modification constraint information may also include restrictions on the generative network model's logic execution, such as restricting the generative network model to using only two given function libraries to modify tree nodes; restricting the generative network model to always generate refactored code that conforms to the input modification description information; and also restricting the logic for code refactoring to minimize code complexity and enhance readability, and ensuring that the execution logic focuses on code modification and refactoring tasks.

[0122] In this embodiment, the generative network model can process the input modification description information based on the modification constraint information containing the above-described content, and output reconstructed modification information for each modification description. It is understood that when inputting modification description information in batches, the reconstructed modification information corresponding to each modification description can also be output in batches.

[0123] Meanwhile, it is understood that to ensure the generative network model possesses the execution capability of the aforementioned processing logic, it needs to be pre-trained. Based on the above embodiments, this embodiment can further optimize the generative network model by combining the modified constraints with given sample modification description information and a code refactoring knowledge base, obtained through model training.

[0124] The above-described technical solution in this third optional embodiment provides an implementation for determining the refactoring change information set. The refactoring change information set determined through this embodiment ensures the correctness of the refactoring change information, thereby avoiding refactoring errors and greatly improving refactoring efficiency.

[0125] Figure 2 This is a schematic diagram of a code refactoring apparatus provided in an embodiment of the present disclosure. This embodiment is applicable to code refactoring. The apparatus can be implemented by software and / or hardware and can be configured in a terminal and / or server to implement the code refactoring method in this embodiment. Specifically, the apparatus may include: a response module 21, a first determining module 22, and a second determining module 23.

[0126] The response module 21 is used to respond to the refactoring configuration command and display the refactoring configuration interface, which includes refactoring configuration items for determining the code file to be refactored.

[0127] The first determining module 22 is used to receive the reconstruction configuration information corresponding to the reconstruction configuration item, and determine the first code file to be reconstructed based on the reconstruction configuration information;

[0128] The second determining module 23 is used to determine the first code to be modified in the first code file and reconstruct the first code into the second code based on the pre-generated set of refactoring modification information, thereby obtaining the second code file;

[0129] The refactoring change information set includes at least one refactoring change information, and each refactoring change information is used to match a piece of code to be modified and to refactor the matched code.

[0130] This embodiment provides a code refactoring device that integrates the execution entity that performs the above-mentioned method logic as a plugin or installation package into the programming platform corresponding to the programming development environment, providing automated code refactoring functionality for those with refactoring needs. Specifically, this technical solution provides a channel for identifying the code files to be refactored through a refactoring configuration interface. By configuring the settings in the interface, the identification of the code files to be refactored can be achieved quickly and easily. Compared to existing technologies, it eliminates the need for manual labor to identify the code files to be refactored one by one from the folders of business projects, achieving intelligent and rapid searching of the code files to be refactored. This saves labor costs and better avoids the risk of missing any code files to be refactored. Furthermore, this technical solution pre-generates a refactoring change information set, which can effectively match the code segments to be modified from the code files to be refactored based on the refactoring change information in the set, and directly refactor the matched code. Compared to existing technologies, this technical solution essentially achieves automatic matching and refactoring of the code to be modified within the code files to be refactored, avoiding the risk of refactoring errors during manual code refactoring and greatly improving the efficiency and accuracy of code refactoring.

[0131] Furthermore, the refactoring configuration items include: code file path configuration items, determination condition configuration items, and determination method configuration items;

[0132] Based on the above optimizations, the first determining module 22 can specifically be used for:

[0133] Receive source path information configured in the path configuration item, filter conditions configured in the determination condition configuration item, and determination execution method configured in the determination method configuration item;

[0134] If the source path information points to a code file, then the code file is identified as the first code file;

[0135] If the source path information points to a code folder, then according to the determined execution method, the first code file that meets the filtering conditions is searched from the code folder.

[0136] Furthermore, the second determining module 23 may specifically include:

[0137] The first determining unit is configured to determine, in the first abstract syntax tree of the first code file, a first tree node that matches any one of the refactoring change information in the refactoring change information set;

[0138] The second determining unit is used to record the code corresponding to the first tree node as the first code in the first code file, and to record the reconstruction modification information matched by the first tree node as the matching reconstruction modification information.

[0139] The third determining unit is used to reconstruct the first tree node into a second tree node based on the matching reconstruction modification information, and obtain the second code corresponding to the second tree node.

[0140] The code replacement unit is used to replace the first code in the first code file with the second code to form a second code file.

[0141] Furthermore, the first determining unit can specifically be used for:

[0142] The root node of the first abstract syntax tree is taken as the node to be matched, and a reconstruction change information is selected from the reconstruction change information set in storage order as the reconstruction change information to be matched.

[0143] If the node to be matched matches the node matching information in the reconstructed modification information to be matched, then the node to be matched is recorded as the first tree node, and the process jumps to the next node to be matched selection operation.

[0144] If the node to be matched does not match the node matching information, the selection operation of the reconstructed modification information to be matched is re-executed until all the reconstructed modification information in the set has been selected, and after all have been selected, the process jumps to the next node to be matched.

[0145] Select the next node to be matched from the first abstract syntax tree according to the given traversal method, return and re-execute the matching operation between the node to be matched and the reconstructed change information, until the node traversal end condition is met.

[0146] Furthermore, the third determining unit can specifically be used for:

[0147] Extract the node transformation information contained in the matched reconstruction modification information;

[0148] Based on the node transformation information, the first tree node is reconstructed into a second tree node;

[0149] The second tree node is converted into second code according to the code generator.

[0150] Furthermore, the device optimizes and refactors modification information through a generative network model; the device also includes an information generation module, which can be specifically used for:

[0151] The steps for generating reconstruction change information using a generative network model include:

[0152] Receive at least one modification description message edited in a format readable by the given model. Each modification description message corresponds to a piece of code to be modified, including a description of the original code content and a description of the modified code content.

[0153] Each received modification description is processed according to the pre-given modification constraint information, and a reconstruction modification information is generated for each modification description.

[0154] Furthermore, the generative network model described in the device is obtained through model training based on the modified constraints, combined with the given sample modification description information and the code refactoring knowledge base.

[0155] The above-described apparatus can execute the methods provided in any embodiment of this disclosure, and has the corresponding functional modules and beneficial effects for executing the methods.

[0156] It is worth noting that the various units and modules included in the above-mentioned device are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of each functional unit are only for easy differentiation and are not used to limit the protection scope of the embodiments of this disclosure.

[0157] Figure 3 This is a schematic diagram of the structure of a computer device provided in an embodiment of this disclosure. Reference is made below. Figure 3 It illustrates a computer device suitable for implementing embodiments of the present disclosure (e.g., Figure 3 The diagram below shows the structure of the terminal device or server 30. The terminal device in this embodiment may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and vehicle terminals (e.g., vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 3 The computer device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.

[0158] like Figure 3As shown, the computer device 30 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 31, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 32 or a program loaded from a storage device 38 into a random access memory (RAM) 33. The RAM 33 also stores various programs and data required for the operation of the computer device 30. The processing unit 31, the ROM 32, and the RAM 33 are interconnected via a bus 35. An edit / output (I / O) interface 34 is also connected to the bus 35.

[0159] Typically, the following devices can be connected to I / O interface 34: input devices 36 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 37 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 38 including, for example, magnetic tapes, hard disks, etc.; and communication devices 39. Communication device 39 allows computer device 30 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 3 A computer device 30 with various devices is shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have instead.

[0160] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory 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 39, or installed from a storage device 38, or installed from a ROM 32. When the computer program is executed by the processing device 31, it performs the functions defined in the methods of embodiments of this disclosure.

[0161] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.

[0162] The computer device provided in this embodiment and the code refactoring method provided in the above embodiments belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.

[0163] This disclosure provides a computer storage medium storing a computer program that, when executed by a processor, implements the code refactoring method provided in the above embodiments.

[0164] It should be noted that the computer-readable medium described above in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.

[0165] In this disclosure, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0166] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol) and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.

[0167] The aforementioned computer-readable medium may be included in the aforementioned computer device; or it may exist independently and not assembled into the computer device.

[0168] The aforementioned computer-readable medium carries one or more programs that, when executed by the computer device, cause the computer device to:

[0169] Computer program code for performing the operations of this disclosure can be written in one or more programming languages ​​or a combination thereof, including but not limited to object-oriented programming languages ​​such as Java, Smalltalk, 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., via the Internet using an Internet service provider).

[0170] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. 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 a 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, can 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.

[0171] The units described in the embodiments of this disclosure can be implemented in software or in hardware. The name of a unit does not necessarily limit the unit itself; for example, the first acquisition unit can also be described as "a unit that acquires at least two Internet Protocol addresses".

[0172] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.

[0173] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on 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 fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0174] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.

[0175] Furthermore, although the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while some specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.

[0176] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.

Claims

1. A code refactoring method, characterized in that, include: In response to a refactoring configuration command, a refactoring configuration interface is displayed, which includes refactoring configuration items for determining the code file to be refactored. Receive the reconstruction configuration information corresponding to the reconstruction configuration item, and determine the first code file to be reconstructed based on the reconstruction configuration information; Based on the pre-generated set of refactoring change information, determine the first code to be modified in the first code file and refactor the first code into the second code to obtain the second code file; The refactoring change information set includes at least one refactoring change information, and each refactoring change information is used to match a piece of code to be modified and to refactor the matched code.

2. The method according to claim 1, characterized in that, The refactoring configuration items include: code file path configuration items, determination condition configuration items, and determination method configuration items; The step of receiving the reconstruction configuration information corresponding to the reconstruction configuration item and determining the first code file to be reconstructed based on the reconstruction configuration information includes: Receive source path information configured in the path configuration item, filter conditions configured in the determination condition configuration item, and determination execution method configured in the determination method configuration item; If the source path information points to a code file, then the code file is identified as the first code file; If the source path information points to a code folder, then according to the determined execution method, the first code file that meets the filtering conditions is searched from the code folder.

3. The method according to claim 1, characterized in that, The step of determining the first code to be modified in the first code file and reconstructing the first code into second code based on the pre-generated set of refactoring modification information to obtain the second code file includes: In the first abstract syntax tree of the first code file, determine the first tree node that matches any refactoring change information in the refactoring change information set; The code corresponding to the first tree node is recorded as the first code in the first code file, and the refactoring modification information matched by the first tree node is recorded as the matching refactoring modification information; Based on the matching reconstruction modification information, the first tree node is reconstructed into a second tree node, and the second code corresponding to the second tree node is obtained; In the first code file, the second code is used to replace the first code to form a second code file.

4. The method according to claim 3, characterized in that, The step of determining the first tree node in the first abstract syntax tree that matches any one of the refactoring change information in the refactoring change information set includes: The root node of the first abstract syntax tree is taken as the node to be matched, and a reconstruction change information is selected from the reconstruction change information set in storage order as the reconstruction change information to be matched. If the node to be matched matches the node matching information in the reconstructed modification information to be matched, then the node to be matched is recorded as the first tree node, and the process jumps to the next node to be matched selection operation. If the node to be matched does not match the node matching information, the selection operation of the reconstructed modification information to be matched is re-executed until all the reconstructed modification information in the set has been selected, and after all have been selected, the process jumps to the next node to be matched. Select the next node to be matched from the first abstract syntax tree according to the given traversal method, return and re-execute the matching operation between the node to be matched and the reconstructed change information, until the node traversal end condition is met.

5. The method according to claim 3, characterized in that, The step of reconstructing the first tree node into a second tree node based on the matching reconstruction modification information and obtaining the second code corresponding to the second tree node includes: Extract the node transformation information contained in the matched reconstruction modification information; Based on the node transformation information, the first tree node is reconstructed into a second tree node; The second tree node is converted into second code according to the code generator.

6. The method according to any one of claims 1-5, characterized in that, The reconstructed modification information is generated through a generative network model; The steps for generating reconstruction change information using a generative network model include: Receive at least one modification description message edited in a format readable by the given model. Each modification description message corresponds to a piece of code to be modified, including a description of the original code content and a description of the modified code content. Each received modification description is processed according to the pre-given modification constraint information, and a reconstruction modification information is generated for each modification description.

7. The method according to claim 6, characterized in that, The generative network model is obtained through model training based on the modified constraints, combined with the given sample modification description information and code reconstruction knowledge base.

8. A code refactoring apparatus, characterized in that, include: The response module is used to respond to the refactoring configuration command and display the refactoring configuration interface, which includes refactoring configuration items for determining the code file to be refactored. The first determining module is used to receive the reconstruction configuration information corresponding to the reconstruction configuration item, and determine the first code file to be reconstructed based on the reconstruction configuration information; The second determining module is used to determine the first code to be modified in the first code file based on the pre-generated set of refactoring modification information, and refactor the first code into the second code to obtain the second code file; The refactoring change information set includes at least one refactoring change information, and each refactoring change information is used to match a piece of code to be modified and to refactor the matched code.

9. A computer device, characterized in that, The computer device includes: One or more processors; a storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the code refactoring method as described in any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the code refactoring method as described in any one of claims 1-7.