A code generation method, device, equipment and storage medium

Through code generation templates and logo matching technology, incremental code coverage is achieved, which solves the problems of business data coverage and code redundancy when generating code, and improves the accuracy and efficiency of code generation.

CN113296789BActive Publication Date: 2024-08-23BEIJING YOUZHUJU NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110668716.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-16
Publication Date
2024-08-23
Estimated Expiration
2041-06-16

AI Technical Summary

Technical Problem

When generating code for application software, business data is easily overwritten after secondary development, requiring reconfiguration, which is time-consuming and labor-intensive. Moreover, the existing technology is error-prone when code is incrementally added and obsolete code cannot be deleted.

Method used

By accurately saving the generated code that needs to be retained, and splicing the code that needs to be retained with the newly generated code, incremental code coverage is achieved, and code generation templates and identification matching are used to determine retained and new code items, reducing redundancy. remaining code.

Benefits of technology

Effectively retain business data, reduce the workload of configuring business data, avoid code matching errors, improve the accuracy of code generation and delete abandoned codes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113296789B
    Figure CN113296789B
Patent Text Reader

Abstract

The present disclosure provides a code generation method, apparatus, device and storage medium. For the target business, multiple first code generation request items of the generated code and multiple second code generation request items of the to-be-generated code can be determined respectively, and then the reserved code items in the multiple first code generation request items and the newly added code items in the multiple second code generation request items for the to-be-generated code are determined, and the partial code fragments corresponding to the reserved code items and the partial code fragments corresponding to the newly added code items are spliced ​​to obtain new code to be generated. In this way, by accurately saving the generated code that needs to be retained, and splicing the code that needs to be retained with the newly generated additional code, incremental code coverage is achieved, business data can be effectively retained, the workload of configuring business data can be reduced, and discarded code can be effectively deleted, effectively avoiding the probability of problems when matching a large number of codes, which is conducive to improving the accuracy of code generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a code generation method, apparatus, device and storage medium. Background Art

[0002] At present, with the rapid development of the Internet, people's lives are closely related to various application software. In the traditional way, the code of application software is manually typed line by line by programmers. In order to improve the development efficiency of application software, a new way can use a development software to automatically or semi-automatically generate the code of application software, and configure the corresponding business data based on the generated code to realize specific business functions.

[0003] In some code generation scenarios, the generated code needs to be redeveloped to update the code. When the code is regenerated after the secondary development, the business data will be overwritten and need to be reconfigured, which is time-consuming and labor-intensive. Summary of the invention

[0004] The embodiments of the present disclosure at least provide a code generation method, apparatus, device, and storage medium.

[0005] The present disclosure provides a code generation method, the method comprising:

[0006] For the acquired generated code of the target business, determine a plurality of first code generation request items used to generate the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code;

[0007] Determining, from the acquired target code generation information corresponding to the code to be generated for the target business, a plurality of second code generation request items for generating the code to be generated, and a second identifier of each second code generation request item;

[0008] Based on the determined multiple first identifiers and the determined multiple second identifiers, determine at least one reserved code item in the multiple first code generation request items that already exists when the code to be generated is generated, and at least one newly added code item in the multiple second code generation request items for the code to be generated relative to the generated code;

[0009] The code to be generated is generated based on the generated code, the location information corresponding to each reserved code item, the at least one newly added code item and the acquired code generation template configured for the target service.

[0010] In an optional implementation, before determining, for the acquired generated code of the target business, a plurality of first code generation request items for generating the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code, the method includes:

[0011] According to a preset file storage path, obtain the code file of the generated code;

[0012] The code content in the code file is read to obtain the generated code.

[0013] In an optional implementation, the step of determining, for the acquired generated code of the target business, a plurality of first code generation request items used to generate the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code includes:

[0014] Performing grammatical structure analysis on the acquired generated code to obtain code logic information of the generated code;

[0015] Based on the code logic information, determining a plurality of first code generation request items for generating the generated code;

[0016] Obtain a code generation template configured for the target business;

[0017] Based on the code generation template and the generated code, a first identifier of each first code generation request item and position information of a first code fragment generated by each first code generation request item in the generated code are determined.

[0018] In an optional implementation, the determining, based on the code generation template and the generated code, the first identifier of each first code generation request item and the position information of the first code fragment generated by each first code generation request item in the generated code includes:

[0019] Traversing the generated code to determine a first code fragment corresponding to each first code generation request item and matching the code generation template;

[0020] For each first code generation request item, determining a first identifier of the first code generation request item based on a first code fragment corresponding to the first code generation request item;

[0021] The position information of the first code fragment corresponding to the first code generation request item in the generated code is determined as the position information corresponding to the first code generation request item in the generated code.

[0022] In an optional implementation, the determining, based on the determined multiple first identifiers and the determined multiple second identifiers, at least one reserved code item that already exists when the code to be generated is generated in the multiple first code generation request items, and at least one newly added code item of the code to be generated relative to the generated code in the multiple second code generation request items includes:

[0023] Constructing a first identification array including the determined plurality of first identifications and a second identification array including the determined plurality of second identifications;

[0024] According to the first identification array and the second identification array, determine at least one reserved code item in the multiple first code generation request items that already exists when the code to be generated is generated, and at least one newly added code item in the multiple second code generation request items for the code to be generated relative to the generated code.

