Automatic generation method of UML sequence diagrams compatible with multilingual code analysis

By distinguishing features and extracting information from C++ and Java code, UML sequence diagrams are generated, solving the problem of understanding large-scale, complex, multilingual code, improving code readability and maintenance efficiency, and optimizing the software development process.

CN119902743BActive Publication Date: 2026-05-26HEFEI UNIV OF TECH

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HEFEI UNIV OF TECH
Filing Date
2024-12-30
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

Existing technologies struggle to quickly and effectively understand and interpret large-scale, complex multilingual mixed code, resulting in high development and maintenance costs and low efficiency.

Method used

By capturing the characteristics of C++ and Java code, differentiating code types, extracting key information using regular expression matching and syntax analysis, generating Plant UML code, and automatically generating UML sequence diagrams using the Plant UML tool to demonstrate the program's execution flow.

Benefits of technology

It improves code readability and maintainability, reduces manual analysis time, quickly identifies system interactions and potential bottlenecks, optimizes program architecture, and enhances software development and debugging efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119902743B_ABST
    Figure CN119902743B_ABST
Patent Text Reader

Abstract

This invention provides an automatic UML sequence diagram generation method compatible with multilingual code analysis. By capturing the characteristics of C++ and Java code, it identifies the code types of each part of the mixed source code and analyzes different code types. For code marked as C++, regular expressions are used to match keywords, class information, and inheritance information of the C++ source code to be analyzed, and these are converted into parameter names. For code marked as Java, syntax and lexical analysis are used to extract class information and method call information of the Java source code to be analyzed. Corresponding Plant UML code is generated and drawn as a comprehensive UML sequence diagram. This invention's automatic UML sequence diagram generation method compatible with multilingual code analysis can intuitively reflect the functional and logical composition of mixed C++ and Java code, and intuitively reflect the interaction relationship between them. It avoids the need to view tedious source code to obtain program information and functional relationships, improving code readability and maintainability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of software design and relates to an automatic generation method for UML sequence diagrams that is compatible with multilingual code analysis. Background Technology

[0002] With the continuous advancement of information technology, the performance of computer hardware has improved year by year, and software development technology has also developed accordingly, making software systems increasingly complex. Modern software not only needs to meet more and more functional requirements, but also needs to adapt to diverse hardware platforms and operating system environments. Furthermore, as user needs constantly change, software must be continuously expanded and maintained, and these functional additions are often accompanied by increased system architecture complexity. The dependencies between different modules become tighter, and the coupling of code increases accordingly. These demands have led to a dramatic expansion in the size of software programs, increasingly complex functions, and code sizes ranging from thousands to millions of lines, far exceeding the scope of traditional software development.

[0003] As software programs continue to grow in size, software engineers need to spend a significant amount of time understanding and interpreting massive amounts of code during development and maintenance. This not only leads to decreased work efficiency but also increases development cycles and costs. Therefore, the ability to quickly and effectively understand an unknown program has become a crucial requirement in modern software development.

[0004] To address this issue, engineers have employed various techniques, including static analysis, dynamic analysis, program visualization, and reverse engineering. Static analysis identifies potential errors and defects by examining the source code, while dynamic analysis focuses on the program's runtime behavior. Reverse engineering is primarily used to analyze programs for which source code is unavailable. Program visualization, due to its intuitive and easy-to-understand nature, has become the most popular tool. By presenting the program's structure, control flow, and data flow graphically, program visualization helps developers gain a clearer understanding of the program's overall architecture and the relationships between modules, thereby improving the efficiency and accuracy of program comprehension.

[0005] UML sequence diagrams are dynamic models used to describe interactions between objects, especially interactions in chronological order. They demonstrate how objects in a system collaborate through message passing to complete a function or behavior. Their advantages lie in their intuitive representation, clear interaction descriptions, and detailed depiction of the system's dynamic behavior. They not only help developers understand and design systems but also promote communication within teams, improve the quality of system design, and reduce potential design problems. Summary of the Invention

[0006] The purpose of this invention is to provide a method for automatically generating UML sequence diagrams by analyzing multilingual codes, addressing the problems existing in the prior art.

[0007] To achieve the objectives described in this invention, this invention provides a method for automatically generating UML sequence diagrams compatible with multilingual code analysis, comprising the following steps:

[0008] Step S1: By capturing the characteristics of C++ and Java code, identify the code types of each part of the mixed source code, and analyze the different types of code;

[0009] Step S2: Use regular expressions to match the C++ code marked as such, matching the keywords, class information, and inheritance information of the C++ source code to be analyzed, and converting them into parameter names;

[0010] Step S3: Use syntax and lexical analysis to extract class information and method call information from the Java source code to be analyzed;

[0011] Step S4: Based on the parameter names extracted from the C++ source code to be analyzed and the class information extracted from the Java source code, the algorithm integrates this information and generates the corresponding Plant UML code;

[0012] Step S5: Use the Plant UML tool to draw the generated Plant UML code as a UML synthesis sequence diagram.

[0013] Further technology of the present invention:

[0014] Preferably, step S1 includes:

[0015] The differences between C++ and Java code can be identified primarily by their syntax and keyword differences. For example, C++ includes concepts like pointers and references, while Java does not support pointers or memory management. Their input / output methods also differ. Another difference lies in the declaration methods of classes and functions. C++ allows functions and classes to be defined outside of classes, and it also allows the use of namespaces and program structures without classes. Java, being object-oriented, requires classes to contain the `class` keyword, and filenames to match class names. These methods can be used to distinguish between C++ and Java code in mixed source code.

[0016] Preferably, step S2 includes:

[0017] The code marked as C++ code is matched using regular expressions, including keywords, class information, and inheritance information of the C++ source code. The successfully matched keywords, class names, class members, and inheritance information are used to organize the call parameters. The extracted call information is stored in a list, and each element is traversed to split it into caller and callee. The parameter list of the callee is then split into parameter names.

[0018] Preferably, step S3 includes:

[0019] The code marked as Java code is analyzed using syntax and lexical methods. The Java source code to be analyzed is transformed into a sequence of words through lexical analysis, and then into a structured grammar through syntax analysis. At a deeper level, an abstract syntax tree can be constructed. By traversing the class declaration nodes and their method child nodes in the abstract syntax tree, class information and method call information can be extracted.

[0020] Preferably, step S4 includes:

[0021] Based on the parameter names extracted from the C++ source code to be analyzed and the class information extracted from the Java source code, the sorted information is added to the Plant UML string, and the Plant UML code generation algorithm is used to integrate these character information to generate Plant UML code that can automatically draw UML sequence diagrams.

[0022] Preferably, step S5 includes:

[0023] The Plant UML tool is used to generate a comprehensive sequence diagram based on the generated Plant UML code. The method call relationship between classes is represented by arrows to indicate message passing. The starting point of the arrow is the class that calls the method, and the ending point is the class that receives the method. The interaction between the two language codes is also passed through arrows.

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

[0025] This invention presents an automated UML sequence diagram generation technology compatible with multilingual code analysis. Through automated methods, it generates UML sequence diagrams for mixed programs containing C++ and Java code, clearly and intuitively illustrating the program's execution flow. This helps developers more easily understand complex cross-language interactions and system behavior. Compared to traditional methods that require examining source code line by line to infer program logic, this technology significantly reduces the time and effort required for manual analysis, improving code readability and maintainability. Furthermore, through the automatically generated UML sequence diagrams, developers can quickly identify key interactions, potential bottlenecks, and exception handling processes within the system, thereby optimizing program architecture and improving system stability. This technology not only enhances the efficiency of code analysis but also provides strong support for software development collaboration and debugging, making it particularly suitable for the development and maintenance of large-scale, complex systems. Attached Figure Description

[0026] Figure 1 This is a flowchart illustrating the specific process of the present invention. Detailed Implementation

[0027] The present invention will be further described below with reference to the accompanying drawings and embodiments. The present invention includes, but is not limited to, the following embodiments.

[0028] like Figure 1 A method for automatically generating UML sequence diagrams compatible with multilingual code analysis, including the following steps:

[0029] Step S1: Input the source code, analyze the different characteristics of C++ and Java code, and mark the specific type of each part of the code to facilitate specific analysis;

[0030] The differences between C++ and Java can be distinguished based on their characteristics, primarily in terms of syntax and keywords.

[0031] The C++ source code to be analyzed is a problem-solving program that outputs each row on the chessboard by traversing the result vector `queen`. For each row, if the current position is the location of a result, the position information of the result is output; otherwise, "#" is output to indicate that there is no result. If the problem has no solution, "No solution!" is output. `EightQueens()` and `IslegalMove()` use pointers and references, and not all functions and classes are defined within classes, allowing the use of namespaces and a program structure without classes. The Java source code to be analyzed is the analysis function code, which contains the following functionalities: initialization, top-down analysis, semantic actions, and other helper methods: outputting elements in the queue as strings; returning the index of a given symbol in the `hang` array; returning the index of a given symbol in the `lie` array; replacing elements in the queue with a specified string; retrieving the symbol on the right-hand side of the production from the production array `produce` based on a given number. It can be seen that it does not support pointers and memory management, contains the `class` keyword, requires filenames to match class names, and its input / output methods differ from those of the C++ program. The above methods can be used to distinguish between C++ and Java code in mixed source code.

[0032] Step S2: Analyze the C++ code using regular expressions, including keywords, class information, and inheritance information, and return the matching results;

