A timing diagram describes a code generation method, device, storage medium and electronic equipment
Patent Information
- Application Number
- CN202611089322.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-21
- Publication Date
- 2026-10-30
AI Technical Summary
[0006]本申请实施例提供了一种时序图描述代码生成方法、装置、存储介质及电子设备,以至少解决相关技术无法处理包含复杂控制流的代码文件,且依赖全量重建静态图片格式,导致代码文件发生变更时的时序图维护成本高、生成效率低的技术问题
[0017]根据本申请实施例的另一方面,还提供了一种电子设备,包括:存储器和处理器,上述存储器中存储有计算机程序,上述处理器被配置为通过计算机程序执行上述任一项方法实施例中的步骤。
Smart Images

Figure CN123011204A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software development technology, and more specifically, to a method, apparatus, storage medium, and electronic device for generating sequence diagram description code. Background Technology
[0002] In complex software development scenarios such as core financial systems, enterprise-level middleware architectures, and microservice governance, sequence diagrams serve as core deliverables for requirements analysis, interface design, and code review, making their accuracy and consistency crucial. However, traditional sequence diagram generation techniques primarily rely on manual drawing or automated tools based on static code analysis, resulting in the following significant technical challenges:
[0003] (1) Existing static analysis tools can only capture flat method call chains and cannot identify dynamic execution paths such as loops (e.g., retry mechanisms), conditional branches (e.g., if-else), and exception handling (e.g., try-catch). For code structures with complex control flows, the false negative rate is extremely high, resulting in the generated sequence diagrams failing to reflect the real business logic. For example, compensation mechanisms or retry logic in distributed transactions are often simplified to single-threaded calls, which seriously misleads design reviews.
[0004] (2) Traditional tools mostly output static image formats, which cannot achieve two-way synchronization between code and documents. When the code changes, the design document needs to be completely rebuilt, resulting in extremely high maintenance costs.
[0005] There is currently no effective solution to the above problems. Summary of the Invention
[0006] This application provides a timing diagram description code generation method, apparatus, storage medium, and electronic device to at least solve the technical problems of related technologies being unable to process code files containing complex control flows and relying on full reconstruction of static image formats, resulting in high timing diagram maintenance costs and low generation efficiency when code files change.
[0007] According to one aspect of the embodiments of this application, a method for generating sequence diagram description code is provided, comprising: traversing the source code file of a target version, determining the target source code text of a target method with sequence diagram generation annotations, wherein the source code file includes source code text corresponding to multiple methods respectively; constructing a target abstract syntax tree of the target method based on the target source code text; serializing the target abstract syntax tree into a target structured data object, and generating structured prompt words based on the target structured data object; and analyzing and processing the structured prompt words based on a generative model to generate target sequence diagram description code.
[0008] According to another aspect of the embodiments of this application, a timing diagram description code generation apparatus is also provided, comprising: a determining module, configured to traverse the source code file of a target version and determine the target source code text of a target method with timing diagram generation annotations, wherein the source code file includes source code text corresponding to multiple methods respectively; a building module, configured to construct a target abstract syntax tree of the target method based on the target source code text; a prompt word generation module, configured to serialize the target abstract syntax tree into a target structured data object and generate structured prompt words based on the target structured data object; and a code generation module, configured to analyze and process the structured prompt words based on a generative model to generate target timing diagram description code.
[0009] In an exemplary embodiment, the above-described apparatus is further configured to construct a target abstract syntax tree for a target method based on the target source code text, including: performing static syntax analysis on the target source code text to obtain a basic abstract syntax tree and code comment text, wherein the basic abstract syntax tree includes multiple syntax nodes, and the types of syntax nodes include at least: class nodes, interface nodes, method signature nodes, method parameter nodes, and return value nodes; performing execution simulation on the target source code text to obtain control flow information, wherein the control flow information includes at least: method call chains, conditional branches, loop structures, and exception handling blocks; scanning the code comment list using regular expressions to convert each code comment in the code comment list into a corresponding business semantic tag, wherein the business semantic tag includes at least one of the following: domain entity tag, business action tag, scene tag, and rule tag; appending the control flow information to the corresponding syntax node in the basic abstract syntax tree, and binding the business semantic tag with the syntax node associated with the business semantic tag to obtain the target abstract syntax tree.
[0010] In an exemplary embodiment, the above-described apparatus is further configured to serialize the target abstract syntax tree into a target structured data object, and generate structured prompt words based on the target structured data object, including: traversing each syntax node in the target abstract syntax tree, mapping the node information, control flow information, and business semantic tags of the syntax nodes into structured data objects of a preset format; integrating the structured data objects of all syntax nodes in the target abstract syntax tree to obtain the target structured data object; and filling the target structured data object into a preset prompt word template to obtain structured prompt words.
[0011] In an exemplary embodiment, the above-described apparatus is further configured to analyze and process structured prompt words based on a generative model to generate target time sequence graph description code, including: analyzing and processing structured prompt words based on a generative model to obtain initial time sequence graph description code; determining whether the initial time sequence graph description code contains a preset start marker and a preset end marker; if the initial time sequence graph description code contains a preset start marker and a preset end marker, determining whether the initial time sequence graph description code has a syntax error; if the initial time sequence graph description code does not have a syntax error, outputting the target time sequence graph description code.
[0012] In an exemplary embodiment, the above-described apparatus is further configured to, when the initial timing diagram description code does not contain a preset start marker or a preset end marker, or when the initial timing diagram description code contains a syntax error, analyze and process the structured prompt words again based on a generative model to generate a new target timing diagram description code.
[0013] In an exemplary embodiment, the above-described apparatus is further configured to, after generating the target timing diagram description code, further include: extracting the timing diagram element identifier set from the target timing diagram description code corresponding to each method in the source code file of the target version, and constructing a mapping table, wherein the mapping table records the association relationship between multiple methods and their corresponding timing diagram identifier sets.
[0014] In an exemplary embodiment, the apparatus is further configured to obtain the source code file of the next version of the target version, and compare the source code file of the target version with the source code file of the next version to obtain a list of change methods. The list of change methods includes: change content corresponding to multiple change methods; searching in a mapping table for the target sequence graph element identifier set corresponding to each change method in the list of change methods; for each change method, constructing a local target abstract syntax tree based on the change content corresponding to the change method, and serializing the local target abstract syntax tree into a structured data fragment object; generating a new structured prompt word based on the structured data fragment object and the target sequence graph element identifier set corresponding to the change method; analyzing and processing the new structured prompt word based on a generative model to generate a sequence graph description code fragment; and replacing the target sequence graph description code of the change method in the target version with the sequence graph description code fragment based on the target sequence graph element identifier set corresponding to the change method to obtain a new target sequence graph description code.
[0015] According to another aspect of the embodiments of this application, a computer-readable storage medium is also provided, which stores a computer program, wherein the computer-readable storage medium, when executed by a processor, performs the steps in any of the above method embodiments.
[0016] According to another aspect of the embodiments of this application, a computer program product or computer program is also provided, which includes a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, causing the computer device to perform the steps in any of the method embodiments described above.
[0017] According to another aspect of the embodiments of this application, an electronic device is also provided, including: a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the steps of any of the above method embodiments through the computer program.
[0018] In this embodiment, the source code file of the target version is traversed to determine the target source code text of the target method with sequence diagram generation annotations. The source code file includes source code text corresponding to multiple methods. A target abstract syntax tree (AST) for the target method is constructed based on the target source code text. The AST is serialized into a target structured data object, and structured prompts are generated based on the target structured data object. The structured prompts are analyzed and processed based on a generative model to generate target sequence diagram description code. Through the above technical solution, the technical effect of reverse engineering from code implementation to generate editable sequence diagram description code containing complex control flow logic such as loops, branches, and exceptions, and with business semantics is achieved. This solves the problems of control flow expression failure, business semantic disconnect, and non-evolvability of design assets in traditional tools, eliminates the gap between code and design documents, and improves the accuracy and maintenance efficiency of sequence diagram generation. Furthermore, it solves the technical problems of related technologies being unable to handle code files containing complex control flows and relying on full reconstruction of static image formats, resulting in high maintenance costs and low generation efficiency of sequence diagrams when code files change. Attached Figure Description
[0019] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0020] Figure 1 This is a schematic flowchart illustrating an optional timing diagram of a code generation method according to an embodiment of this application;
[0021] Figure 2 This is a flowchart illustrating an optional method for constructing a target abstract syntax tree according to an embodiment of this application;
[0022] Figure 3 This is a schematic diagram of an optional process for generating structured prompt words according to an embodiment of this application;
[0023] Figure 4 This is a flowchart illustrating an optional generation of target timing diagram description code according to an embodiment of this application;
[0024] Figure 5 This is a structural block diagram of an optional timing diagram describing a code generation apparatus according to an embodiment of this application;
[0025] Figure 6 This is a structural block diagram of a computer terminal for implementing a timing diagram description code generation method according to an embodiment of this application. Detailed Implementation
[0026] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0027] It should be noted that the terms "first," "second," etc., used in the specification, claims, and drawings of this application 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 this application 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.
[0028] To better understand the embodiments of this application, the following is a translation and explanation of some nouns or terms that appear in the description of the embodiments of this application:
[0029] Abstract Syntax Tree (AST): A tree-like abstract representation of the syntactic structure of source code. Each node in the tree represents a structure in the code (such as declaration, assignment, operation). It removes redundant details such as parentheses and retains only the core elements that determine the program logic.
[0030] A Control Flow Graph (CFG) is an abstract representation of a process or program. It's an abstract data structure used in the compiler, maintained internally, and represents all paths traversed during program execution. It represents the possible flow of execution for all basic blocks within a process in graph form, reflecting the actual execution process. In a CFG, each node represents a basic block—a straight line of code leading to any jump or jump target—while directed edges represent jumps in the control flow. In most demonstrations, two specifically designated blocks are the Entry Block, through which control enters the graph, and the Exit Block, through which all control flow leaves.
[0031] According to an embodiment of this application, a timing diagram description code generation method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0032] Figure 1 This is a flowchart illustrating a timing diagram description code generation method according to an embodiment of this application, such as... Figure 1 As shown, the method includes the following steps:
[0033] Step S102: Traverse multiple methods within the source code file of the target version to determine the target source code text of the target method with sequence diagram generation annotations.
[0034] In this embodiment, the target version of the source code file is the programming source file after code changes, including the latest revisions (i.e., patches or changesets). Generally, in object-oriented programming languages, source code files act as containers, containing multiple methods, member variables, inner classes, etc., that can be defined within a class or interface. Therefore, a source code file includes the source code text corresponding to multiple methods.
[0035] In this embodiment, the aforementioned source code text is a set of program instructions written by humans and provided to be read by a compiler or interpreter, existing in plain text form. It has the following characteristics:
[0036] (1) Linear sequence: It is a linear arrangement of characters (from the first row and first column to the last), without a tree-like or graph-like structure.
[0037] (2) Readability: It is for human reading and includes keywords, identifiers, operators, comments, spaces, etc.
[0038] (3) Static: It is only a "blueprint" of code and does not contain dynamic information during execution (such as the current value of variables and specific execution path branches).
[0039] (4) Carrier: Usually stored in files with suffixes such as ".java", ".py", ".js".
[0040] Step S104: Construct the target abstract syntax tree of the target method based on the target source code text.
[0041] In the embodiments of this application, the target abstract syntax tree is an enhanced abstract syntax tree with control flow attributes constructed based on the target source code text.
[0042] Step S106: Serialize the target abstract syntax tree into a target structured data object, and generate structured prompt words based on the target structured data object.
[0043] In the embodiments of this application, the aforementioned target structured data object is a data exchange format that converts data in the target abstract syntax tree into a machine-readable, standardized format.
[0044] In the embodiments of this application, the above-mentioned structured prompts are engineered prompts, which include, but are not limited to, system instructions, constraints, and data injection bits.
[0045] Step S108: Analyze and process the structured prompt words based on the generative model to generate target time sequence diagram description code.
[0046] In the embodiments of this application, the above-mentioned generative model is an intelligent model that is based on deep learning technology (such as based on the Transformer architecture), pre-trained with massive amounts of code and natural language data, and has the ability to understand code logic, code semantics and natural language instructions, and can automatically generate high-quality time sequence diagrams to describe the code based on the input.
[0047] In this embodiment of the application, the target time series diagram description code is a text format code generated by the generative large model based on structured cue words, which conforms to the syntax specifications of a specific modeling language. This code can be directly parsed by the rendering engine and converted into a visual time series diagram.
[0048] Based on the scheme defined in steps S102 to S108 above, it can be understood that in this embodiment of the application, the target source code text of the target method based on the sequence diagram generation annotation is used. The target abstract syntax tree is constructed based on the target source code text, and then it is serialized into a target structured data object and structured prompt words are generated. The generative model is driven to output the target sequence diagram description code. This achieves the technical effect of reverse generating editable sequence diagram description code containing complex control flow logic such as loops, branches and exceptions and with business semantics from the code implementation. It achieves the goal of solving the problems of control flow expression failure, business semantic disconnect and non-evolvability of design assets in traditional tools, eliminating the gap between code and design documents, and improving the accuracy of sequence diagram generation and maintenance efficiency.
[0049] The following describes each step of the timing diagram description code generation method provided in the embodiments of this application, with reference to specific implementation processes.
[0050] As an alternative approach, constructing a target abstract syntax tree for the target method based on the target source code text can be achieved through methods such as... Figure 2 The execution steps shown are implemented as follows:
[0051] Step S104a: Perform static syntax analysis on the target source code text to generate a basic abstract syntax tree and a list of code comments.
[0052] Specifically, a static parser (such as JavaParser) is invoked to read the character stream of the target source code text and convert it into a token stream (i.e., lexical analysis). The processing logic is as follows: the static parser ignores irrelevant content such as whitespace characters and comments (usually extracted separately) according to the lexical rules defined by the programming language, and then identifies the continuous character sequence as the smallest semantic unit, namely a token, thus obtaining an ordered list of tokens.
[0053] Subsequently, a static parser is invoked to read the token stream and construct a hierarchical tree structure based on grammatical rules. The processing logic is as follows: The static parser uses a predefined context-free grammar to match the ordered list of tokens. Starting from the root node, it progressively combines tokens into higher-level grammatical nodes (including identifying the innermost expression or statement; combining statements into blocks; combining blocks and method signatures into method definitions; and combining method definitions, fields, inner classes, etc., into class definitions). If a token sequence is found to violate grammatical rules during the combination process (e.g., missing parentheses, misspelled keywords), the tool will throw a grammatical error, ultimately resulting in a basic abstract syntax tree. Each node in the tree represents a grammatical structure in the source code.
[0054] Therefore, the above technical solution can be understood as: calling a static syntax analysis tool to perform lexical and syntactic analysis on the target source code text, thereby parsing the target source code text into a tree structure to obtain the skeleton information of the code, generally including:
[0055] (1) Method signature: It is a unique feature that identifies a method. It usually includes the method name, parameter list (parameter type and order) and access modifier (such as public, private). It is used to accurately locate the specific method implementation in the code and is the key basis for generating "message arrows" or "life nodes" in the sequence diagram.
[0056] (2) Class structure: This describes the hierarchical relationship, inheritance relationship (extends / implements), and member variables (Fields) of the classes. It is used to determine the "participant" (Participant / Lifeline) in the sequence diagram, that is, which class initiates the call and which class receives the call.
[0057] (3) Interface definition: This describes the method declarations of the interface, the parent interfaces it inherits from, etc. It is represented by the InterfaceDeclaration node in the AST. It is used to identify interface calls in polymorphic behavior or dependency injection scenarios, and to help determine the interaction objects in the sequence diagram.
[0058] (4) Parameter type: is the data type of the parameter when the method is defined or called (such as String, Integer, custom object, etc.).
[0059] (5) Return value type: This is the data type returned after the method is executed. It is generally used to distinguish between "synchronous call" (with return value) and "asynchronous / void call" (without return value). Sometimes it is also used to determine whether the method has been successfully completed.
[0060] Therefore, the basic abstract syntax tree constructed includes multiple syntax nodes, the types of which include, but are not limited to: class nodes, interface nodes, method signature nodes, method parameter nodes, and return value nodes.
[0061] In addition, code comments (such as "single-line comments" and "multi-line comments" in Java) are character content in source code files. They are written by developers and stored in the files. Therefore, by parsing the target source code text with a parser, the existing code comment text in the source code of the target method can be directly extracted.
[0062] Step S104b: Perform execution simulation on the target source code text to obtain control flow information.
[0063] Specifically, symbolic execution engines (such as Soot) are used to simulate the execution of the target source code text. By tracing the program's execution path, the control flow information of the code is obtained, which generally includes:
[0064] (1) Method call chain: describes the order and hierarchy of other methods called from an entry method. For example, if A() calls B(), and B() calls C(), then the method call chain is A->B->C.
[0065] (2) Conditional branch: is a structure in the code that judges different paths of execution based on Boolean expressions, such as if-else and switch-case.
[0066] (3) Loop structure: is a structure in the code that repeatedly executes a certain piece of logic, such as for, while, do-while.
[0067] (4) Exception handling block: is a code block that catches and handles runtime errors, such as try-catch-finally.
[0068] It should be noted that the symbolic execution engine described above, which simulates the execution of target source code text and obtains control flow information, does not "realistically" execute every line of code and change the memory state as if running a program. Instead, it constructs a control flow graph through static analysis techniques. If the target source code text is Java code, the symbolic execution engine can simulate the execution flow in the following way:
[0069] First, the Java source code text is compiled or loaded into Java bytecode and then converted into an intermediate representation called Jimple. Jimple is a three-address code form of intermediate language that simplifies complex Java syntax into basic atomic operations.
[0070] Next, the Jimple code is broken down into multiple basic blocks. For example, if(x>0){...} will be split into the conditional block x>0 and two branch blocks (True branch and False branch).
[0071] Then, multiple basic blocks are used as control nodes in the control flow graph (such as branch nodes, loop nodes, exception handling nodes, entry method nodes, and exit method nodes). The control transfer relationship between basic blocks is represented by the edges between the corresponding control nodes. For example, sequential execution: from basic block A to basic block B. Conditional branching: from the condition block to the "true" branch block and the "false" branch block. Loop structure: from the loop body block to the loop condition block (forming a loop). Exception handling: from the block that may throw an exception to the exception handling block.
[0072] Finally, starting from the entry method, the engine traverses all possible paths in the control flow graph. For example, for `if(user.valid())`, the engine will explore both the paths `user.valid()==true` and `user.valid()==false`. Simultaneously, it tracks data using symbolic values (such as `x`) to obtain corresponding control flow information. This control flow information can include the entire method call chain, which code is in loops, which is in try-catch blocks, and the location where exceptions are thrown.
[0073] Step S104c: Use regular expressions to scan the code comment list to convert each code comment in the code comment list into a corresponding business semantic tag.
[0074] In this embodiment, the regular expression is a pattern string composed of characters and special symbols, used for searching, replacing, or extracting text. As a text processing tool, it utilizes these regular expression patterns (e.g., / / \s (Validation|Call|Processing)\s (. This involves scanning these code comments to identify which comments contain key business verbs relevant to the domain. Then, the core business meanings (such as "verify SWIFT" and "risk control interface") are extracted from these texts containing key business verbs, and natural language processing techniques are used to convert these core business meanings into predefined business semantic tags.
[0075] Specifically, predefined regular expressions are used to scan each code comment in the code comment list to match specific business description patterns. Successfully matched code comments are converted into business semantic tags, such as domain entity tags (e.g., "user", "account"), business action tags (e.g., "validate", "pay"), scenario tags (e.g., "cross-border", "retry"), and rule tags (e.g., "insufficient balance").
[0076] Step S104d: The control flow information is appended to the corresponding syntax node in the basic abstract syntax tree, and the business semantic tags are bound to the syntax nodes associated with the business semantic tags to obtain the target abstract syntax tree.
[0077] Specifically: using the basic abstract syntax tree (BST) as the skeleton, traversing each control node within the control flow graph, and utilizing the node correspondence between the BST and the control flow graph (usually matched through source code line numbers, method signatures, or unique node identifiers), the control flow information of that control node (such as loop boundaries, conditional branch paths, etc.) is appended as attributes or substructures to the corresponding syntax nodes (such as method call nodes, statement block nodes) in the BST. For example, "loop count" or "loop body range" information is added to the semantic node representing a for or while statement, and "exception handling type" is added to the semantic node representing a try block, thereby... Dynamic execution logic is then injected into the static syntax structure. Next, by locating the positions of these code comments in the target source code text, their associated semantic nodes are found, and the business semantic tags corresponding to the code comments are bound to the syntax nodes as metadata. For example, the tag "validate SWIFT format" is bound to the syntax node or control node corresponding to the checkSwiftCode method. Finally, the semantic nodes that have been enhanced with control flow information and bound with business semantic tags are recombined to form a new tree data structure, namely the target abstract syntax tree. This structure retains the static syntax hierarchy of the code and contains dynamic control flow logic and domain business meaning.
[0078] In the scheme defined in steps S104a to S104d above, by combining static syntax analysis to obtain basic semantic structure information, execution simulation to obtain dynamic control flow information, and regular expression scanning to extract business semantic tags, and integrating the three to construct a target abstract syntax tree, the problem of traditional technology being able to only capture static method calls while ignoring dynamic behaviors such as loops, branches, and exceptions, and being unable to parse the business meaning in code comments, resulting in logical gaps and semantic disconnects in the generated sequence diagram, is addressed. Thus, in the process of generating high-fidelity, editable sequence diagrams from code, it is ensured that the generated sequence diagrams can completely restore complex control flow logic and accurately express business domain knowledge, significantly improving the accuracy, readability, and consistency with the code implementation of the sequence diagrams.
[0079] As an alternative approach, the target abstract syntax tree can be serialized into a target structured data object, and structured prompt words can be generated based on the target structured data object. This can be achieved through methods such as... Figure 3 The execution steps shown are implemented as follows:
[0080] Step S106a: Traverse each syntax node in the target abstract syntax tree and map the node information, control flow information, and business semantic tags of the syntax nodes into structured data objects in a preset format.
[0081] In this embodiment, the above-mentioned node information refers to the basic attributes of the syntax node, such as class, interface, method signature, parameter or return value type; control flow information refers to the method call chain, conditional branch, loop structure or exception handling block embedded in the syntax node; business semantic tag is the domain entity tag, business action tag, scene tag or rule tag bound to the syntax node.
[0082] In this embodiment, the aforementioned preset format is a predefined standard template or protocol used to standardize data structures and data types, such as JavaScript Object Notation (JSON), Extensible Markup Language (XML), Protocol Buffers, MessagePacks, or custom text formats. This embodiment does not impose specific limitations on this; any format that meets the following characteristics can be used as a preset format:
[0083] (1) It can transform unstructured code semantics into code with clear hierarchical relationships.
[0084] (2) The expected data type of each field is clearly defined (e.g., string, integer, boolean, array, object).
[0085] (3) The required keyword can be used to force certain key information to exist.
[0086] (4) Lightweight, versatile, and easy to be parsed and processed by programs.
[0087] Therefore, step S106a above can be understood as: integrating the three types of key information extracted in previous steps—static syntax information (i.e., node attributes from the basic abstract syntax tree, such as method name and parameter type), dynamic logic information (i.e., control flow information from execution simulation, such as loops, branches, and exception paths), and domain knowledge information (i.e., business semantic tags from annotation scanning). Then, the integrated data is reorganized according to a preset format (such as the skeleton defined by JSON Schema). This means: mapping syntax nodes to objects or arrays in JSON; mapping specific attribute values (such as method signature strings) to key-value pairs in JSON; and ensuring that nested relationships (such as methods containing parameters, and parameters containing types) are preserved in the data structure, forming a hierarchical data structure. This transforms the messy code analysis results into standard, machine-readable, and clearly structured data.
[0088] Step S106b: Integrate the structured data objects of all syntax nodes in the target abstract syntax tree to obtain the target structured data object.
[0089] Step S106b above can be understood as: combining the structured data objects of these independent syntax nodes together according to the original hierarchical structure or traversal order of the target abstract syntax tree. For example, if there is a parent-child relationship between syntax nodes (e.g., a "method node" is a child node of a "class node", or a "loop body node" is nested within a "for loop node"), then this nesting or referencing relationship is preserved in the final structured data to ensure the integrity of the data structure. Ultimately, it ensures that all the structured data objects of the syntax nodes are contained in a unified data container, forming a complete structured data object that represents the semantic panorama of the entire target source code file.
[0090] Step S106c: Fill the target structured data object into the preset prompt word template to obtain the structured prompt word.
[0091] In this embodiment, the aforementioned prompt word template is a predefined string or data structure (containing a fixed text frame and dynamic placeholders) used to convert machine-readable structured data objects into natural language instructions or structured input formats that the model can understand. Specifically, the prompt word template includes the following parts:
[0092] (1) Role and task definition: This means clearly informing the model of its identity (such as "senior Java architect" or "UML modeling expert") and the specific task it needs to perform (such as "generating PlantUML sequence diagram code based on the provided code semantic model"). By setting the model's context, the model's expertise in a specific domain (such as Java sequence diagram generation) is activated.
[0093] (2) Constraints and Rules: This section details the specifications that the generated results must adhere to, such as the output format must be PlantUML or Mermaid source code, it must include @startuml and @enduml tags, it must strictly follow the control flow logic in the input data (such as loop counts and exception branches), and it prohibits the generation of undefined participants or illegal message arrows. By using strong constraints to limit the "illusion" of the model, the syntactic correctness and logical consistency of the generated code are ensured.
[0094] (3) Dynamic data placeholders: i.e., reserved specific marker positions (such as {{cfast_model_data}} or<input_data> This section is used to insert the "target structured data object" generated in the preceding steps. The model needs to read the content entered here to generate specific time series diagram elements.
[0095] For example, the prompt word template generated for the sequence diagram description code can be in the following form:
[0096] [Character Setting] You are an expert in Java and PlantUML.
[0097] [Task] Please generate a standard PlantUML sequence diagram based on the provided target structured data object.
[0098] [Constraints] (1) The output must contain only PlantUML code and no Markdown tags or other explanatory text. (2) It must be wrapped with @startuml and @enduml. (3) Loops and exceptions must be handled strictly according to the control flow information in the input data. (4) Business semantic tags are converted into annotations or message tags for participants.
[0099] [Input Data] The following is the target structured data object of the target source code: {{Put the target structured data object here}}.
[0100] Therefore, step S106c can be understood as: filling the target structured data object into the prompt word template to obtain structured prompt words for input into the model.
[0101] In the technical solutions provided by steps S106a to S106c above, by constructing standardized structured data objects and accurately filling them into preset prompt word templates, the problems of missing control flow logic (such as loops and abnormal branches not being restored) and biased understanding of business semantics caused by unstructured or semantically missing input information are specifically solved. This achieves the key purpose of transforming complex static code syntax, dynamic control flow and domain business semantics into structured instructions that can be accurately parsed and reasoned by large models, and significantly improves the degree of restoration of complex business logic and the syntactic correctness of the generated sequence diagram description code.
[0102] As an alternative approach, a generative model is used to analyze and process structured prompt words to generate target time sequence diagram description code. This can be achieved through methods such as... Figure 4 The execution steps shown are implemented as follows:
[0103] Step S108a: Analyze and process the structured prompt words based on the generative model to obtain the initial time sequence diagram description code.
[0104] Specifically, the above steps can be understood as follows: After receiving the structured prompts generated in the preceding steps, the generative model can first perform semantic understanding of the "role and task definition" and "constraint and rule description" in the structured prompts to establish the generation target; the model then parses the target structured data object filled in the placeholders, extracts the key entities within it for reasoning and mapping, including: the model maps the "class / interface nodes" in the target structured data object to "actors / participants" in the sequence diagram; the model generates corresponding "message" arrows based on the "method call chain" in the target structured data object, determining the message direction (synchronous / asynchronous) and label; if the target structured data object is marked as LOOP, the model inserts a loop or alt block in the code and adds iteration variables or conditions based on the loop depth information. If the target structured data object is marked as TRY_CATCH, the model inserts an opt (optional) or alt (alternative) block, representing the normal flow and exception handling branch, respectively. Subsequently, the model reads the business semantic tags bound to the syntax nodes and converts them into comments or message tags in the code to ensure the readability of the diagram. Finally, the model follows the format constraints in the prompt words to generate complete time series diagram description code.
[0105] Specifically, the aforementioned generative model can be a large language model based on the Transformer architecture. This large language model is pre-trained on a large-scale codebase (such as Java / C++ code on GitHub) and natural language processing, possessing general editing comprehension and language generation capabilities. The embodiments of this application employ a zero-shot or few-shot learning approach, using carefully designed structured prompts to stimulate the capabilities of the pre-trained large language model.
[0106] Therefore, this application embodiment utilizes the powerful semantic understanding and code generation capabilities of generative models, combined with high-fidelity, structured input constructed from template abstract syntax trees, to specifically solve the technical problem that traditional tools cannot automatically parse complex control flows (such as loops and exception branches) and implicit business semantics in code.
[0107] Step S108b: Determine whether the initial timing diagram description code contains a preset start marker and a preset end marker.
[0108] In the embodiments of this application, the aforementioned preset start tag (such as @startuml) is the script's start tag, used to inform the parser to start reading the timing diagram definition.
[0109] In the embodiments of this application, the aforementioned preset end marker (such as @enduml) is the end tag of the script, used to inform the parser that the timing diagram definition has ended.
[0110] It should be noted that if Mermaid format is used, explicit start / end markers are not required; instead, they are defined by code block language identifiers or specific structures. Therefore, this application does not impose specific restrictions on the form of preset start and end markers.
[0111] Therefore, if the initial timing diagram description code contains a preset start mark and a preset end mark, the following step S108c is executed; if the initial timing diagram description code does not contain a preset start mark and / or a preset end mark, the following step S108e is executed.
[0112] Step S108c: Determine if there are any syntax errors in the initial timing diagram description code.
[0113] In other words, if the initial sequence diagram description code contains preset start and end markers, it means the format of the description code generated by the model is completely correct. In this case, a deeper syntax check will be performed to determine if there are any syntax errors in the initial sequence diagram description code. If the initial sequence diagram description code does not contain preset start and / or preset end markers, it means the format of the description code generated by the model is incorrect, and therefore no further syntax analysis is required.
[0114] Therefore, if there are no syntax errors in the initial timing diagram description code, the following step S108d is executed; if there are syntax errors in the initial timing diagram description code, the following step S108e is executed.
[0115] Step S108d: Output the target timing diagram description code.
[0116] In other words, only sequence diagram description code that passes format and syntax checks will be considered valid sequence diagram description code and output.
[0117] Step S108e: The structured prompt words are analyzed and processed again based on the generative model to generate new target time series diagram description code.
[0118] In other words, if the initial sequence diagram description code does not contain a preset start mark or a preset end mark, or if the initial sequence diagram description code has syntax errors (such as unclosed brackets, misspelled keywords, incorrect arrow direction, etc.), the code will not be output directly. Instead, a retry mechanism will be triggered to ensure that the final output target sequence diagram description code is high-quality code that can be directly parsed. This solves the "illusion" or non-standard syntax problems that often occur in model-generated code.
[0119] In the technical solutions provided by steps S108a to S108e above, a dual closed-loop control mechanism of "format integrity verification + syntax validity verification" is constructed to specifically solve the common problems of output truncation, missing tags and syntax illusion in code generation tasks of large language models, thereby achieving the purpose of filtering illegal output, reducing the invalidity of retry and significantly improving the industrial usability of generated code.
[0120] Furthermore, after generating the target sequence diagram description code, the sequence diagram element identifier set in the target sequence diagram description code corresponding to each method in the source code file of the target version can be extracted to construct a mapping table, where the mapping table records the association between multiple methods and their corresponding sequence diagram identifier sets.
[0121] Specifically: The process involves traversing the target sequence diagram description code corresponding to each method within the source code file, performing structured parsing of the target sequence diagram description code, identifying specific syntax identifiers in the code, and thus obtaining a unique identifier for each sequence diagram element. These specific syntax identifiers include at least one of the following: ID attribute, alias, etc., and sequence diagram elements include at least: participants, messages, and lifelines, etc. Then, a key-value mapping table is constructed, using the method signature of each method as the key and all sequence diagram elements belonging to that method as the value. For example, for the UserService.auth() method, its corresponding value could contain the identifier set ["participant_user", "message_checkToken", "participant_authService"].
[0122] It should be noted that this key-value mapping table can be persistently stored (e.g., in a database or memory cache) for use during subsequent incremental updates.
[0123] Furthermore, incremental updates can also be achieved through the following methods:
[0124] Step 1: Obtain the source code file of the next version of the target version, and compare the differences between the source code file of the target version and the source code file of the next version to obtain a list of change methods.
[0125] Specifically, the source code files of the target version and the next version are compared using version control tools (such as Git Diff) or static code analysis techniques. By comparing the code changes, the methods that have been changed are accurately identified, thus generating a list of changed methods. Therefore, this list of changed methods includes the specific change details for multiple changed methods, such as adding branches, modifying logic, and updating comments. This step aims to accurately pinpoint the code scope that needs to have its sequence diagram regenerated, avoiding a full rebuild.
[0126] Step 2: Locate the target sequence diagram element identifier set corresponding to each change method in the change method list within the mapping table.
[0127] Specifically, by using the method signatures of each changed method in the list of changed methods as indexes, the system reversely searches the set of all element identifiers corresponding to these changed methods in the sequence diagram within the previously constructed "key-value pair mapping table," thus achieving precise positioning from code changes to visual elements.
[0128] Step 3: For each change method, construct a local target abstract syntax tree based on the change content corresponding to the change method, and serialize the local target abstract syntax tree into a structured data fragment object. Generate new structured prompt words based on the structured data fragment object and the target sequence diagram element identifier set corresponding to the change method. Analyze and process the new structured prompt words based on the generative model to generate a sequence diagram description code fragment. Based on the target sequence diagram element identifier set corresponding to the change method, replace the target sequence diagram description code of the change method under the target version with the sequence diagram description code fragment to obtain a new target sequence diagram description code.
[0129] Specifically: For each change method, only the changed code text fragments (i.e., the changes corresponding to the change method) are extracted and parsed to generate a "local target abstract syntax tree" to capture the changed local syntax structure. Then, the local target abstract syntax tree is serialized into a structured data fragment object (such as JSON format) and combined with the target sequence graph element identifier set corresponding to the change method. This is then populated into a preset prompt word generation template to generate a "new structured prompt word" containing "change context" and "old graph element references," providing the model with minimal necessary information and guiding it to focus only on the logical transformations of the changed parts. Next, the constructed new structured prompt word is input into the generative model, requiring the model to generate a corresponding "sequence graph description code fragment" based on the change content and old graph element identifiers. This fragment should contain the updated element definitions and the added or modified message flow. Finally, based on the target sequence graph element identifier set corresponding to the change method, the specific line of code is located in the target sequence graph description code under the target version, and the newly generated "sequence graph description code fragment" precisely replaces the corresponding identifier in the original code. It should be noted that if new elements are added, new code is inserted; if deletions or modifications are involved, the corresponding code is updated. Ultimately, the complete code after partial replacement becomes the new target sequence diagram description code for the changed method in the next version.
[0130] In the above technical solution, a method for accurately locating changes based on difference comparison is used, and a mapping table is used to lock the specific sequence diagram element identifiers, thereby achieving a precise mapping from code changes to graph updates. By constructing a local abstract syntax tree and integrating old element identifiers to generate targeted prompt words, the generative model is guided to generate only the affected incremental code fragments, thus avoiding the high computational cost and resource consumption caused by full reconstruction. At the same time, precise replacement using identifiers ensures the continuity and logical consistency of the sequence diagram structure, significantly improving the maintenance efficiency of sequence diagram documents and the real-time version synchronization of large-scale complex systems.
[0131] In summary, the sequence diagram description code generation method provided in this application solves the problems of traditional tools being unable to effectively parse complex control flows (such as loops and exception branches) and the disconnect between business semantics and logic. It achieves high-precision reverse generation from code to sequence diagrams, significantly improving the logical reconstruction accuracy and business readability of sequence diagrams. At the same time, it ensures the syntactic validity and editability of the output code, overcoming the pain point of unmaintainable design assets caused by static image formats.
[0132] Meanwhile, the incremental update mechanism based on element identifier mapping provided in this application accurately locates the scope of changes through code difference comparison, constructs targeted prompt words using a local abstract syntax tree and old identifiers, and only requires regenerating the affected time sequence image segments and performing precise replacements, avoiding the high computational cost of full reconstruction. This mechanism achieves dynamic bidirectional synchronization between code changes and time sequence diagram documents, significantly reducing the maintenance time of design documents, and is particularly suitable for agile iteration and compliance audit scenarios of large-scale complex software projects such as financial core systems.
[0133] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0134] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as read-only memory (ROM) / random access memory (RAM), magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.
[0135] According to another aspect of the embodiments of this application, a timing diagram description code generation apparatus for implementing the timing diagram description code generation method provided in the above embodiments is also provided; details already described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0136] Figure 5 This is a structural block diagram of an optional timing diagram describing a code generation apparatus according to an embodiment of this application, such as... Figure 5 As shown in the diagram, the timing diagram describes a code generation apparatus comprising:
[0137] The determination module 52 is used to traverse the source code files of the target version and determine the target source code text of the target methods with sequence diagram generation annotations. The source code files include source code text corresponding to multiple methods.
[0138] Module 54 is used to construct the target abstract syntax tree of the target method based on the target source code text;
[0139] The prompt word generation module 26 is used to serialize the target abstract syntax tree into a target structured data object, and generate structured prompt words based on the target structured data object;
[0140] The code generation module 58 is used to analyze and process structured prompt words based on a generative model to generate target time sequence diagram description code.
[0141] In an exemplary embodiment, the above-described apparatus is further configured to construct a target abstract syntax tree for a target method based on the target source code text, including: performing static syntax analysis on the target source code text to obtain a basic abstract syntax tree and code comment text, wherein the basic abstract syntax tree includes multiple syntax nodes, and the types of syntax nodes include at least: class nodes, interface nodes, method signature nodes, method parameter nodes, and return value nodes; performing execution simulation on the target source code text to obtain control flow information, wherein the control flow information includes at least: method call chains, conditional branches, loop structures, and exception handling blocks; scanning the code comment list using regular expressions to convert each code comment in the code comment list into a corresponding business semantic tag, wherein the business semantic tag includes at least one of the following: domain entity tag, business action tag, scene tag, and rule tag; appending the control flow information to the corresponding syntax node in the basic abstract syntax tree, and binding the business semantic tag with the syntax node associated with the business semantic tag to obtain the target abstract syntax tree.
[0142] In an exemplary embodiment, the above-described apparatus is further configured to serialize the target abstract syntax tree into a target structured data object, and generate structured prompt words based on the target structured data object, including: traversing each syntax node in the target abstract syntax tree, mapping the node information, control flow information, and business semantic tags of the syntax nodes into structured data objects of a preset format; integrating the structured data objects of all syntax nodes in the target abstract syntax tree to obtain the target structured data object; and filling the target structured data object into a preset prompt word template to obtain structured prompt words.
[0143] In an exemplary embodiment, the above-described apparatus is further configured to analyze and process structured prompt words based on a generative model to generate target time sequence graph description code, including: analyzing and processing structured prompt words based on a generative model to obtain initial time sequence graph description code; determining whether the initial time sequence graph description code contains a preset start marker and a preset end marker; if the initial time sequence graph description code contains a preset start marker and a preset end marker, determining whether the initial time sequence graph description code has a syntax error; if the initial time sequence graph description code does not have a syntax error, outputting the target time sequence graph description code.
[0144] In an exemplary embodiment, the above-described apparatus is further configured to, when the initial timing diagram description code does not contain a preset start marker or a preset end marker, or when the initial timing diagram description code contains a syntax error, analyze and process the structured prompt words again based on a generative model to generate a new target timing diagram description code.
[0145] In an exemplary embodiment, the above-described apparatus is further configured to, after generating the target timing diagram description code, further include: extracting the timing diagram element identifier set from the target timing diagram description code corresponding to each method in the source code file of the target version, and constructing a mapping table, wherein the mapping table records the association relationship between multiple methods and their corresponding timing diagram identifier sets.
[0146] In an exemplary embodiment, the apparatus is further configured to obtain the source code file of the next version of the target version, and compare the source code file of the target version with the source code file of the next version to obtain a list of change methods. The list of change methods includes: change content corresponding to multiple change methods; searching in a mapping table for the target sequence graph element identifier set corresponding to each change method in the list of change methods; for each change method, constructing a local target abstract syntax tree based on the change content corresponding to the change method, and serializing the local target abstract syntax tree into a structured data fragment object; generating a new structured prompt word based on the structured data fragment object and the target sequence graph element identifier set corresponding to the change method; analyzing and processing the new structured prompt word based on a generative model to generate a sequence graph description code fragment; and replacing the target sequence graph description code of the change method in the target version with the sequence graph description code fragment based on the target sequence graph element identifier set corresponding to the change method to obtain a new target sequence graph description code.
[0147] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.
[0148] According to another aspect of the embodiments of this application, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein the program executes the steps in any of the above method embodiments when it is run.
[0149] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as USB flash drives, ROMs, RAMs, portable hard drives, magnetic disks, or optical disks.
[0150] According to another aspect of the embodiments of this application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor is configured to perform the steps of any of the method embodiments described above via the computer program. In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0151] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.
[0152] According to another aspect of the embodiments of this application, a computer program product is also provided, the computer program product including a computer program / instructions containing program code for performing the method shown in the flowchart.
[0153] Specifically, the computer program executes the following steps during runtime: traversing the source code file of the target version to determine the target source code text of the target method with sequence diagram generation annotations, wherein the source code file includes source code text corresponding to multiple methods; constructing a target abstract syntax tree for the target method based on the target source code text; serializing the target abstract syntax tree into a target structured data object, and generating structured prompt words based on the target structured data object; analyzing and processing the structured prompt words based on a generative model to generate target sequence diagram description code.
[0154] As an alternative implementation, the above-mentioned electronic device may exist in the form of a mobile terminal, a computer terminal, or a similar computing device. Figure 6 A block diagram of a computer terminal for implementing a timing diagram-based code generation method is shown. Figure 6 As shown, the computer terminal 60 may include a processor 602, a memory 604 for storing data, and a transmission device 606 for communication functions. The processor 602 may include one or more processors. For ease of explanation, Figure 6 The diagram illustrates multiple processors, including a first processor 602a, a second processor 602b, ..., an nth processor 602n. Processor 602 may be, but is not limited to, a processing device such as a microprocessor (MCU) or a field-programmable gate array (FPGA).
[0155] In addition, the computer terminal 60 may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 6 The structure shown is for illustrative purposes only and does not limit the structure of the computer terminal described above. For example, computer terminal 60 may also include... Figure 6 The more or fewer components shown, or having the same Figure 6 The different configurations shown.
[0156] Processor 602 may include one or more processing units. For example, processor 602 may include processing devices such as central processing unit (CPU), graphics processing unit (GPU), digital signal processing (DSP) chip, microcontroller unit (MCU), field-programmable gate array (FPGA), neural network processing unit (NPU), tensor processing unit (TPU), artificial intelligence (AI) type processor, etc. Different processing units may be independent components or integrated into one or more processors.
[0157] It should be noted that the aforementioned one or more processors 602 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 60. As described in the embodiments of this application, the data processing circuits serve as processor control (e.g., selection of a variable resistor termination path connected to an interface).
[0158] The memory 604 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the timing diagram description code generation method in the embodiments of this application. The processor 602 executes various functional applications and data processing by running the software programs and modules stored in the memory 604, thereby realizing the aforementioned timing diagram description code generation method. The memory 604 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 604 may further include memory remotely located relative to the processor 602, and these remote memories can be connected to the computer terminal 60 via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0159] The transmission device 606 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 60. In one example, the transmission device 606 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 606 may be a Radio Frequency (RF) module, used for data interaction with external networks or devices via wired and / or wireless network connections.
[0160] The display can be, for example, a liquid crystal display (LCD) or a touchscreen display (also known as a "touchscreen" or "touch display screen"). This LCD allows the user to interact with the user interface of the mobile terminal. Furthermore, the computer terminal 60 can be connected to a cursor control device and a keyboard via an input / output interface. The cursor control device (e.g., a mouse, trackball, or touchpad) is primarily used to transmit directional information and command selections to the terminal and control the movement of the cursor on the display; the keyboard is primarily used to receive letters, numbers, and other control commands input by the user, thereby enabling interaction between the user and the computer terminal 60.
[0161] It should be noted here that, in some optional embodiments, the above... Figure 6 The computer terminal shown may include hardware elements (including circuitry), software elements (including computer code stored on a computer-readable medium), or a combination of both hardware and software elements. It should be noted that... Figure 6 This is only one instance of a specific particular instance, and is intended to illustrate the types of components that may exist in the aforementioned computer terminal.
[0162] Obviously, those skilled in the art should understand that the modules or steps of this application described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, this application is not limited to any particular combination of hardware and software.
[0163] The above are merely preferred embodiments of this application and are not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the principles of this application should be included within the protection scope of this application.
Claims
1. A method for generating sequence diagram description code, characterized in that, include: Traverse the source code files of the target version to determine the target source code text of the target method with sequence diagram generation annotations, wherein the source code file includes source code text corresponding to multiple methods respectively; Construct the target abstract syntax tree of the target method based on the target source code text; The target abstract syntax tree is serialized into a target structured data object, and structured prompt words are generated based on the target structured data object; The structured prompt words are analyzed and processed based on a generative model to generate target time sequence diagram description code.
2. The method according to claim 1, characterized in that, Constructing the target abstract syntax tree of the target method based on the target source code text, including: Static syntax analysis is performed on the target source code text to obtain a basic abstract syntax tree and code comment text. The basic abstract syntax tree includes multiple syntax nodes, and the types of the syntax nodes include at least: class nodes, interface nodes, method signature nodes, method parameter nodes, and return value nodes. The target source code text is subjected to execution simulation to obtain control flow information, wherein the control flow information includes at least: method call chain, conditional branch, loop structure and exception handling block; The code comment list is scanned using regular expressions to convert each code comment in the code comment list into a corresponding business semantic tag, wherein the business semantic tag includes at least one of the following: domain entity tag, business action tag, scenario tag, and rule tag; The control flow information is appended to the corresponding syntax node in the basic abstract syntax tree, and the business semantic tag is bound to the syntax node associated with the business semantic tag to obtain the target abstract syntax tree.
3. The method according to claim 2, characterized in that, The process involves serializing the target abstract syntax tree into a target structured data object, and generating structured prompt words based on the target structured data object, including: Traverse each syntax node within the target abstract syntax tree and map the node information, control flow information, and business semantic tags of the syntax node into a structured data object in a preset format; The structured data objects of all syntax nodes within the target abstract syntax tree are integrated to obtain the target structured data object; The target structured data object is filled into a preset prompt word template to obtain the structured prompt word.
4. The method according to claim 1, characterized in that, The structured prompt words are analyzed and processed based on a generative model to generate target time series diagram description code, including: The structured prompt words are analyzed and processed based on a generative model to obtain the initial time sequence diagram description code; Determine whether the initial timing diagram description code contains a preset start marker and a preset end marker; If the initial timing diagram description code contains the preset start marker and the preset end marker, determine whether the initial timing diagram description code has a syntax error; If the initial timing diagram description code is free of syntax errors, the target timing diagram description code is output.
5. The method according to claim 4, characterized in that, The method further includes: If the initial sequence diagram description code does not contain a preset start marker or a preset end marker, or if the initial sequence diagram description code has a syntax error, the structured prompt words are analyzed and processed again based on the generative model to generate a new target sequence diagram description code.
6. The method according to claim 1, characterized in that, After generating the target timing diagram description code, the method further includes: Extract the sequence graph element identifier set from the target sequence graph description code corresponding to each method in the source code file of the target version, and construct a mapping table, wherein the mapping table records the association relationship between multiple methods and their corresponding sequence graph identifier sets.
7. The method according to claim 6, characterized in that, The method further includes: Obtain the source code file of the next version of the target version, and compare the differences between the source code file of the target version and the source code file of the next version to obtain a list of change methods, wherein the list of change methods includes: the change content corresponding to multiple change methods; Search the mapping table for the target sequence diagram element identifier set corresponding to each change method in the change method list; For each of the aforementioned change methods, a local target abstract syntax tree is constructed based on the change content corresponding to the change method, and the local target abstract syntax tree is serialized into a structured data fragment object. A new structured prompt word is generated based on the structured data fragment object and the target time sequence graph element identifier set corresponding to the change method. The new structured prompt word is analyzed and processed based on a generative model to generate a time sequence graph description code fragment. Based on the target time sequence graph element identifier set corresponding to the change method, the target time sequence graph description code of the change method under the target version is replaced using the time sequence graph description code fragment to obtain a new target time sequence graph description code.
8. A timing diagram description code generation apparatus, characterized in that, include: The determination module is used to traverse the source code files of the target version and determine the target source code text of the target method with the timing diagram generation annotation. The source code file includes the source code text corresponding to multiple methods. The building module is used to construct the target abstract syntax tree of the target method based on the target source code text; The prompt word generation module is used to serialize the target abstract syntax tree into a target structured data object, and generate structured prompt words based on the target structured data object; The code generation module is used to analyze and process the structured prompt words based on a generative model to generate target time sequence diagram description code.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the device containing the computer-readable storage medium executes the timing diagram description code generation method according to any one of claims 1 to 7 by running the computer program.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the timing diagram description code generation method according to any one of claims 1 to 7 through the computer program.
