Code generation method of application program, electronic equipment, medium and program product

By performing real-time static analysis and repair of AI-generated code segments during the code generation process, the problem of code quality uncertainty is solved, high-quality automated code generation is achieved, and manual intervention and feedback cycles are reduced.

CN121979511APending Publication Date: 2026-05-05INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
INDUSTRIAL AND COMMERCIAL BANK OF CHINA
Filing Date
2026-02-13
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

In existing technologies, the quality of AI-generated code is highly uncertain, which leads to the need for a lot of manual inspection and modification, long feedback cycles, low automation, heavy reliance on human intervention, and inability to achieve high-quality automated code generation.

Method used

During the code generation process, the output code segments are acquired in real time, and static analysis is performed through preset code defect rules to identify and fix security and accuracy defects until defect-free code is generated. Preset repair templates are then used for automated repair.

Benefits of technology

It achieves high-quality automation in the code generation process, reduces human intervention, improves the degree of automation, shortens the feedback cycle, and ensures that the generated code meets safety and accuracy requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121979511A_ABST
    Figure CN121979511A_ABST
Patent Text Reader

Abstract

The invention discloses a code generation method of an application program, electronic equipment, a medium and a program product, and relates to the technical field of financial science and technology. The method comprises the steps that in the process of generating a target application program code in response to a code generation request containing business function description and compliance constraint conditions, an output first code segment is acquired; performing static analysis on the first code segment based on a preset code defect rule, identifying security and precision defects existing in the first code segment, and modifying the first code segment based on a preset repair template corresponding to the security and precision defects to obtain a repaired first code segment; generating a second code segment based on the repaired first code segment; and continuously executing the operation of performing static analysis on the second code segment based on the preset code defect rule until the security and precision defects of the generated code are not detected, and outputting the application program code. According to the scheme, high-quality automatic generation of codes can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of financial technology, and more particularly to the field of code generation technology, specifically to a method for generating application code, an electronic device, a medium, and an application product. Background Technology

[0002] With the increasing popularity of artificial intelligence (AI)-assisted programming technologies, developers are increasingly using AI tools to automatically generate code snippets. However, the quality of AI-generated code is uncertain, often failing to meet project coding standards, security requirements, and performance standards, leading to the need for significant time for subsequent review and modification.

[0003] Currently, code generation and quality inspection are two separate, sequential steps: first, an AI-powered code generation tool outputs code based on functional requirements; then, the generated code is input into a static code analysis tool for defect detection based on preset rules; if problems are detected, they are fixed manually. This sequential process suffers from long feedback cycles, low automation, and heavy reliance on human intervention, making it impossible to achieve high-quality automated code generation. Summary of the Invention

[0004] This invention provides a method for generating application code, an electronic device, a medium, and an application product to solve the problems of long feedback cycles, low automation, and heavy reliance on manual intervention in the serial process of code generation and inspection, thereby achieving high-quality automated code generation.

[0005] According to one aspect of the present invention, a method for generating code for an application is provided, the method comprising: During the process of generating the target application code in response to a code generation request that includes a description of business functions and compliance constraints, the first output code segment is obtained; Static analysis is performed on the first code segment based on preset code defect rules to identify security and precision defects. The first code segment is then modified based on preset repair templates corresponding to the security and precision defects to obtain the repaired first code segment. A second code segment is generated based on the repaired first code segment; Continue performing static analysis on the second code segment based on preset code defect rules until no security or accuracy defects are detected in the generated code, and then output the application code.

[0006] According to another aspect of the present invention, an application code generation apparatus is provided, the apparatus comprising: The first code segment output module is used to obtain the first code segment that has been output during the process of generating the target application code in response to a code generation request containing a description of business functions and compliance constraints. The first code segment repair module is used to perform static analysis on the first code segment based on preset code defect rules, identify the security and precision defects therein, and modify the first code segment based on the preset repair template corresponding to the security and precision defects to obtain the repaired first code segment. The second code segment generation module is used to generate a second code segment based on the repaired first code segment; The application code output module is used to continue performing static analysis on the second code segment based on preset code defect rules until no security or accuracy defects are detected in the generated code, and then output the application code.

[0007] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: At least one processor; and a memory communicatively connected to the at least one processor; The memory stores a computer program that can be executed by the at least one processor, which is then executed by the at least one processor to enable the at least one processor to execute the code generation method for the application described in any embodiment of the present invention.

[0008] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the code generation method for an application program according to any embodiment of the present invention.

[0009] According to another aspect of the present invention, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the code generation method for the application program described in any embodiment of the present invention.

[0010] The technical solution of this invention, in the process of generating target application code in response to a code generation request containing business function descriptions and compliance constraints, obtains the first code segment that has been output; it can achieve real-time acquisition of the generated code segment during the application generation process; static analysis is performed on the first code segment based on preset code defect rules to identify security and precision defects, and the first code segment is modified based on preset repair templates corresponding to the security and precision defects to obtain a repaired first code segment; if the first code segment has defects, it can be repaired in a timely manner; a second code segment is generated based on the repaired first code segment; the operation of static analysis of the second code segment based on preset code defect rules continues until no security and precision defects are detected in the generated code, and the application code is output. This solves the problems of long feedback cycles, low automation, and heavy reliance on manual intervention in the serial process of generation and inspection, and can achieve high-quality automated code generation.

[0011] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0012] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 This is a flowchart of an application code generation method provided according to Embodiment 1 of the present invention; Figure 2 This is a flowchart of an application code generation method provided according to Embodiment 2 of the present invention; Figure 3 This is a flowchart of another application code generation method provided according to Embodiment 2 of the present invention; Figure 4 This is a schematic diagram of the structure of an application code generation device according to Embodiment 3 of the present invention; Figure 5 This is a schematic diagram of the structure of an electronic device that implements the code generation method for the application program according to an embodiment of the present invention. Detailed Implementation

