Code file generation method and device, storage medium and electronic device

By obtaining the project architecture information and requirements information of the target project, and generating high-quality microservice structure code, the existing code generators have solved the problems of low code quality and complex operation, and achieved fast and accurate code file generation.

CN119065674APending Publication Date: 2024-12-03GUANGZHOU XIAOPENG MOTORS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411091516.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-08
Publication Date
2024-12-03

AI Technical Summary

Technical Problem

Existing code generators cannot generate high-quality and readable microservice structure code, and the operation is complex and cannot meet the coexistence of multiple services.

Method used

By receiving code generation requests, we obtain the project architecture information and requirements information of the target project, and generate target code files based on this information, including the control layer, service layer, data access layer, entity class and XML mapping files, etc., supporting intelligent analysis and formatting Process to ensure uniform code style.

Benefits of technology

Improves the efficiency and quality of code generation, simplifies operational steps, supports complete microservice structure code generation, and ensures the accuracy and readability of generated code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119065674A_ABST
    Figure CN119065674A_ABST
Patent Text Reader

Abstract

The invention discloses a code file generation method and device, a storage medium and an electronic device, and relates to the technical field of computers. The method comprises the steps that in response to a received code generation request, project architecture information of a target project is obtained, the code generation request is used for requesting to generate a code file related to the target project, the code generation request carries demand information, and the demand information is used for indicating code content of a to-be-generated target code file; and generating a target code file based on the demand information, the project architecture information, the project code of the target project and the project configuration of the target project. According to the method and the device, the technical problems of low quality, poor performance and complicated operation of the code file generated by the code generator in the related technology are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] With the rapid development of cloud computing technology, more and more companies are beginning to adopt cloud services to achieve rapid deployment and expansion of their businesses. Under this trend, microservice architecture, as a popular software architecture style, is widely used in cloud computing environments due to its flexibility, scalability, and maintainability. The core of the microservice architecture is to split a large monolithic application into multiple small services, each of which can be deployed and expanded independently, thereby improving the flexibility and maintainability of the system. When implementing a microservice architecture, developers usually need to write and maintain a lot of code, such as creating code files such as the control layer, service layer, data access layer, entity class, mapper, and Extensible Markup Language (XML) mapping files, and make these code files follow certain coding specifications.

[0003] Existing code generators usually only support code generation at some levels, cannot provide complete microservice structure code, lack intelligent analysis capabilities, and cannot learn and imitate the code style habits of existing projects, resulting in poor readability of the generated code, low code quality, and even prone to performance problems. Secondly, existing code generators can usually only generate a single service and cannot meet the needs of multiple services coexisting in a microservice architecture. In addition, existing code generators usually require developers to perform a lot of configuration and settings, which makes them more complicated to use. Summary of the invention

[0004] The embodiments of the present invention provide a code file generation method, device, storage medium and electronic device to at least solve the technical problems in the related art that the code file generated by the code generator is of low quality, poor performance and complex operation.

[0005] According to one embodiment of the present invention, a code file generation method is provided, comprising: in response to receiving a code generation request, obtaining project architecture information of a target project, wherein the code generation request is used to request generation of a code file related to the target project, and the code generation request carries requirement information, and the requirement information is used to indicate the code content of the target code file to be generated; generating the target code file based on the requirement information, the project architecture information, the project code of the target project, and the project configuration of the target project.

[0006] Optionally, before obtaining the project architecture information of the target project in response to receiving the code generation request, the method also includes: obtaining a project loading configuration of the target project, wherein the project loading configuration is used to represent a configuration file or parameter loaded by the target project at startup; establishing a database configuration based on the project loading configuration, wherein the database configuration is used to establish a database connection for the target project; determining a code structure directory based on the project structure of the target project, wherein the code structure directory is used to represent a directory structure for storing project codes and a domain division rule for the target project; and analyzing and extracting the project code to obtain a code template, wherein the code template is used to represent the writing logic of the project code.

[0007] Optionally, analyzing and extracting the project code to obtain the code template includes: traversing the project code multiple times, analyzing and extracting the project code to obtain the core code, wherein the core code is used to represent the execution logic of the project code; analyzing and extracting the core code to obtain the code template.