[0025] In an optional implementation, determining, according to the first identification array and the second identification array, at least one reserved code item that already exists in the multiple first code generation request items when the code to be generated is generated, and at least one newly added code item of the code to be generated relative to the generated code in the multiple second code generation request items includes:

[0026] Traversing the first identification array and the second identification array to detect whether there are first identifications and second identifications with the same identification between the first identification array and the second identification array;

[0027] If so, determining the first code generation request item corresponding to the first identifier with the consistent identifier as the at least one reserved code item that already exists when generating the code to be generated;

[0028] The second code generation request items corresponding to the other second identifiers except the second identifier with a consistent identifier among the multiple second code generation request items are determined as new code items of the code to be generated relative to the generated code.

[0029] In an optional implementation, the generating the code to be generated based on the generated code, the location information corresponding to each reserved code item, the at least one newly added code item, and the acquired code generation template configured for the target service includes:

[0030] Based on the position information corresponding to each reserved code item, obtaining a first code segment corresponding to each reserved code item from the generated code;

[0031] Based on the acquired code generation template configured for the target service and the at least one newly added code item, generate a second code segment corresponding to each newly added code item in the code to be generated;

[0032] According to the business logic information of the target business, the obtained at least one first code fragment and the obtained at least one second code fragment are spliced ​​to obtain the code to be generated.

[0033] In an optional implementation, the generating, based on the acquired code generation template configured for the target service and the at least one newly added code item, a second code fragment corresponding to each newly added code item in the code to be generated includes:

[0034] For each newly added code item, obtain a metadata set corresponding to the newly added code item;

[0035] The metadata set corresponding to the newly added code item is injected into the acquired code generation template configured for the target business, so as to obtain a second code fragment corresponding to the newly added code item in the code to be generated.

[0036] The present disclosure also provides a code generation device, the device comprising:

[0037] A first determination module is used to determine, for the acquired generated code of the target business, a plurality of first code generation request items used to generate the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code;

[0038] a second determination module, configured to determine, from the acquired target code generation information corresponding to the code to be generated for the target business, a plurality of second code generation request items for generating the code to be generated, and a second identifier of each second code generation request item;

[0039] A third determination module is used to determine, based on the determined multiple first identifiers and the determined multiple second identifiers, at least one reserved code item that already exists when the code to be generated is generated in the multiple first code generation request items, and at least one newly added code item of the code to be generated relative to the generated code in the multiple second code generation request items;

[0040] A generation module is used to generate the to-be-generated code based on the generated code, the location information corresponding to each reserved code item, the at least one newly added code item and the acquired code generation template configured for the target business.

[0041] In an optional implementation, the code generation device further includes a code acquisition module, and the code acquisition module is used to:

[0042] According to a preset file storage path, obtain the code file of the generated code;

[0043] The code content in the code file is read to obtain the generated code.

[0044] In an optional implementation manner, the first determining module is specifically configured to:

[0045] Performing grammatical structure analysis on the acquired generated code to obtain code logic information of the generated code;

[0046] Based on the code logic information, determining a plurality of first code generation request items for generating the generated code;

[0047] Obtain a code generation template configured for the target business;

[0048] Based on the code generation template and the generated code, a first identifier of each first code generation request item and position information of a first code fragment generated by each first code generation request item in the generated code are determined.

[0049] In an optional implementation manner, the first determination module, when used to determine the first identifier of each first code generation request item and the position information of the first code fragment generated by each first code generation request item in the generated code based on the code generation template and the generated code, is specifically used to:

[0050] Traversing the generated code to determine a first code fragment corresponding to each first code generation request item and matching the code generation template;

[0051] For each first code generation request item, determining a first identifier of the first code generation request item based on a first code fragment corresponding to the first code generation request item;

[0052] The position information of the first code fragment corresponding to the first code generation request item in the generated code is determined as the position information corresponding to the first code generation request item in the generated code.

[0053] In an optional implementation manner, the third determination module is specifically configured to:

[0054] Constructing a first identification array including the determined plurality of first identifications and a second identification array including the determined plurality of second identifications;

[0055] According to the first identification array and the second identification array, determine at least one reserved code item in the multiple first code generation request items that already exists when the code to be generated is generated, and at least one newly added code item in the multiple second code generation request items for the code to be generated relative to the generated code.

[0056] In an optional implementation manner, the third determination module, when used to determine, according to the first identification array and the second identification array, at least one reserved code item that already exists when the code to be generated is generated in the multiple first code generation request items, and at least one newly added code item of the code to be generated relative to the generated code in the multiple second code generation request items, is specifically used to:

[0057] Traversing the first identification array and the second identification array to detect whether there are first identifications and second identifications with the same identification between the first identification array and the second identification array;

[0058] If so, determining the first code generation request item corresponding to the first identifier with the consistent identifier as the at least one reserved code item that already exists when generating the code to be generated;

[0059] The second code generation request items corresponding to the other second identifiers except the second identifier with a consistent identifier among the multiple first code generation request items are determined as new code items of the code to be generated relative to the generated code.

[0060] In an optional implementation manner, the generating module is specifically used for:

[0061] Based on the position information corresponding to each reserved code item, obtaining a first code segment corresponding to each reserved code item from the generated code;

[0062] Based on the acquired code generation template configured for the target service and the at least one newly added code item, generate a second code segment corresponding to each newly added code item in the code to be generated;