[0014] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0015] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0016] Example 1 Figure 1 This is a flowchart of an application code generation method according to Embodiment 1 of the present invention. This embodiment is applicable to situations where real-time repair is performed during the code generation process to improve code generation quality. This method can be executed by an application code generation device, which can be implemented in hardware and / or software and can be configured in electronic devices such as computers, servers, or tablet computers. Figure 1 As shown, the method includes: Step 110: During the process of generating the target application code in response to a code generation request containing a business function description and compliance constraints, obtain the first output code segment.

[0017] The business function description can be a user-provided explanation of the functional logic required by the target application. It is typically expressed in natural language, pseudocode, or structured requirements and serves to guide the code generation agent in generating program code that conforms to the expected behavior. This description focuses on what tasks the application should accomplish. For example, in financial application development, the business function description could be implementing an interface that supports real-time multi-currency exchange rate conversion, or building a decision-making module that automatically approves loan amounts based on user credit scores.

[0018] Compliance constraints can be normative restrictions imposed on code implementation to ensure that the generated code meets the security, reliability, accuracy, or maintainability requirements of a specific domain. These constraints can originate from industry standards, coding conventions, security policies, or project agreements, explicitly defining how the code should be implemented or prohibiting certain patterns. For example, in a financial context, compliance constraints might include requiring all variables involved in monetary calculations to use the Decimal type instead of float, requiring transaction operations to include explicit rollback mechanisms, or requiring sensitive fields (e.g., phone numbers) to be anonymized in logs.

[0019] The target application code is the source code that, to meet business functionalities and compliance constraints, is ultimately produced through the code generation process and can be directly run or integrated into a software project. The first code segment refers to a portion of the source code that has been generated and is currently available during the iterative or streaming output process of generating the complete target application code. It may be a segment of a complete functional module, such as a function definition, a class declaration, or a set of related statements. It should be noted that the first code segment does not refer to the first code segment output; in this embodiment, it is only named the first code segment for ease of description and is not intended to limit this embodiment.

[0020] Optionally, in this embodiment, upon receiving a code generation request containing a business function description and compliance constraints, the code generation engine (e.g., a code generation agent based on a large language model) initiates its reasoning process. First, it parses and understands the input request, mapping the natural language description to an internal programming logic representation, and identifies the compliance constraint rules that need to be embedded. Further, based on its trained knowledge base and algorithm model, it begins to gradually construct a sequence of source code that meets the functional requirements and satisfies the constraints.

[0021] In the intermediate stage of code construction, when the code generation agent generates a relatively complete and independently identifiable code unit in terms of syntax and logic (e.g., a completed function body, a class configured with attributes and methods, or a set of statements implementing specific sub-steps), this part of the code is placed in the output buffer or provided externally through a streaming interface as the first code segment output. In this embodiment, the generation status of this segment can be marked, usually accompanied by a flag indicating whether generation is still ongoing, so that the caller can obtain and process this stage of results in a timely manner without having to wait for the entire code generation task to be completed.

[0022] In one optional implementation of this embodiment, when a user submits a code generation request containing a business function description and compliance constraints through a front-end interface or application programming interface, the service scheduling module receives the request and encapsulates it into a structured task payload. The generation task payload is passed to the code generation engine, which loads the pre-trained code generation agent and initializes the agent's context state, using the generated business function description as a generation prompt and encoding the generated compliance constraints as generation constraint rules. Further, the code generation agent begins to execute autoregressive text generation, outputting the code stream of the target programming language in sequence and storing the code stream in a buffer in real time. Simultaneously, a syntax integrity monitoring thread can be started to periodically call the incremental syntax parser of the target language to attempt to parse the current content of the buffer. If the parsing is successful and the generated abstract syntax tree contains at least one closed syntax unit, it is determined that a semantically and syntactically complete code segment has been formed. At this time, the content of the segment can be frozen, extracted from the buffer, and marked as the first code segment for subsequent static analysis and repair modules to call. At the same time, the buffer is reset to empty or the incomplete tail code stream is retained to continue receiving subsequent output.

[0023] For example, when generating a financial function program for calculating loan installment repayment plans, the user-submitted request includes a business function description: generating equal principal and interest repayment details based on principal, annual interest rate, and number of periods; and compliance constraints: all amounts and interest rates must use high-precision numeric types, and floating-point operations are prohibited. The code generation agent begins streaming output, first completing the logic of a full function, including parameter declarations, interest calculation formulas, and return structures. The system detects that the function has formed a closed syntactic unit through the syntax parser, and even if the entire application has not yet output import statements or call logic, it immediately extracts the entire function as the first code segment for subsequent defect analysis and repair.

[0024] Step 120: Perform static analysis on the generated first code segment based on the preset code defect rules to identify the security and precision defects present therein, and modify the generated first code segment based on the preset repair template corresponding to the generated security and precision defects to obtain the repaired first code segment.

[0025] The preset code defect rules are predefined sets of detection logic used to identify specific types of defects in the source code. They can exist in the form of pattern matching, data flow analysis, or control flow constraints, and are used to determine whether the code violates security, precision, or compliance requirements. For example, in financial applications, a defect rule could be defined as: if a variable is a floating-point number and is involved in monetary calculations, it is marked as a precision defect.

[0026] Static analysis refers to the process of analyzing the source code of a program without actually executing the code, by performing syntax parsing, control flow, and data flow analysis to discover potential errors, security vulnerabilities, or violations of coding standards.

[0027] Security and accuracy defects refer to issues in the code that may lead to system security risks or numerical calculation errors. Security defects may include unverified input processing, leakage of sensitive information, etc., which are not limited in this embodiment; accuracy defects may refer to numerical distortion caused by the use of low-precision data types or improper rounding strategies, which are also not limited in this embodiment. For example, using the float type to store the principal in interest calculation may lead to deviations in the final amount due to binary floating-point errors, which is a typical accuracy defect.