[0008] Optionally, in response to receiving a code generation request, obtaining project architecture information of the target project includes: in response to receiving a first code generation request, obtaining a code structure directory and a code template, wherein the first code generation request carries first requirement information, and the first requirement information includes at least one of an application interface definition and a requirement document.

[0009] Optionally, generating a target code file based on the requirement information, project architecture information, the project code of the target project and the project configuration of the target project includes: batch generating first code files based on first requirement information, a code structure directory, a code template, a project code and a project configuration; formatting the first code file to obtain a second code file; and annotating the second code file to obtain a target code file.

[0010] Optionally, in response to receiving a code generation request, obtaining project architecture information of the target project includes: in response to receiving a second code generation request, obtaining a code structure directory, a code template, and a database configuration, wherein the second code generation request carries second requirement information, the second requirement information includes a table structure and input information, and the input information includes at least one of an application interface definition and a requirement document.

[0011] Optionally, generating a target code file based on the requirement information, project architecture information, the project code of the target project and the project configuration of the target project includes: batch generating a third code file based on the second requirement information, the code structure directory, the code template, the database configuration, the project code and the project configuration; formatting the third code file to obtain a fourth code file; and annotating the fourth code file to obtain a target code file.

[0012] Optionally, the method further includes: in response to the code generation request carrying a target directory, saving the target code file to the target directory; or, performing intelligent judgment on the target code file, determining the target directory, and saving the target code file to the target directory.

[0013] According to one embodiment of the present invention, there is also provided a code file generating device, comprising: an acquiring module, for acquiring project architecture information of a target project in response to receiving a code generation request, wherein the code generation request is used to request generation of a code file related to the target project, and the code generation request carries requirement information, and the requirement information is used to indicate the code content of the target code file to be generated; and a generating module, for generating the target code file based on the requirement information, the project architecture information, the project code of the target project and the project configuration of the target project.

[0014] Optionally, it also includes: an analysis module, used to obtain the project loading configuration of the target project, wherein the project loading configuration is used to represent the configuration file or parameters loaded when the target project is started; establishing a database configuration based on the project loading configuration, wherein the database configuration is used to establish a database connection for the target project; determining a code structure directory based on the project structure of the target project, wherein the code structure directory is used to represent the directory structure for storing the project code and the domain division rules of the target project; analyzing and extracting the project code to obtain a code template, wherein the code template is used to represent the writing logic of the project code.

[0015] Optionally, the analysis module is also used to traverse the project code multiple times, analyze and extract the project code to obtain the core code, wherein the core code is used to represent the execution logic of the project code; analyze and extract the core code to obtain a code template.

[0016] Optionally, the acquisition module is further used to acquire a code structure directory and a code template in response to receiving a first code generation request, wherein the first code generation request carries first requirement information, and the first requirement information includes at least one of an application interface definition and a requirement document.

[0017] Optionally, the generation module is also used to batch generate first code files based on the first requirement information, code structure directory, code template, project code and project configuration; format the first code files to obtain second code files; and annotate the second code files to obtain target code files.

[0018] Optionally, the acquisition module is also used to obtain a code structure directory, a code template and a database configuration in response to receiving a second code generation request, wherein the second code generation request carries second requirement information, the second requirement information includes a table structure and input information, and the input information includes at least one of an application interface definition and a requirement document.

[0019] Optionally, the generation module is also used to batch generate third code files based on the second requirement information, code structure directory, code template, database configuration, project code and project configuration; format the third code files to obtain fourth code files; and annotate the fourth code files to obtain target code files.

[0020] Optionally, it also includes: a saving module, which is used to save the target code file to the target directory in response to the code generation request carrying the target directory; or, to perform intelligent judgment on the target code file, determine the target directory, and save the target code file to the target directory.

[0021] According to one embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute any of the above code file generation methods when running on a computer or a processor.

[0022] According to one embodiment of the present invention, there is further provided an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute any of the above code file generation methods.

[0023] According to one embodiment of the present invention, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the code file generation method in any one of the above items is implemented.

