Open code generation system

By using YAML format to store business data and FreeMarker template engine combined with FTL format code templates, the problem of high business coupling and low customization in existing code generation technology is solved, and the flexibility and customization of code generation are achieved. , improves development efficiency and user experience.

CN119440487APending Publication Date: 2025-02-14EAST CHINA INST OF COMPUTING TECH
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411567559.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-05
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

Existing code generation technologies have problems such as high business coupling, low customization and poor flexibility, which cannot meet the needs of user custom code templates and direct access to configuration data.

Method used

Use YAML format to store business data, and use the FreeMarker template engine and FTL format code templates. Users can customize the code template and directly access the configuration data to generate code that meets business needs.

Benefits of technology

It realizes the flexibility and customization of code generation, and users can customize code generation rules according to business needs to improve development efficiency and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440487A_ABST
    Figure CN119440487A_ABST
Patent Text Reader

Abstract

The technical scheme of the invention discloses an open type code generation system which is characterized by comprising a data storage module used for storing service data in a YAML format; according to the code template, a user compiles a corresponding code template in an FTL format through a template engine according to the implementation mode of the business; and after the business data in the YAML format and the code template are handed over to the template engine, the template engine transmits specified data to the code template so as to generate a configuration code. The method is mainly and technically characterized in that a YAML language is used as a data storage format, an FTL language is used as a code template, and FreeMarker is used as a template engine.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to an open code generation system and belongs to the technical field of computers. Background Art

[0002] The Chinese invention patent application with publication number CN118466917A discloses a code generation system based on configuration and applied to the power digital platform, including a configuration module, a parsing module and a generation module; the configuration module is used to perform variable configuration, template configuration, generation type configuration, table configuration and scheme configuration in sequence according to the data requirements of the power project; the parsing module is used to perform parameter parsing, template parsing and table information parsing on the configuration information respectively; the generation module is used to generate corresponding engineering codes according to the configured modules and the parsed parameters, and package them into compressed files according to the code structure directory. The invention patent application visualizes and flexibly configures relevant information, supports online configuration of data tables, multi-data source access, supports batch generation of multi-scheme codes, master and sub-table code generation, and front-end and back-end code generation, and can realize the entire set of code generation operation processes without multi-application switching, which fully improves the business R&D efficiency. The main disadvantage of the invention patent application is the high degree of industry customization, because the configuration module, parsing module and generation module of the core technology are designed according to the data requirements of the power project, so as to realize the code of the power digital platform, but for other non-power projects or power projects with different requirements, the configuration module, parsing module and generation module cannot be opened to users for customized settings.

[0003] The Chinese invention patent application with publication number CN118394322A discloses a code generation method for E2E functions that conform to the AUTOSAR architecture, including: obtaining an Excel table, the Excel table contains data information, and the data information is the design requirement data of the E2E function; using a code generation tool to read the Excel table and extract the data information in the Excel table; using the code generation tool to fill each data information into a pre-established message template, respectively, to obtain a code file that conforms to the AUTOSAR architecture standard, which can solve the problem of low code generation efficiency of the E2E function of the AUTOSAR architecture. The main disadvantage of this invention patent application is that it does not have direct data access capabilities. Because the principle is to use Excel tables to store data information, and then generate code through a code generator, but the data in the Excel table and the code generator need to be connected through a special data parsing method to extract data, and it is not possible to directly access the data and then generate the required code.

[0004] The Chinese invention patent application with publication number CN117992028A discloses a code generation method, device and medium based on a configuration file, which belongs to the field of computer software development technology and is used to solve the technical problem that the existing code generation tools are difficult to meet complex business needs, and manual modification may be required for demand changes, and automatic adjustment and adaptation cannot be achieved. The method includes: based on business characteristics, pre-setting business demand data in a configuration file; parsing the type of the calling interface of the configuration file to obtain a code template corresponding to the business demand data; through the code template, performing code generation processing on the business demand data under the response of relevant code parameters to obtain a demand code class; configuring the demand code class into the business characteristic engineering to complete the source code generation processing of the business demand data. The main disadvantage of this invention patent application is that the code template does not have the user's customization capability, because the business demand data needs to be pre-set in the configuration file to obtain the code template corresponding to the business demand data. Once the business demand changes or there is a new business demand, the business demand data in the configuration file needs to be pre-set, and the user cannot change it in real time. Summary of the invention

[0005] The purpose of the present invention is to provide an open code generation framework in view of the shortcomings of the existing code generation technology pointed out in the background technology, so that users can customize code templates and directly access configuration data to generate code that can meet business needs, thereby solving the technical problems of high business coupling, low customizability and poor flexibility of existing code generation.

[0006] In order to achieve the above object, the technical solution of the present invention is to disclose an open code generation system, which is characterized by comprising:

[0007] Data storage module, used to store business data in YAML format;

[0008] Code templates: users use the template engine to compile corresponding FTL format code templates according to the business implementation method;