[0028] The preset repair template is a structured repair solution bound to a specific defect pattern. It can include replacement rules for target syntax nodes, context adaptation logic, and legality verification conditions, and can be used to automatically generate repair code that conforms to language specifications. For example, for a floating-point amount defect, the repair template can be defined as replacing float with Decimal in variable declarations and calculations, and adding the import statement from decimal import Decimal.

[0029] In an optional implementation of this embodiment, after obtaining the first code segment, a static analysis engine corresponding to the target programming language can be loaded, and a preset code defect rule set can be injected. The static analysis engine performs lexical analysis and syntax parsing on the first code segment to generate an abstract syntax tree. Further, all nodes of the generated abstract syntax tree are traversed, and for each node, its node type, operator, text representation, and path information from the root node to the current node are extracted to form a node feature vector. The generated node feature vector is matched and compared with the defect features defined in the preset defect rules. When the feature of a node completely matches the feature of a defect rule, it is determined that the code corresponding to the node has a security or precision defect, and the defect type, location, and associated repair template identifier are recorded.

[0030] Furthermore, the corresponding preset repair template can be retrieved based on the generated repair template identifier, and the syntax type constraints that the repaired node needs to satisfy can be derived by combining the parent node type of the node in the abstract syntax tree and its position in the child node sequence. Based on the generated repair template and syntax type constraints, a repaired node that meets the requirements of the abstract syntax tree structure is generated. The original defective node is replaced with the generated repaired node to obtain the repaired abstract syntax tree. Furthermore, the code generator bound to the target programming language is called to decompile the repaired abstract syntax tree into source code text, which is output as the first code segment after repair.

[0031] For example, when generating a functional module for handling cross-border payment currency conversion, static analysis is performed on the extracted first code segment, identifying an operation that uses single-precision floating-point numbers to represent currency amounts. This defect matches a preset financial precision defect rule, triggering an associated repair template. Further, based on this template, relevant variables and operational expressions are replaced with high-precision decimal types, ensuring the replaced syntax conforms to language specifications. Finally, a repaired first code segment is generated, serving as the context input for subsequent code generation.

[0032] Step 130: Generate the second code segment based on the first code segment after it has been repaired.

[0033] In one optional implementation of this embodiment, after obtaining the repaired first code segment, the repaired first code segment can be concatenated as text to the end of the original generation prompt to form an updated context input. The updated context includes the repaired code, the original business function description, and compliance constraints. This context is submitted to the input interface of the code generation agent. Based on this context, the code generation agent continues to perform autoregressive code flow generation, starting from the end position of the repaired first code segment, and outputs subsequent code that is syntactically and semantically continuous. The output is captured in real time through a streaming monitoring mechanism, and the output stream is checked for integrity using the incremental syntax parser of the target programming language. When the first complete syntactic unit is detected, the unit is extracted and identified as the second code segment for processing by the subsequent static analysis module.

[0034] For example, when generating a financial interest calculation module, the first code segment (a complete interest calculation function) that has been extracted is repaired by replacing the floating-point amount operation inside it with a high-precision decimal type. After the repair is completed, the compliant function is used as the context to directly input code to generate an agent. The agent then continues to generate subsequent business logic for receiving user input, calling the function and returning formatted results. The first complete syntactic unit is extracted from the output stream as the second code segment.

[0035] In another optional implementation of this embodiment, after obtaining the repaired first code segment, a data flow and control flow analysis can be performed on all cached generated code segments based on a program dependency analysis engine to identify associated code segments that have interface calls, variable references, or type dependencies with the first code segment. For each associated code segment, the items to be modified in its interaction with the first code segment are extracted, including function call parameter types, return value processing logic, or variable declaration matching. Based on the interface changes of the repaired first code segment, a preset association repair rule is invoked to automatically correct the generated items to be modified, generating the repaired associated code segment. Further, the repaired first code segment and all repaired associated code segments are reorganized into a complete context in their original order, and this context is used as a prompt input to the code generation agent. Based on this consistent context, the code generation agent continues to generate syntactically coherent subsequent code and outputs the second code segment.

[0036] For example, when generating a financial process that includes amount verification and interest calculation, the first code segment (originally using a float-based interest function) is first obtained and repaired, and then changed to a Decimal type. Further, the previously generated but not yet output related code segments are analyzed, revealing verification logic that calls this function, with parameter passing and result parsing still based on floating-point types. The variable declarations and type conversion operations in this verification logic are automatically modified to be consistent with the repaired function interface. After completing the synchronous correction of all related code segments, the overall consistency context is submitted to the code generation agent, which continues to generate subsequent log recordings or exception handling code, and the first complete unit is extracted as the second code segment.

[0037] Step 140: Continue to perform static analysis on the generated second code segment based on the preset code defect rules until no security or precision defects are detected in the generated code, and then output the generated application code.

[0038] Optionally, in this embodiment, after generating the second code segment through the above steps, it can be sent to the static analysis module to perform the same processing flow as the first code segment: constructing an abstract syntax tree, traversing nodes, matching preset defect rules, and applying a repair template to obtain the repaired second code segment; further, it can be determined whether there is any subsequent business logic that needs to be generated. If so, the repaired second code segment is used as the context input code generation agent to trigger the generation of the third code segment, and static analysis and repair are repeatedly performed on it; this process continues to loop, and defect detection and repair are performed after each round of generating a new code segment, and the repair results are included in the generated code set; at the end of each iteration, a global static analysis is performed on the current set of all generated code segments to verify whether there are still unrepaired security or precision defects; when the global analysis result confirms that all code segments are defect-free, and the code generation agent returns a generation end signal, the iteration process is terminated; finally, all repaired code segments are concatenated into a single source file according to the generation order and written to the specified output path as the final application code.