[0024] In an embodiment of the present invention, a code generation request for requesting to generate a code file related to a target project is received, and then the project architecture information of the target project is obtained, wherein the code generation request carries requirement information, and the requirement information is used to indicate the code content of the target code file to be generated. Afterwards, the corresponding target code file is generated based on the requirement information, the project architecture information, the project code of the target project, and the project configuration of the target project, so as to achieve the purpose of efficiently and accurately generating the required code file according to the requirement information, thereby realizing the technical effect of quickly generating the corresponding code file according to the configuration requirements of the user, improving the generation efficiency of the code file, improving the quality and accuracy of the generated code file, simplifying the operation steps, and thus solving the technical problems of low quality, poor performance, and complex operation of the code file generated by the code generator in the related art. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0026] Figure 1 is a flow chart of a code file generating method according to one embodiment of the present invention;

[0027] Figure 2 is a flowchart of a project analysis according to one embodiment of the present invention;

[0028] Figure 3 is a flowchart of generating code according to one embodiment of the present invention;

[0029] Figure 4 It is a structural block diagram of a code file generating device according to one embodiment of the present invention. DETAILED DESCRIPTION

[0030] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0031] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In the description of this embodiment, unless otherwise specified, the meaning of "multiple" is two or more. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0032] According to one embodiment of the present invention, an embodiment of a code file generation method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0033] The method embodiment can be executed in an electronic device including a memory and a processor, a similar control device or a system. Taking an electronic device as an example, the electronic device may include one or more processors and a memory for storing data. Optionally, the electronic device may also include a communication device and a display device for communication functions. It can be understood by a person of ordinary skill in the art that the above structural description is only illustrative and does not limit the structure of the above electronic device. For example, the electronic device may also include more or fewer components than the above structural description, or have a configuration different from the above structural description.

[0034] The processor may include one or more processing units. For example, the processor may include a central processing unit (CPU), a graphics processing unit (GPU), a digital signal processing (DSP) chip, a microcontroller unit (MCU), a field-programmable gate array (FPGA), a neural network processor (NPU), a tensor processing unit (TPU), an artificial intelligence (AI) type processor, and the like. Among them, different processing units may be independent components or integrated into one or more processors. In some instances, the electronic device may also include one or more processors.

[0035] The memory can be used to store computer programs, such as storing the computer programs corresponding to the code file generation method in the embodiment of the present invention, and the processor implements the above-mentioned code file generation method by running the computer program stored in the memory. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0036] The communication device is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the communication device includes a network adapter (network interface controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the communication device can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0037] The display device may be, for example, a touch screen type liquid crystal display (LCD) and a touch display (also referred to as a "touch screen" or "touch display screen"). The liquid crystal display may enable a user to interact with a user interface of a mobile terminal. In some embodiments, the mobile terminal has a graphical user interface (GUI), and a user may interact with the GUI by finger contact and / or gestures on a touch-sensitive surface, wherein the human-computer interaction functions here may optionally include the following interactions: creating web pages, drawing, word processing, making electronic documents, games, video conferencing, instant messaging, sending and receiving emails, call interfaces, playing digital videos, playing digital music and / or web browsing, etc. The executable instructions for executing the above human-computer interaction functions are configured / stored in a computer program product or a readable storage medium executable by one or more processors.

[0038] In this embodiment, a method for generating a code file running on an electronic device is provided. Figure 1 is a flow chart of a code file generation method according to one embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0039] Step S11, in response to receiving a code generation request, obtaining project architecture information of the target project, wherein the code generation request is used to request generation of a code file related to the target project, and the code generation request carries requirement information, and the requirement information is used to indicate the code content of the target code file to be generated.

[0040] Step S12, generating a target code file based on the requirement information, the project architecture information, the project code of the target project and the project configuration of the target project.

[0041] The execution subject of the code file generation method proposed in the embodiment of the present invention can be an intelligent code generation plug-in based on artificial intelligence (AI), hereinafter referred to as plug-in. The user triggers the generation of a code generation request by triggering a preset touch button on the user interface (UI), and sends the code generation request to the plug-in. After that, the plug-in generates a corresponding code file according to the received code generation request. Optionally, the touch button preset on the UI interface can be a single touch button, so that the user can generate the corresponding code file by touching the touch button, simplifying the operation steps.

