UML (Unified Modeling Language) time sequence diagram automatic generation method compatible with multilingual code analysis

By analyzing the characteristics of C++ and Java code, generating Plant UML code and drawing UML timing charts, the code understanding problem caused by the complexity of cross-language interaction in modern software systems is solved, and fast and effective code analysis and system behavior understanding are achieved.

CN119902743AActive Publication Date: 2025-04-29HEFEI UNIV OF TECH
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411971641.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-04-29
Estimated Expiration
2044-12-30

AI Technical Summary

Technical Problem

Due to its huge scale and complex functions, modern software systems require a lot of time to understand and interpret code during development and maintenance. It is difficult for existing technologies to quickly and effectively analyze and understand complex systems that interact across languages.

Method used

By capturing the characteristics of C++ and Java code, confirming the code types of various parts of the mixed source code, using regular expressions to match C++ code, analyzing Java code, integrating the extracted information to generate Plant UML code, and using Plant UML tool to draw UML timing charts.

Benefits of technology

It realizes automated analysis of multilingual code and generates clear and intuitive UML timing charts, helping developers to understand complex cross-language interactions and system behaviors more easily, reducing the time and energy of manual analysis, and improving code readability and maintainability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119902743A_ABST
    Figure CN119902743A_ABST
Patent Text Reader

Abstract

The invention provides a UML (Unified Modeling Language) time sequence diagram automatic generation method compatible with multilingual code analysis, which comprises the following steps of: by capturing the characteristics of C + + and Java codes, confirming the code type of each part of a mixed source code, and analyzing different types of codes; matching the codes marked as the C + + codes with a regular expression, matching keywords, class information and inheritance information of the C + + source codes to be analyzed, and converting the keywords, the class information and the inheritance information into parameter names; analyzing the code marked as the Java code by grammar and lexical, and extracting class information and method calling information of the Java source code to be analyzed; generating a corresponding Plant UML (Unified Modeling Language) code; and drawing a UML comprehensive time sequence diagram. According to the UML time sequence diagram automatic generation method compatible with multilingual code analysis, the function and logic composition of a mixed C + + code and a Java code can be intuitively reflected, the interaction relation between the C + + code and the Java code can be intuitively reflected, program information and the function relation which can only be obtained by checking tedious source codes are avoided, and the readability and maintainability of the codes are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of software design and relates to a method for automatically generating a UML timing diagram compatible with multi-language code analysis. Background Art

[0002] With the continuous advancement of information technology, the performance of computer hardware has been improved year by year, and software development technology has also developed accordingly, making software systems more and more complex. Modern software must not only meet more and more functional requirements, but also adapt to diverse hardware platforms and operating system environments. In addition, as user needs continue to change, software must continue to expand and maintain its functions, and the increase in these functions is often accompanied by the complexity of the system architecture. The dependencies between different modules have become closer, and the coupling degree of the code has also increased. These requirements have led to a sharp expansion in the scale of software programs, increasingly complex functions, and the amount of code ranging from thousands to millions of lines. The complexity of the program far exceeds the scope of traditional software development.

[0003] As the scale of software programs continues to expand, software engineers need to spend a lot of time understanding and interpreting huge codes during development and maintenance. This not only leads to a decrease in work efficiency, but also increases development cycles and costs. Therefore, how to quickly and effectively understand an unknown program has become an important requirement in modern software development.

[0004] To solve this problem, engineers have adopted a variety of technical means, including static analysis, dynamic analysis, program visualization, and reverse engineering. Static analysis identifies potential errors and defects by checking the source code, dynamic analysis focuses on the behavior of the program at runtime, and reverse engineering is mainly used to analyze programs without source code. Program visualization has become the most popular tool because of its intuitive and easy-to-understand features. By presenting the structure, control flow, and data flow of the program in a graphical way, program visualization helps developers more clearly understand the overall architecture of the program and the relationship between modules, thereby improving the efficiency and accuracy of program understanding.

[0005] UML sequence diagram is a dynamic model used to describe the interaction between objects, especially the interaction in time sequence. It shows how the various objects in the system collaborate through message passing to complete a certain function or behavior. Its advantages lie in its intuitive representation, clear description of interaction and detailed presentation of the dynamic behavior of the system. It not only helps developers understand and design the system, but also promotes communication between teams, improves the quality of system design and reduces potential design problems. Summary of the invention

[0006] The purpose of the present invention is to provide a method for automatically generating UML sequence diagrams by analyzing multi-language codes in order to solve the problems existing in the above-mentioned prior art.

[0007] To achieve the objective of the present invention, the present invention provides a method for automatically generating a UML sequence diagram compatible with multi-language code analysis, comprising the following steps:

