Metaprogramming code generation method, electronic equipment and storage medium

By acquiring language configuration files and structured metadata, identifying target strategy tags, and generating metaprogramming code, the problem of low efficiency in manual coding in existing technologies is solved, achieving efficient and accurate code generation and improving software development efficiency and consistency.

CN121807313APending Publication Date: 2026-04-07SHENZHEN LANYOU TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-06
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

In existing technologies, developers need to manually write and maintain high-level structures, which involves a large amount of repetitive, patterned, and error-prone manual coding work, resulting in low work efficiency and high maintenance costs.

Method used

By acquiring language configuration files, determining structured metadata, identifying target strategy tags, and generating metaprogramming code based on target templates, a semantic leap from structured metadata to high-level programming strategies is achieved. Intelligent and combinatorial template selection reduces the developer's involvement in repetitive tasks.

Benefits of technology

It significantly improves the accuracy and consistency of code generation, reduces the burden on developers to remember the underlying syntax details, enhances software development efficiency and consistency, and is suitable for the automated implementation of complex language features.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121807313A_ABST
    Figure CN121807313A_ABST
Patent Text Reader

Abstract

The invention provides a meta-programming code generation method, electronic equipment and a storage medium, and the method comprises the steps that a language configuration file is acquired, structured metadata is determined according to the language configuration file, and the language configuration file is used for indicating the requirement of a developer for a meta-programming code; determining at least one target strategy label according to the structured metadata, and determining each target template according to each target strategy label; and according to the structured metadata and each target template, generating a target meta programming code. Accurate analysis and structured expression of the intention of the developer are realized, and the accuracy and consistency of code generation are improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of code generation, in particular to a meta-programming code generation method, an electronic device and a storage medium. BACKGROUND

[0002] In modern application development, Swift language provides strong support for application developers with its type safety, high performance and elegant syntax characteristics. As the complexity of software systems continues to increase, developers widely use the features provided by Swift language such as generics, property wrappers and complex protocol structures to improve code reusability, maintainability and runtime safety.

[0003] In the prior art, developers need to manually write and maintain high-level structures, which involves a lot of repetitive, patterned and error-prone manual coding work, resulting in low work efficiency and high maintenance cost. SUMMARY

[0004] The present application aims to solve the problems in the prior art and provide a meta-programming code generation method to improve the accuracy of the meta-programming code generation method.

[0005] To achieve the above-mentioned purpose, the technical solutions adopted by the embodiments of the present application are as follows: In a first aspect, the embodiments of the present application provide a meta-programming code generation method, which comprises: obtaining a language configuration file and determining structured metadata according to the language configuration file, the language configuration file being used to indicate the needs of developers for meta-programming code; determining at least one target strategy tag according to the structured metadata, and determining each target template according to each target strategy tag; generating target meta-programming code according to the structured metadata and each target template.

[0006] Optionally, the determining of the structured metadata according to the language configuration file comprises: parsing the language configuration file to obtain metadata, the metadata comprising model attribute information, a field table, protocol constraint information and generic parameter information, and the field table comprising field name, data type, primary key identifier, property wrapper type, log recording requirement, optional property and default value; structuring the metadata to obtain the structured metadata.

[0007] Optionally, the determining of the at least one target strategy tag according to the structured metadata comprises: performing key feature extraction on the structured metadata to obtain at least one target key feature, the key feature including a primary key feature, an attribute wrapper feature, and a log record feature; determining each target policy tag according to each target key feature and a preset policy mapping table, the policy tag including a protocol implementation tag, a wrapper application tag, and a log extension tag.

[0008] Optionally, the performing key feature extraction on the structured metadata to obtain at least one target key feature includes: if a primary key identifier in the metadata is a preset value, determining that the target key feature is a primary key feature; if an attribute wrapper type in the metadata is non-empty, determining that the target key feature is an attribute wrapper feature; if a log record requirement in the metadata is a preset value, determining that the target key feature is a log record feature.

[0009] Optionally, the determining each target policy tag according to each target key feature and a preset policy mapping table includes: if the target key feature is a primary key feature, determining from the preset policy mapping table that the target policy tag is a protocol implementation tag; if the target key feature is the attribute wrapper feature, determining from the preset policy mapping table that the target policy tag is a wrapper application tag; if the target key feature is the log record feature, determining from the preset policy mapping table that the target policy tag is a log extension tag.

