CN116578282A - Code generation method, device, electronic equipment and medium - Google Patents

Code generation method, device, electronic equipment and medium Download PDF

Info

Publication number
CN116578282A
CN116578282A CN202310437462.9A CN202310437462A CN116578282A CN 116578282 A CN116578282 A CN 116578282A CN 202310437462 A CN202310437462 A CN 202310437462A CN 116578282 A CN116578282 A CN 116578282A
Authority
CN
China
Prior art keywords
code
information
meta information
annotation information
plug
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310437462.9A
Other languages
Chinese (zh)
Inventor
闵大双
夏志佳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Wuba Ganji Information Technology Co ltd
Original Assignee
Beijing Wuba Ganji Information Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Wuba Ganji Information Technology Co ltd filed Critical Beijing Wuba Ganji Information Technology Co ltd
Priority to CN202310437462.9A priority Critical patent/CN116578282A/en
Publication of CN116578282A publication Critical patent/CN116578282A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention discloses a code generation method, a code generation device, electronic equipment and a medium, and relates to the technical field of computers. The method comprises the following steps: introducing a code generation plug-in into the target engineering; compiling source codes of target projects in response to the compiling instructions, and generating abstract syntax trees corresponding to the target projects; triggering a code generation plug-in, collecting meta information corresponding to the annotation information based on the annotation information in the abstract syntax tree by the code generation plug-in, and automatically generating codes corresponding to the annotation information according to the meta information and a preset generation rule. The code generating plug-in of the method operates in a plug-in mode, acquires meta information based on annotation information in a project source code compiling stage, realizes automatic generation of codes based on the meta information, reduces code development workload, improves development efficiency, has low invasiveness to source codes, and is easy to maintain.

Description