[0008] Step S1: by capturing the features of C++ and Java codes, confirming the code types of each part of the mixed source code, and analyzing different types of codes;

[0009] Step S2: Match the C++ code with a regular expression to match the keywords, class information and inheritance information of the C++ source code to be analyzed, and convert them into parameter names;

[0010] Step S3: Analyze the Java code marked as grammar and lexical, and extract the class information and method call information of the Java source code to be analyzed;

[0011] Step S4: According to the parameter names extracted from the C++ source code to be analyzed and the class information extracted from the Java source code, the information is integrated through an algorithm to generate the corresponding Plant UML code;

[0012] Step S5: Using the Plant UML tool, draw the generated Plant UML code into a UML comprehensive sequence diagram.

[0013] Further technology of the present invention:

[0014] Preferably, step S1 comprises:

[0015] C++ and Java codes are distinguished based on their characteristics, mainly including the differences in their syntax and keywords. For example, C++ has concepts such as pointer reference, while Java does not support pointers and memory management, and the input and output methods of the two are also different. On the other hand, the two are distinguished by the different declaration methods of classes and functions. For example, C++ does not allow all functions and classes to be defined within the class, and also allows the use of namespaces and program structures that do not use classes. Java is object-oriented, and classes must contain the class keyword, and the file name must match the class name, etc. The above methods can be used to distinguish C++ and Java codes in mixed source code.

[0016] Preferably, step S2 comprises:

[0017] Match the code marked as C++ with regular expressions, including the keywords, class information and inheritance information of the C++ source code, sort the successfully matched keywords, class names, class members and inheritance information call parameters, store the extracted call information in a list, traverse each element, split it into callers and callees, and split the callee's parameter list into parameter names.

[0018] Preferably, step S3 includes:

[0019] The Java code marked as grammar and lexical analysis is used to convert the Java source code to be analyzed into a word sequence through lexical analysis, and then converted into a structured grammar through grammatical analysis. At a deeper level, an abstract syntax tree can be constructed. By traversing the class declaration node and its method subnodes in the abstract syntax tree, class information and method call information can be extracted.

[0020] Preferably, step S4 comprises:

[0021] According to 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 these character information are integrated through the Plant UML code generation algorithm to generate Plant UML code that can automatically draw UML timing diagrams.

[0022] Preferably, step S5 comprises:

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

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

[0025] The UML sequence diagram automatic generation technology of the present invention is compatible with multi-language code analysis. Through an automated method, a UML sequence diagram of a mixed program containing C++ and Java codes is generated, which can clearly and intuitively display the program running process, and help developers to more easily understand complex cross-language interactions and system behaviors. Compared with the traditional method of needing to view the source code line by line to infer the program logic, this technology greatly reduces the time and effort of manual analysis and improves the readability and maintainability of the code. In addition, through the automatically generated UML sequence diagram, developers can quickly identify key interactions, potential bottlenecks and exception handling processes in the system, thereby optimizing the program architecture and improving system stability. This technology not only improves the efficiency of code analysis, but also provides strong support for collaboration and debugging of software development, and is particularly suitable for the development and maintenance of large-scale and complex systems. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 It is a specific flow chart of the present invention. DETAILED DESCRIPTION

[0027] The present invention is further described below in conjunction with the accompanying drawings and embodiments. The present invention includes but is not limited to the following embodiments.

[0028] like Figure 1 , a UML sequence diagram automatic generation method compatible with multi-language code analysis includes the following steps:

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

[0030] The distinction is based on the characteristics of C++ and Java codes, mainly including the differences in their syntax and keywords.

[0031] The C++ source code to be analyzed is a problem-solving program, which outputs each row on the chessboard by traversing the result vector queen. For each row, if the current position is the position of the 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() have pointers and references, and not all functions and classes are defined in the class, allowing the use of namespaces and program structures that do not use classes. The Java source code to be analyzed is the analysis function code, which contains the following functions: initialization, top-down analysis, semantic actions and other auxiliary methods: output the elements in the queue as strings; return its index in the hang array according to the given symbol; return its index in the lie array according to the given symbol; replace the elements in the queue with the specified string; get the symbol on the right side of the corresponding production from the production array produce according to the given number. It can be seen that it does not support pointers and memory management, contains the class keyword, the file name must match the class name, etc., and the input and output methods are also different from C++ programs. The above method can be used to distinguish C++ and Java codes in mixed source code.

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

[0033] Use regular expressions to match the code marked as C++, including the keywords, class information, and inheritance information of the C++ source code. Arrange the successfully matched keywords, class names, class members, and inheritance information call parameters, store the extracted call information in a list, traverse each element, split it into callers and callees, and split the callee's parameter list into parameter names. Through regular matching, it can be seen that the C++ code defines a Solution class, which contains two functions EightQueens() and IslegalMove(). Finally, these two methods are called in the main() function, and there are multiple conditional judgments in the program.

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