[0042] In the embodiment of the present invention, the target project can be understood as a developed project, and the code generation request is used to request the generation of a code file related to the target project. Exemplarily, the code generation request can be a request for a user to touch a touch button on a UI interface to trigger the generation with one click.

[0043] The code generation request carries requirement information, which is used to indicate the code content of the target code file to be generated. The requirement information can be understood as the requirement information input by the user. It can be understood that a configuration interface can be provided in the UI interface, and the user can enter the requirement information such as the Application Programming Interface (API) definition, requirement document, table structure, etc. in the configuration interface, so that the plug-in generates the corresponding target code file according to the requirement information input by the user.

[0044] The project architecture information of the target project is used to represent the design and organization of the overall structure of the target project, including the relationship between various components and modules, data flow, functional division, etc. In the embodiment of the present invention, the project architecture information may include information such as the database configuration, code structure directory, and code template of the target project, which is not limited here.

[0045] It should be noted that the target project is usually analyzed when the plug-in is first started, so as to obtain the project structure information of the target project, which can be used directly in subsequent use without analyzing the target project every time.

[0046] The project code of the target project and the project configuration of the target project can be understood as the complete project code file and configuration information of the target project, that is, the project code and configuration information of the existing project.

[0047] The target code file can be understood as a code file related to the target project generated according to the requirement information (i.e., the API definition and other requirement information). For example, the target code file may include a complete microservice structure code including the control layer (controller), service layer (service), data access layer (dao), entity class (entity), mapper (mapper) and XML mapping file (mapperXML), etc., which is not limited here.

[0048] In an embodiment of the present invention, if the plug-in receives a code generation request for requesting the generation of a code file related to a target project, the project architecture information of the target project will be obtained, wherein the code generation request carries requirement information, and the requirement information is used to indicate the code content of the target code file to be generated. Then, the plug-in will generate the corresponding target code file based on the requirement information, project architecture information, the project code of the target project, and the project configuration of the target project. As a result, the user only needs to make a simple configuration to quickly generate the required code file through the "one-click generation" function of the plug-in, which supports flexible configuration of different projects, thereby greatly improving the code generation efficiency. In addition, the plug-in can use AI to intelligently analyze existing project codes to ensure the accuracy of the generated target code files and ensure the uniform style of the generated target code files.

[0049] Through the above steps, by receiving a code generation request for requesting to generate a code file related to a target project, and then obtaining the project architecture information of the target project, wherein the code generation request carries requirement information, and the requirement information is used to indicate the code content of the target code file to be generated. Afterwards, the corresponding target code file is generated based on the requirement information, the project architecture information, the project code of the target project, and the project configuration of the target project, so as to achieve the purpose of efficiently and accurately generating the required code file according to the requirement information, thereby realizing the technical effect of quickly generating the corresponding code file according to the configuration requirements of the user, improving the generation efficiency of the code file, improving the quality and accuracy of the generated code file, simplifying the operation steps, and thus solving the technical problems of low quality, poor performance, and complex operation of the code file generated by the code generator in the related technology.

[0050] Optionally, before obtaining the project architecture information of the target project in response to receiving the code generation request in step S11, the following execution steps may also be included:

[0051] Step S101, obtaining a project loading configuration of a target project, wherein the project loading configuration is used to represent a configuration file or parameter loaded when the target project is started;

[0052] Step S102, establishing a database configuration based on the project loading configuration, wherein the database configuration is used to establish a database connection for the target project;

[0053] Step S103, determining a code structure directory based on the project structure of the target project, wherein the code structure directory is used to represent the directory structure storing the project code and the domain division rule of the target project;

[0054] Step S104, analyzing and extracting the project code to obtain a code template, wherein the code template is used to represent the writing logic of the project code.

[0055] In an embodiment of the present invention, when the plug-in is started for the first time, that is, before the plug-in receives a code generation request and obtains the project architecture information of the target project, the target project will also be analyzed to obtain the database configuration, code structure directory and code template for use in subsequent code file generation.

[0056] Specifically, the plug-in will obtain the project loading configuration of the target project, which is used to represent the configuration file or parameters loaded by the target project at startup, and then establish a database configuration based on the project loading configuration, which is used to establish a database connection for the target project. It can be understood that the plug-in will automatically establish a database configuration based on the project loading configuration of the target project, thereby automatically establishing a database connection.

[0057] The plug-in will also determine the code structure directory based on the project structure of the target project. The code structure directory is used to represent the directory structure of the project code and the domain division rules of the target project. It can be understood that the plug-in will automatically analyze the project code structure of the target project (including multi-module projects), extract various types of files and domain division rules, and thus obtain the code structure directory.

[0058] The plug-in will also analyze and extract the project code to obtain a code template, which is used to represent the writing logic of the project code. It can be understood that the plug-in will automatically analyze and extract the project code, analyze the writing logic of the project code, and obtain a code template.

[0059] Figure 2 is a flowchart of a project analysis according to one embodiment of the present invention. Figure 2 As shown, when the plug-in is started for the first time, that is, when the project is started, the plug-in will analyze the target project to obtain the database configuration, code structure directory and code template. Specifically, the plug-in will analyze the project code structure of the target project (including multi-module projects) to extract various types of files and domain division rules. The plug-in will also extract the database configuration in the project configuration to automatically establish a database connection. The plug-in will also automatically analyze and extract the core code, thereby extracting the code template through multiple rounds of core code summarization.

[0060] Optionally, in step S104, analyzing and extracting the project code to obtain a code template may include the following execution steps:

[0061] Step S1041, traversing the project code multiple times, analyzing and extracting the project code to obtain the core code, wherein the core code is used to represent the execution logic of the project code;

[0062] Step S1042, analyzing and extracting the core code to obtain a code template.

[0063] In an embodiment of the present invention, when analyzing and extracting the project code to obtain the code template, the project code of the target project can be traversed multiple times, the project code can be analyzed and extracted to obtain the core code in the project code used to represent the execution logic of the project code, and then the core code can be analyzed and extracted to analyze the writing logic of the core code to obtain the code template.

[0064] Optionally, in step S11, in response to receiving the code generation request, obtaining the project architecture information of the target project may include the following execution steps:

[0065] Step S111, in response to receiving a first code generation request, obtaining a code structure directory and a code template, wherein the first code generation request carries first requirement information, and the first requirement information includes at least one of an application program interface definition and a requirement document.

[0066] In an embodiment of the present invention, when obtaining project architecture information of a target project in response to receiving a code generation request, if a first code generation request is received, a code structure directory and a code template are obtained, wherein the first code generation request carries first requirement information, and the first requirement information includes at least one of an application interface definition and a requirement document.

[0067] It can be understood that if the plug-in receives the first code generation request carrying only the API definition, or receives the first code generation request carrying only the requirement document, or receives the first code generation request carrying both the API definition and the requirement document, then it is only necessary to obtain the code structure directory and the code template without obtaining the database configuration.

[0068] Optionally, in step S12, generating a target code file based on the requirement information, the project architecture information, the project code of the target project, and the project configuration of the target project may include the following execution steps:

[0069] Step S121, batch-generating first code files based on the first requirement information, the code structure directory, the code template, the project code, and the project configuration;

[0070] Step S122, formatting the first code file to obtain a second code file;

[0071] Step S123, annotate the second code file to obtain a target code file.

[0072] In an embodiment of the present invention, when a target code file is generated based on requirement information, project architecture information, project code of a target project and project configuration of a target project, if a first code generation request is received, the first code files are generated in batches based on the first requirement information, code structure directory, code template, project code and project configuration, that is, the first code files are generated in batches based on the API definition, requirement document, code structure directory, code template, project code and project configuration.

[0073] The first code file is then formatted to obtain a second code file, and the second code file is annotated to finally obtain a target code file. That is, the plug-in can automatically format and annotate the generated code file, so that the generated target code file follows a unified coding style and contains detailed comments, thereby improving the readability and maintainability of the code file.