[0039] In one example of this embodiment, when generating a complete financial transaction reconciliation module, multiple code segments such as the interest calculation function, amount verification logic, and log recording component are generated and repaired sequentially. Each time a new segment is generated, defect scanning and repair are performed immediately, and the global code set is updated. After the agent completes the output of the last exception handling block, an eventual consistency check is performed on all generated content to confirm that there are no floating-point operations, type mismatches, or security vulnerabilities. At the same time, it is detected that the generation stream has ended, so all compliant code segments are merged into a complete module and output.

[0040] The technical solution of this embodiment, in the process of generating target application code in response to a code generation request containing business function descriptions and compliance constraints, obtains the first code segment that has been output; it can realize the real-time acquisition of the generated code segment during the application generation process; it performs static analysis on the generated first code segment based on preset code defect rules to identify security and precision defects, and modifies the generated first code segment based on preset repair templates corresponding to the generated security and precision defects to obtain a repaired first code segment; if the first code segment has defects, it can be repaired in a timely manner; it generates a second code segment based on the repaired first code segment; it continues to perform static analysis on the generated second code segment based on preset code defect rules until no security and precision defects are detected in the generated code, and then outputs the generated application code. This solves the problems of long feedback cycles, low automation, and heavy reliance on manual intervention in the serial process of first generation and then checking, and can achieve high-quality automated code generation.

[0041] Example 2 Figure 2 This is a flowchart of an application code generation method according to Embodiment 2 of the present invention. This embodiment is a further refinement of the above technical solution, and the technical solution in this embodiment can be combined with various optional solutions in one or more of the above embodiments. Figure 2 As shown, the method includes: Step 210: Receive code fragments from the code output stream of the code generation agent; when it is detected that the generated code fragments constitute a complete syntactic unit, determine the generated code fragments as the first code segment to be generated.

[0042] The generation of a complete syntax unit includes at least one of the following: function definition, control structure block, and transaction processing block.

[0043] A code-generating agent is an artificial intelligence system that generates source code. It can be built on a large language model and can output code text word by word and line by line based on natural language descriptions or structured instructions. A code output stream is the process by which the code-generating agent outputs code as a continuous sequence of characters. A code fragment is a continuous piece of source code text extracted from the code output stream that has not yet been determined to be syntactically complete; it may be an incomplete statement, a partial expression, or an unclosed block of code spanning multiple lines.

[0044] Optionally, in this embodiment, a real-time communication channel can be established with the code generation agent. The system continuously receives the output code unit sequence via an event listener or stream reader, and appends the received code units sequentially to the input buffer in memory. Simultaneously, a syntax integrity detection thread is started, periodically calling the incremental syntax parser corresponding to the target programming language to attempt to construct an abstract syntax tree from the current content of the buffer. If parsing fails, it is determined that the current code segment does not yet constitute a complete syntax structure, and the system continues to wait for new code unit input. If parsing succeeds and the generated abstract syntax tree contains at least one closed syntax subtree, the root node type of the subtree can be further analyzed. When the generated root node type belongs to a preset complete syntax unit category, and the subtree covers the end of the buffer at the source code location, it is determined that the current code segment constitutes a complete syntax unit. At this point, the source code range corresponding to the subtree is extracted from the buffer as the first code segment, and its start and end positions and syntax type are recorded for use by the subsequent static analysis module.

[0045] For example, when generating a financial risk control rule engine, the code generation agent outputs a function step by step to determine the user's credit limit. During the receiving process, syntax parsing is continuously performed. When the end marker of the function definition is detected and it is confirmed that the function contains a complete parameter list, logic body and return statement, the entire function is immediately identified as a complete syntactic unit and extracted as the first code segment, even if there are still import statements or main call logic that have not yet been generated.

[0046] The solution in this embodiment dynamically detects syntactic integrity during the streaming output process, ensuring that the extracted code segments are structurally self-consistent and have independent analytical value, thus avoiding misjudgments of incomplete statements or half-expressions. It enables quality assurance to be intervened early in the generation process, effectively supporting a low-latency, highly reliable integrated code generation architecture.

[0047] Step 220: Perform static analysis on the generated first code segment based on the preset code defect rules to identify the security and precision defects present therein.

[0048] Optionally, in this embodiment, static analysis of the generated first code segment based on preset code defect rules to identify security and precision defects may include: loading a preset lexical analyzer and syntax parser according to the programming language used by the target application, parsing the generated first code segment, and generating an abstract syntax tree; traversing the nodes of the generated abstract syntax tree, matching the syntax structure of each node with the defect patterns defined in the preset code defect rules; when a target node matches the generated defect pattern, determining that the code corresponding to the generated target node has security and precision defects, and recording the defect type and location information.

[0049] The parser is a tool that converts a sequence of characters in source code into a series of meaningful morphemes or tokens. It can identify and classify basic elements such as keywords, identifiers, literals, and operators, while ignoring spaces and comments. The parser, based on the syntax rules of the programming language, receives the token sequence produced by the lexical analyzer and constructs a tree-like representation (e.g., an abstract syntax tree) reflecting the hierarchical syntactic structure of the code. It can check whether the code conforms to the syntax rules. The abstract syntax tree is a tree-like abstract representation of the source code that preserves the code's structure, operations, and intent, but omits specific syntactic details such as semicolons and parentheses. The nodes of the tree represent syntactic constructs (e.g., expressions, statements), and the child nodes represent their components. The target node is the abstract syntax tree node currently being checked during the traversal of the abstract syntax tree, whose syntactic structure attempts to match a certain defect pattern. It can be any node in the abstract syntax tree; this embodiment does not limit its selection.