[0009] Template engine: After the business data and code template in YAML format are handed over to the template engine, the template engine passes the specified data to the code template to generate the configuration code.

[0010] Preferably, the template engine uses FreeMarker, which queries corresponding data, replaces tags in the code template, and generates final text output.

[0011] Preferably, the code template is written in FreeMarker Template Language.

[0012] Compared with the prior art solutions, the present invention has the following beneficial effects:

[0013] The main technical feature of the present invention is to use YAML language as data storage format, FTL language as code template, FreeMarker as template engine. YAML language and FTL language themselves are not related, but after research, it is found that data is stored in YAML language using dictionary structure, and FreeMarker template engine also performs data parsing in dictionary structure, so that the data in YAML format can be directly passed to the template in FTL format by FreeMarker template engine, and the data extraction and data parsing links required for the prior art are not required, and customization is not required specifically for different business needs, because users can directly access data according to their own business needs in the code template to customize code generation rules. In addition, because the FTL format code template, in addition to supporting the value function of the traditional code template, also supports conditional judgment, loop and rich built-in functions and instructions, so that users can efficiently generate dynamic content in development, improve development efficiency and user experience, and together with YAML format data and FreeMarker engine, form a truly open code generation framework. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 The code generation process is illustrated;

[0015] Figures 2 to 6 An application example of using the code generation system of the present invention to generate Ruihua embedded operating system configuration code is illustrated. DETAILED DESCRIPTION

[0016] The present invention will be further described below in conjunction with specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and are not intended to limit the scope of the present invention. In addition, it should be understood that after reading the content taught by the present invention, those skilled in the art can make various changes or modifications to the present invention, and these equivalent forms fall within the scope limited by the appended claims of the application equally.

[0017] The open code generation system disclosed in the embodiment of the present invention is composed of a template engine and a code template. The template engine is a tool for parsing the code template and generating code according to the code template. The code template is a completely open editable text.

[0018] The template engine uses FreeMarker, which is a free Java template engine that generates text output based on templates and data. When using FreeMarker, it queries the corresponding data, replaces the tags in the template, and generates the final text output, such as HTML, email, configuration files, source code, etc.

[0019] Code templates are written in FreeMarker Template Language (FTL). FTL is the markup language used by the FreeMarker template engine. It is specially designed to embed dynamic content in templates, allowing developers to write instructions and expressions in templates to generate dynamic text output when the data model is combined with the template. FTL allows developers to perform advanced functions such as data access, conditional judgment, loops, macro definitions, built-in functions, etc.

[0020] Data is stored in the "YAML Ain't a Markup Language (YAML)" format. YAML is an intuitive, computer-readable data serialization format that emphasizes the data itself rather than the markup language. It is highly readable and easy for humans to read. It is also easy to interact with scripting languages ​​and is used to express data sequences. YAML is often used in scenarios such as configuration file formats, data interaction formats, and descriptions of structured data.

[0021] The user compiles the corresponding code template according to the implementation mode of the business. After the external program prepares the data, it is handed over to the template engine for processing together with the code template. The template engine passes the specified data to the code template to generate the configuration code. Figure 1 As shown, the following steps are included:

[0022] 1. Data preparation: Users prepare business data in YAML format;

[0023] 2. Template writing: Users compile corresponding FTL format code templates according to the implementation method of the business;

[0024] 3. Template rendering: Combine the prepared data with the template and generate the final code through Freemarker's rendering engine.

[0025] The following is an application example of using the code generation framework of the present invention to generate Ruihua embedded operating system configuration code:

[0026] Step 1: Complete the Ruihua embedded operating system configuration data and store it in YAML format, such as Figures 2 to 4 shown.

[0027] Step 2: Write an FTL format code template to access the Ruihua embedded operating system configuration data, and make conditional judgments based on the rules defined in the template to generate a C language header file code, such as Figure 5 shown.

[0028] Step 3: Submit the Ruihua embedded operating system configuration data and code template to the Freemarker template engine for rendering. The generated code is as follows: Figure 6 shown.

Claims

1. An open code generation system, characterized in that: include: Data storage module, used to store business data in YAML format; Code templates: users use the template engine to compile corresponding FTL format code templates according to the business implementation method; Template engine: After the business data and code template in YAML format are handed over to the template engine, the template engine passes the specified data to the code template to generate the configuration code.

2. An open code generation system as claimed in claim 1, characterized in that: The template engine uses FreeMarker, which queries corresponding data, replaces tags in the code template, and generates final text output.

3. An open code generation system as claimed in claim 1, characterized in that: The code template is written in FreeMarker Template Language.

Citation Information

Patent Citations

  • Code generation method and device based on configuration file and medium

    CN117992028A

  • Code generation method of E2E function conforming to AUTOSAR architecture

    CN118394322A

  • Configuration-based code generation system applied to electric power digital platform

    CN118466917A