[0010] Optionally, the determining each target template according to each target policy tag includes: if the target policy tag is a protocol implementation tag, determining that the target template is a generic template; if the target policy tag is a wrapper application tag, determining that the target template is an attribute wrapper template; if the target policy tag is a log extension tag, determining that the target template is a log extension template.

[0011] Optionally, the generating target meta-programming code according to the structured metadata and each target template includes: performing template rendering on each target template according to the metadata to generate the target meta-programming code.

[0012] Optionally, the performing template rendering on each target template according to the metadata to generate the target meta-programming code includes: performing semantic enhancement analysis on the metadata to obtain context information; performing template variable replacement processing on each of the target templates according to the context information to obtain a rendered code segment corresponding to each of the target templates; performing assembly processing on the rendered code segments according to the context information to obtain initial meta-programming code; performing format and code optimization processing on the initial meta-programming code to obtain the target meta-programming code.

[0013] In a second aspect, the embodiments of the present application further provide a meta-programming code generation device, and the device comprises: an obtaining module configured to obtain a language configuration file and determine structured metadata according to the language configuration file, wherein the language configuration file is used to indicate the requirement of a developer for meta-programming code; a determining module configured to determine at least one target strategy label according to the structured metadata, and determine target templates according to the target strategy labels; a generating module configured to generate target meta-programming code according to the structured metadata and the target templates.

[0014] Optionally, the obtaining module is specifically configured to: perform parsing on the language configuration file to obtain metadata, wherein the metadata comprises model attribute information, a field table, protocol constraint information and generic parameter information, and the field table comprises a field name, a data type, a primary key identifier, an attribute wrapper type, a log recording requirement, an optionality and a default value; perform structured processing on the metadata to obtain the structured metadata.

[0015] Optionally, the determining module is specifically configured to: perform key feature extraction on the structured metadata to obtain at least one target key feature, wherein the key feature comprises a primary key feature, an attribute wrapper feature and a log recording feature; determine the target strategy labels according to the target key features and a preset strategy mapping table, wherein the strategy label comprises a protocol implementation label, a wrapper application label and a log extension label.

[0016] Optionally, the determining module is specifically configured to: if the primary key identifier in the metadata is a preset value, determine that the target key feature is a primary key feature; if the attribute wrapper type in the metadata is not empty, determine that the target key feature is an attribute wrapper feature; If the log record requirement in the metadata is a preset value, it is determined that the target key feature is a log record feature.

[0017] Optionally, the determining module is specifically configured to: If the target key feature is a primary key feature, it is determined from the preset strategy mapping table that the target strategy tag is a protocol implementation tag. If the target key feature is the attribute wrapper feature, it is determined from the preset strategy mapping table that the target strategy tag is a wrapper application tag. If the target key feature is the log record feature, it is determined from the preset strategy mapping table that the target strategy tag is a log extension tag.

[0018] Optionally, the determining module is specifically configured to: If the target strategy tag is a protocol implementation tag, it is determined that the target template is a generic template. If the target strategy tag is a wrapper application tag, it is determined that the target template is an attribute wrapper template. If the target strategy tag is a log extension tag, it is determined that the target template is a log extension template.

[0019] Optionally, the generating module is specifically configured to: According to the metadata, template rendering is performed on each target template to generate the target meta-programming code.

[0020] Optionally, the generating module is specifically configured to: Semantic enhancement analysis is performed on the metadata to obtain context information. According to the context information, template variable replacement processing is performed on each target template to obtain a rendered code segment corresponding to each target template. According to the context information, each rendered code segment is assembled to obtain an initial meta-programming code. The initial meta-programming code is formatted and code-optimized to obtain the target meta-programming code.

[0021] In a third aspect, the embodiments of the present application further provide an electronic device, comprising a processor, a memory and a bus, the memory stores program instructions executable by the processor, when an application program runs, the processor and the memory communicate through the bus, and the processor executes the program instructions to perform the steps of the meta-programming code generation method of the first aspect.

[0022] In a fourth aspect, the embodiments of the present application further provide a computer readable storage medium, which stores a computer program. The computer program is read and executed to perform the steps of the meta-programming code generation method in the first aspect.