[0074] Optionally, in step S11, in response to receiving the code generation request, obtaining the project architecture information of the target project may include the following execution steps:

[0075] Step S112, in response to receiving a second code generation request, obtaining a code structure directory, a code template, and a database configuration, wherein the second code generation request carries second requirement information, the second requirement information includes a table structure and input information, and the input information includes at least one of an application interface definition and a requirement document.

[0076] In an embodiment of the present invention, in response to receiving a code generation request, when obtaining project architecture information of a target project, if a second code generation request is received, a code structure directory, a code template, and a database configuration are obtained, wherein the second code generation request carries second requirement information, the second requirement information includes a table structure and input information, and the input information includes at least one of an API definition and a requirement document.

[0077] It can be understood that if the plug-in receives the second code generation request carrying the table structure, it needs to obtain the code structure directory, the code template and the database configuration at the same time.

[0078] Optionally, in step S12, generating a target code file based on the requirement information, the project architecture information, the project code of the target project, and the project configuration of the target project may include the following execution steps:

[0079] Step S124, batch-generating third code files based on the second requirement information, the code structure directory, the code template, the database configuration, the project code and the project configuration;

[0080] Step S125, formatting the third code file to obtain a fourth code file;

[0081] Step S126, annotate the fourth code file to obtain a target code file.

[0082] In an embodiment of the present invention, when a target code file is generated based on requirement information, project architecture information, a project code of a target project, and a project configuration of a target project, if a second code generation request is received, a third code file is generated in batches based on the second requirement information, a code structure directory, a code template, a database configuration, a project code, and a project configuration, that is, the third code file is generated in batches based on the table structure, input information, a code structure directory, a code template, a database configuration, a project code, and a project configuration.

[0083] The third code file is then formatted to obtain a fourth code file, and the fourth code file is annotated to finally obtain a target code file. That is, the plug-in can automatically format and annotate the generated code file, so that the generated target code file follows a unified coding style and contains detailed comments, thereby improving the readability and maintainability of the code file.

[0084] Optionally, the method may further include the following execution steps:

[0085] Step S13, in response to the code generation request carrying a target directory, saving the target code file to the target directory; or,

[0086] Step S14, intelligently judge the target code file, determine the target directory, and save the target code file to the target directory.

[0087] In the embodiment of the present invention, after the target code file is generated, the target code file is also saved.

[0088] Specifically, if the code generation request carries a target directory, the target code file is saved to the target directory. It can be understood that if the user specifies the save location of the generated target code file, the target code file is saved to the save location specified by the user. If the code generation request does not carry a target directory, the plug-in will make an intelligent judgment on the target code file to determine the target directory and save the target code file to the target directory.

[0089] It can be seen that the method proposed in the embodiment of the present invention has the following beneficial effects compared with the related art:

[0090] (1) The embodiment of the present invention can use AI to intelligently analyze existing codes, automatically extract and generate templates, and the generated codes follow a unified coding style, thereby ensuring the accuracy and style of the generated codes, thereby improving the code quality.

[0091] (2) The embodiment of the present invention can support the generation of complete microservice structure code, that is, the embodiment of the present invention can batch generate all necessary components under the microservice architecture, including the control layer (controller), service layer (service), service interface (service interface), mapper (mapper) and XML mapping file (mapper XML), data access layer (dao), entity class (entity), etc.

[0092] (3) The embodiments of the present invention can significantly improve the efficiency of code generation. The batch API can be completed in just one minute from tens of minutes or half an hour, thereby improving development efficiency.

[0093] (4) The UI interface design of the plug-in in the embodiment of the present invention is simple, and the user can quickly generate the required code through the "one-click generation" function of the plug-in, and supports flexible configuration of different projects.

[0094] (5) The embodiments of the present invention can reduce repetitive basic code writing work, allowing developers to focus more time and energy on business logic and core functions.

[0095] Figure 3 is a flow chart of generating code according to one embodiment of the present invention, such as Figure 3 As shown, when the plug-in generates a code file, the user will enter any one or any combination of API definition, requirement document, and table structure on the UI interface. The plug-in then generates code in batches based on the requirement information entered by the user, formats the code, and finally displays the newly generated code to the user through the UI interface.