Code generation method, device, electronic equipment and medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a code generating method, a code generating device, an electronic device, and a medium.
Background
Currently, in developing software projects, developers cannot avoid a large number of code of duplicate logic, of which only a small portion is inconsistent. In order to solve the problem of repeated code writing, improve the software development efficiency and save the software development cost, various code generator tools appear to assist developers in completing the development of software projects. However, existing code generator tools can only be used in newly created software engineering and cannot be used in existing software engineering; the invasiveness to the software item is strong, so that the software item is deeply bound with the code generator tool, and the subsequent maintenance work is extremely risky.
Disclosure of Invention
In order to solve the above technical problems or at least partially solve the above technical problems, embodiments of the present invention provide a code generation method, a device, an electronic apparatus, and a medium.
In a first aspect, an embodiment of the present invention provides a code generating method, including:
introducing a code generation plug-in into the target engineering;
compiling source codes of the target engineering in response to a compiling instruction, and generating an abstract syntax tree corresponding to the target engineering;
triggering the code generation plug-in, collecting meta information corresponding to the annotation information based on the code generation plug-in according to the annotation information in the abstract syntax tree, and automatically generating codes corresponding to the annotation information according to the meta information and a preset generation rule.
In some optional embodiments of the present invention, the triggering the code generation plug-in, based on the code generation plug-in, collects meta information corresponding to the annotation information according to the annotation information in the abstract syntax tree, and automatically generates a code corresponding to the annotation information according to the meta information and a preset generation rule, including:
triggering a code generator corresponding to annotation information in the abstract syntax tree according to a preset mapping relation; the preset mapping relation is used for indicating the corresponding relation between annotation information and a code generator;
triggering the meta information collector based on the code generator, and collecting meta information corresponding to annotation information in the abstract syntax tree based on the meta information collector;
and automatically generating codes corresponding to the annotation information based on the codes generator according to the meta information and a preset generation rule.
In some optional embodiments of the invention, the method further comprises: comparing the source code of the target project with the automatically generated code; combining the source code of the target project with the automatically generated code under the condition that the source code of the target project is different from the automatically generated code; and discarding the automatically generated code under the condition that the source code of the target project is determined to be the same as the automatically generated code.
In some optional embodiments of the present invention, the comparing the source code of the target project with the automatically generated code includes: determining a catalog where an automatically generated code is located, and determining whether a code file exists under the catalog; under the condition that a code file exists under the catalog, taking the code file as an original code, and acquiring key information of the original code based on the annotation information; and comparing the key information of the original code with the automatically generated code.
In some optional embodiments of the present invention, the meta information includes one or more of abstract syntax tree, configuration information, network information, and environment information corresponding to the target project.
In a second aspect, an embodiment of the present invention provides a code generating apparatus, including:
the introducing module is used for introducing the code generation plug-in the target engineering;
the compiling module is used for responding to the compiling instruction, compiling the source code of the target project and generating an abstract syntax tree corresponding to the target project;
the generation module is used for triggering the code generation plug-in, collecting meta information corresponding to the annotation information based on the code generation plug-in according to the annotation information in the abstract syntax tree, and automatically generating codes corresponding to the annotation information according to the meta information and a preset generation rule.
In some optional embodiments of the invention, the code generation plug-in includes a meta information collector and a code generator;
the generating module is used for:
triggering a code generator corresponding to annotation information in the abstract syntax tree according to a preset mapping relation; the preset mapping relation is used for indicating the corresponding relation between annotation information and a code generator;
triggering the meta information collector based on the code generator, and collecting meta information corresponding to annotation information in the abstract syntax tree based on the meta information collector;
and automatically generating codes corresponding to the annotation information based on the codes generator according to the meta information and a preset generation rule. And acquiring meta information corresponding to the annotation information based on the corresponding meta information acquirer.
In some optional embodiments of the present invention, the apparatus further comprises an alignment module for:
comparing the source code of the target project with the automatically generated code;
combining the source code of the target project with the automatically generated code under the condition that the source code of the target project is different from the automatically generated code;
and discarding the automatically generated code under the condition that the source code of the target project is determined to be the same as the automatically generated code.
In some optional embodiments of the invention, the comparison module is further configured to:
determining a catalog where an automatically generated code is located, and determining whether a code file exists under the catalog;
under the condition that a code file exists under the catalog, taking the code file as an original code, and acquiring key information of the original code based on the annotation information;
and comparing the key information of the original code with the automatically generated code.
In a third aspect, an embodiment of the present invention provides an electronic device, including: one or more processors; and a storage means for storing one or more programs that, when executed by the one or more processors, cause the one or more processors to implement the code generation method of any of the embodiments of the present invention.
In a fourth aspect, embodiments of the present invention provide a computer readable medium having stored thereon a computer program which, when executed by a processor, implements the code generation method of any of the embodiments of the present invention.
One embodiment of the above invention has the following advantages or benefits:
according to the code generation method, a code generation plug-in is introduced into a target project; compiling source codes of target projects in response to the compiling instructions, and generating abstract syntax trees corresponding to the target projects; and triggering a code generation plug-in, acquiring meta information corresponding to the annotation information based on the code generation plug-in according to the annotation information in the abstract syntax tree, and automatically generating codes corresponding to the annotation information according to the meta information and a preset generation rule. The code generating plug-in of the method runs in a plug-in mode, a jar packet except the code generating plug-in does not need to be introduced into the project, annotation information in source codes is of source level, the generated code does not carry any annotation information, trace of the code generating plug-in is avoided, and the method is low in invasiveness to the source codes and easy to maintain; meta information is collected at the project source code compiling stage, and automatic generation of codes is realized based on the meta information, so that the code development workload is remarkably reduced, and the development efficiency is effectively improved.
Further effects of the above-described non-conventional alternatives are described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a flow chart of a code generation method according to an embodiment of the present invention;
FIG. 2 is a flow chart of a code generation method according to another embodiment of the present invention;
fig. 3 is a schematic diagram showing the structure of a code generating apparatus according to an embodiment of the present invention;
fig. 4 shows a schematic diagram of an electronic device according to an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 shows a flow chart of a code generation method of an embodiment of the present invention. The execution subject of the code generation method of the embodiment of the present invention may be a code generation apparatus or other electronic devices that can implement the same function and include the code generation apparatus.
As shown in fig. 1, the code generation method includes:
step S101: code generation plug-ins are introduced in the target engineering.
The target project may be a software project constructed based on a maven tool (maven is a management tool specially used for constructing and managing java software projects), or may be a software project constructed based on other software management tools such as garden, IDE (eclipse, ideal) and java. It can be understood that the code generation plug-in of the embodiment of the invention is triggered at the compiling stage of the target engineering source code, so that the code generation plug-in of the embodiment of the invention can automatically generate the code as long as the compiling action exists. Taking a maven project as an example of the target project, a code generation plug-in can be introduced into a project object model (Project Object Model, POM) file of the maven project. The POM file defines basic information of a software project, comprises project information and configuration details of maven for constructing the project, and is mainly used for managing source codes, configuration files, information and roles of developers, organization information, dependency relationship of the project and the like. The developer may specify plug-ins, project dependencies, etc. that need to be introduced in the POM file. In the embodiment of the invention, the code generation plug-in is introduced into the POM file so as to run the code generation plug-in a maven plug-in mode, so that the code generation plug-in can be referenced in newly built maven software engineering or in existing maven software projects. Therefore, the target engineering of the present embodiment may be a newly created software engineering or an existing software engineering, and the present invention is not limited herein.
A code generation plug-in (i.e., a code generation tool) may be understood as a jar packet for automatically generating code, where the jar packet defines logic (code generation rules or methods) for code generation, and when the plug-in to be code generated is triggered, the logic method for code generation in the jar packet is executed to automatically generate code.
In an alternative embodiment, if the target project is a maven project, after the code generation plug-in is introduced into the project object model file of the target project, the scope of the code generation plug-in may be set to be comp.
The scope is used for controlling the loading range and the using range of the code generation plug-in. Compile (default) is used to indicate that the code generation plug-in needs to participate in the compilation, testing, packaging, running, etc. phases of the current project. And setting the scope of the code generation plug-in as a combile, so that the code generation plug-in is automatically triggered in the project source code encoding stage, namely, the working mode of the code generation plug-in is an automatic triggering mode, and manual triggering of a worker is not required.
Step S102: and compiling source codes of the target engineering in response to the compiling instruction, and generating an abstract syntax tree corresponding to the target engineering.
The compiling instruction is used for indicating compiling of source codes of the target engineering. The user can trigger the compiling operation of the source codes through the interactive interface of the project construction tool. And generating a compiling instruction under the condition that the compiling operation of the user is detected. And responding to the compiling instruction, and compiling the source code of the target engineering by a compiler to obtain an abstract syntax tree corresponding to the source code. Wherein the abstract syntax tree (Abstract Syntax Tree, ATS) corresponds to a data structure represented by a code program with a tree structure, each node on the abstract syntax tree representing a structure in source code.
Step S103: triggering the code generation plug-in, collecting meta information corresponding to the annotation information based on the code generation plug-in according to the annotation information in the abstract syntax tree, and automatically generating codes corresponding to the annotation information according to the meta information and a preset generation rule.
Annotation information is some information appended to the source code that provides a secure annotation-like mechanism for associating any information or metadata (metadata) with a program element (class, method, member variable, etc.). And the abstract syntax tree generated after the source codes are compiled comprises annotation information of the source codes. Among them, java annotations can be divided into three classes: standard annotations, meta annotations, and custom annotations. Standard annotations are defined annotations that are typically used to initiate code compilation checks. Meta-notes are notes used to modify notes, and other notes are explained. Custom annotations are annotations that are custom according to project needs. The format of the custom annotation is:
public@interface annotation name {
Content/annotation, list of attributes
}
Different annotation information may be used to indicate that code for different functions is generated, and code generated based on the annotation information may implement the corresponding function. In the process of compiling source codes to obtain an abstract syntax tree, if the abstract syntax tree comprises annotation information, triggering a code generation plug-in, and acquiring corresponding meta information by using the code generation plug-in. Meta information (meta) refers to information that can be collected by a code generation plug-in, such as configuration information of an item, development environment information, network information, and all information of source code. In particular, the meta information may include, but is not limited to, abstract syntax trees, configuration information, network information, and environment information corresponding to the target project. In the embodiment of the invention, the meta information required to be collected by different annotation information is different, the corresponding relation between the annotation information and the required meta information can be configured when the code generation plug-in is constructed, and the code generation plug-in collects the meta information required by the annotation information according to the corresponding relation.
The code generation plug-in automatically generates codes corresponding to the annotation information according to preset code generation rules based on the meta information.
According to the code generation method, a code generation plug-in is introduced into a target project; compiling source codes of target projects in response to the compiling instructions, and generating abstract syntax trees corresponding to the target projects; and triggering a code generation plug-in, acquiring meta information corresponding to the annotation information based on the code generation plug-in according to the annotation information in the abstract syntax tree, and automatically generating codes corresponding to the annotation information according to the meta information and a preset generation rule. The code generating plug-in of the method runs in a plug-in mode, a jar packet except the code generating plug-in does not need to be introduced into the project, annotation information in source codes is of source level, the generated code does not carry any annotation information, trace of the code generating plug-in is avoided, and the method is low in invasiveness to the source codes and easy to maintain; the meta information is collected at the project source code compiling stage, and the automatic generation of codes is realized based on the meta information, so that the code development workload is remarkably reduced, and the development efficiency is effectively improved; the automatically generated codes do not cover the original codes, so that a user can develop the automatically generated codes for the second time conveniently; the code generation plug-in is easy to develop, and a user can develop the corresponding code generation plug-in according to the requirements. The code generation method of the embodiment of the invention can be applied to web development scenes, automatically generates codes such as a controller layer, a service layer, a dao layer and the like (the controller layer is used for receiving and responding, the service layer is used for processing business logic and calling an API of the dao layer, and the dao layer performs addition, deletion and correction on single or multiple tables), and can perform static processing on logics such as object mapping, dynamic agents and the like which need dynamic processing, thereby improving development efficiency and performance.
In some alternative embodiments, the code generation plug-in includes a meta information collector and a code generator. The code generator is used for automatically generating codes according to the acquired meta information and a preset code generation rule.
In some alternative embodiments, there may be multiple code generators. Different code generators are used for responding to different annotation information and triggering the information collector to collect different meta information. When constructing the code generator, the annotation information responded by the code generator, namely, the mapping relation between the code generator and the annotation information can be configured, wherein the mapping relation is used for indicating the corresponding relation between the code generator and the annotation information. When compiling source codes, triggering a code generator corresponding to the current annotation information based on the mapping relation, and calling a meta-information collector to collect meta-information corresponding to the current annotation information by the code generator.
Fig. 2 is a flow chart of a code generating method according to another embodiment of the present invention, and as shown in fig. 2, the code generating method includes:
step S201: introducing a code generation plug-in into the target engineering, wherein the code generation plug-in comprises a meta-information collector and a code generator;
step S202: compiling source codes of the target engineering in response to a compiling instruction, and generating an abstract syntax tree corresponding to the target engineering;
step S203: triggering a code generator corresponding to annotation information in the abstract syntax tree according to a preset mapping relation; the preset mapping relation is used for indicating the corresponding relation between annotation information and a code generator;
step S204: triggering the meta information collector based on the code generator, and collecting meta information corresponding to annotation information in the abstract syntax tree based on the meta information collector;
step S205: automatically generating codes corresponding to the annotation information based on the codes generator according to the meta information and preset generation rules
Step S206: comparing the source code of the target project with the automatically generated code;
step S207: under the condition that the source code of the target project is different from the automatically generated code, combining the source code of the target project with the automatically generated code;
step S208: and discarding the automatically generated code under the condition that the source code of the target project is determined to be the same as the automatically generated code.
In the embodiments shown in fig. 1, steps S201 to S205 may be referred to, and the present invention is not described herein.
For steps S206-S208, in the case that the code generating plug-in automatically generates a code, determining a directory in which the automatically generated code is located, determining whether a code file exists under the directory, if the code file exists under the directory, taking the code file under the directory as an original code, checking the difference between the original code and the automatically generated code, merging the differences between the original code and the automatically generated code, and outputting the merged code under the directory. The original code and the automatically generated code can be compared by using a prior code comparison tool, and the comparison can be performed according to the following process: analyzing the original code based on a preset analysis item, determining key information of the original code, and comparing the key information of the original code with the automatically generated code, so as to determine the identity and the difference of the original code and the automatically generated code. The preset analysis items can be determined according to annotation information corresponding to the automatically generated codes, and different annotation information corresponds to different analysis items.
Fig. 3 shows a schematic diagram of the structure of a code generating apparatus according to an embodiment of the present invention. As shown in fig. 3, the code generating apparatus 300 includes:
an introducing module 301, configured to introduce a code generation plug-in a target project;
the compiling module 302 is configured to compile source codes of the target engineering in response to a compiling instruction, and generate an abstract syntax tree corresponding to the target engineering;
the generating module 303 is configured to trigger the code generating plug-in, collect meta information corresponding to the annotation information based on the code generating plug-in according to the annotation information in the abstract syntax tree, and automatically generate a code corresponding to the annotation information according to the meta information and a preset generating rule.
In some alternative embodiments, the code generation plug-in includes a meta information collector and a code generator;
the generating module is used for: triggering a code generator corresponding to annotation information in the abstract syntax tree according to a preset mapping relation; the preset mapping relation is used for indicating the corresponding relation between annotation information and a code generator; triggering the meta information collector based on the code generator, and collecting meta information corresponding to annotation information in the abstract syntax tree based on the meta information collector; and automatically generating codes corresponding to the annotation information based on the codes generator according to the meta information and a preset generation rule. Collecting meta information corresponding to the annotation information based on the corresponding meta information collector
In some optional embodiments of the present invention, the apparatus further comprises an alignment module for:
comparing the source code of the target project with the automatically generated code;
combining the source code of the target project with the automatically generated code under the condition that the source code of the target project is different from the automatically generated code;
and discarding the automatically generated code under the condition that the source code of the target project is determined to be the same as the automatically generated code.
In some optional embodiments of the invention, the comparison module is further configured to:
determining a catalog where an automatically generated code is located, and determining whether a code file exists under the catalog;
under the condition that a code file exists under the catalog, taking the code file as an original code, and acquiring key information of the original code based on the annotation information;
and comparing the key information of the original code with the automatically generated code.
The device can execute the method provided by the embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method. Technical details not described in detail in this embodiment may be found in the methods provided in the embodiments of the present invention.
The embodiment of the invention also provides an electronic device, as shown in fig. 4, which comprises a processor 401, a communication interface 402, a memory 403 and a communication bus 404, wherein the processor 401, the communication interface 402 and the memory 403 complete communication with each other through the communication bus 404,
a memory 403 for storing a computer program;
the processor 401, when executing the program stored in the memory 403, implements the following steps: introducing a code generation plug-in into the target engineering; compiling source codes of the target engineering in response to a compiling instruction, and generating an abstract syntax tree corresponding to the target engineering; triggering the code generation plug-in, acquiring meta information corresponding to the annotation information based on the code generation plug-in according to the annotation information in the abstract syntax tree, and automatically generating codes corresponding to the annotation information according to the meta information and a preset generation rule.
The communication bus 404 mentioned by the above terminal may be a peripheral component interconnect standard (Peripheral Component Interconnect, abbreviated as PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, abbreviated as EISA) bus, etc. The communication bus 404 may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface 402 is used for communication between the above-described terminal and other devices.
The memory 403 may include a random access memory (Random Access Memory, abbreviated as RAM) or may include a non-volatile memory (non-volatile memory), such as at least one magnetic disk memory. Alternatively, the memory may be at least one memory device located remotely from the aforementioned processor 401.
The processor 401 may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU for short), a network processor (Network Processor, NP for short), etc.; but also digital signal processors (Digital Signal Processing, DSP for short), application specific integrated circuits (Application Specific Integrated Circuit, ASIC for short), field-programmable gate arrays (Field-Programmable Gate Array, FPGA for short) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In yet another embodiment of the present invention, a computer readable medium having instructions stored therein, which when run on a computer, cause the computer to perform the code generation method of any of the above embodiments is also provided.
In yet another embodiment of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform the code generation method of any of the above embodiments.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions in accordance with embodiments of the present invention are produced in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, fiber optic, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.) means from one website, computer, server, or data center. Computer readable storage media can be any available media that can be accessed by a computer or data storage devices, such as servers, data centers, etc., that contain an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises an element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing is merely illustrative of the preferred embodiments of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (10)