[0050] Optionally, in this embodiment, after obtaining the first code segment, the target programming language type used by the first code segment can be identified first, and a lexical analyzer and a syntax parser corresponding to the language can be loaded from a preset analyzer library; further, the generated lexical analyzer is called to scan the first code segment and convert it into a lexical unit sequence that conforms to the language specification; then the lexical unit sequence is input to the syntax parser, which constructs an abstract syntax tree based on the context-free grammar of the language; the node traversaler is initialized to access all nodes in the generated abstract syntax tree in sequence; when accessing each node, its syntactic structure information is extracted, and the syntactic structure information is matched with the defect patterns defined in the preset code defect rule library; when the syntactic structure information of a certain node completely matches a certain defect pattern, it is determined that there is a security or precision defect in the source code location corresponding to the node, and the type identifier of the defect and its starting line number and column number in the first code segment are recorded.

[0051] The solution in this embodiment achieves accurate and automated detection of code defects by converting the source code into a precise structured representation and performing deep matching based on syntax tree patterns. It can identify complex security vulnerabilities and logical errors that are difficult to detect through surface text scanning alone and are closely related to the context, significantly improving the coverage and accuracy of defect identification.

[0052] Optionally, in this embodiment, traversing the nodes of the generated abstract syntax tree and matching the syntax structure of each node with the defect patterns defined in the preset code defect rules may include: traversing each node of the generated abstract syntax tree and obtaining the node features of each generated node; comparing each generated node feature with preset defect features respectively; and determining the generated target node as the node to be repaired if it is determined that the target node matches the generated preset defect features; wherein, the generated node features include at least one of the following: node type, text representation of the current node in the source code, operator, and path information from the root node of the abstract syntax tree to the generated current node.

[0053] In one optional implementation of this embodiment, during the traversal of each node of the abstract syntax tree, for the currently visited node, its node features can be obtained. The generated node features include at least one of the following: node type, text representation of the current node in the source code, operator, and path information from the root node of the abstract syntax tree to the current node. Furthermore, the generated node features can be compared item by item with each preset defect feature in the preset defect feature library. When all matching conditions of the generated node features match a certain preset defect feature, the current node can be marked as a node to be repaired and associated with its corresponding defect rule identifier for subsequent repair modules to call.

[0054] In one example of this embodiment, when analyzing a financial function used to calculate investment returns, a syntax analyzer and a syntax parser can be loaded to parse the received code snippet into an abstract syntax tree. During the traversal, it is found that one of the operands of a multiplication expression is a floating-point literal, and the expression is located in the monetary calculation context. If the structural features of the node match the preset financial precision defect pattern, the defect type can be recorded as floating-point monetary usage, and its specific location in the source code can be marked to trigger the subsequent repair process.

[0055] The solution in this embodiment achieves accurate location and identification of code defects by extracting and comparing the multi-dimensional structured features of abstract syntax tree nodes. It utilizes composite features such as node type, operators, precise text representation, and unique paths within the syntax tree for comprehensive judgment, significantly improving the accuracy and specificity of defect pattern matching and effectively reducing false positives and false negatives.

[0056] Step 230: Modify the generated first code segment based on the preset repair template corresponding to the generated security and accuracy defects to obtain the repaired first code segment.

[0057] Optionally, in this embodiment, modifying the generated first code segment based on a preset repair template corresponding to the generated security and accuracy defects to obtain a repaired first code segment may include: obtaining a repair template associated with a preset defect feature matching the generated node to be repaired; determining the syntax node type required by the parent node for the position of the child node based on the parent node type and the position of the generated node to be repaired in the child node sequence; generating a repaired node that meets the requirements of the abstract syntax tree structure based on the generated repair template and the generated syntax node type; replacing the generated node to be repaired with the generated repaired node to obtain the repaired abstract syntax tree; and calling a code generator corresponding to the generated application programming language to convert the generated repaired abstract syntax tree into code, which serves as the repaired first code segment.

[0058] The pre-defined defect feature-associated repair template is a structured repair scheme predefined during system initialization and bound to a specific defect pattern, containing generation rules or replacement logic for the target syntax node. The parent node type is the syntax type of the direct parent node of the node to be repaired in the abstract syntax tree. The position in the child node sequence is the specific index or logical position of the node to be repaired in the list of all child nodes of its parent node.

[0059] Optionally, in this embodiment, a repair template associated with the node to be repaired can be retrieved from the repair template library based on the preset defect features matched by the node to be repaired. Further, the parent node of the node to be repaired in the abstract syntax tree can be obtained, and the node type of the parent node can be read. Simultaneously, the specific position index or semantic role of the node to be repaired in the child node list of its parent node can be determined. Based on the parent node type and child node position, the syntax specification of the target programming language is queried to determine the set of allowed syntax node types at that position. The repair template is parsed, and combined with the constraints of the generated syntax node type, a new syntax node that meets the type requirements and implements the repair logic is instantiated as the repaired node. The original node to be repaired in the abstract syntax tree is removed from the child node list of its parent node, and the generated repaired node is inserted into the same position. After the replacement is completed, a structurally complete and type-conflict-free repaired abstract syntax tree is obtained. Finally, a code generator corresponding to the target application programming language is called to perform a decompilation operation on the generated repaired abstract syntax tree, converting it into source code text that conforms to the language specification, and outputting this text as the first code segment after repair.

[0060] For example, when generating a financial function for calculating compound interest, static analysis reveals that its interest calculation formula incorrectly multiplies the annual interest rate directly by the number of months without performing a division conversion from annualized to monthly. The formula structure matches a pre-defined pattern of flaws in financial calculation logic. Based on the associated repair template and the syntax requirements of the parent node for the operation type, a repaired expression node containing the correct annualization conversion logic is generated. After the replacement is completed, the repaired abstract syntax tree is converted into source code and output as the first compliant code segment.