[0096] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0097] In the present embodiment, a code file generating device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived.

[0098] Figure 4 is a structural block diagram of a code file generating device according to one embodiment of the present invention. Figure 4 As shown, a code file generating device 400 is taken as an example, and the device includes: an obtaining module 401, which is used to obtain project architecture information of a target project in response to receiving a code generation request, wherein the code generation request is used to request generation of a code file related to the target project, and the code generation request carries requirement information, and the requirement information is used to indicate the code content of the target code file to be generated; a generating module 402, which is used to generate a target code file based on the requirement information, the project architecture information, the project code of the target project and the project configuration of the target project.

[0099] Optionally, it also includes: an analysis module, used to obtain the project loading configuration of the target project, wherein the project loading configuration is used to represent the configuration file or parameters loaded when the target project is started; establishing a database configuration based on the project loading configuration, wherein the database configuration is used to establish a database connection for the target project; determining a code structure directory based on the project structure of the target project, wherein the code structure directory is used to represent the directory structure for storing the project code and the domain division rules of the target project; analyzing and extracting the project code to obtain a code template, wherein the code template is used to represent the writing logic of the project code.

[0100] Optionally, the analysis module is also used to traverse the project code multiple times, analyze and extract the project code to obtain the core code, wherein the core code is used to represent the execution logic of the project code; analyze and extract the core code to obtain a code template.

[0101] Optionally, the acquisition module 401 is further used to acquire a code structure directory and a code template in response to receiving a first code generation request, wherein the first code generation request carries first requirement information, and the first requirement information includes at least one of an application interface definition and a requirement document.

[0102] Optionally, the generation module 402 is also used to batch generate first code files based on the first requirement information, code structure directory, code template, project code and project configuration; format the first code files to obtain second code files; and annotate the second code files to obtain target code files.

[0103] Optionally, the acquisition module 401 is also used to obtain a code structure directory, a code template and a database configuration in response to receiving a second code generation request, wherein the second code generation request carries second requirement information, the second requirement information includes a table structure and input information, and the input information includes at least one of an application interface definition and a requirement document.

[0104] Optionally, the generation module 402 is also used to batch generate a third code file based on the second requirement information, the code structure directory, the code template, the database configuration, the project code and the project configuration; format the third code file to obtain a fourth code file; and annotate the fourth code file to obtain a target code file.

[0105] Optionally, it also includes: a saving module, which is used to save the target code file to the target directory in response to the code generation request carrying the target directory; or, to perform intelligent judgment on the target code file, determine the target directory, and save the target code file to the target directory.

[0106] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0107] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any of the above method embodiments when running on a computer or a processor.

[0108] Optionally, in this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:

[0109] Step S11, in response to receiving a code generation request, obtaining project architecture information of the target project, wherein the code generation request is used to request generation of a code file related to the target project, and the code generation request carries requirement information, and the requirement information is used to indicate the code content of the target code file to be generated.

[0110] Step S12, generating a target code file based on the requirement information, the project architecture information, the project code of the target project and the project configuration of the target project.

[0111] Optionally, in this embodiment, the above-mentioned computer-readable storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.

[0112] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0113] Optionally, in this embodiment, the processor in the electronic device may be configured to run a computer program to perform the following steps:

[0114] Step S11, in response to receiving a code generation request, obtaining project architecture information of the target project, wherein the code generation request is used to request generation of a code file related to the target project, and the code generation request carries requirement information, and the requirement information is used to indicate the code content of the target code file to be generated.

[0115] Step S12, generating a target code file based on the requirement information, the project architecture information, the project code of the target project and the project configuration of the target project.

[0116] An embodiment of the present invention further provides a computer program product, including a computer program, which implements the steps in any of the above method embodiments when executed by a processor.

[0117] Optionally, in this embodiment, the computer program in the above computer program product may be configured to perform the following steps when executed by a processor:

[0118] Step S11, in response to receiving a code generation request, obtaining project architecture information of the target project, wherein the code generation request is used to request generation of a code file related to the target project, and the code generation request carries requirement information, and the requirement information is used to indicate the code content of the target code file to be generated.