1. A code generation method, comprising:
introducing a code generation plug-in into the target engineering;
compiling source codes of the target engineering in response to a compiling instruction, and generating an abstract syntax tree corresponding to the target engineering;
triggering the code generation plug-in, collecting meta information corresponding to the annotation information based on the code generation plug-in according to the annotation information in the abstract syntax tree, and automatically generating codes corresponding to the annotation information according to the meta information and a preset generation rule.
2. The method of claim 1, wherein the code generation plug-in comprises a meta information collector and a code generator;
the triggering the code generation plug-in, collecting meta information corresponding to the annotation information based on the code generation plug-in according to the annotation information in the abstract syntax tree, and automatically generating codes corresponding to the annotation information according to the meta information and a preset generation rule, wherein the triggering comprises the following steps:
triggering a code generator corresponding to annotation information in the abstract syntax tree according to a preset mapping relation; the preset mapping relation is used for indicating the corresponding relation between annotation information and a code generator;
triggering the meta information collector based on the code generator, and collecting meta information corresponding to annotation information in the abstract syntax tree based on the meta information collector;
and automatically generating codes corresponding to the annotation information based on the codes generator according to the meta information and a preset generation rule.
3. The method according to claim 1 or 2, characterized in that the method further comprises:
comparing the source code of the target project with the automatically generated code;
combining the source code of the target project with the automatically generated code under the condition that the source code of the target project is different from the automatically generated code;
and discarding the automatically generated code under the condition that the source code of the target project is determined to be the same as the automatically generated code.
4. The method of claim 3, wherein the comparing the source code of the target project to the automatically generated code comprises:
determining a catalog where an automatically generated code is located, and determining whether a code file exists under the catalog;
under the condition that a code file exists under the catalog, taking the code file as an original code, and acquiring key information of the original code based on the annotation information;
and comparing the key information of the original code with the automatically generated code.
5. The method of claim 1, wherein the meta information includes one or more of abstract syntax trees, configuration information, network information, and environment information corresponding to the target project.
6. A code generating apparatus, comprising:
the introducing module is used for introducing the code generation plug-in the target engineering;
the compiling module is used for responding to the compiling instruction, compiling the source code of the target project and generating an abstract syntax tree corresponding to the target project;
the generation module is used for triggering the code generation plug-in, collecting meta information corresponding to the annotation information based on the code generation plug-in according to the annotation information in the abstract syntax tree, and automatically generating codes corresponding to the annotation information according to the meta information and a preset generation rule.
7. The apparatus of claim 6, wherein the code generation plug-in comprises a meta information collector and a code generator;
the generating module is used for:
triggering a code generator corresponding to annotation information in the abstract syntax tree according to a preset mapping relation; the preset mapping relation is used for indicating the corresponding relation between annotation information and a code generator;
triggering the meta information collector based on the code generator, and collecting meta information corresponding to annotation information in the abstract syntax tree based on the meta information collector;
and automatically generating codes corresponding to the annotation information based on the codes generator according to the meta information and a preset generation rule. And acquiring meta information corresponding to the annotation information based on the corresponding meta information acquirer.
8. The apparatus of claim 6 or 7, further comprising an alignment module for:
comparing the source code of the target project with the automatically generated code;
combining the source code of the target project with the automatically generated code under the condition that the source code of the target project is different from the automatically generated code;
and discarding the automatically generated code under the condition that the source code of the target project is determined to be the same as the automatically generated code.
9. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs,
when executed by the one or more processors, causes the one or more processors to implement the method of any of claims 1-5.
10. A computer readable medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-5.
CN202310437462.9A 2023-04-21 2023-04-21 Code generation method, device, electronic equipment and medium Pending CN116578282A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310437462.9A CN116578282A (en) 2023-04-21 2023-04-21 Code generation method, device, electronic equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310437462.9A CN116578282A (en) 2023-04-21 2023-04-21 Code generation method, device, electronic equipment and medium