[0061] The solution in this embodiment dynamically combines the repair template with the parent node's syntax constraints to ensure that the generated repaired nodes strictly conform to the syntax rules of the target programming language in terms of type and structure, thus avoiding the introduction of new syntax errors due to the repair. The context-aware mechanism based on the child node position enables the repair operation to adapt to the type requirements under different semantic roles, improving the universality and security of the repair. The repair process is completed entirely at the abstract syntax tree level, ensuring the consistency and legality of the code structure.

[0062] Step 240: Generate a second code segment based on the first code segment after it has been repaired.

[0063] Optionally, in this embodiment, generating the second code segment based on the generated and repaired first code segment may include: inputting the generated and repaired first code segment into the code generation agent, determining each associated code segment related to the generated and repaired first code segment; determining the items to be modified in each associated code segment based on the modifications in the generated and repaired first code segment, and modifying the generated items to be modified to obtain the repaired associated code segment; and generating the second code segment based on the generated and repaired first code segment and the generated and repaired associated code segment.

[0064] The associated code segment refers to other code fragments that have a dependency relationship with the repaired first code segment (i.e., the first code segment) in terms of syntax, data flow, or control flow. This dependency may manifest as: code calling the modified function or method, code using the modified variable or parameter, code inheriting from the modified class, or code affected by the modified exception handling logic. The modification content refers to the specific changes that occur in the repaired first code segment compared to the original first code segment, including but not limited to: changes in function signature (such as adding, removing, or changing the type of parameters), changes in return value type, adjustments to external interface behavior, introduction of new dependencies, or changes in the type of exception thrown. This embodiment does not limit these changes. It can be understood that the item to be modified is the specific code element in the associated code segment that needs to be adjusted accordingly due to the modifications in the first code segment. For example, the list of actual parameters passed when calling the modified function needs to be adjusted, the way the modified return value is used needs to be adapted, and the type of exception caught needs to be updated.

[0065] In an optional implementation of this embodiment, after obtaining the repaired first code segment, the repaired first code segment can be further submitted in text form to the context input interface of the code generation agent; simultaneously, the program dependency analysis module is activated to perform cross-process data flow and control flow analysis on all currently cached but not yet repaired code segments; based on variable definitions, usage chains, function call graphs, and type dependencies, all code segments that have direct or indirect interactions with the repaired first code segment can be identified and marked as associated code segments; for each associated code segment, its interaction points with the first code segment can be extracted. This includes function call parameter lists, return value receiving variables, shared variable references, or exception handling bindings; based on the modifications that occurred in the repaired first code segment, such as interface changes, type adjustments, or behavioral semantic changes, the adaptation rules required for each interaction point are derived; according to the generated adaptation rules, the corresponding items to be modified in the associated code segments are automatically corrected to generate repaired associated code segments with consistent syntax and semantics; finally, the repaired first code segment and all repaired associated code segments are concatenated in the original logical order to form a consistent context, and the code generation agent is triggered to output the second code segment based on this context.

[0066] In one example of this embodiment, when generating a financial risk assessment module, a function in the first code segment used to calculate the probability of default was fixed by changing its output type from a Boolean value to a structure containing a confidence interval. Furthermore, it was identified that there was a direct conditional judgment on the return value of this function in the previously generated related code segments. Based on the interface change, the conditional judgment logic was automatically modified to access and compare the confidence field in the structure. After completing the synchronous correction of all related code segments, the overall consistency context was input into the code generation agent, which continued to generate the log output logic for recording the assessment results, and the log function was extracted as the second code segment.

[0067] The solution in this embodiment achieves automated propagation and adaptation of the impact of defect repairs, ensuring that when a core code segment is corrected, all its dependencies in the entire codebase are updated synchronously, thereby maintaining the overall consistency and correctness of the program. It avoids introducing new interface mismatches, type errors, or behavioral inconsistencies due to local modifications, significantly reducing the risk of cascading errors caused by omissions in change propagation.

[0068] Step 250: Continue to perform static analysis on the generated second code segment based on the preset code defect rules until no security or precision defects are detected in the generated code, and output the generated application code.

[0069] Optionally, in this embodiment, continuing to perform static analysis on the generated second code segment based on preset code defect rules until no security or accuracy defects are detected in the generated code, and then outputting the generated application code, may include: performing static analysis on the generated second code segment based on preset code defect rules; when security or accuracy defects are identified, modifying the generated second code segment based on a preset repair template associated with preset defect features that match the generated defect, and generating the next code segment based on the modified second code segment; when no security or accuracy defects are identified, generating the next code segment based on the generated second code segment; when the latest generated code segment does not detect security or accuracy defects and no subsequent code needs to be generated, outputting the application code consisting of all generated code segments.

[0070] In an optional implementation of this embodiment, after generating the second code segment based on the repaired first code segment, the same static analysis process as the first code segment can be further performed on the second code segment: loading the lexical analyzer and syntax parser of the target language, constructing an abstract syntax tree, traversing nodes and matching them with preset code defect rules; if at least one security or precision defect is identified during the analysis, then the associated preset repair template is retrieved according to the matched defect features, and a repaired node is generated based on the parent node's syntax constraints, thus completing the modification of the second code segment and obtaining the repaired second code segment; furthermore, the repaired second code segment is used as context input to the code segment. The code generation agent triggers the generation of the next code segment. If no security or accuracy defects are detected, the original second code segment is directly input as context to the code generation agent to generate the next code segment. After each new code segment is generated and fixed, it can be checked whether the code generation agent returns a generation end signal, and a global static analysis is performed on the current set of all generated code segments. When the following conditions are met: no security or accuracy defects are detected in the latest generated code segment and its historical set, and no subsequent code needs to be generated, the iteration process is terminated, and all generated and verified compliant code segments are concatenated into a single source file in the order of generation, which is the final output application code.