[0119] Step S12, generating a target code file based on the requirement information, the project architecture information, the project code of the target project and the project configuration of the target project.

[0120] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.

[0121] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0122] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0123] In the several embodiments provided by the present invention, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be 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 interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0124] 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 units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0125] In addition, each functional unit in each embodiment of the present invention 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. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0126] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of 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 invention. The aforementioned storage medium includes: U disk, read-only memory (ROM), random access memory (RAM), mobile hard disk, magnetic disk or optical disk, etc., various media that can store program codes.

[0127] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A code file generation method, characterized in that: include: In response to receiving a code generation request, obtaining project architecture information of a target project, wherein the code generation request is used to request generation of a code file related to the target project, and the code generation request carries requirement information, and the requirement information is used to indicate code content of a target code file to be generated; The target code file is generated based on the requirement information, the project architecture information, the project code of the target project, and the project configuration of the target project.

2. The method according to claim 1, characterized in that Before obtaining the project architecture information of the target project in response to receiving the code generation request, the method further includes: Obtaining a project loading configuration of the target project, wherein the project loading configuration is used to represent a configuration file or parameter loaded when the target project is started; Establishing a database configuration based on the project loading configuration, wherein the database configuration is used to establish a database connection for the target project; Determine a code structure directory based on the project structure of the target project, wherein the code structure directory is used to represent the directory structure storing the project code and the domain division rule of the target project; The project code is analyzed and extracted to obtain a code template, wherein the code template is used to represent the writing logic of the project code.

3. The method according to claim 2, characterized in that The code template obtained by analyzing and extracting the project code includes: Traversing the project code multiple times, analyzing and extracting the project code to obtain a core code, wherein the core code is used to represent the execution logic of the project code; The core code is analyzed and extracted to obtain the code template.

4. The method according to claim 3, characterized in that In response to receiving the code generation request, obtaining the project architecture information of the target project includes: In response to receiving a first code generation request, the code structure directory and the code template are obtained, wherein the first code generation request carries first requirement information, and the first requirement information includes at least one of an application program interface definition and a requirement document.

5. The method according to claim 4, characterized in that Generating the target code file based on the requirement information, the project architecture information, the project code of the target project, and the project configuration of the target project includes: Batch generate first code files based on the first requirement information, the code structure directory, the code template, the project code and the project configuration; Formatting the first code file to obtain a second code file; The second code file is annotated to obtain the target code file.

6. The method according to claim 3, characterized in that: In response to receiving the code generation request, obtaining the project architecture information of the target project includes: In response to receiving a second code generation request, the code structure directory, the code template and the database configuration are obtained, wherein the second code generation request carries second requirement information, the second requirement information includes a table structure and input information, and the input information includes at least one of an application interface definition and a requirement document.

7. The method according to claim 6, characterized in that Generating the target code file based on the requirement information, the project architecture information, the project code of the target project, and the project configuration of the target project includes: Batch generate third code files based on the second requirement information, the code structure directory, the code template, the database configuration, the project code and the project configuration; Formatting the third code file to obtain a fourth code file; The fourth code file is annotated to obtain the target code file.

8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: In response to the code generation request carrying a target directory, saving the target code file to the target directory; or, An intelligent judgment is performed on the target code file, the target directory is determined, and the target code file is saved in the target directory.

9. A code file generating device, characterized in that: include: an acquisition module, configured to acquire project architecture information of a target project in response to receiving a code generation request, wherein the code generation request is used to request generation of a code file related to the target project, and the code generation request carries requirement information, and the requirement information is used to indicate code content of a target code file to be generated; A generation module is used to generate the target code file based on the requirement information, the project architecture information, the project code of the target project and the project configuration of the target project.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the code file generation method described in any one of claims 1 to 8 when running on a computer or a processor.

11. An electronic device comprising a memory and a processor, characterized in that: The memory stores a computer program, and the processor is configured to run the computer program to execute the code file generation method described in any one of claims 1 to 8.

12. A computer program product, characterized in that The invention comprises a computer program, which implements the code file generating method as claimed in any one of claims 1 to 8 when being executed by a processor.