A front-end service code automatic generation method and system
Patent Information
- Application Number
- CN202510984863.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-17
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2045-07-17
Smart Images

Figure CN120491931B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and system for automatically generating front-end Service codes. Background Art
[0002] As business needs are constantly updated and adjusted, the requirements for updating front-end service code are becoming increasingly higher. By automatically generating front-end service code, user needs can be quickly parsed, the corresponding code syntax tree can be matched, and the initial code can be automatically generated, greatly reducing the time and workload of manual code writing.
[0003] The existing technology has the following problems: the analysis of user code generation requirements is not comprehensive enough, and it is difficult to sort out the dependencies between different types of requirements and the constraints of interface calls, resulting in the generated code not accurately meeting the actual needs; in the syntax tree matching process, a single matching method is used to directly match a large number of syntax trees, resulting in low matching accuracy and efficiency; there is a lack of an optimization process for the syntax tree, which makes the generated code have problems of unreasonable structure and high redundancy; the code optimization process lacks a mechanism for detailed block and point optimization of the code, resulting in the code optimization process being not accurate enough; in order to solve at least one of the above problems, the present invention proposes a front-end Service code automatic generation method and system. Summary of the Invention
[0004] In view of the shortcomings of the existing technology, the main purpose of the present invention is to provide a method and system for automatically generating front-end service code, which can effectively solve the problems in the background technology. The specific technical solutions of the present invention are as follows:
[0005] A method for automatically generating front-end Service code, comprising:
[0006] In response to the user's code generation requirements, the dependency relationship between the code generation requirements is parsed through a preset requirement parsing model to obtain a requirement parsing result;
[0007] According to the requirement analysis result, matching is performed in a preset code syntax tree library to obtain a target code syntax tree;
[0008] Optimizing the branch structure of the target code syntax tree by branch merging or branch expansion processing to obtain an optimized target code syntax tree;
[0009] Combining the optimized target code syntax tree and YApi interface data to generate initial code;
[0010] The initial code is optimized through a preset code optimization mechanism to obtain an updated code, which is output in the front-end window to achieve automatic generation of the front-end Service code.
[0011] Specifically, in response to the user's code generation requirements, the dependency relationship between the code generation requirements is parsed using a preset requirement parsing model to obtain a requirement parsing result, including:
[0012] According to the user's code generation requirements, the preset requirement parsing model is used to parse the requirements and generate multiple types of requirements;
[0013] By analyzing the dependencies between different types of requirements, a demand association map is constructed;
[0014] By analyzing the call constraint relationship between interfaces, an interface call chain is constructed;
[0015] The demand analysis result is obtained by combining the demand association graph and the interface call chain.
[0016] Specifically, the requirement parsing result is matched in a preset code syntax tree library to obtain a target code syntax tree, including:
[0017] According to the demand analysis results, feature extraction is performed through the preset demand feature extraction model to obtain multiple demand features;
[0018] Encoding the multiple demand features to construct a demand feature vector;
[0019] Combining the requirement parsing result and the requirement feature vector, multi-level matching is performed in a preset code syntax tree library to obtain a target code syntax tree.
[0020] Specifically, the requirement parsing result and the requirement feature vector are combined to perform multi-level matching in a preset code syntax tree library to obtain a target code syntax tree, including:
[0021] According to the requirement analysis result, a preset code syntax tree library is screened to obtain a first code syntax tree set;
[0022] Extracting coarse-grained features from the requirement parsing result and the requirement feature vector, and screening the first code syntax tree set according to the coarse-grained features to obtain a second code syntax tree set;
[0023] Extracting fine-grained features from the requirement parsing result and the requirement feature vector, and screening the second code syntax tree set according to the fine-grained features to obtain a third code syntax tree set;
[0024] According to the third code syntax tree set, syntax tree nodes that meet preset fusion conditions are selected from each code syntax tree for fusion to obtain a target code syntax tree.
[0025] Specifically, the branch structure of the target code syntax tree is optimized by branch merging or branch expansion to obtain an optimized target code syntax tree, including:
[0026] Analyze the parameter nodes in the target code syntax tree to obtain initial syntax tree parameters;
[0027] Optimize the initial syntax tree parameters according to the preset parameter constraint rules configured by YApi to obtain optimized syntax tree parameters;
[0028] According to the optimized syntax tree parameters, the branch structure of the target code syntax tree is optimized through branch merging or branch expansion processing to obtain an optimized target code syntax tree.
[0029] Specifically, the optimizing the branch structure of the target code syntax tree by branch merging or branch expansion according to the optimized syntax tree parameters to obtain the optimized target code syntax tree includes:
[0030] Analyze the dependency between syntax tree nodes in the target code syntax tree according to the optimized syntax tree parameters, and identify redundant branches and missing branches;
[0031] For redundant branches, by analyzing the repetition rate of logic blocks in adjacent conditional branches, branches with a repetition rate greater than a preset repetition rate threshold are merged to obtain a merged branch;
[0032] For missing branches, generate corresponding extended branches according to the parameter type of the missing branch;
[0033] The target code syntax tree is updated and optimized according to the merged branch and the extended branch to obtain an optimized target code syntax tree.
[0034] Specifically, the generating of the initial code by combining the optimized target code syntax tree and the YApi interface data includes:
[0035] Analyze the syntax tree of the optimized target code and identify the key nodes and corresponding syntax rules in the syntax tree;
[0036] Extract interface information related to the front-end Service code from the YApi interface data;
[0037] According to the key nodes and corresponding grammatical rules, the interface information is mapped into the target code grammar tree to generate a code framework;
[0038] Based on the code framework and in accordance with preset code writing standards, code and corresponding syntax prompt information are generated to obtain initial code.
[0039] Specifically, the initial code is optimized through a preset code optimization mechanism to obtain updated code, which is output in the front-end window to achieve automatic generation of front-end Service code, including:
[0040] According to the logical relationship and function of the code, the initial code is divided into blocks to obtain multiple code blocks;
[0041] Through the preset optimization point identification model, the part that needs to be optimized in each code block is identified to obtain multiple code optimization points;
[0042] Analyze the code optimization type corresponding to each code optimization point to obtain the optimization type corresponding to each code optimization point;
[0043] According to the optimization type, the code block corresponding to each code optimization point is optimized through the preset code optimization mechanism to obtain the updated code, which is output in the front-end window to realize the automatic generation of the front-end Service code.
[0044] Specifically, according to the optimization type, the code block corresponding to each code optimization point is optimized through a preset code optimization mechanism to obtain updated code, which is output in the front-end window to achieve automatic generation of front-end Service code, wherein the optimization type includes redundant code optimization points, missing code optimization points, and error code optimization points, including:
[0045] For redundant code optimization points, the first updated code is obtained by deleting the code with repeated functions in the code block;
[0046] For the missing code optimization points, the missing code is supplemented by analyzing the logical relationship and functional connection of the context code to obtain the second updated code;
[0047] For the error code optimization point, the error code is corrected according to the error prompt information of the static code analysis tool to obtain the third updated code;
[0048] According to the first update code, the second update code and the third update code, the code block is optimized to obtain the update code, which is output in the front-end window to realize the automatic generation of the front-end Service code.
[0049] A front-end service code automatic generation system, used to implement the front-end service code automatic generation method, comprising:
[0050] The requirement parsing module, in response to the user's code generation requirements, parses the dependencies between the code generation requirements through a preset requirement parsing model to obtain the requirement parsing results;
[0051] The syntax tree matching module matches the target code syntax tree in a preset code syntax tree library according to the requirement parsing result;
[0052] A syntax tree optimization module optimizes the branch structure of the target code syntax tree by branch merging or branch expansion processing to obtain an optimized target code syntax tree;
[0053] A code generation module generates initial code by combining the optimized target code syntax tree and YApi interface data;
[0054] The code optimization module optimizes the initial code through a preset code optimization mechanism to obtain an updated code, which is output in the front-end window to realize automatic generation of the front-end Service code.
[0055] Compared with the prior art, this application has the following beneficial effects:
[0056] This application constructs a requirement association graph and interface call chain based on code generation requirements, performs multi-level matching in the code syntax library, screens out highly matching syntax trees, generates corresponding code and performs code optimization, and generates code that is highly consistent with the requirements by parsing the user's code generation requirements. The corresponding code is generated based on the highly matching syntax tree, which improves the quality of the generated code, and fine-tunes the optimization points in different positions of the generated code, thereby improving the stability and reliability of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 This is a workflow diagram of a method for automatically generating front-end Service code in Example 1 of the present invention;
[0058] Figure 2 Schematic diagram of the target code syntax tree matching process in Example 1 of the present invention;
[0059] Figure 3 This is a schematic diagram of the target code syntax tree update optimization process in Example 1 of the present invention;
[0060] Figure 4 This is a structural diagram of a front-end Service code automatic generation system in Example 2 of the present invention. DETAILED DESCRIPTION
[0061] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0062] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0063] Secondly, the term "one embodiment" or "embodiment" herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in one embodiment" appearing in various places throughout this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive of other embodiments.
[0064] Example 1
[0065] This embodiment provides a method for automatically generating front-end Service code. Figure 1 As shown, the method for automatically generating front-end Service code includes:
[0066] S101, in response to a user's code generation requirement, parsing the dependency relationship between the code generation requirements using a preset requirement parsing model to obtain a requirement parsing result;
[0067] S102: Match the target code syntax tree in a preset code syntax tree library according to the requirement analysis result;
[0068] S103, optimizing the branch structure of the target code syntax tree by branch merging or branch expansion processing to obtain an optimized target code syntax tree;
[0069] S104, combining the optimized target code syntax tree and YApi interface data to generate initial code;
[0070] S105. Optimize the initial code through a preset code optimization mechanism to obtain an updated code, which is output in a front-end window to achieve automatic generation of the front-end Service code.
[0071] This embodiment parses the user's code generation requirements, matches the code syntax tree based on the parsing results, and matches a code syntax tree that highly matches the code generation requirements. The code generated based on the highly matching code syntax tree can meet the requirements; by optimizing the branch structure of the code syntax tree and comprehensively optimizing the generated initial code, the generated code structure is clear, the logic is reasonable, the error rate is low, and it has high quality and maintainability.
[0072] In this embodiment, after receiving the code generation requirements proposed by the user, the code generation requirements are parsed, and an associated graph and an interface call chain are constructed based on the code generation requirement parsing results. By deeply parsing the user's code generation requirements, the user's real needs can be accurately grasped, deviations in the code generation process can be avoided, the cost of rework and modification can be reduced, and development efficiency and accuracy can be improved. After obtaining the requirements parsing results, based on the requirements parsing results, a code syntax tree that highly matches it is screened out from a preset code syntax tree library through multi-level matching as the basic framework for generating code; through multi-level matching, the target code syntax tree that best meets the code generation requirements can be accurately screened out from the code syntax tree library, improving the accuracy and efficiency of syntax tree matching and providing a matching basic framework for the code generation process.
[0073] Specifically, after filtering out the target code syntax tree, the preset syntax tree cannot fully meet the requirements of the YApi configuration in the actual usage scenario. According to the preset parameter constraint rules declared in the YApi configuration, the parameters of the target code syntax tree are optimized, and the branch structure in the target code syntax tree is optimized, including the identification and optimization of redundant branches and missing branches, to obtain a syntax tree that better meets the actual code generation requirement scenario; by optimizing the syntax tree parameters and branch structure, the optimized code syntax tree structure is made more reasonable, redundant code branches are reduced, missing branches are supplemented, and the quality and performance of the generated code are improved. Based on the optimized target code syntax tree and combined with the YApi interface data, the interface information is generated according to the structure and rules of the syntax tree to generate a code framework, and the corresponding complete initial code is automatically generated according to the code framework, and the corresponding syntax prompt information is generated. Accurate and standardized initial code is generated according to the requirements and interface data, which can reduce the workload and error probability of manual code writing. At the same time, the syntax prompt information helps developers understand and modify the code.
[0074] At the same time, after the initial code is generated, the initial code is optimized to avoid redundancy, omissions or errors in the generated initial code that affect user use. Through the preset code optimization mechanism, the initial code is analyzed in blocks, and the optimization points that need to be optimized in the code are identified. The optimization points are classified, and the corresponding code optimization is performed on each optimization point according to the type of optimization point. After code optimization is performed on each code optimization point that needs to be optimized, the updated code is obtained and output in the front-end window to complete the automatic generation of the front-end Service code. Through comprehensive and targeted code optimization, the quality of the code can be significantly improved, the generated code can be made more concise, efficient and stable, the cost of code maintenance is reduced, and the user's development experience is also improved.
[0075] This application constructs a requirement association graph and interface call chain based on code generation requirements, performs multi-level matching in the code syntax library, screens out highly matching syntax trees, generates corresponding code and performs code optimization, and generates code that is highly consistent with the requirements by parsing the user's code generation requirements. The corresponding code is generated based on the highly matching syntax tree, which improves the quality of the generated code, and fine-tunes the optimization points in different positions of the generated code, thereby improving the stability and reliability of the code.
[0076] Furthermore, in response to the user's code generation requirements, the dependency relationships between the code generation requirements are parsed using a preset requirement parsing model to obtain a requirement parsing result, including:
[0077] S201, according to the user's code generation requirements, the requirements are parsed through a preset requirements parsing model to generate multiple types of requirements;
[0078] S202. Build a demand association map by analyzing the dependency relationships between different types of demands;
[0079] S203, constructing an interface call chain by analyzing the call constraint relationship between interfaces;
[0080] S204: Combine the demand association graph and the interface call chain to obtain demand analysis results.
[0081] In this embodiment, the system receives code generation requirements input by the user in text, voice or other forms. For example, the user inputs "generate a front-end Service code for displaying a product list, which can obtain product data and display it on the page"; the code generation requirements are analyzed through a preset requirement analysis model, and the sentence is split into multiple words or phrases, including words such as "generate", "product list", "obtain product data", and "display page". The requirement analysis model includes but is not limited to a semantic recognition model. The requirement analysis model of this embodiment is a semantic recognition model. The semantic recognition model is trained with a large amount of historical data to obtain a pre-trained requirement analysis model, which performs semantic analysis on the user requirements to determine the requirement type corresponding to each word or phrase. For example, "obtain product data" belongs to the data acquisition requirement, and "display on the page" belongs to the page display requirement; according to the requirement analysis results, the requirement type is clarified and a requirement set is obtained; by subdividing the user's vague code generation requirements into multiple specific types of requirements, the system can accurately understand all aspects of the requirements, avoid omissions or misunderstandings in the code generation process, and improve the accuracy of requirement understanding.
[0082] Specifically, according to the dependency relationships between different types of requirements, multiple requirements are associated to construct a requirement association graph; first, multiple types of requirements are analyzed one by one to determine the dependency relationships between each type of requirement. For example, the data acquisition requirement of "obtaining product data" must be completed before the page display requirement of "displaying the product list" can be performed, that is, the page display requirement depends on the data acquisition requirement; with the requirement type as the node and the dependency relationship between requirements as the edge, directed edges are used to connect the requirements to construct a requirement association graph; by constructing a requirement association graph, the logical relationship between requirements can be displayed, and the development process can be planned according to the graph to avoid development errors caused by the confusion of the requirement sequence, improve development efficiency, and also help users understand and modify the code.
[0083] Specifically, based on the calling relationship between interface constraints, an interface calling chain is constructed. By analyzing the calling order, parameter passing and other constraint relationships between interfaces, the order and process of interface calls are clarified to ensure the correctness and stability of the code when interacting with the backend. First, information related to the interface call is extracted from the demand analysis results, including the interface names, interface functions, data transfer relationships between interfaces, etc. For example, the interface for obtaining product data needs to pass specific parameters, and the returned data format must meet the requirements of the display page. According to the logical relationship and constraints between the interfaces, the calling order of the interfaces is determined. For example, the interface for obtaining product classification is called first, and then the interface for obtaining specific product data is called according to the classification. With the interface as the node and the interface calling order and data transfer relationship as the edge, an interface calling chain is constructed, and the interface calling chain is verified and optimized to check whether there are any interface calling conflicts or unreasonable places, and make adjustments. By constructing the interface calling chain, the interface calling process can be clarified, interface calling errors can be avoided, the data interaction between the frontend and the backend can be ensured to be smooth, the stability and reliability of the integration of the code with the external system can be improved, and the debugging time can be reduced.
[0084] After obtaining the requirement association graph and interface call chain, combine the requirement association graph and the interface call chain, combine the logical relationship between the requirements and the interface call process information, and match the interface information in the interface call chain with the requirement type in the requirement association graph; for example, clarify the implementation of the requirement type corresponding to the interface call; sort out and supplement the integrated information to form the requirement analysis result, and verify the requirement analysis result to ensure the accuracy and completeness of the result; by combining various aspects of the requirements and interface call details, it provides a clear and accurate basis for syntax tree matching and code generation, ensuring the smooth progress of the entire code automation generation process.
[0085] Furthermore, the requirement parsing result is matched in a preset code syntax tree library to obtain a target code syntax tree, including:
[0086] S301. Based on the demand analysis results, feature extraction is performed using a preset demand feature extraction model to obtain multiple demand features;
[0087] S302: Encode the multiple demand features to construct a demand feature vector;
[0088] S303: Combine the requirement analysis result and the requirement feature vector, perform multi-level matching in a preset code syntax tree library, and obtain a target code syntax tree.
[0089] This embodiment matches the preset code syntax tree based on the result of the requirement analysis, and matches the code syntax tree that meets the result of the requirement analysis. By performing feature extraction, feature vector construction and multi-level matching on the result of the requirement analysis, the user requirements can be compared with the code syntax tree in a comprehensive and detailed manner, thereby improving the probability of finding the correct target code syntax tree and ensuring that the generated code meets the requirements; avoiding the problem of using a single syntax tree matching method resulting in a large deviation between the matched syntax tree and the actual code generation requirements.
[0090] In this embodiment, based on the code requirement analysis results, key features that can represent the core content of the requirements are extracted through a preset requirement extraction model; the requirement feature extraction model analyzes the requirement analysis results and adopts different extraction strategies for different types of requirement information. For data-related requirements, features such as data types and data operations are extracted. The data types specifically include product names, and data operations specifically include filtering and sorting. For page display requirements, features such as page layout and interactive elements are extracted. The page layout specifically includes a list layout, and the interactive elements specifically include a filter button. For interface call requirements, features such as the interface parameter format and the return data structure are extracted. The various types of extracted key information are integrated to obtain multiple requirement features, for example, "string type product name data", "list page layout", "interface call with filtering parameters", etc. By performing feature extraction on the requirement analysis results, the requirements can be converted into clear and quantifiable key information, providing a data basis for encoding and matching operations, improving the pertinence and accuracy of matching, and avoiding mismatching due to unclear information during the matching process.
[0091] Specifically, after obtaining multiple demand features, the features are encoded according to the encoding rules and constructed into a demand feature vector. The encoding rules include one-hot encoding, word vector encoding, etc. This embodiment adopts one-hot encoding. For example, for the feature of "data type", it includes three types: "string", "integer", and "Boolean". The "string" type can be encoded as [1,0,0], "integer" is encoded as [0,1,0], and "Boolean" is encoded as [0,0,1]; according to the encoding rules, each demand feature is encoded and processed, and the encoded values of all demand features are combined together to obtain a demand feature vector; through standardized encoding and processing, the demand features can be matched and calculated in a unified format, thereby improving the efficiency and accuracy of matching, and also facilitating quantitative comparison with the information in the code syntax tree library.
[0092] Specifically, based on the requirements analysis results and the requirements feature vectors, the target code syntax tree that best meets the requirements is screened out from the code syntax tree library. A multi-level matching strategy is adopted to first perform a large-scale screening, and then gradually narrow the scope. The target syntax tree is located through feature matching at different granularities. Multi-level matching can efficiently and accurately find the target code syntax tree that best meets the requirements from the code syntax tree library. By gradually refining the screening conditions, unnecessary matching calculations are reduced and matching efficiency is improved. At the same time, by fusing different syntax tree nodes, a syntax tree structure that better meets the requirements can be generated, providing a better basic framework for code generation and reducing code modification and debugging costs.
[0093] Furthermore, the requirement parsing result and the requirement feature vector are combined to perform multi-level matching in a preset code syntax tree library to obtain a target code syntax tree, including:
[0094] S401. Screening a preset code syntax tree library based on the demand analysis result to obtain a first code syntax tree set;
[0095] S402: extracting coarse-grained features from the requirement parsing result and the requirement feature vector, and screening the first code syntax tree set according to the coarse-grained features to obtain a second code syntax tree set;
[0096] S403: extracting fine-grained features from the requirement parsing result and the requirement feature vector, and screening the second code syntax tree set according to the fine-grained features to obtain a third code syntax tree set;
[0097] S404: According to the third code syntax tree set, select syntax tree nodes that meet preset fusion conditions from each code syntax tree for fusion to obtain a target code syntax tree.
[0098] This embodiment performs multi-level screening and matching on the code syntax tree. First, based on the demand analysis results, the syntax tree library is preliminarily screened. For example, the demand analysis results include "front-end Service", "order information display" and other contents. The screening conditions are set in the code syntax tree library to screen out all syntax trees marked as "front-end Service" type, or syntax trees containing keywords related to "order information display"; through database query, index matching and other technical means, the syntax trees that meet the conditions are screened from the preset code syntax tree library to obtain the first code syntax tree set; through preliminary and rapid screening, a large number of syntax trees that obviously do not meet the requirements can be quickly eliminated, reducing the computational complexity of subsequent matching, improving matching efficiency, and narrowing the candidate range, making the next step of screening more targeted.
[0099] Specifically, based on the demand analysis results and the demand feature vector, coarse-grained features are extracted, and the first code syntax tree set is screened based on the coarse-grained features to further screen out syntax trees that better meet the demand, so that the candidate syntax trees are closer to the target; coarse-grained features are extracted from the demand analysis results and the demand feature vector. For example, in the example of order information display, the coarse-grained features include "data display type is list", "involving data query operations", etc.; for each syntax tree in the first code syntax tree set, its structure and function description are analyzed to determine whether it has the extracted coarse-grained features, and the syntax trees with these coarse-grained features are screened out to form the second code syntax tree set; for example, check whether there is a node structure for constructing a list display in the syntax tree, and whether it contains functions or operations related to data query; further screening through coarse-grained features can further narrow the range of candidate syntax trees on the basis of preliminary screening, and screen based on the key general features of the demand, thereby improving the accuracy of matching and making the screened syntax trees better meet user needs.
[0100] Furthermore, fine-grained features are extracted based on the demand analysis results and demand feature vectors, and the second code syntax tree set is screened based on the fine-grained features, so that the syntax tree that best meets the user's needs can be accurately found; fine-grained features are extracted from the demand analysis results and demand feature vectors. For example, in the order information display scenario, fine-grained features include "order data contains order number, order time, order amount fields", "list display must be arranged in reverse order by order time", etc.; each syntax tree in the second code syntax tree set is analyzed, and whether the fine-grained features are met is determined based on the syntax tree nodes and structural details, and the syntax trees that meet the fine-grained features are screened out to form the third code syntax tree set; screening through specific demand characteristics improves the accuracy of matching, so that the screened syntax trees are highly matched with user needs.
[0101] Specifically, such as Figure 2After obtaining the third code syntax tree set, combining the advantages of each syntax tree in the third code syntax tree, the tree nodes in multiple syntax trees that meet the fusion conditions and match the code generation requirements are fused to obtain the target code syntax tree; setting the fusion conditions according to the accuracy requirements of system code generation, including node similarity reaching a certain threshold, functional integrity meeting the requirements, and good compatibility of syntax rules, traversing each syntax tree in the third code syntax tree set, and analyzing the node structure and function of each syntax tree; selecting nodes that meet the fusion conditions from each syntax tree, and combining and integrating them according to logical relationships and connection relationships; for example, connecting efficient data processing nodes with beautiful page display nodes, adjusting parameter transfer and logical relationships between nodes, and finally generating the target code syntax tree; by fusing the tree nodes of multiple syntax trees, the advantages of multiple syntax trees can be fully utilized, and the generated target code syntax tree can better meet user needs. Compared with a single syntax tree, its structure is more reasonable and its functions are more complete, providing an ideal basic framework for code generation, and reducing the modification and adjustment work during the code development process.
[0102] Furthermore, the branch structure of the target code syntax tree is optimized by branch merging or branch expansion to obtain an optimized target code syntax tree, including:
[0103] S501, analyzing the parameter nodes in the target code syntax tree to obtain initial syntax tree parameters;
[0104] S502. Optimize the initial syntax tree parameters according to the preset parameter constraint rules declared in the YApi configuration to obtain optimized syntax tree parameters;
[0105] S503 : Optimize the branch structure of the target code syntax tree by branch merging or branch expansion according to the optimized syntax tree parameters to obtain an optimized target code syntax tree.
[0106] This embodiment performs parameter optimization and structural optimization on the screened target code syntax tree, which can ensure that the optimized syntax tree parameters are more accurate and standardized, the optimized syntax tree branch structure is clearer and more reasonable, reduces redundancy, supplements missing functions, improves the execution efficiency and readability of the code, and reduces development and maintenance costs.
[0107] In this embodiment, first, the target code syntax tree is analyzed to obtain initial syntax tree parameters. Specifically, a traversal algorithm is used to analyze all tree nodes in the syntax tree one by one to identify parameter nodes. The parameter nodes include input parameters of functions, definition parameters of variables, etc., such as the page number parameter and the number of items to be displayed per page parameter in the order data acquisition function. The parameter name, data type, default value and other information in the parameter nodes are integrated to form initial syntax tree parameters. By extracting the parameter information in the target code syntax tree, the parameter status of the current syntax tree can be reflected, providing a data basis for parameter optimization.
[0108] Specifically, according to the preset parameter constraint rules declared in the YApi configuration, the initial syntax tree parameters are optimized to obtain optimized syntax tree parameters; first, the parameter constraint rules in the YApi configuration are read, for example, the page number parameter of the order data interface must be an integer greater than 0, and the value range of the parameter displayed per page is between 10-100; the initial syntax tree parameters are compared with the rules of the YApi configuration one by one, and the parameters that do not meet the rules are optimized and adjusted accordingly. For example, the default value of the page number parameter is 0, which does not meet the rule of being greater than 0, so its default value is changed to 1; the data type of the parameter displayed per page is a string, which does not meet the integer requirement, so its type is converted to an integer. After adjustment, the optimized syntax tree parameters are obtained; by optimizing the syntax tree parameters, the syntax tree parameters strictly follow the rules of the YApi configuration, ensuring that the code can correctly pass and process parameters when interacting with the interface, avoiding problems such as interface call failure and data acquisition exceptions caused by parameter errors, and improving the stability and reliability of the code.
[0109] At the same time, according to the optimized syntax tree parameters, the branch structure of the target code syntax tree is optimized to obtain the optimized target code syntax tree. According to the optimized syntax tree parameters, the dependency relationship between the syntax tree nodes in the target code syntax tree is analyzed, redundant branches and missing branches are identified, and corresponding optimization processing is performed. The optimized branch structure makes the code logic more concise, reduces redundant code, and improves the execution efficiency of the code; at the same time, supplementing the missing branches ensures the integrity of the code function, reduces the risk of errors caused by logical vulnerabilities, and makes the generated code easier to understand and maintain.
[0110] Furthermore, the branch structure of the target code syntax tree is optimized by branch merging or branch expansion processing according to the optimized syntax tree parameters to obtain the optimized target code syntax tree, including:
[0111] S601: Analyze the dependency relationship between syntax tree nodes in the target code syntax tree according to the optimized syntax tree parameters, and identify redundant branches and missing branches;
[0112] S602: For redundant branches, by analyzing the repetition rate of logic blocks in adjacent conditional branches, branches with a repetition rate greater than a preset repetition rate threshold are merged to obtain a merged branch;
[0113] S603. For a missing branch, generate a corresponding extended branch according to the parameter type of the missing branch;
[0114] S604: Update and optimize the target code syntax tree according to the merged branch and the extended branch to obtain an optimized target code syntax tree.
[0115] In this embodiment, based on the optimized syntax tree parameters, a search is performed in the target code syntax tree to identify redundant branches and missing branches; the dependency relationship between the target code syntax tree nodes is analyzed through a graph theory analysis method or a dependency analysis method, and in the analysis process, branches with similar execution logic and repeated functions are identified as redundant branches; at the same time, based on business needs and parameter associations, branches lacking key functions are identified as missing branches, and key functions specifically include displaying products in order of price; by accurately locating problematic branches in the syntax tree, a target is provided for optimizing the syntax tree branch structure, avoiding blind code modification, improving optimization efficiency, and reducing errors caused by logical confusion.
[0116] Specifically, for redundant branches, by calculating the repetition rate of logic blocks in adjacent conditional branches, branches with high repetition rates are merged to streamline code logic and reduce code redundancy; according to the actual code accuracy requirements, a repetition rate threshold is set, which is set to 80% in this embodiment; for the identified redundant branches, their adjacent conditional branches are analyzed one by one; a code similarity calculation algorithm is used, specifically including methods based on text editing distance, abstract syntax tree comparison, etc., and this embodiment uses an abstract syntax tree comparison method to calculate the repetition rate of logic blocks in adjacent conditional branches; when the repetition rate is greater than the preset repetition rate threshold, the redundant branches are merged; when merging, the common logic blocks are integrated, the repeated parts are removed, and the logical judgment of the different parts is retained to obtain a merged branch; by merging redundant branches, code redundancy can be eliminated, the code logic can be made more concise and compact, the difficulty of code maintenance is reduced, unnecessary calculations and execution paths are reduced, the code running efficiency is improved, and it is also convenient for developers to understand and modify the code.
[0117] Specifically, for missing branches, generate corresponding extended branches based on the parameter type and business requirements of the missing branches to supplement the code functions; for the identified missing branches, analyze the parameter types and business logic involved in the missing branches. For example, in the product list display, there is a missing functional branch for displaying products sorted by "sales volume". This branch involves the "sales volume" parameter, and the business logic is to sort the product data according to sales volume; select the corresponding code template or algorithm based on the parameter type and business logic; for sorting by "sales volume", you can use common sorting algorithms, including quick sort, bubble sort, etc., and generate a new branch code structure based on the structural characteristics of the syntax tree; add the generated branch code structure to the target code syntax tree, establish the correct connection relationship and logical judgment conditions with the existing nodes, and form a complete extended branch; by expanding the missing branches, you can improve the code function, fill in the functional gaps, make the generated front-end Service code more in line with actual business needs, improve the practicality and integrity of the code, and reduce the later modification and supplement work caused by insufficient functions.
[0118] At the same time, if Figure 3 , according to the merged branches and expanded branches, the target code syntax tree is updated, and the connection relationship between the syntax tree nodes is adjusted to ensure that the data and control flow can be transmitted correctly, and an optimized target code syntax tree is obtained; by optimizing the branch structure of the target code syntax tree, the structure and logic of the target code syntax tree are optimized, and the quality of the front-end Service code generated based on the syntax tree is improved. The optimized syntax tree can generate more efficient and stable code, reduce the probability of code errors, and improve development efficiency and code quality.
[0119] Furthermore, the generating of the initial code by combining the optimized target code syntax tree and the YApi interface data includes:
[0120] S701, analyzing the syntax tree of the optimized target code to identify key nodes in the syntax tree and corresponding syntax rules;
[0121] S702. Extract interface information related to the front-end Service code from the YApi interface data;
[0122] S703: Map the interface information to a target code syntax tree according to the key nodes and corresponding syntax rules to generate a code framework;
[0123] S704: Based on the code framework and in accordance with a preset code writing standard, generate code and corresponding syntax prompt information to obtain initial code.
[0124] This embodiment quickly builds a code framework based on the optimized code syntax tree and interface information, and automatically generates corresponding initial code and syntax prompt information according to preset standards based on the code framework, thereby improving the speed of automatic generation of initial code. By generating syntax prompt information, code guidance is provided to users to help them quickly understand and master the code logic, reduce the difficulty and learning cost of development, and improve development efficiency and code quality.
[0125] In this embodiment, the syntax tree of the optimized target code is analyzed, and a tree traversal algorithm, specifically including a depth-first search and a breadth-first search, is used to traverse the syntax tree to identify key nodes of the syntax tree. The key nodes include function definition nodes, data processing nodes, variable declaration nodes, etc.; the function definition nodes specifically include functions for obtaining order data, the data processing nodes specifically include operation nodes for order data screening and sorting, etc., and the variable declaration nodes specifically include variables for storing order lists; based on the identified key nodes, for each key node, corresponding syntax rules are extracted, for example, the function definition node follows a specific function declaration syntax, including function name naming specifications, parameter list format, return value type definition, etc.; the data processing node involves syntax rules for data operations, including the writing of conditional expressions for data screening, the calling method of the sorting function, etc.; by extracting the key nodes in the code syntax tree and analyzing the syntax rules of the corresponding nodes, the core elements and writing specifications of the syntax tree can be clarified, and syntax guidance can be provided for the code generation process, so that the generated code structure is reasonable and logically correct, avoiding code generation errors caused by unclear understanding of the syntax tree.
[0126] Specifically, extract interface information related to the front-end Service code from the YApi interface data, and filter out relevant interface information based on the functional requirements of the front-end Service code; for example, for the user order display function, filter out relevant interfaces such as the interface for obtaining the order list and the interface for obtaining the order details, and extract key information from the filtered interfaces, including the URL address of the interface used to determine the target of the request, the request method (GET (get), POST (send), etc.), the name, type and value range of the request parameters, and the structure and field meaning of the data returned by the interface; integrate the interface information to obtain complete interface information; by extracting the interface information, provide the corresponding interface data basis for the code to correctly call the interface and process the data, and avoid problems such as interface call failure and data acquisition exception due to missing or incorrect interface information.
[0127] Specifically, according to the identified key nodes and grammatical rules, each key node needs to be associated with the interface information; for example, the data acquisition function node needs to be associated with the URL address, request method and parameter information in the YApi interface; according to the association relationship, the interface information is filled in the corresponding node of the syntax tree, and in the data acquisition function node, the function parameters are set as the interface request parameters, and the calling logic inside the function is written according to the interface request method and URL address to ensure that the function can correctly initiate the interface request; according to the grammatical rules, each node is connected to build a complete code framework, and the data acquisition node, data processing node and page display node are connected through corresponding logical relationships to form a code framework that can realize the front-end Service function; by generating a code framework, the overall structure and function implementation method of the code can be clarified, the workload and error probability of manually writing the code framework can be reduced, and the efficiency and quality of code generation can be improved.
[0128] Furthermore, on the basis of the code framework, according to the preset code writing standards, including code indentation format, naming conventions, comment requirements, etc., specific code is written in each node of the code framework, and corresponding syntax prompt information is added to the written code. For function definitions, parameter descriptions and return value descriptions are added; for variable declarations, the purpose and data type of the variables are marked, and the prompt information is embedded in the code in the form of comments; at the same time, the generated initial code is checked and sorted to ensure that the automatically generated initial code meets the writing standards and the syntax prompt information is accurate, so as to obtain the initial code; by automatically generating the initial code and adding the corresponding syntax prompt information, users can quickly understand the code function and reduce the difficulty of code learning and modification.
[0129] Furthermore, the initial code is optimized by a preset code optimization mechanism to obtain updated code, which is output in the front-end window to realize automatic generation of front-end Service code, including:
[0130] S801, dividing the initial code into blocks according to the logical relationship and function of the code to obtain multiple code blocks;
[0131] S802: Using a preset optimization point identification model, identify the portion of each code block that needs to be optimized to obtain multiple code optimization points;
[0132] S803: Analyze the code optimization type corresponding to each code optimization point to obtain the optimization type corresponding to each code optimization point;
[0133] S804. According to the optimization type, the code block corresponding to each code optimization point is optimized through a preset code optimization mechanism to obtain updated code, which is output in the front-end window to achieve automatic generation of front-end Service code.
[0134] This embodiment optimizes the automatically generated initial code, divides the initial code into blocks, identifies the optimization points in the initial code that need to be optimized, performs corresponding optimization processing on each optimization point, and optimizes redundancy, omissions, errors and other problems in the code respectively. The optimized code structure is more reasonable, the logic is clearer, the performance is optimized, and the overall quality of the code is improved.
[0135] In this embodiment, the initial code is divided into blocks to avoid the problem of low optimization efficiency caused by directly optimizing the initially generated complex code. By analyzing the logical relationship and functions between the initial codes, function definitions, class declarations, code segments with different functions, etc. are identified, and the initial code is divided to obtain multiple code blocks with independent functions; for example, the code responsible for obtaining order data from the back-end interface is divided into a data acquisition module, the code for filtering and sorting order data is divided into a data processing module, and the HTML, CSS and JavaScript codes used to display order information on the page are divided into a page rendering module; by dividing the code into blocks, complex codes can be simplified, the code structure can be made clearer, and code optimization can be facilitated according to the functions of the code blocks.
[0136] Specifically, after dividing into multiple code blocks, the locations in the code that need to be optimized are identified through a preset optimization point identification model. The optimization point identification model can be a model based on code static analysis, a machine learning model, etc. The optimization point identification model in this embodiment is a code static analysis model, which checks the syntax structure, variable usage, function calls, etc. of the code, and identifies errors and redundant points in the code. For example, in the data acquisition module, the model checks for problems such as unreasonable interface call timeout settings and unhandled interface call errors; in the data processing module, redundant data processing logic and unoptimized algorithms are found; in the page rendering module, repeated CSS style definitions and unreleased resources in JavaScript code are identified; the identified parts that need to be optimized are marked as code optimization points; by identifying code optimization points, problems and optimizable areas in the code can be accurately located, providing a basis for code optimization, avoiding blind code modifications, and improving optimization efficiency and code quality improvement.
[0137] Furthermore, for each identified code optimization point, the cause and manifestation are analyzed, the code optimization points are classified, and each optimization point is classified into the corresponding optimization type; for example, for the optimization point of "duplicate order status judgment logic exists in the data processing module", it is judged to be a redundant code optimization point due to its repeated functions; for "the page rendering module lacks the code for the order details click jump function", it is a missing code optimization point; for "the interface parameter type error in the data acquisition module", it is identified as an error code optimization point; by classifying the optimization types of code optimization points, the processing direction of each optimization point can be clarified, and corresponding optimization methods can be adopted for different types of optimization points to more effectively solve code problems and improve code quality.
[0138] Specifically, according to each code optimization point and the corresponding optimization type, the code block where each code optimization point is located is optimized through the corresponding optimization strategy in the preset code optimization mechanism to obtain updated code; through targeted code optimization of each code optimization point, various problems existing in the code can be effectively solved, making the code more concise, efficient and stable; the optimized code is improved in terms of performance, readability and maintainability, reducing the cost and workload in the subsequent development and maintenance process, and at the same time output in the front-end window makes it convenient for developers to obtain optimization results in a timely manner, thereby improving development efficiency.
[0139] Furthermore, according to the optimization type, the code block corresponding to each code optimization point is optimized through a preset code optimization mechanism to obtain updated code, which is output in the front-end window to realize automatic generation of front-end Service code, wherein the optimization type includes redundant code optimization points, missing code optimization points and error code optimization points, including:
[0140] S901: For redundant code optimization points, obtain first updated code by deleting functionally duplicated code in a code block.
[0141] S902: For the missing code optimization point, by analyzing the logical relationship and functional connection of the context code, supplement the missing code to obtain a second updated code;
[0142] S903: For the error code optimization point, correct the error code according to the error prompt information of the static code analysis tool to obtain a third updated code;
[0143] S904. Optimize the code block according to the first update code, the second update code, and the third update code to obtain the update code, and output it in the front-end window to realize automatic generation of the front-end Service code.
[0144] In this embodiment, the types of code optimization points include redundant code optimization points, missing code optimization points and erroneous code optimization points. For redundant code optimization points, a code similarity detection algorithm is used, specifically including abstract syntax tree comparison, text hash comparison and other algorithms, to identify the code block and find out the code fragments with repeated functions; the repeated code fragments are deleted, and a section of the code that can fully implement the corresponding function is retained to obtain the first updated code; by deleting the redundant code, code redundancy can be effectively reduced, code complexity can be reduced, and the code structure can be made clearer. There is no need to repeatedly execute the same logic when the code is running, thereby improving execution efficiency.
[0145] For the missing code optimization point, the context code of the location is analyzed, and according to the business requirements and overall functional design, the logic and functions that the missing code needs to implement are identified. The missing code is written according to the corresponding logic and functions, and the code is supplemented into the code block to obtain the second updated code. By filling in the missing code, the consistency of the code logic can be guaranteed, avoiding poor user experience or business process interruption due to missing functions, and improving the availability and practicality of the system.
[0146] For error code optimization points, run static code analysis tools, including ESLint, TSLint and other tools, scan the code blocks with error code optimization points, obtain the corresponding error prompt information, locate the specific error code line according to the error prompt information, correct the code of the error code line, and obtain the third updated code; by correcting the error code, errors in the code can be fixed in time, avoiding serious problems such as system crashes and data errors caused by error codes, enhancing the stability and reliability of the code, ensuring that the code complies with programming specifications, and improving code quality.
[0147] Specifically, the first update code, the second update code and the third update code are merged to replace the corresponding parts in the original code block, and a comprehensive check is performed on the integrated code block to verify whether the logical relationship between the code blocks is correct and whether the data transmission is smooth. The integrated code is verified and the final optimized update code is output in the front-end window to realize the automatic generation of the front-end Service code; the code quality is improved through automatic code generation and optimization.
[0148] Example 2
[0149] In this embodiment, if Figure 4 , provides a front-end Service code automatic generation system for implementing the front-end Service code automatic generation method, including:
[0150] The requirement parsing module, in response to the user's code generation requirements, parses the dependencies between the code generation requirements through a preset requirement parsing model to obtain the requirement parsing results;
[0151] The syntax tree matching module matches the target code syntax tree in a preset code syntax tree library according to the requirement parsing result;
[0152] A syntax tree optimization module optimizes the branch structure of the target code syntax tree by branch merging or branch expansion processing to obtain an optimized target code syntax tree;
[0153] A code generation module generates initial code by combining the optimized target code syntax tree and YApi interface data;
[0154] The code optimization module optimizes the initial code through a preset code optimization mechanism to obtain an updated code, which is output in the front-end window to realize automatic generation of the front-end Service code.
[0155] In this embodiment, the requirement parsing module converts the user's vague and diverse code generation requirements into structured information that can be processed by a computer. When the user inputs the code generation requirements, the requirements are disassembled through a preset requirement parsing model to construct a requirement association graph; at the same time, the interface call constraint relationship is sorted out to form an interface call chain, and the requirement association graph and the interface call chain are combined to output a complete and accurate requirement parsing result, providing a clear and definite requirement basis for code generation and ensuring the correctness of the code generation direction; the syntax tree matching module searches for a target code syntax tree that meets the requirements in a preset code syntax tree library based on the results output by the requirement parsing module, uses a requirement feature extraction model to extract key features from the requirement parsing results to construct a requirement feature vector, performs multi-level screening on the code syntax tree library, and generates a target code syntax tree. By efficiently and accurately positioning the syntax tree, a high-quality basic framework is built for code generation, reducing the workload and error rate of manual screening.
[0156] Specifically, the syntax tree optimization module optimizes the target code syntax tree according to the rules in the YApi configuration, and optimizes the initial parameters of the target code syntax tree according to the preset parameter constraint rules of the YApi configuration to obtain optimized syntax tree parameters that meet the specifications. Based on the optimized parameters, the branch structure of the syntax tree is optimized and the optimized syntax tree is updated to make the syntax tree structure more reasonable and functionally more complete, thereby improving the quality and performance of the generated code. The code generation module generates the initial code of the front-end service based on the optimized target code syntax tree and YApi interface data. According to the key nodes and corresponding syntax rules of the optimized target code syntax tree, the interface information related to the front-end service code is extracted from the YApi interface data, including the interface address, request method, etc. The interface information is mapped to the key nodes of the syntax tree according to the syntax rules to construct a code framework. According to the preset code writing standards, the specific code is filled in the framework, and syntax prompt information is generated to form a complete initial code, providing initial code for code optimization and reducing the workload of developers writing code from scratch.
[0157] Specifically, the code optimization module comprehensively optimizes the generated initial code to improve the quality of the front-end output code. According to the logical relationship and function of the code, the initial code is divided into multiple independent code blocks. The preset optimization point recognition model is used to identify the parts that need to be optimized and determine their corresponding optimization types. For different optimization types, corresponding optimization strategies are adopted, the optimized code blocks are integrated, the correctness of the logic and data transmission is checked, and the optimized updated code is output in the front-end window to realize the automatic generation and optimization of the front-end Service code, thereby improving the quality, efficiency and maintainability of the code.
[0158] The basic principles, main features, and advantages of the present invention are shown and described above. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The above embodiments and descriptions are merely illustrative of the principles of the present invention. Various changes and modifications may be made to the present invention without departing from the spirit and scope of the present invention. Such changes and modifications are intended to fall within the scope of the present invention. The scope of protection claimed in the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for automatically generating front-end Service code, characterized in that: include: In response to the user's code generation requirements, the dependency relationship between the code generation requirements is parsed through a preset requirement parsing model to obtain a requirement parsing result; According to the requirement analysis result, matching is performed in a preset code syntax tree library to obtain a target code syntax tree; Optimizing the branch structure of the target code syntax tree by branch merging or branch expansion processing to obtain an optimized target code syntax tree; Combining the optimized target code syntax tree and YApi interface data to generate initial code; The initial code is optimized through a preset code optimization mechanism to obtain an updated code, which is output in the front-end window to achieve automatic generation of the front-end Service code; The branch structure of the target code syntax tree is optimized by branch merging or branch expansion processing to obtain an optimized target code syntax tree, including: Analyze the parameter nodes in the target code syntax tree to obtain initial syntax tree parameters; Optimize the initial syntax tree parameters according to the preset parameter constraint rules configured by YApi to obtain optimized syntax tree parameters; Analyze the dependency between syntax tree nodes in the target code syntax tree according to the optimized syntax tree parameters, and identify redundant branches and missing branches; For redundant branches, by analyzing the repetition rate of logic blocks in adjacent conditional branches, branches with a repetition rate greater than a preset repetition rate threshold are merged, common logic blocks are integrated, duplicate parts are removed, and the logical judgment of the difference parts is retained to obtain the merged branch; For missing branches, generate corresponding extension branches based on the parameter type and business logic of the missing branches; According to the merged branches and the expanded branches and the connection relationship between the syntax tree nodes is adjusted, the target code syntax tree is updated and optimized to obtain an optimized target code syntax tree.
2. A front-end service code automatic generation method according to claim 1, characterized in that: In response to the user's code generation requirements, the dependency relationship between the code generation requirements is parsed using a preset requirement parsing model to obtain a requirement parsing result, including: According to the user's code generation requirements, the preset requirement parsing model is used to parse the requirements and generate multiple types of requirements; By analyzing the dependencies between different types of requirements, a demand association map is constructed; By analyzing the call constraint relationship between interfaces, an interface call chain is constructed; The demand analysis result is obtained by combining the demand association graph and the interface call chain.
3. A front-end service code automatic generation method according to claim 1, characterized in that: The requirement parsing result is matched in a preset code syntax tree library to obtain a target code syntax tree, including: According to the demand analysis results, feature extraction is performed through the preset demand feature extraction model to obtain multiple demand features; Encoding the multiple demand features to construct a demand feature vector; Combining the requirement parsing result and the requirement feature vector, multi-level matching is performed in a preset code syntax tree library to obtain a target code syntax tree.
4. A front-end service code automatic generation method according to claim 3, characterized in that: The method combines the requirement analysis result and the requirement feature vector, performs multi-level matching in a preset code syntax tree library, and obtains a target code syntax tree, including: According to the requirement analysis result, a preset code syntax tree library is screened to obtain a first code syntax tree set; Extracting coarse-grained features from the requirement parsing result and the requirement feature vector, and screening the first code syntax tree set according to the coarse-grained features to obtain a second code syntax tree set; Extracting fine-grained features from the requirement parsing result and the requirement feature vector, and screening the second code syntax tree set according to the fine-grained features to obtain a third code syntax tree set; According to the third code syntax tree set, syntax tree nodes that meet preset fusion conditions are selected from each code syntax tree for fusion to obtain a target code syntax tree.
5. A front-end service code automatic generation method according to claim 1, characterized in that: The step of combining the optimized target code syntax tree and the YApi interface data to generate the initial code includes: Analyze the syntax tree of the optimized target code and identify the key nodes and corresponding syntax rules in the syntax tree; Extract interface information related to the front-end Service code from the YApi interface data; According to the key nodes and corresponding grammatical rules, the interface information is mapped into the target code grammar tree to generate a code framework; Based on the code framework and in accordance with preset code writing standards, code and corresponding syntax prompt information are generated to obtain initial code.
6. A front-end service code automatic generation method according to claim 1, characterized in that: The initial code is optimized by a preset code optimization mechanism to obtain updated code, which is output in the front-end window to realize automatic generation of front-end Service code, including: According to the logical relationship and function of the code, the initial code is divided into blocks to obtain multiple code blocks; Through the preset optimization point identification model, the part that needs to be optimized in each code block is identified to obtain multiple code optimization points; Analyze the code optimization type corresponding to each code optimization point to obtain the optimization type corresponding to each code optimization point; According to the optimization type, the code block corresponding to each code optimization point is optimized through the preset code optimization mechanism to obtain the updated code, which is output in the front-end window to realize the automatic generation of the front-end Service code.
7. A front-end service code automatic generation method according to claim 6, characterized in that: According to the optimization type, the code block corresponding to each code optimization point is optimized through a preset code optimization mechanism to obtain updated code, which is output in the front-end window to realize automatic generation of front-end Service code. The optimization type includes redundant code optimization points, missing code optimization points, and error code optimization points, including: For redundant code optimization points, the first updated code is obtained by deleting the code with repeated functions in the code block; For the missing code optimization points, the missing code is supplemented by analyzing the logical relationship and functional connection of the context code to obtain the second updated code; For the error code optimization point, the error code is corrected according to the error prompt information of the static code analysis tool to obtain the third updated code; According to the first update code, the second update code and the third update code, the code block is optimized to obtain the update code, which is output in the front-end window to realize the automatic generation of the front-end Service code.
8. A front-end Service code automatic generation system, characterized by: A method for automatically generating front-end Service code according to any one of claims 1 to 7, comprising: The requirement parsing module, in response to the user's code generation requirements, parses the dependencies between the code generation requirements through a preset requirement parsing model to obtain the requirement parsing results; The syntax tree matching module matches the target code syntax tree in a preset code syntax tree library according to the requirement parsing result; A syntax tree optimization module optimizes the branch structure of the target code syntax tree by branch merging or branch expansion processing to obtain an optimized target code syntax tree, including: analyzing the parameter nodes in the target code syntax tree to obtain initial syntax tree parameters; optimizing the initial syntax tree parameters according to the preset parameter constraint rules configured by YApi to obtain optimized syntax tree parameters; analyzing the dependency relationship between syntax tree nodes in the target code syntax tree according to the optimized syntax tree parameters to identify redundant branches and missing branches; for redundant branches, by analyzing the repetition rate of logic blocks in adjacent conditional branches, merging branches with a repetition rate greater than a preset repetition rate threshold, integrating common logic blocks, removing repeated parts, retaining the logical judgment of the difference part, and obtaining merged branches; for missing branches, generating corresponding extended branches according to the parameter type and business logic of the missing branches; updating and optimizing the target code syntax tree according to the merged branches and extended branches and adjusting the connection relationship between syntax tree nodes to obtain an optimized target code syntax tree; A code generation module generates initial code by combining the optimized target code syntax tree and YApi interface data; The code optimization module optimizes the initial code through a preset code optimization mechanism to obtain an updated code, which is output in the front-end window to realize automatic generation of the front-end Service code.
Citation Information
Patent Citations
Dynamic code generation method and system based on interface document
CN118860356A