[0033] The code marked as C++ code is matched using regular expressions, including keywords, class information, and inheritance information from the C++ source code. Successfully matched keywords, class names, class members, and inheritance information are then used to compile call parameters. The extracted call information is stored in a list, and each element is iterated through, splitting it into caller and callee. The callee's parameter list is then split into parameter names. The regular expression matching reveals that the C++ code defines a `Solution` class containing two functions, `EightQueens()` and `IslegalMove()`, which are ultimately called in the `main()` function. Furthermore, the program contains multiple conditional checks.

[0034] Step S3: Parse the Java code using the Javalang toolkit, and obtain the Java source code call information through the generated abstract syntax tree;

[0035] The Javalang toolkit is used to parse the source code and generate its Abstract Syntax Tree (AST), then all class declaration nodes are selected. Next, each class declaration node and its internal method nodes are traversed along the AST structure, and the method names are collected into a list. After traversing all methods of a class, the class name and its corresponding method list are stored as key-value pairs in a dictionary, with the class name as the key and the method name list as the value. Through parsing, it can be seen that the Java program defines multiple methods: Output(), Gethang(), Getlie(), Set(), Getformula(), Findhead(), and Init1(). The program also has multiple nested functions and conditional statements, and global variable classes such as Productio and Equ.

[0036] Step S4: Process the information extracted from the C++ and Java source code using the UML code generation algorithm, and save the generated Plant UML code;

[0037] Based on the parameter names extracted from the C++ source code to be analyzed, such as EightQueens() and IslegalMove(), and conditional statements, as well as class information extracted from the Java source code, including Output(), Gethang(), Getlie(), Set(), Getformula(), Findhead(), Init1() methods, global variable classes such as Productio and Equ, and nesting and conditional statements, the processed information is added to the Plant UML string. This string information is then integrated using a Plant UML code generation algorithm to generate Plant UML code that can automatically draw UML sequence diagrams.

[0038] Step S5: Import the Plant UML code to generate a multilingual UML synthesis sequence diagram.

[0039] Using the Plant UML tool, a comprehensive sequence diagram is generated from the generated Plant UML code. The method call relationship between classes is represented by arrows to indicate message passing. The starting point of the arrow is the class that calls the method, and the ending point is the class that receives the method. The interaction between the two language codes is also passed through arrows. The Gethang() method in the Java program points to the EightQueens() method in the C++ program, indicating that the Gethang() method is used in EightQueens() for analysis.

[0040] The above description is merely an example and illustration of the structure of the present invention. Those skilled in the art can make various modifications or additions to the specific embodiments described, or use similar methods to replace them, as long as they do not deviate from the structure of the invention or exceed the scope defined in the claims, all of which should fall within the protection scope of the present invention.

Claims

1. A method for automatically generating UML sequence diagrams compatible with multilingual code analysis, characterized by: Includes the following steps: Step S1: By capturing the characteristics of C++ and Java code, identify the code types of each part of the mixed source code, and analyze the different types of code; Step S1 includes: The differences between C++ and Java can be distinguished by the characteristics of their code, including differences in syntax and keywords, as well as differences in the way classes and functions are declared. Step S2: Use regular expressions to match the C++ code marked as such, matching the keywords, class information, and inheritance information of the C++ source code to be analyzed, and converting them into parameter names; Step S2 includes: The code marked as C++ code is matched using regular expressions, including keywords, class information, and inheritance information of the C++ source code. The successfully matched keywords, class names, class members, and inheritance information are used to organize the call parameters. The extracted call information is stored in a list. Each element is traversed and split into the caller and the callee. The parameter list of the callee is then split into parameter names. Step S3: Use syntax and lexical analysis to extract class information and method call information from the Java source code to be analyzed; Step S3 includes: The code marked as Java code is analyzed using syntax and lexical methods. The Java source code to be analyzed is transformed into a sequence of words through lexical analysis, and then into a structured syntax through syntax analysis. An abstract syntax tree is constructed at a deeper level. By traversing the class declaration nodes and their method child nodes in the abstract syntax tree, class information and method call information are extracted. Step S4: Based on the parameter names extracted from the C++ source code to be analyzed and the class information extracted from the Java source code, the algorithm integrates this information and generates the corresponding Plant UML code; Step S4 includes: Based on the parameter names extracted from the C++ source code to be analyzed and the class information extracted from the Java source code, the sorted information is added to the Plant UML string, and the Plant UML code generation algorithm is used to integrate these character information to generate Plant UML code that can automatically draw UML sequence diagrams; Step S5: Use the Plant UML tool to draw the generated Plant UML code as a UML synthesis sequence diagram.

2. The method for automatically generating UML sequence diagrams compatible with multilingual code analysis according to claim 1, characterized in that, Step S5 includes: The Plant UML tool is used to generate a comprehensive sequence diagram based on the generated Plant UML code. The method call relationship between classes is represented by arrows to indicate message passing. The starting point of the arrow is the class that calls the method, and the ending point is the class that receives the method. The interaction between the two language codes is also passed through arrows.