[0035] Use the Javalang toolkit to parse the source code and generate its abstract syntax tree (AST), then filter out all class declaration nodes. Next, traverse each class declaration node and its internal method nodes along the AST structure, and collect the method names into a list. After traversing all methods of a class, store the class name and the corresponding method list as key-value pairs in a dictionary, with the class name as the key of the dictionary and the method name list as the value of the dictionary. Through parsing, it can be obtained that the Java program defines multiple methods: Output() method, Gethang() method, Getlie() method, Set() method, Getformula() method, Findhead() method, Init1() method. At the same time, the program has multiple nested functions and conditional judgments, and has global variable classes such as Productio and Equ.

[0036] Step S4: Processing the information in the extracted C++ and Java source codes through the UML code generation algorithm, and saving the generated Plant UML code;

[0037] According to the parameter names extracted from the C++ source code to be analyzed, such as EightQueens() and IslegalMove() and conditional judgment information, the class information extracted from the Java source code includes Output() method, Gethang() method, Getlie() method, Set() method, Getformula() method, Findhead() method, Init1() method, Productio, Equ and other global variable classes and nesting, conditional judgment and other information. The sorted information is added to the Plant UML string, and the character information is integrated through the 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 UML integrated sequence diagram of the multi-language code.

[0039] The Plant UML tool is used to generate a comprehensive timing diagram based on the generated Plant UML code. The calling relationship between methods of classes uses arrows to represent message passing. The starting point of the arrow is the class that calls the method, and the end point is the class of the called method. The interaction between the two language codes is also transmitted through arrows. The Gethang() method in the Java program points to the EightQueens() of the C++ program, indicating that the Gethang() method is used in EightQueens() for analysis.

[0040] The above contents are merely examples and explanations of the structure of the present invention. The technicians in this technical field may make various modifications or additions to the specific embodiments described or replace them in a similar manner. As long as they do not deviate from the structure of the invention or exceed the scope defined by the claims, they should all fall within the protection scope of the present invention.

Claims

1. A method for automatically generating UML sequence diagrams compatible with multi-language code analysis, characterized in that: The following steps are involved: Step S1: by capturing the features of C++ and Java codes, confirming the code types of each part of the mixed source code, and analyzing different types of codes; Step S2: Match the C++ code with a regular expression to match the keywords, class information and inheritance information of the C++ source code to be analyzed, and convert them into parameter names; Step S3: Analyze the Java code marked as grammar and lexical, and extract the class information and method call information of the Java source code to be analyzed; Step S4: According to the parameter names extracted from the C++ source code to be analyzed and the class information extracted from the Java source code, the information is integrated through an algorithm to generate the corresponding Plant UML code; Step S5: Using the Plant UML tool, draw the generated Plant UML code into a UML comprehensive sequence diagram.

2. The method for automatically generating a UML sequence diagram compatible with multilingual code analysis according to claim 1, characterized in that: Step S2 includes: Match the code marked as C++ with regular expressions, including the keywords, class information and inheritance information of the C++ source code, sort the successfully matched keywords, class names, class members and inheritance information call parameters, store the extracted call information in a list, traverse each element, split it into callers and callees, and split the callee's parameter list into parameter names.

3. The method for automatically generating a UML sequence diagram compatible with multilingual code analysis according to claim 2, characterized in that: Step S3 includes: The Java code marked as grammar and lexical analysis is used to convert the Java source code to be analyzed into a word sequence through lexical analysis, and then converted into a structured grammar through grammatical analysis. The abstract syntax tree is constructed at a deeper level, and the class information and method call information are extracted by traversing the class declaration node and its method subnodes in the abstract syntax tree.

4. The method for automatically generating a UML sequence diagram compatible with multi-language code analysis according to claim 3, characterized in that: Step S4 includes: According to 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 these character information are integrated through the Plant UML code generation algorithm to generate Plant UML code that can automatically draw UML timing diagrams.

5. The method for automatically generating a UML sequence diagram compatible with multi-language code analysis according to claim 4, 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 calling relationship between methods of classes is represented by arrows to represent message passing. The starting point of the arrow is the class that calls the method, and the end point is the class of the called method. The interaction between the two language codes is also transmitted through arrows.

Citation Information

Patent Citations

  • Programming language capable of cross-language reusing

    CN102880452A

  • Method and device for drawing program flow chart, computer system and medium

    CN110764760A

  • Code generation method supporting complex model structure conversion

    CN113626026A

  • Code analysis method and device and electronic equipment

    CN116257243A

  • Industrial protocol software source code vulnerability detection and positioning method based on association diagram

    CN117744085A