[0071] The solution in this embodiment achieves adaptive collaboration between repair and generation by dynamically deciding whether repair is needed after each generation round and selecting the repaired or original code segment as the subsequent generation context accordingly. At the same time, it significantly improves the automation level and delivery quality of end-to-end code generation in high-reliability application scenarios without the need for manual intervention or external tools.

[0072] To better understand the application code generation method involved in this embodiment, Figure 3 This is a flowchart of another application code generation method provided according to Embodiment 2 of the present invention, see reference. Figure 3The solution includes the following: The system constrains the code generation process according to preset application specifications (including but not limited to coding standards, exception handling mechanisms, security control strategies, etc.); the generation application specifications are input to the coding agent as the context for generating or repairing code; the coding agent performs code generation or repair operations based on the generation application specifications and outputs preliminary code content; this output content is transmitted in real time to the static detection module in the integrated development environment (IDE) plugin; the IDE plugin performs real-time analysis of the output code at the syntax and semantic levels to determine whether it conforms to the generation application specifications; if the detection result is that it conforms to the specifications, the current code segment is output as high-quality code, completing the generation task; if the detection result finds a violation, the specific problem information (including the problem type, location, and suggested correction method) is fed back to the coding agent; after receiving the feedback, the coding agent adjusts the generation strategy or triggers a partial repair process based on the problem information, regenerates or modifies the corresponding code part, and submits the updated code back to the IDE plugin for detection until the output code fully conforms to the application specifications.

[0073] The solution of this invention deeply integrates code generation, quality inspection, and intelligent repair, constructing an automated closed-loop mechanism for simultaneous generation and repair, significantly reducing manual intervention. Developers no longer need to spend a lot of time manually correcting AI-generated defective code, allowing them to focus more on the design and optimization of core business logic. At the same time, through real-time and mandatory rule linkage, it ensures from the source that the generated code meets high-quality standards in terms of security, accuracy, and standardization, effectively reducing the maintenance risks and costs caused by defect repair and security vulnerabilities in the later stages of the project.

[0074] Example 3 Figure 4 This is a schematic diagram of the structure of an application code generation device according to Embodiment 3 of the present invention. Figure 4 As shown, the device includes: a first code segment output module 410, a first code segment repair module 420, a second code segment generation module 430, and an application code output module 440.

[0075] The first code segment output module 410 is used to obtain the output first code segment during the process of generating target application code in response to a code generation request containing business function descriptions and compliance constraints. The first code segment repair module 420 is used to perform static analysis on the generated first code segment based on preset code defect rules, identify the security and precision defects present therein, and modify the generated first code segment based on the preset repair template corresponding to the generated security and precision defects to obtain the repaired first code segment. The second code segment generation module 430 is used to generate a second code segment based on the generated and repaired first code segment. The application code output module 440 is used to continue performing static analysis on the generated second code segment based on preset code defect rules until no security or accuracy defects are detected in the generated code, and then output the generated application code.

[0076] In an optional implementation of this embodiment, the first code segment output module 410 is specifically used to receive code segments from the code output stream of the code generation agent; When it is detected that the generated code fragment constitutes a complete syntactic unit, the generated code fragment is determined to be the first code segment to be generated; The generation of a complete syntax unit includes at least one of the following: function definition, control structure block, and transaction processing block.

[0077] In an optional implementation of this embodiment, the first code segment repair module 420 is specifically used to load a preset lexical analyzer and syntax parser according to the programming language used by the target application, parse the generated first code segment, and generate an abstract syntax tree; Traverse the nodes that generate the abstract syntax tree and match the syntax structure of each node with the defect patterns defined in the preset code defect rules; When the target node matches the generated defect pattern, it is determined that the code corresponding to the generated target node has security and accuracy defects, and the defect type and location information are recorded.

[0078] In an optional implementation of this embodiment, the first code segment repair module 420 is further specifically used to traverse each node of the generated abstract syntax tree and obtain the node features of each generated node. Each generated node feature is compared with the preset defect features. If the target node matches the generated preset defect features, the generated target node is identified as the node to be repaired. The generated node features include at least one of the following: node type, text representation of the current node in the source code, operator, and path information from the root node of the abstract syntax tree to the generated current node.

[0079] In an optional implementation of this embodiment, the first code segment repair module 420 is further specifically used to obtain a repair template associated with a preset defect feature that matches the generated node to be repaired; Based on the parent node type of the node to be repaired and the position of the node to be repaired in the child node sequence, determine the syntax node type required by the parent node for the position of the child node. Based on the generated repair template and the generated syntax node type, a repaired node that meets the requirements of the abstract syntax tree structure is generated; Replace the generated nodes to be repaired with the generated nodes after repair to obtain the repaired abstract syntax tree; Call the code generator corresponding to the application programming language to convert the generated repaired abstract syntax tree into code, which will serve as the first repaired code segment.

[0080] In an optional implementation of this embodiment, the second code segment generation module 430 is specifically used to input the generated and repaired first code segment into the code generation agent and determine each associated code segment associated with the generated and repaired first code segment; Based on the modifications in the first code segment after repair, determine the items to be modified in each generated related code segment, and modify the generated items to be modified to obtain the repaired related code segment. The second code segment is generated based on the first code segment after the repair and the associated code segment after the repair.

[0081] In an optional implementation of this embodiment, the application code output module 440 is specifically used to perform static analysis on the generated second code segment based on preset code defect rules; When a safety and accuracy defect is identified, the second code segment is modified based on a preset repair template associated with a preset defect feature that matches the generated defect, and the next code segment is generated based on the modified second code segment. If no safety or accuracy defects are identified, the next code segment is generated based on the generation of the second code segment; When no security or accuracy defects are detected in the latest generated code segment and no further code needs to be generated, the output consists of the application code composed of all generated code segments.

[0082] The application code generation apparatus provided in this embodiment of the invention can execute the application code generation method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0083] The collection, storage, use, processing, transmission, provision, and disclosure of application code involved in the technical solutions of this invention comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0084] Example 4 Figure 5A schematic diagram of an electronic device 10, which can be used to implement embodiments of the present invention, is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0085] like Figure 5 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded into the RAM 13 from the storage unit 18. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0086] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0087] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods described above, such as application code generation methods.

[0088] In some embodiments, the application code generation method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the application code generation method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the application code generation method by any other suitable means (e.g., by means of firmware).

[0089] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0090] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0091] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, RAM, ROM, erasable programmable read-only memory (EPROM), optical fibers, compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0092] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device for displaying information to the user (e.g., a cathode ray tube (CRT) or liquid crystal display (LCD) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0093] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0094] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system. It addresses the shortcomings of traditional physical hosts and Virtual Private Servers (VPS) in terms of management difficulty and weak business scalability.

[0095] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0096] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

[0097] This invention also provides a computer program product, including a computer program that, when executed by a processor, implements a database detection method as provided in any embodiment of this application.

[0098] In implementing the computer program product, computer program code for performing the operations of this invention can be written in one or more programming languages ​​or a combination thereof. Programming languages ​​include object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including LANs or WANs—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0099] It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, they do not mean that the solution has been or necessarily used.

[0100] Note that the above description is merely a preferred embodiment of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, the scope of which is determined by the scope of the appended claims.

Claims

1. A method for generating code for an application, characterized in that, The method includes: During the process of generating the target application code in response to a code generation request that includes a description of business functions and compliance constraints, the first output code segment is obtained; Static analysis is performed on the first code segment based on preset code defect rules to identify security and precision defects. The first code segment is then modified based on preset repair templates corresponding to the security and precision defects to obtain the repaired first code segment. A second code segment is generated based on the repaired first code segment; Continue performing static analysis on the second code segment based on preset code defect rules until no security or accuracy defects are detected in the generated code, and then output the application code.

2. The application code generation method according to claim 1, characterized in that, During the process of generating the target application code in response to a code generation request that includes a description of business functions and compliance constraints, the first output code segment is obtained, including: Receive code snippets from the code output stream of the code-generating agent; When the code fragment is detected to constitute a complete syntactic unit, the code fragment is identified as the first code segment; The complete syntax unit includes at least one of the following: function definition, control structure block, and transaction processing block.

3. The application code generation method according to claim 1, characterized in that, The static analysis of the first code segment based on preset code defect rules identifies security and precision defects, including: Based on the programming language used by the target application, a pre-set lexical analyzer and syntax parser are loaded to parse the first code segment and generate an abstract syntax tree; Traverse the nodes of the abstract syntax tree and match the syntax structure of each node with the defect patterns defined in the preset code defect rules; When a target node matches the defect pattern, it is determined that the code corresponding to the target node has security and accuracy defects, and the defect type and location information are recorded.

4. The application code generation method according to claim 3, characterized in that, The step of traversing the nodes of the abstract syntax tree and matching the syntax structure of each node with the defect patterns defined in the preset code defect rules includes: Traverse each node of the abstract syntax tree to obtain the node features of each node; Each node feature is compared with a preset defect feature. If the target node matches the preset defect feature, the target node is identified as the node to be repaired. The node features include at least one of the following: node type, text representation of the current node in the source code, operator, and path information from the root node of the abstract syntax tree to the current node.

5. The application code generation method according to claim 4, characterized in that, The first code segment is modified based on a preset repair template corresponding to the security and accuracy defects to obtain a repaired first code segment, including: Obtain a repair template associated with a preset defect feature that matches the node to be repaired; Based on the parent node type of the node to be repaired and the position of the node to be repaired in the child node sequence, determine the syntax node type required by the parent node for the position of the child node; Based on the repair template and the syntax node type, a repaired node that meets the requirements of the abstract syntax tree structure is generated; The node to be repaired is replaced with the node after repair to obtain the repaired abstract syntax tree; The code generator corresponding to the application programming language is invoked to convert the repaired abstract syntax tree into code, which serves as the first repaired code segment.

6. The application code generation method according to claim 1, characterized in that, The generation of the second code segment based on the repaired first code segment includes: The repaired first code segment is input into the code generation agent to determine the associated code segments associated with the repaired first code segment; Based on the modifications in the repaired first code segment, the items to be modified in each of the associated code segments are determined, and the items to be modified are modified to obtain the repaired associated code segments. A second code segment is generated based on the repaired first code segment and the repaired associated code segment.

7. The application code generation method according to claim 1, characterized in that, The step of continuing to perform static analysis on the second code segment based on preset code defect rules until no security or accuracy defects are detected in the generated code, and then outputting the application code, includes: Static analysis is performed on the second code segment based on preset code defect rules; When a safety and accuracy defect is identified, the second code segment is modified based on a preset repair template associated with a preset defect feature that matches the defect, and the next code segment is generated based on the modified second code segment. If no safety or accuracy defects are identified, the next code segment is generated based on the second code segment; When no security or accuracy defects are detected in the latest generated code segment and no further code needs to be generated, the output consists of the application code composed of all generated code segments.

8. An electronic device, characterized in that, The electronic device includes: At least one processor; and a memory communicatively connected to the at least one processor; The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to execute the code generation method of the application program according to any one of claims 1-7.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the code generation method for the application program as described in any one of claims 1-7.

10. A computer program product comprising a computer program that, when executed by a processor, implements the code generation method for an application according to any one of claims 1-7.