[0023] The present application has the following beneficial effects: The meta-programming code generation method, the electronic device and the storage medium provided by the present application lay a solid foundation for subsequent intelligent template selection and code generation based on policy tags by obtaining a language configuration file and determining structured metadata according to the language configuration file; determining at least one target policy tag according to the structured metadata, and determining each target template according to each target policy tag; and generating target meta-programming code according to the structured data and each target template. Compared with the manual coding method in the prior art, the present application significantly reduces the participation of developers in repetitive meta-programming tasks, improves the accuracy and consistency of code generation, and realizes semantic transition from structured metadata to high-level programming strategies by obtaining target templates according to the structured metadata obtained in the foregoing. The present application breaks through the limitation of traditional static template engines that only rely on field filling, and instead selects intelligent and combined templates based on the intentions of developers. The present application significantly improves the flexibility and expressiveness of the code generation system, and is particularly suitable for the automatic implementation of complex language features. Finally, the present application generates target meta-programming code according to the structured metadata and the target template, reduces the memory burden of developers on underlying syntax details, enables developers to quickly obtain high-quality code output through high-level configuration, effectively reduces human errors, and improves software development efficiency and consistency. BRIEF DESCRIPTION OF DRAWINGS

[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be considered as limiting the scope. For those skilled in the art, other related drawings can also be obtained without creative labor.

[0025] Figure 1 A flowchart of a meta-programming code generation method provided by the embodiments of the present application; Figure 2 A flowchart of a second meta-programming code generation method provided by the embodiments of the present application; Figure 3 A flowchart of a third meta-programming code generation method provided by the embodiments of the present application; Figure 4 A flowchart of a fourth meta-programming code generation method provided by the embodiments of the present application; Figure 5 A device schematic diagram of a meta-programming code generation method provided in an embodiment of the present application; Figure 6 A structural block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. It should be understood that the drawings in the present application only serve the purpose of description and illustration, and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn according to the actual proportions. The flowcharts in the present application show the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowcharts can not be implemented in sequence, and the steps without logical context relationship can be reversed in sequence or implemented simultaneously. In addition, one or more other operations can be added to the flowcharts or one or more operations can be removed from the flowcharts under the guidance of the content of the present application.

[0027] In addition, the described embodiments are only some of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.

[0028] It should be noted that the term “comprising” will be used in the embodiments of the present application to indicate the presence of the features declared thereafter, but does not exclude the addition of other features.

[0029] Optionally, the meta-programming code generation method provided in the embodiments of the present application is applied in an electronic device, which can be, for example, a terminal device with computing processing capability and display function, such as a mobile phone, a tablet computer, a notebook computer, a palm computer, a desktop computer, or a server. Specifically, it can be applied to an application program in a terminal device, such as an application program (application, APP) of a mobile phone, an application system on a computer, etc.

[0030] The specific implementation process of the meta-programming code generation method provided in the embodiments of the present application will be explained in detail below.

[0031] Figure 1This is a flowchart illustrating a metaprogramming code generation method provided in an embodiment of this application. The execution subject of this method is as described above: the electronic device. Figure 1 As shown, the method includes: S101. Obtain the language configuration file and determine the structured metadata based on the language configuration file.

[0032] The language configuration file refers to the input interface for developers regarding their needs for metaprogramming code. This configuration file can be in structured or semi-structured text formats such as JSON, YAML, XML, or a custom DSL. It carries the technical intent pre-defined by the developer before code generation, such as the required data model structure, field attribute constraints, protocol compliance requirements, logging strategies, and generic parameter configurations.

[0033] Optionally, after obtaining the language configuration file, the corresponding structured metadata can be obtained using a preset method. This structured metadata is a standardized internal data structure with good type consistency and extensibility, facilitating feature recognition, template matching, and code rendering operations in subsequent modules.

[0034] S102. Determine at least one target policy tag based on structured metadata, and determine each target template based on each target policy tag.

[0035] Optionally, after obtaining the structured metadata, the system enters the intelligent decision-making stage, where at least one target strategy tag is determined based on the obtained structured metadata using a preset method. The strategy tag can include one or more of the following: protocol implementation tag, wrapper application tag, log extension tag. Different target templates are matched according to the different target strategy tags. Each target template is a parameterized source code skeleton, pre-designed to implement a certain type of programming pattern, and supports customized rendering through variable substitution.

[0036] The target template can be stored in a local resource directory or a cloud template center, supporting version management and dynamic updates. At runtime, the required template is loaded, preparing for the next stage of the template rendering process. This target template can include one or more of the following: generic templates, attribute wrapper templates, and log extension templates.

[0037] S103. Generate target metaprogramming code based on structured data and target templates.

[0038] Optionally, after identifying the target strategy label and matching the corresponding target template, target metaprogramming code is generated using a preset method based on metadata and each target template. Specifically, the generated target metaprogramming code may be generated as follows: if the determined target template is a generic template, a generic metaprogramming code snippet can be generated, which can be used for subsequent application programming; if the determined target template is an attribute wrapper template, a metaprogramming code snippet with a wrapper declaration containing projection values ​​and observation logic will be generated; if the determined target template is a log extension template, a metaprogramming code snippet that automatically concatenates all field values ​​can be generated for subsequent log output.

[0039] The generated target metaprogramming code is a syntactically valid, clearly structured source code file that can be directly integrated into a development project. It supports saving as `.swift`, `.kt`, or other target language formats, depending on the language environment specified in the language configuration file.

[0040] In this embodiment, a language configuration file is obtained, and structured metadata is determined based on the language configuration file. At least one target strategy tag is determined based on the structured metadata, and each target template is determined based on each target strategy tag. Target metaprogramming code is generated based on the structured data and each target template. By automating the conversion of the language configuration file into machine-processable structured metadata, a solid foundation is laid for subsequent intelligent template selection and code generation based on strategy tags. Compared to the existing technology that relies entirely on manual coding, this significantly reduces the developer's involvement in repetitive metaprogramming tasks and improves the accuracy and consistency of code generation. Subsequently, target templates are obtained based on the aforementioned structured metadata, achieving a semantic leap from structured metadata to high-level programming strategies. This breaks through the limitations of traditional static template engines that only rely on field filling, instead opting for intelligent, combinable template selection based on developer intent. This significantly improves the flexibility and expressiveness of the code generation system, especially suitable for the automated implementation of complex language features. Finally, target metaprogramming code is generated based on the structured metadata and target templates, reducing the developer's burden of remembering low-level syntax details. This allows them to quickly obtain high-quality code output through high-level configuration, effectively reducing human error and improving software development efficiency and consistency.

[0041] Figure 2 This is a flowchart illustrating the second metaprogramming code generation method provided in the embodiments of this application, as shown below. Figure 2 As shown, determining the structured metadata based on the language configuration file in S101 above may include: S201. Parse the language configuration file to obtain metadata.

[0042] The metadata includes: model attribute information, field tables, protocol constraint information, and generic parameter information. The field tables include field names, data types, primary key identifiers, attribute wrapper types, logging requirements, optionality, and default values. Model attribute information describes the basic attributes of the data model corresponding to the metaprogramming code, such as class names and struct names. Each data model corresponds to one field table, which may include one or more fields. Each field may include a field name, data type, primary key identifier (whether the field is a primary key), optionality (whether the field is optional), default value setting, associated attribute wrapper type, and logging requirements (whether logging is enabled). Protocol constraint information refers to one or more programming language-level protocols that the data model must follow. Generic parameter information refers to the range placeholders and constraints included in the configuration file when designing generics for the data model.

[0043] For example, the process of parsing a language configuration file can be achieved by combining lexical analysis and syntax analysis, depending on the format type of the language configuration file.

[0044] S202. Perform structuring processing on the metadata to obtain structured metadata.

[0045] Optionally, this structured processing may include, but is not limited to: standardized mapping of field types, default filling of missing fields, illegal value validation and exception prompts, and flattening of multi-level nested structures.

[0046] Optionally, the metadata obtained in step S201 is non-standardized and diverse in format. Therefore, through structuring processing, the metadata is converted into unified, standardized, and easily callable structured metadata for subsequent modules. This ensures that upper-layer strategy identification and template rendering can make accurate decisions based on consistent data.

[0047] In this structured metadata, the root node represents each data model, and the child nodes represent the fields and attribute information of each field corresponding to each data model. The edge relationships reflect the dependency, combination, or inheritance logic between fields. This structured organization not only improves the efficiency of subsequent key feature extraction but also provides unified data context support for cross-template collaborative rendering.

[0048] In this embodiment, a structured processing flow effectively solves the problems of high code generation error rate and poor compatibility caused by diverse configuration formats and semantic ambiguity in existing technologies. The generated structured metadata not only has high consistency and completeness, but also provides a reliable data foundation for subsequent key feature extraction, strategy label matching, and template rendering, significantly improving the overall system's intelligence level and engineering practicality.

[0049] Figure 3 A flowchart illustrating the third metaprogramming code generation method provided in this application embodiment is shown below. Figure 3 The step of determining at least one target policy label based on structured metadata in S102 above may include: S301. Extract key features from structured metadata to obtain at least one target key feature.

[0050] Key features include primary key features, attribute wrapper features, and log record features.

[0051] Optionally, after obtaining standardized structured metadata, the process proceeds to the intelligent semantic analysis stage. This stage involves conditionally judging the field attributes in the structured metadata to identify semantic features with specific technical meanings. Key features reflect the developer's implicit technical intent in the language configuration file and are the core basis for achieving automated code generation. Specifically, the feature extraction process can include primary key identification, wrapper identification, and log requirement identification.

[0052] S302. Determine the strategy label for each target based on the key features of each target and the preset strategy mapping table.

[0053] Optionally, the extracted key features can be compared with a preset policy mapping table to determine the target policy label corresponding to each key feature. The preset policy mapping table is a built-in rule configuration used to establish a one-to-one or many-to-one mapping relationship between "key features" and "policy labels".

[0054] This embodiment achieves a semantic leap from language configuration to high-level programming intent. Unlike traditional template engines that simply fill in fields based on their existence, it understands the technical context behind the fields and makes intelligent decisions accordingly. This endows the entire code generation system with human-like reasoning capabilities, significantly differentiating it from existing static and isolated template replacement solutions.

[0055] Optionally, the key feature extraction of the structured metadata in S301 above to obtain at least one target key feature may include: If the primary key identifier in the metadata is a preset value, then the target key feature is determined to be the primary key feature. This preset value, for example, is `true` or `primary_key`, which indicates that the data model containing this primary key identifier has a unique identification requirement and must support operations such as comparison, hashing, or database mapping based on the primary key.

[0056] If the attribute wrapper type in the metadata is not null, then the target key feature is determined to be an attribute wrapper feature. Specifically, if the attribute wrapper type in the metadata is not null, then it can be determined that the field needs to introduce runtime behavior enhancement mechanisms, involving features such as access control, value listening, or lazy evaluation.

[0057] If the logging requirement in the metadata is a preset value, then the target key feature is determined to be the logging feature. For example, if the preset value is `true` or `enabled`, then the data model containing this field must have self-descriptive output capabilities for debugging, tracing, or auditing log output.

[0058] Optionally, determining the policy label for each target in S302 based on the key features of each target and a preset policy mapping table may include: If the target key feature is the primary key feature, then the target policy label is determined from the preset policy mapping table as the protocol implementation label, such as the Identifiable protocol.

[0059] If the target key feature is an attribute wrapper feature, then the target policy label is determined as the wrapper application label from the preset policy mapping table.

[0060] If the target key feature is a log recording feature, then the target policy label is determined as the log extension label from the preset policy mapping table.

[0061] Optionally, determining each target template based on each target strategy label in S102 above may include: If the target strategy tag is a protocol implementation tag, then the target template is determined to be a generic template. This generic template can contain protocol declarations, generic constraints, `id` field bindings, and consistency implementation code, and is suitable for building reusable data model base classes.

[0062] If the target strategy tag is a wrapper application tag, then the target template is determined to be a property wrapper template. This property wrapper template encapsulates the wrapper declaration, projected properties, initialization logic, and value observation mechanism, and can automatically generate a wrapper implementation that conforms to Swift syntax rules.

[0063] If the target policy tag is a log extension tag, then the target template is determined to be a log extension template. This log extension template provides an extended implementation of the custom logging protocol, automatically concatenating field names with current values ​​to generate highly readable log output strings.

[0064] Optionally, the generation of target metaprogramming code in S103 above, based on structured data and each target template, may include: Specifically, template rendering can be performed on each target template based on metadata to generate target metaprogramming code.

[0065] Figure 4 A flowchart illustrating the fourth metaprogramming code generation method provided in this application embodiment is shown below. Figure 4 The aforementioned process of performing template rendering on each target template based on metadata to generate target metaprogramming code may include: S401. Perform semantic enhancement analysis on the metadata to obtain contextual information.

[0066] Specifically, semantic enhancement analysis includes: type inference completion: automatically completing the specific type for data types that are not explicitly specified but can be inferred from the context, such as associated types in generic constraints; dependency resolution: identifying reference relationships or wrapper nesting levels between fields, constructing a dependency graph to control the generation order of code snippets; namespace and visibility handling: determining the access control level and import declarations of the generated code based on the module or package name to which the model belongs; protocol consistency inference: if a template involves protocol implementation, it is necessary to determine whether custom coding logic is required, or whether the compiler can synthesize a default implementation.

[0067] S402. Based on the context information, perform template variable replacement processing on each target template to obtain the rendered code snippet corresponding to each target template.

[0068] Optionally, variable substitution can be performed using an abstract syntax tree or string template engine to avoid rendering errors caused by special characters or syntax conflicts. After substitution, each target template is converted into an independent rendered code snippet.

[0069] Specifically, for each target template, the template variables inside each target template can be parsed, and variable replacement operations can be performed based on the corresponding field values ​​in the context information.

[0070] S403. Assemble the rendered code fragments according to the context information to obtain the initial metaprogramming code.

[0071] Specifically, the multiple rendered code snippets obtained in step S402 above can be assembled based on context information to obtain complete initial metaprogramming code. These multiple rendered code snippets are not simply concatenated, otherwise it would lead to problems such as syntax repetition or structural confusion.

[0072] Specifically, based on the module organization rules and dependency topology defined in the context information, multiple rendered code fragments can be spliced ​​and integrated in a predetermined order and structure to form complete initial metaprogramming code.

[0073] S404. The initial metaprogramming code is formatted and optimized to obtain the target metaprogramming code.

[0074] Specifically, standard code formatting tools can be used to uniformly indent, add blank lines, etc., to the initial metaprogramming code, remove redundant statements, and insert comments to indicate the automatically generated nature of the code.

[0075] Figure 5 A schematic diagram of an apparatus for a metaprogramming code generation method provided in an embodiment of this application is shown below. Figure 5 As shown, the device includes: The acquisition module 501 is used to acquire the language configuration file and determine the structured metadata based on the language configuration file, wherein the language configuration file is used to indicate the developer's requirements for metaprogramming code; The determination module 502 is used to determine at least one target policy tag based on the structured metadata, and to determine each target template based on each target policy tag; The generation module 503 is used to generate target metaprogramming code based on the structured metadata and each of the target templates.

[0076] Optionally, the acquisition module 501 is specifically used for: The language configuration file is parsed to obtain metadata, which includes: model attribute information, field table, protocol constraint information and generic parameter information. The field table includes field name, data type, primary key identifier, attribute wrapper type, logging requirements, optionality and default value. The metadata is processed into a structured form to obtain the structured metadata.

[0077] Optionally, the determining module 502 is specifically used for: Key features are extracted from the structured metadata to obtain at least one target key feature, which includes primary key features, attribute wrapper features, and log record features. Based on the key features of each target and the preset policy mapping table, the policy tags of each target are determined. The policy tags include protocol implementation tags, wrapper application tags, and log extension tags.

[0078] Optionally, the determining module 502 is specifically used for: If the primary key identifier in the metadata is a preset value, then the target key feature is determined to be the primary key feature; If the attribute wrapper type in the metadata is not empty, then the target key feature is determined to be an attribute wrapper feature; If the log recording requirement in the metadata is a preset value, then the target key feature is determined to be a log recording feature.

[0079] Optionally, the determining module 502 is specifically used for: If the target key feature is the primary key feature, then the target policy label is determined to be the protocol implementation label from the preset policy mapping table; If the target key feature is the attribute wrapper feature, then the target policy tag is determined to be the wrapper application tag from the preset policy mapping table; If the target key feature is the log record feature, then the target policy tag is determined to be the log extension tag from the preset policy mapping table.

[0080] Optionally, the determining module 502 is specifically used for: If the target strategy tag is a protocol implementation tag, then the target template is determined to be a generic template; If the target strategy tag is a wrapper application tag, then the target template is determined to be an attribute wrapper template; If the target policy tag is a log extension tag, then the target template is determined to be a log extension template.

[0081] Optionally, the generation module 503 is specifically used for: Based on the metadata, template rendering is performed on each of the target templates to generate the target metaprogramming code.

[0082] Optionally, the generation module 503 is specifically used for: Semantic enhancement analysis is performed on the metadata to obtain contextual information; Based on the context information, template variable replacement processing is performed on each of the target templates to obtain the rendered code snippets corresponding to each target template; The rendered code fragments are assembled based on the context information to obtain the initial metaprogramming code; The initial metaprogramming code is formatted and optimized to obtain the target metaprogramming code.

[0083] Figure 6 This is a structural block diagram of an electronic device 600 provided in an embodiment of this application. (See diagram below.) Figure 6 As shown, the electronic device may include: a processor 601 and a memory 602.

[0084] Optionally, a bus 603 may also be included, wherein the memory 602 is used to store machine-readable instructions executable by the processor 601. When the electronic device 600 is running, the processor 601 and the memory 602 communicate via the bus 603, and the processor 601 executes the machine-readable instructions to perform the method steps in the above method embodiments.

[0085] This application also provides a computer-readable storage medium storing a computer program, which, when run by a processor, executes the method steps described in the metaprogramming code generation method embodiments.

[0086] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the method embodiments, and will not be repeated here. In the several embodiments provided in this application, it should be understood that the disclosed systems and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or modules may be electrical, mechanical, or other forms.

[0087] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. If the functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.

[0088] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.

Claims

1. A method for generating metaprogramming code, characterized in that, The method includes: Obtain the language configuration file and determine the structured metadata based on the language configuration file, which is used to indicate the developer's requirements for metaprogramming code; At least one target policy tag is determined based on the structured metadata, and each target template is determined based on each target policy tag; Based on the structured metadata and each of the target templates, target metaprogramming code is generated.

2. The metaprogramming code generation method according to claim 1, characterized in that, The step of determining structured metadata based on the language configuration file includes: The language configuration file is parsed to obtain metadata, which includes: model attribute information, field table, protocol constraint information and generic parameter information. The field table includes field name, data type, primary key identifier, attribute wrapper type, logging requirements, optionality and default value. The metadata is processed into a structured form to obtain the structured metadata.

3. The metaprogramming code generation method according to claim 1, characterized in that, The step of determining at least one target policy tag based on the structured metadata includes: Key features are extracted from the structured metadata to obtain at least one target key feature, which includes primary key features, attribute wrapper features, and log record features. Based on the key features of each target and the preset policy mapping table, the policy tags of each target are determined. The policy tags include protocol implementation tags, wrapper application tags, and log extension tags.

4. The metaprogramming code generation method according to claim 3, characterized in that, The key feature extraction of the structured metadata yields at least one target key feature, including: If the primary key identifier in the metadata is a preset value, then the target key feature is determined to be the primary key feature; If the attribute wrapper type in the metadata is not empty, then the target key feature is determined to be an attribute wrapper feature; If the log recording requirement in the metadata is a preset value, then the target key feature is determined to be a log recording feature.

5. The metaprogramming code generation method according to claim 3, characterized in that, The step of determining the target policy label based on the key features of each target and a preset policy mapping table includes: If the target key feature is the primary key feature, then the target policy label is determined to be the protocol implementation label from the preset policy mapping table; If the target key feature is the attribute wrapper feature, then the target policy tag is determined to be the wrapper application tag from the preset policy mapping table; If the target key feature is the log record feature, then the target policy tag is determined to be the log extension tag from the preset policy mapping table.

6. The metaprogramming code generation method according to claim 1, characterized in that, The step of determining each target template based on each target strategy label includes: If the target strategy tag is a protocol implementation tag, then the target template is determined to be a generic template; If the target strategy tag is a wrapper application tag, then the target template is determined to be an attribute wrapper template; If the target policy tag is a log extension tag, then the target template is determined to be a log extension template.

7. The metaprogramming code generation method according to claim 1, characterized in that, The step of generating target metaprogramming code based on the structured metadata and each of the target templates includes: Based on the metadata, template rendering is performed on each of the target templates to generate the target metaprogramming code.

8. The metaprogramming code generation method according to claim 7, characterized in that, The step of performing template rendering on each of the target templates based on the metadata to generate the target metaprogramming code includes: Semantic enhancement analysis is performed on the metadata to obtain contextual information; Based on the context information, template variable replacement processing is performed on each of the target templates to obtain the rendered code snippets corresponding to each target template; The rendered code fragments are assembled based on the context information to obtain the initial metaprogramming code; The initial metaprogramming code is formatted and optimized to obtain the target metaprogramming code.

9. An electronic device, characterized in that, The method includes a memory and a processor, wherein the memory stores a computer program executable by the processor, and the processor executes the computer program to implement the steps of the metaprogramming code generation method according to any one of claims 1-8.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the metaprogramming code generation method as described in any one of claims 1-8.