[0063] According to the business logic information of the target business, the obtained at least one first code fragment and the obtained at least one second code fragment are spliced ​​to obtain the code to be generated.

[0064] In an optional implementation manner, when the generation module is used to generate the second code fragment corresponding to each newly added code item in the code to be generated based on the acquired code generation template configured for the target business and the at least one newly added code item, it is specifically used to:

[0065] For each newly added code item, obtain a metadata set corresponding to the newly added code item;

[0066] The metadata set corresponding to the newly added code item is injected into the acquired code generation template configured for the target business, so as to obtain a second code fragment corresponding to the newly added code item in the code to be generated.

[0067] An embodiment of the present disclosure also provides an electronic device, including: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps in the above-mentioned implementation are performed.

[0068] The embodiment of the present disclosure further provides a computer storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned embodiment are executed.

[0069] The embodiments of the present disclosure provide a code generation method, apparatus, device and storage medium. For an acquired generated code of a target business, a plurality of first code generation request items for generating the generated code and a first identifier of each first code generation request item, as well as position information corresponding to each first code generation request item in the generated code are determined; from the acquired target code generation information corresponding to the code to be generated for the target business, a plurality of second code generation request items for generating the code to be generated and a second identifier of each second code generation request item are determined; based on the determined plurality of first identifiers and the determined plurality of second identifiers, at least one reserved code item existing in the plurality of first code generation request items when the code to be generated is generated and at least one newly added code item of the code to be generated relative to the generated code in the plurality of second code generation request items are determined; based on the generated code, the position information corresponding to each reserved code item, the at least one newly added code item and the acquired code generation template configured for the target business, the code to be generated is generated.

[0070] In this way, by accurately saving the generated code that needs to be retained and splicing the code to be retained with the newly generated code, incremental code coverage can be achieved. This can effectively retain business data and reduce the workload of configuring business data. It can also effectively delete abandoned code and effectively avoid the chance of problems occurring when matching a large number of codes, which is conducive to improving the accuracy of code generation.

[0071] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0072] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following briefly introduces the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.

[0073] Figure 1 A flow chart of a code generation method provided by an embodiment of the present disclosure is shown;

[0074] Figure 2 A flowchart of another code generation method provided by an embodiment of the present disclosure is shown;

[0075] Figure 3 A schematic diagram of a code generation device provided by an embodiment of the present disclosure is shown;

[0076] Figure 4 A second schematic diagram of a code generating device provided by an embodiment of the present disclosure is shown;

[0077] Figure 5 A schematic diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0078] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.

[0079] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0080] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.

[0081] According to research, with the rapid development of the Internet, people's lives are closely related to various application software. In the traditional way, the code of application software is manually typed out line by line by programmers. In order to improve the development efficiency of application software, a new way can use a development software to automatically or semi-automatically generate the code of application software, and configure the corresponding business data based on the generated code to implement specific business functions. In some scenarios where code is generated, the generated code needs to be redeveloped to update the code. When the code is regenerated after secondary development, the business data will be overwritten and need to be reconfigured, which is time-consuming and labor-intensive.

[0082] Currently, there is a method of using regular matching to incrementally append code to address this problem, which can reduce the problem of code overwriting during secondary development to a certain extent. However, matching between a large number of codes is prone to matching errors in complex scenarios, and it is impossible to delete the abandoned generated code. The amount of code accumulates and the redundancy is complex.

[0083] Based on the above research, the present disclosure provides a code generation method, which realizes incremental code coverage by accurately saving the generated code that needs to be retained and splicing the code to be retained with the newly generated additional code. It can effectively retain business data and reduce the workload of configuring business data. It can also effectively delete discarded code and effectively avoid the probability of problems occurring when matching a large number of codes, which is conducive to improving the accuracy of code generation.

[0084] To facilitate understanding of the present embodiment, a code generation method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the code generation method provided in the embodiment of the present disclosure is generally a computer device with certain computing capabilities, and the computer device includes, for example: a terminal device or a server or other processing device, and the terminal device can be a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. In some possible implementations, the code generation method can be implemented by a processor calling a computer-readable instruction stored in a memory.

[0085] See also Figure 1 As shown, Figure 1 Flow chart of a code generation method provided by an embodiment of the present disclosure. The code generation method provided by an embodiment of the present disclosure, such as Figure 1 As shown in , the method includes:

[0086] S101: for an acquired generated code of a target business, determine a plurality of first code generation request items used to generate the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code.

[0087] In this step, after obtaining the generated code of the target business, multiple first code generation request items used to generate the generated code when generating the generated code can be determined by parsing the generated code, etc., and the first identifier of each first code generation request item, that is, the identifier of the first code generation request item, and the location information of each first code generation request item corresponding to the generated code can be further determined.

[0088] Among them, the position information corresponding to the first code generation request item in the generated code may refer to the position information of the code snippet generated by the first code generation request item in the generated code, that is, the position information corresponding to the first code generation request item in the generated code can be determined through the code snippet corresponding to the first code generation request item.

[0089] Among them, the automatic or semi-automatic generation of application software code is mostly done through some software development tools, through files that record data information, such as files containing test JSON strings of page information, or interface description language IDL files, which record code generation information that needs to be generated, such as information of metadata sets that can be called, etc., so as to generate code through the call of data. For the content recorded in the file, such as a callable data, it can be abstracted to correspond to a code generation request item. As described later, the second code generation request item can be determined through the target large code generation information. Correspondingly, through a code generation request item, calling its corresponding callable data can generate a piece of code, so a code generation request item also corresponds to a piece of code.

[0090] The first identifier of the first code generation request item may be an identifier of specific information such as the name of the first code generation request item.

[0091] S102: Determine, from the acquired target code generation information corresponding to the code to be generated for the target service, a plurality of second code generation request items for generating the code to be generated, and a second identifier of each second code generation request item.

[0092] In this step, when secondary code development is required for the target business, the target code generation information corresponding to the code to be generated for the target business can be first obtained, and then through the interpretation of the target code generation information, multiple second code generation request items for generating the code to be generated can be determined, as well as the second identifier of each second code generation request item, that is, the identifier of the second code generation request item of the code to be generated.

[0093] In actual applications, the target code generation information corresponding to the to-be-generated code of the target business may be recorded and presented in a file of a test JSON string containing page information, or an interface description language IDL file.

[0094] S103: Based on the determined multiple first identifiers and the determined multiple second identifiers, determine at least one reserved code item in the multiple first code generation request items that already exists when generating the code to be generated, and at least one newly added code item in the multiple second code generation request items for the code to be generated relative to the generated code.

[0095] In this step, after obtaining multiple first identifiers and determined multiple second identifiers, multiple first code generation request items and second code generation request items can be screened by matching multiple first identifiers with multiple second identifiers, etc., to determine at least one reserved code item among the multiple first code generation request items, that is, determine at least one reserved code item that already exists when generating the code to be generated, and at least one newly added code item among the multiple second code generation request items, that is, at least one newly added code item of the code to be generated relative to the generated code.

[0096] In this way, by identifying the match, the retained code items and the newly added code items can be determined, which can reduce the amount of data processing, effectively avoid the probability of problems occurring when matching a large number of codes, and save time and effort.

[0097] S104: Generate the code to be generated based on the generated code, the location information corresponding to each reserved code item, the at least one newly added code item and the acquired code generation template configured for the target service.

[0098] In this step, after determining the retained code items and the newly added code items, the part of the code that needs to be retained can be obtained through the retained code items and the corresponding location information, as well as the generated code, and the newly added part of the code can be obtained through the newly added code items and the code generation template, so that the final code to be generated can be generated.

[0099] Among them, the code generation template may refer to the corresponding code structure logic obtained by abstractly parsing the business logic of the target business before the code generation for the target business, so as to obtain an agreed template for generating code according to the code structure logic configuration, which may be obtained by manually configuring the obtained code structure logic, or by configuring using corresponding tools. For the code generation template of the target business, generally speaking, if the business direction of the target business, or the business logic, remains unchanged, the code generation template is unchanged, that is, for the generated code and the to-be-generated code of the target business, the code generation template used to generate the two is the same.

[0100] In a specific implementation, the code to be generated can be generated by first obtaining a first code fragment corresponding to each reserved code item from the generated code based on the position information corresponding to each reserved code item, that is, through the position information corresponding to the reserved code item, the code starting point and code ending point of a section of code in the generated code can be determined, and then by calling an interception function or the like, the section of code can be intercepted from the generated code as the first code fragment corresponding to the corresponding reserved code item.

[0101] Next, based on the acquired code generation template configured for the target service and the at least one newly added code item, a second code segment corresponding to each newly added code item in the code to be generated is generated.

[0102] Then, according to the business logic information of the target business, the at least one first code fragment and the at least one second code fragment are spliced ​​to obtain the code to be generated. That is, according to the business logic information of the target business, the connection logic, connection order and position of each code segment can be known. According to the obtained information, the code segments are spliced ​​accordingly to obtain the final required code to be generated.

[0103] In this way, by retaining part of the code corresponding to the code items and part of the code corresponding to the newly added code items, incremental code coverage can be achieved, and part of the code corresponding to the code items that need to be removed in addition to the retained code items in the generated code can be filtered out, thereby reducing code redundancy.

[0104] Further, the generating, based on the acquired code generation template configured for the target service and the at least one newly added code item, a second code fragment corresponding to each newly added code item in the code to be generated includes:

[0105] For each newly added code item, obtain a metadata set corresponding to the newly added code item;

[0106] The metadata set corresponding to the newly added code item is injected into the acquired code generation template configured for the target business, so as to obtain a second code fragment corresponding to the newly added code item in the code to be generated.

[0107] In this step, for each newly added code item, data calls can be made through data call functions or the like to obtain a metadata set corresponding to the newly added code item, and then the obtained metadata sets are injected into the obtained code generation template configured for the target business to generate a second code snippet corresponding to each newly added code item.

[0108] A code generation method provided by an embodiment of the present disclosure determines, for an acquired generated code of a target business, a plurality of first code generation request items for generating the generated code and a first identifier of each first code generation request item, as well as position information corresponding to each first code generation request item in the generated code; determines, from the acquired target code generation information corresponding to the code to be generated for the target business, a plurality of second code generation request items for generating the code to be generated and a second identifier of each second code generation request item; determines, based on the determined plurality of first identifiers and the determined plurality of second identifiers, at least one reserved code item existing in the plurality of first code generation request items when generating the code to be generated and at least one newly added code item of the code to be generated relative to the generated code in the plurality of second code generation request items; generates the code to be generated based on the generated code, the position information corresponding to each reserved code item, the at least one newly added code item, and the acquired code generation template configured for the target business.

[0109] In this way, by accurately saving the generated code that needs to be retained and splicing the code to be retained with the newly generated code, incremental code coverage can be achieved. This can effectively retain business data and reduce the workload of configuring business data. It can also effectively delete abandoned code and effectively avoid the chance of problems occurring when matching a large number of codes, which is conducive to improving the accuracy of code generation.

[0110] See also Figure 2 , Figure 2 Flow chart of another code generation method provided by the embodiment of the present disclosure. The code generation method provided by the embodiment of the present disclosure, such as Figure 2 As shown in , the method includes:

[0111] S201: Obtain the code file of the generated code according to a preset file storage path.

[0112] In this step, the preset file storage path for the target business can be determined according to the storage location of the code file of the target business, so as to obtain the code file of the generated code.

[0113] S202: Read the code content in the code file to obtain the generated code.

[0114] In this step, the generated code is obtained by reading the code content in the code file.

[0115] S203: For the acquired generated code of the target business, determine a plurality of first code generation request items used to generate the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code.

[0116] S204: Determine, from the acquired target code generation information corresponding to the code to be generated for the target service, a plurality of second code generation request items for generating the code to be generated, and a second identifier of each second code generation request item.

[0117] S205: Based on the determined multiple first identifiers and the determined multiple second identifiers, determine at least one reserved code item in the multiple first code generation request items that already exists when generating the code to be generated, and at least one newly added code item in the multiple second code generation request items for the code to be generated relative to the generated code.

[0118] S206: Generate the code to be generated based on the generated code, the location information corresponding to each reserved code item, the at least one newly added code item and the acquired code generation template configured for the target service.

[0119] Among them, the description of step S203 to step S206 can refer to the description of step S101 to step S104, and can achieve the same technical effects and solve the same technical problems, so they are not repeated here.

[0120] Next, this embodiment is further described in conjunction with specific implementation methods.

[0121] In an optional implementation, the step of determining, for the acquired generated code of the target business, a plurality of first code generation request items used to generate the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code includes:

[0122] Performing grammatical structure analysis on the acquired generated code to obtain code logic information of the generated code;

[0123] Based on the code logic information, determining a plurality of first code generation request items for generating the generated code;

[0124] Obtain a code generation template configured for the target business;

[0125] Based on the code generation template and the generated code, a first identifier of each first code generation request item and position information of a first code fragment generated by each first code generation request item in the generated code are determined.

[0126] In this step, after obtaining the generated code, the generated code can be subjected to grammatical structure parsing processing, for example, by parsing the abstract syntax tree AST of the generated code by calling a parser, etc., so as to abstractly obtain the code logic information of the generated code. From the logical relationship between the various parts of the code indicated by the code logic information, multiple first code generation request items used to generate the generated code can be determined. In addition, from the code file, the code generation template used to generate the generated code for the target business configuration can also be obtained. The match between the code generation template and the generated code can determine the position information of the first code fragment generated by each first code generation request item in the generated code, that is, the position information corresponding to each first code generation request item in the generated code, and the first identifier of each first code generation request item.

[0127] The code logic information may be an abstract syntax tree AST of the generated code. AST is a tree structure that represents the syntax structure of a programming language. The abstract syntax tree can be used to conveniently represent the logic information of the code.

[0128] Specifically, in an optional implementation, the determining, based on the code generation template and the generated code, the first identifier of each first code generation request item and the position information of the first code fragment generated by each first code generation request item in the generated code includes:

[0129] Traversing the generated code to determine a first code fragment corresponding to each first code generation request item and matching the code generation template;

[0130] For each first code generation request item, determining a first identifier of the first code generation request item based on a first code fragment corresponding to the first code generation request item;

[0131] The position information of the first code fragment corresponding to the first code generation request item in the generated code is determined as the position information corresponding to the first code generation request item in the generated code.

[0132] Since the generated code is generated by the code generation template and complies with the code generation template, in this step, the generated code can be traversed. By pattern matching and the like, when the generated code is traversed through the AST of the generated code, partial code that conforms to the code generation template can be obtained. This partial code can be considered to be a first code fragment that matches the code generation template and corresponds to the corresponding first code generation request item. Then, based on the first code fragment corresponding to the first code generation request item, the first identifier of the first code generation request item is determined. For example, information such as the data name corresponding to the first code fragment can be used as the identifier. Accordingly, the position information of the first code fragment in the generated code can be determined, and this position information can be used as the position information of the first code generation request item in the generated code.

[0133] In an optional implementation, the determining, based on the determined multiple first identifiers and the determined multiple second identifiers, at least one reserved code item that already exists when the code to be generated is generated in the multiple first code generation request items, and at least one newly added code item of the code to be generated relative to the generated code in the multiple second code generation request items includes:

[0134] Constructing a first identification array including the determined plurality of first identifications and a second identification array including the determined plurality of second identifications;

[0135] According to the first identification array and the second identification array, determine at least one reserved code item in the multiple first code generation request items that already exists when the code to be generated is generated, and at least one newly added code item in the multiple second code generation request items for the code to be generated relative to the generated code.

[0136] In this step, after obtaining multiple first identifiers and second identifiers, by respectively constructing a first identifier array for the generated code and a second identifier array for the code to be generated, the first identifier data includes the multiple first identifiers obtained, and the second identifier array includes the multiple second identifiers obtained. By matching the first identifier array and the second identifier array, it is possible to determine at least one reserved code item that already exists when generating the code to be generated in the multiple first code generation request items, and at least one new code item of the code to be generated relative to the generated code in the multiple second code generation request items.

[0137] Specifically, determining, according to the first identification array and the second identification array, at least one reserved code item that already exists in the multiple first code generation request items when the code to be generated is generated, and at least one newly added code item of the code to be generated relative to the generated code in the multiple second code generation request items includes:

[0138] Traversing the first identification array and the second identification array to detect whether there are first identifications and second identifications with the same identification between the first identification array and the second identification array;

[0139] If so, determining the first code generation request item corresponding to the first identifier with the consistent identifier as the at least one reserved code item that already exists when generating the code to be generated;

[0140] The second code generation request items corresponding to the other second identifiers except the second identifier with a consistent identifier among the multiple first code generation request items are determined as new code items of the code to be generated relative to the generated code.

[0141] In this step, after the first identifier array and the second identifier array are constructed, multiple first identifiers in the first identifier array and multiple second identifiers in the second identifier array can be traversed, such as comparing each first identifier in the first identifier array with the second identifier array, or comparing each second identifier in the second identifier array with the first identifier array, so as to detect whether there are first identifiers and second identifiers with consistent identifiers between the first identifier array and the second identifier array, that is, whether there is a situation where the first identifier and the second identifier are the same. If there are first identifiers and second identifiers with consistent identifiers, it can be considered that there is a first code generation request item corresponding to the first identifier with consistent identifier, which is also required when the code to be generated is generated, that is, for at least one reserved code item that already exists when the code to be generated is generated, and there is a second code generation request item corresponding to the second identifier with consistent identifier. Since it already exists, it is not necessary to use it to generate the code when generating the code to be generated. For other second identifiers, since there is no first identifier with consistent identifier, that is, there is no corresponding code in the generated code, it is necessary to generate the corresponding code through its corresponding second code generation request item. Therefore, these second code generation request items can be determined as newly added code items of the code to be generated relative to the generated code.

[0142] The code generation method provided by the embodiment of the present disclosure obtains the code file of the generated code according to a preset file storage path, reads the code content in the code file, obtains the generated code, determines, for the generated code of the target business, a plurality of first code generation request items for generating the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code, determines, from the target code generation information corresponding to the code to be generated for the target business, a plurality of second code generation request items for generating the code to be generated and a second identifier of each second code generation request item, determines, based on the determined plurality of first identifiers and the determined plurality of second identifiers, at least one reserved code item existing in the plurality of first code generation request items when generating the code to be generated, and at least one newly added code item of the code to be generated relative to the generated code in the plurality of second code generation request items, and generates the code to be generated based on the generated code, the position information corresponding to each reserved code item, the at least one newly added code item, and the obtained code generation template configured for the target business.

[0143] In this way, by accurately saving the generated code that needs to be retained and splicing the code to be retained with the newly generated code, incremental code coverage can be achieved. This can effectively retain business data and reduce the workload of configuring business data. It can also effectively delete abandoned code and effectively avoid the chance of problems occurring when matching a large number of codes, which is conducive to improving the accuracy of code generation.

[0144] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.

[0145] Based on the same inventive concept, a code generation device corresponding to the code generation method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned code generation method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.

[0146] See also Figure 3 to Figure 4 , Figure 3 A schematic diagram of a code generation device provided in an embodiment of the present disclosure, Figure 4 This is a second schematic diagram of a code generation device provided by an embodiment of the present disclosure. Figure 3 As shown in , the code generation device 300 provided by the embodiment of the present disclosure includes:

[0147] A first determining module 310 is used to determine, for the acquired generated code of the target business, a plurality of first code generation request items used to generate the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code;

[0148] A second determination module 320 is used to determine, from the acquired target code generation information corresponding to the code to be generated for the target business, a plurality of second code generation request items for generating the code to be generated, and a second identifier of each second code generation request item;

[0149] A third determining module 330 is configured to determine, based on the determined multiple first identifiers and the determined multiple second identifiers, at least one reserved code item that already exists when the code to be generated is generated in the multiple first code generation request items, and at least one newly added code item of the code to be generated relative to the generated code in the multiple second code generation request items;

[0150] The generation module 340 is used to generate the to-be-generated code based on the generated code, the location information corresponding to each reserved code item, the at least one newly added code item and the acquired code generation template configured for the target service.

[0151] In an optional implementation, the code generation device 300 further includes a code acquisition module 350, and the code acquisition module 350 is used to:

[0152] According to a preset file storage path, obtain the code file of the generated code;

[0153] The code content in the code file is read to obtain the generated code.

[0154] In an optional implementation manner, the first determining module 310 is specifically configured to:

[0155] Performing grammatical structure analysis on the acquired generated code to obtain code logic information of the generated code;

[0156] Based on the code logic information, determining a plurality of first code generation request items for generating the generated code;

[0157] Obtain a code generation template configured for the target business;

[0158] Based on the code generation template and the generated code, a first identifier of each first code generation request item and position information of a first code fragment generated by each first code generation request item in the generated code are determined.

[0159] In an optional implementation manner, the first determination module 310, when used to determine the first identifier of each first code generation request item and the position information of the first code fragment generated by each first code generation request item in the generated code based on the code generation template and the generated code, is specifically used to:

[0160] Traversing the generated code to determine a first code fragment corresponding to each first code generation request item and matching the code generation template;

[0161] For each first code generation request item, determining a first identifier of the first code generation request item based on a first code fragment corresponding to the first code generation request item;

[0162] The position information of the first code fragment corresponding to the first code generation request item in the generated code is determined as the position information corresponding to the first code generation request item in the generated code.

[0163] In an optional implementation manner, the third determining module 330 is specifically configured to:

[0164] Constructing a first identification array including the determined plurality of first identifications and a second identification array including the determined plurality of second identifications;

[0165] According to the first identification array and the second identification array, determine at least one reserved code item in the multiple first code generation request items that already exists when the code to be generated is generated, and at least one newly added code item in the multiple second code generation request items for the code to be generated relative to the generated code.

[0166] In an optional implementation manner, the third determination module 330, when used to determine, according to the first identification array and the second identification array, at least one reserved code item that already exists in the multiple first code generation request items when the code to be generated is generated, and at least one newly added code item of the code to be generated relative to the generated code in the multiple second code generation request items, is specifically used to:

[0167] Traversing the first identification array and the second identification array to detect whether there are first identifications and second identifications with the same identification between the first identification array and the second identification array;

[0168] If so, determining the first code generation request item corresponding to the first identifier with the consistent identifier as the at least one reserved code item that already exists when generating the code to be generated;

[0169] The second code generation request items corresponding to the other second identifiers except the second identifier with a consistent identifier among the multiple first code generation request items are determined as new code items of the code to be generated relative to the generated code.

[0170] In an optional implementation manner, the generating module 340 is specifically used for:

[0171] Based on the position information corresponding to each reserved code item, obtaining a first code segment corresponding to each reserved code item from the generated code;

[0172] Based on the acquired code generation template configured for the target service and the at least one newly added code item, generate a second code segment corresponding to each newly added code item in the code to be generated;

[0173] According to the business logic information of the target business, the obtained at least one first code fragment and the obtained at least one second code fragment are spliced ​​to obtain the code to be generated.

[0174] In an optional implementation manner, the generation module 340, when used to generate the second code fragment corresponding to each newly added code item in the code to be generated based on the acquired code generation template configured for the target business and the at least one newly added code item, is specifically used to:

[0175] For each newly added code item, obtain a metadata set corresponding to the newly added code item;

[0176] The metadata set corresponding to the newly added code item is injected into the acquired code generation template configured for the target business, so as to obtain a second code fragment corresponding to the newly added code item in the code to be generated.

[0177] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.

[0178] The embodiments of the present disclosure provide a code generation method, apparatus, device and storage medium. For an acquired generated code of a target business, a plurality of first code generation request items for generating the generated code and a first identifier of each first code generation request item, as well as position information corresponding to each first code generation request item in the generated code are determined; from the acquired target code generation information corresponding to the code to be generated for the target business, a plurality of second code generation request items for generating the code to be generated and a second identifier of each second code generation request item are determined; based on the determined plurality of first identifiers and the determined plurality of second identifiers, at least one reserved code item existing in the plurality of first code generation request items when the code to be generated is generated and at least one newly added code item of the code to be generated relative to the generated code in the plurality of second code generation request items are determined; based on the generated code, the position information corresponding to each reserved code item, the at least one newly added code item and the acquired code generation template configured for the target business, the code to be generated is generated.

[0179] In this way, by accurately saving the generated code that needs to be retained and splicing the code to be retained with the newly generated code, incremental code coverage can be achieved. This can effectively retain business data and reduce the workload of configuring business data. It can also effectively delete abandoned code and effectively avoid the chance of problems occurring when matching a large number of codes, which is conducive to improving the accuracy of code generation.

[0180] Based on the same technical concept, an embodiment of the present application also provides an electronic device.

[0181] The present disclosure also provides an electronic device 500, such as Figure 5FIG. 5 is a schematic diagram of the structure of an electronic device 500 provided in an embodiment of the present disclosure, including:

[0182] Processor 510, memory 520, and bus 530; memory 520 is used to store execution instructions, including internal memory 521 and external memory 522; the internal memory 521 here is also called internal memory, which is used to temporarily store the operation data in the processor 510, and the data exchanged with the external memory 522 such as a hard disk. The processor 510 exchanges data with the external memory 522 through the internal memory 521. When the electronic device 500 is running, the processor 510 communicates with the memory 520 through the bus 530, so that the processor 510 can execute the steps of the code generation method shown in the above method embodiment.

[0183] The present disclosure also provides a computer storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the code generation method described in the above method embodiment are executed. The storage medium may be a volatile or non-volatile computer-readable storage medium.

[0184] The present disclosure also provides a computer program product that carries a program code. The program code includes instructions that can be used to execute the steps of the code generation method described in the above method embodiment. For details, please refer to the above method embodiment, which will not be repeated here.

[0185] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).

[0186] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.

[0187] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0188] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0189] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0190] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.

Claims

1. A code generation method, characterized in that: The method comprises: For the acquired generated code of the target business, determine a plurality of first code generation request items used to generate the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code, wherein the plurality of first code generation request items and the plurality of second code generation request items are used to generate code by calling data; Determining, from the acquired target code generation information corresponding to the code to be generated for the target business, a plurality of second code generation request items for generating the code to be generated, and a second identifier of each second code generation request item; Based on the determined multiple first identifiers and the determined multiple second identifiers, determine at least one reserved code item in the multiple first code generation request items that already exists when the code to be generated is generated, and at least one newly added code item in the multiple second code generation request items for the code to be generated relative to the generated code; The code to be generated is generated based on the generated code, the location information corresponding to each reserved code item, the at least one newly added code item and the acquired code generation template configured for the target service.

2. The method according to claim 1, characterized in that Before determining, for the acquired generated code of the target service, a plurality of first code generation request items for generating the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code, the method includes: According to a preset file storage path, obtain the code file of the generated code; The code content in the code file is read to obtain the generated code.

3. The method according to claim 1, characterized in that: The step of determining, for the acquired generated code of the target business, a plurality of first code generation request items for generating the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code includes: Performing grammatical structure analysis on the acquired generated code to obtain code logic information of the generated code; Based on the code logic information, determining a plurality of first code generation request items for generating the generated code; Obtain a code generation template configured for the target business; Based on the code generation template and the generated code, a first identifier of each first code generation request item and position information of a first code fragment generated by each first code generation request item in the generated code are determined.

4. The method according to claim 3, characterized in that The determining, based on the code generation template and the generated code, a first identifier of each first code generation request item and position information of a first code fragment generated by each first code generation request item in the generated code includes: Traversing the generated code to determine a first code fragment corresponding to each first code generation request item and matching the code generation template; For each first code generation request item, determining a first identifier of the first code generation request item based on a first code fragment corresponding to the first code generation request item; The position information of the first code fragment corresponding to the first code generation request item in the generated code is determined as the position information corresponding to the first code generation request item in the generated code.

5. The method according to claim 1, characterized in that The determining, based on the determined multiple first identifiers and the determined multiple second identifiers, at least one reserved code item existing in the multiple first code generation request items when the code to be generated is generated, and at least one newly added code item of the code to be generated relative to the generated code in the multiple second code generation request items includes: Constructing a first identification array including the determined plurality of first identifications and a second identification array including the determined plurality of second identifications; According to the first identification array and the second identification array, determine at least one reserved code item in the multiple first code generation request items that already exists when the code to be generated is generated, and at least one newly added code item in the multiple second code generation request items for the code to be generated relative to the generated code.

6. The method according to claim 5, characterized in that The determining, according to the first identification array and the second identification array, at least one reserved code item existing in the plurality of first code generation request items when the code to be generated is generated, and at least one newly added code item of the code to be generated relative to the generated code in the plurality of second code generation request items, comprises: Traversing the first identification array and the second identification array to detect whether there are first identifications and second identifications with the same identification between the first identification array and the second identification array; If so, determining the first code generation request item corresponding to the first identifier with the consistent identifier as the at least one reserved code item that already exists when generating the code to be generated; The second code generation request items corresponding to the other second identifiers except the second identifier with a consistent identifier among the multiple second code generation request items are determined as new code items of the code to be generated relative to the generated code.

7. The method according to claim 1, characterized in that The generating the to-be-generated code based on the generated code, the position information corresponding to each reserved code item, the at least one newly added code item, and the acquired code generation template configured for the target service includes: Based on the position information corresponding to each reserved code item, obtaining a first code segment corresponding to each reserved code item from the generated code; Based on the acquired code generation template configured for the target service and the at least one newly added code item, generate a second code fragment corresponding to each newly added code item in the code to be generated; According to the business logic information of the target business, the obtained at least one first code fragment and the obtained at least one second code fragment are spliced ​​to obtain the code to be generated.

8. The method according to claim 7, characterized in that The step of generating a second code segment corresponding to each newly added code item in the code to be generated based on the acquired code generation template configured for the target service and the at least one newly added code item comprises: For each newly added code item, obtain a metadata set corresponding to the newly added code item; The metadata set corresponding to the newly added code item is injected into the acquired code generation template configured for the target business, so as to obtain a second code fragment corresponding to the newly added code item in the code to be generated.

9. A code generating device, characterized in that: The device comprises: a first determination module, configured to determine, for the acquired generated code of the target business, a plurality of first code generation request items for generating the generated code and a first identifier of each first code generation request item, and position information corresponding to each first code generation request item in the generated code, wherein the plurality of first code generation request items and the plurality of second code generation request items are used to generate code by calling data; a second determination module, configured to determine, from the acquired target code generation information corresponding to the code to be generated for the target business, a plurality of second code generation request items for generating the code to be generated, and a second identifier of each second code generation request item; A third determination module is used to determine, based on the determined multiple first identifiers and the determined multiple second identifiers, at least one reserved code item that already exists when the code to be generated is generated in the multiple first code generation request items, and at least one newly added code item of the code to be generated relative to the generated code in the multiple second code generation request items; A generation module is used to generate the to-be-generated code based on the generated code, the location information corresponding to each reserved code item, the at least one newly added code item and the acquired code generation template configured for the target business.

10. A computer device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the computer device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the code generation method according to any one of claims 1 to 8 are performed.

11. A computer storage medium, characterized in that: The computer storage medium stores a computer program, which, when executed by a processor, executes the steps of the code generation method according to any one of claims 1 to 8.