Publications (1)

Publication Number Publication Date
CN116578282A true CN116578282A (en) 2023-08-11

Family

ID=87533230

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310437462.9A Pending CN116578282A (en) 2023-04-21 2023-04-21 Code generation method, device, electronic equipment and medium

Country Status (1)

Country Link
CN (1) CN116578282A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117369783A (en) * 2023-12-06 2024-01-09 之江实验室 Training method and device for security code generation model

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117369783A (en) * 2023-12-06 2024-01-09 之江实验室 Training method and device for security code generation model
CN117369783B (en) * 2023-12-06 2024-02-23 之江实验室 Training method and device for security code generation model

Similar Documents

Publication Publication Date Title
US8930884B2 (en) Efficient extraction of software dependencies from program code
US9122490B2 (en) Code dependency calculation
CN111124906B (en) Tracking method, compiling method and device based on dynamic embedded points and electronic equipment
Safi et al. Detecting event anomalies in event-based systems
US11650905B2 (en) Testing source code changes
US9170787B2 (en) Componentization of compiler functionality
KR20090017598A (en) Iterative static and dynamic software analysis
US10514898B2 (en) Method and system to develop, deploy, test, and manage platform-independent software
US10083029B2 (en) Detect application defects by correlating contracts in application dependencies
Sottile et al. Semi-automatic extraction of software skeletons for benchmarking large-scale parallel applications
CN113778445A (en) Cross-platform component generation method and device, electronic equipment and storage medium
CN103186463A (en) Method and system for determining testing range of software
CN116578282A (en) Code generation method, device, electronic equipment and medium
CN111240987B (en) Method and device for detecting migration program, electronic equipment and computer readable storage medium
CN111352631A (en) Interface compatibility detection method and device
US20070124723A1 (en) Monitoring dynamic aspect oriented applications at execution time
JP2006294019A (en) Generic software requirement analyzer
US9396239B2 (en) Compiling method, storage medium and compiling apparatus
CN110737438A (en) data processing method and device
CN115705250A (en) Monitoring stack usage to optimize programs
Vysocký et al. Application instrumentation for performance analysis and tuning with focus on energy efficiency
CN115730305A (en) Application program detection method and device, nonvolatile storage medium and processor
CN113031964A (en) Management method, device, equipment and storage medium for big data application
CN111367796A (en) Application program debugging method and device
CN111694729A (en) Application testing method and device, electronic equipment and computer readable medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination