Code generation method and system, electronic equipment and storage medium
By converting the function configuration table into a code logic table and performing the graph tree construction processing, the problem of developers in the existing technology that manually write and maintain duplicate functional modules is solved, and the efficiency and complexity of code generation are improved.
Patent Information
- Application Number
- CN202411709169.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2044-11-27
AI Technical Summary
In the prior art, developers need to manually write and maintain duplicate functional modules, resulting in the inability to share common code between projects, increasing duplicate work and waste of resources. At the same time, traditional code development is complex, increasing the difficulty of getting started, and affecting the efficiency of code generation.
A code generation method is proposed, by obtaining the function configuration table, converting it into a code logic table, and performing graphic tree construction processing, displaying the editing interface, and programming in the programming canvas in response to operation instructions, generating an extensible markup language file, and finally obtaining the target code.
Through visual operations and modular design, the function calling process is simplified and the code is generated quickly, which reduces the workload of developers and improves the efficiency of code generation.
Smart Images

Figure CN119739370A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a code generation method, system, electronic device and storage medium. Background Art
[0002] In the related technologies, developers need to manually write and maintain repeated functional modules, which results in the inability to share common codes between projects, increasing duplication of work and waste of resources. In addition, traditional code development requires developers to master various underlying libraries and tools, which increases the complexity and entry difficulty of project development, limits the use of non-professionals, and affects the efficiency of code generation. In summary, the technical problems existing in the related technologies need to be improved. Summary of the invention
[0003] The main purpose of the embodiments of the present application is to provide a code generation method, system, electronic device and storage medium, which can improve the efficiency of code generation.
[0004] To achieve the above purpose, an embodiment of the present application provides a code generation method, the method comprising:
[0005] Obtain a function configuration table, and convert the function configuration table into a code logic table;
[0006] Performing a graphic tree construction process on the code logic table to obtain a function graphic tree;
[0007] Display an editing interface, the editing interface including the function graph tree and a programming canvas;
[0008] In response to the target operation instruction, programming the nodes of the function graph tree in the programming canvas to generate an extensible markup language file;
[0009] The extensible markup language file is subjected to code generation processing to obtain a target code.
[0010] In some embodiments, converting the function configuration table into a code logic table comprises the following steps:
[0011] Classify the function configuration table according to function functions and application scenarios to obtain a classification configuration table;
[0012] The classification configuration table is numbered and subjected to control logic conversion processing to obtain the code logic table.
[0013] In some embodiments, the step of performing a graphic tree construction process on the code logic table to obtain a function graphic tree comprises the following steps:
[0014] Performing object conversion processing on the code logic table to obtain a table data structure object;
[0015] Sorting the table data structure object to obtain a preprocessed data set;
[0016] The preprocessed data set is subjected to instance adding processing according to the tree control to obtain the function graphic tree.
[0017] In some embodiments, the sorting of the table data structure objects to obtain a preprocessed data set includes the following steps:
[0018] Performing hierarchical processing on the table data structure objects according to the serial numbers to obtain hierarchical data;
[0019] Sub-category search and sequence number sorting are performed on the hierarchical data to obtain the pre-processed data set.
[0020] In some embodiments, in response to the target operation instruction, programming the nodes of the function graph tree in the programming canvas to generate an extensible markup language file includes the following steps:
[0021] In response to a drag operation instruction for the function graphic tree, dragging a tree node of the function graphic tree to the programming canvas;
[0022] In response to a click operation instruction on the tree node, displaying a function parameter panel in the editing interface;
[0023] In response to an editing operation instruction for the function parameter panel, parameter editing processing is performed on the function parameter panel to generate the extensible markup language file.
[0024] In some embodiments, the step of performing parameter editing processing on the function parameter panel to generate the extensible markup language file includes the following steps:
[0025] Perform parameter editing processing on the function parameter panel to obtain a tree control object;
[0026] Perform parameter transfer processing on the root node of the tree control object to obtain a document object;
[0027] The document object is saved according to the write function to generate the extensible markup language file.
[0028] In some embodiments, the code generation process is performed on the extensible markup language file to obtain the target code, including the following steps:
[0029] Reading and processing the extensible markup language file to obtain an element node object;
[0030] Performing attribute parsing on the element node object to obtain a function name and function parameters;
[0031] The function name and the function parameters are subjected to code concatenation processing to generate the target code.
[0032] To achieve the above object, another aspect of the embodiment of the present application provides a code generation system, the system comprising:
[0033] The first module is used to obtain a function configuration table and convert the function configuration table into a code logic table;
[0034] The second module is used to perform a graphic tree construction process on the code logic table to obtain a function graphic tree;
[0035] A third module is used to display an editing interface, wherein the editing interface includes the function graph tree and a programming canvas;
[0036] A fourth module is used for, in response to a target operation instruction, programming the nodes of the function graph tree in the programming canvas to generate an extensible markup language file;
[0037] The fifth module is used to perform code generation processing on the extensible markup language file to obtain the target code.
[0038] To achieve the above-mentioned purpose, another aspect of an embodiment of the present application provides an electronic device, the electronic device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the above-mentioned method when executing the computer program.
[0039] To achieve the above objective, another aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described above is implemented.
[0040] The embodiments of the present application include at least the following beneficial effects: the present application provides a code generation method, system, electronic device and storage medium, which converts the function configuration table into a code logic table by obtaining a function configuration table; performs a graphic tree construction process on the code logic table to obtain a function graphic tree; displays an editing interface, the editing interface includes a function graphic tree and a programming canvas; in response to a target operation instruction, the nodes of the function graphic tree are programmed in the programming canvas to generate an extensible markup language file; the extensible markup language file is code generated to obtain a target code. The embodiments of the present application can simplify the function calling process and quickly generate code through visual operation and modular design, reduce the workload of developers, and improve the efficiency of code generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 is a flow chart of a code generation method provided by an embodiment of the present application;
[0042] Figure 2 is a schematic diagram of a function graph tree provided in an embodiment of the present application;
[0043] Figure 3 is a schematic diagram of an editing interface provided in an embodiment of the present application;
[0044] Figure 4 It is a schematic diagram of the structure of the code generation system provided in the embodiment of the present application;
[0045] Figure 5 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described in detail below in conjunction with the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the embodiments of the present application. They are only examples of systems and methods consistent with some aspects of the embodiments of the present application as detailed in the attached claims.
[0047] It is understood that the terms "first", "second", etc. used in this application can be used to describe various concepts in this article, but unless otherwise specified, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another concept. For example, without departing from the scope of the embodiment of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the words "if" and "if" as used herein can be interpreted as "at the time of" or "when" or "in response to determination".
[0048] The terms "at least one", "multiple", "each", "any", etc. used in this application, at least one includes one, two or more, multiple includes two or more, each refers to each of the corresponding multiple, and any refers to any one of the multiple.
[0049] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0050] Before describing the embodiments of the present application in detail, some nouns and terms involved in the embodiments of the present application are first described. The nouns and terms involved in the embodiments of the present application are subject to the following explanations.
[0051] 1) Extensible Markup Language (XML) is a markup language used to store and transmit data. It is mainly used to define custom data structures so that different applications can share information more easily.
[0052] 2) Graphical User Interface (GUI), also known as graphical user interface, refers to a computer operation user interface that is displayed in graphical form, allowing users to use input devices such as a mouse to manipulate icons or menu options on the screen to select commands, call files, start programs, or perform other daily tasks.
[0053] 3) Python is a high-level, general-purpose, interpreted programming language that provides efficient high-level data structures and simple and effective object-oriented programming.
[0054] 4) Integrated Development Environment (IDE) is an application used to provide a program development environment, generally including tools such as code editors, compilers, debuggers, and graphical user interfaces.
[0055] In the related art, when using Python to develop projects, it is usually necessary to rely on an integrated development environment (IDE) for code writing. One of the most popular IDEs currently is PyCharm. When creating a project in PyCharm, you first need to define the project name and storage directory. At this time, the created project is an empty project. Next, you need to write or introduce various components, such as database read and write components and application programming interface components (API). Although there are many basic libraries available, these libraries often need to be encapsulated and customized by the project team to meet specific functional requirements. This approach often leads to a long project cycle and makes it difficult to reuse components.
[0056] For example, in traditional development, developers need to manually write and maintain duplicate functional modules, which results in the inability to share common code between projects, increases duplication of work and waste of resources, and often causes application crashes or abnormal terminations, resulting in poor application stability and affecting the user experience. When multiple project teams use the same function, any changes to the source function must be updated synchronously in all projects, which is not only inefficient but also prone to version inconsistencies and errors. Traditional code development requires developers to master various underlying libraries and tools, which increases the complexity and entry difficulty of project development and limits the use of non-professionals.
[0057] In view of this, a code generation method, system, electronic device and storage medium are provided in the embodiments of the present application. The scheme converts the function configuration table into a code logic table by acquiring a function configuration table; performs a graphic tree construction process on the code logic table to obtain a function graphic tree; displays an editing interface, the editing interface includes a function graphic tree and a programming canvas; in response to a target operation instruction, the nodes of the function graphic tree are programmed in the programming canvas to generate an extensible markup language file; and performs code generation process on the extensible markup language file to obtain a target code. The embodiments of the present application can simplify the function calling process and quickly generate code through visual operation and modular design, reduce the workload of developers, and improve the efficiency of code generation.
[0058] The code generation method provided in the embodiment of the present application relates to the field of computer technology. The code generation method provided in the embodiment of the present application can be applied to a terminal, can also be applied to a server, and can also be software running in a terminal or a server. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, and a car terminal, etc., but is not limited to this; the server side can be configured as an independent physical server, or it can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured to provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and cloud servers for basic cloud computing services such as big data and artificial intelligence platforms. The server can also be a node server in a blockchain network; the software can be an application that implements the code generation method, etc., but is not limited to the above forms.
[0059] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0060] Figure 1 is an optional flowchart of the code generation method provided in the embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S105.
[0061] Step S101, obtaining a function configuration table, and converting the function configuration table into a code logic table;
[0062] Step S102, performing a graphic tree construction process on the code logic table to obtain a function graphic tree;
[0063] Step S103, displaying an editing interface, wherein the editing interface includes the function graph tree and a programming canvas;
[0064] Step S104, in response to the target operation instruction, programming the nodes of the function graph tree in the programming canvas to generate an extensible markup language file;
[0065] Step S105, performing code generation processing on the extensible markup language file to obtain target code.
[0066] Steps S101 to S105 shown in the embodiment of the present application are obtained by obtaining a manually maintained function configuration table, which includes relevant data that each function needs to be configured, such as function code, category, etc., and then using Python code to convert the function configuration table into a code logic table. A function graphic tree is obtained by performing a graphic tree construction process on the code logic table, and the function graphic tree includes multiple different functions and is displayed in the form of a tree. An editing interface is displayed on the screen of the terminal, and the editing interface includes a function graphic tree and a programming canvas. The function graphic tree can be arranged on the left side of the programming canvas, that is, on the left side of the screen, and the programming canvas can be arranged in the center of the screen. In response to the target operation instruction, the nodes of the function graphic tree are programmed in the programming canvas to generate an extensible markup language file. The target operation instruction is the user's operation instruction for the editing interface, which may include operations such as dragging and clicking the mouse, and may also include editing operations such as keyboard input. Finally, the generated extensible markup language file is parsed to generate the target code. The embodiment of the present application helps developers drag the nodes of the function graphic tree to the canvas according to the rules, and can generate the target code according to the business logic construction process, thereby quickly completing the development of the project and improving the efficiency of code generation.
[0067] In step S101 of some embodiments, converting the function configuration table into a code logic table includes the following steps:
[0068] Classify the function configuration table according to function functions and application scenarios to obtain a classification configuration table;
[0069] The classification configuration table is numbered and subjected to control logic conversion processing to obtain the code logic table.
[0070] In an embodiment of the present application, the preset function can be configured through an Excel file to obtain a function configuration table. The function configuration table is a manually maintained table, which is mainly used for easy management, but cannot be directly used to generate a graphical tree. In a feasible embodiment, the function configuration table includes field names, interpretations and specific data. For example, the field name can include a primary classification, a secondary classification, a tertiary classification, a function code, whether it is an activity, whether it can be included and an icon. The interpretation is used to explain each field name, wherein the primary classification is the highest level classification for building a tree diagram, the secondary classification is the secondary classification for building a graphical tree, and is a subclass of the primary classification. The tertiary classification is the classification of functions, and each classification identifies a function. The function code is the unique code of the function. Whether it is an activity indicates yes if it is a third-level classification, otherwise it is no; whether it can be included indicates whether this activity can be put into other functions, and the icon indicates the displayed icon name or the corresponding save path. Specifically, "system" is a primary classification, and the "system" includes the secondary classification "file", and "file" includes two third-level classifications: "create folder" and "does the path exist".
[0071] Specifically, the function configuration table is classified according to the function function and application scenario to obtain a classification configuration table, which is obtained by numbering the classification configuration table and converting the control logic. The id and parent_id fields are added to the classification configuration table to store the relationship between the first-level classification and the second-level classification, and the relationship between the second-level classification and the third-level classification. The specific rules are as follows: The first-level classification defines a unique id starting from 1 and increases successively (1, 2, 3...), and their parent_id (parent id) is set to 0. The id of the second-level classification increases following the id of the first-level classification, and the id of the third-level classification increases following the id of the second-level classification. The parent_id of the second-level classification points to the id of the corresponding first-level classification according to the relationship in the function configuration table, and the parent_id of the third-level classification points to the id of the second-level classification, ensuring that the correct hierarchical relationship is established with the corresponding parent-child nodes. The embodiment of the present application can obtain a classification configuration table by converting using python code, and the conversion code is as follows:
[0072]
[0073]
[0074] When configuring functions in the embodiment of the present application, it is necessary to group functions according to functional categories and set the properties of each function. Function properties may include function name, function code, whether it is active, whether it can be included, etc. Among them, the corresponding control logic is set for each field, wherein the first-level classification is the highest level classification of the function graphic tree, and the second-level classification is a subcategory under the first-level classification, which is mainly divided by functional type. For example, under the first-level classification of [application software integration], [Excel] and [PDF] belong to the second-level classification, indicating that they process different document types. The third-level classification refers to the callable function, which can be directly dragged to the canvas for graphical programming, while the first and second levels cannot be dragged. The function code defines a unique code for the third-level classification (i.e., a specific function), which is also used as the function name in the Python code. The Python code generated by the process file written by the canvas can be executed normally. The core principle is that the code in the graphic tree corresponds to the function name in the written function library one by one, so as to ensure that the generated code can accurately call the corresponding function. It should be noted that the first-level and second-level classifications are only used for organization and classification, and do not contain function codes. Whether it is an activity can be understood as an identification field of the three-level classification. In the function configuration table, if it is a three-level classification, it is marked as "yes" otherwise it is left blank. When converted into a code logic table, it is marked as 1 if it is an activity, otherwise it is marked as 0. Whether it can be included indicates whether this function can be placed in other functions in the node after being dragged to the canvas. It can be included if other functions can be placed in it, and it cannot be included if other functions cannot be placed in it. The icon indicates the file name of the icon displayed on the graphical tree of the function, which is used to bind the icon when generating the tree to improve the recognition of the function. A serial number field can be added in the code logic table to indicate the serial number when the program is converted, starting from 0 and increasing.
[0075] One of the above technical solutions has the following advantages or beneficial effects: the embodiment of the present application obtains a code logic table by classifying the function configuration table and converting the control logic, and can convert the manually configured function configuration table into a format recognizable by the programming language, thereby facilitating subsequent code generation processing and improving data processing efficiency.
[0076] In step S102 of some embodiments, the processing of constructing a graphic tree on the code logic table to obtain a function graphic tree includes the following steps:
[0077] Performing object conversion processing on the code logic table to obtain a table data structure object;
[0078] Sorting the table data structure object to obtain a preprocessed data set;
[0079] The preprocessed data set is subjected to instance adding processing according to the tree control to obtain the function graphic tree.
[0080] In an embodiment of the present application, a third-party library of Python language can be used, such as Pandas library, to read control configuration data from the code logic table, and convert it into a table data structure object that can be processed by Python language, i.e., DataFrame object, wherein DataFrame is one of the core data structures in Pandas, used to represent two-dimensional tabular data. It is similar to an Excel spreadsheet or SQL table, with rows and columns. Each column can contain different data types, such as integers, floating-point numbers, strings, or Boolean values. The table data structure object is sorted by the number in the code logic table to obtain a pre-processed data set. Finally, the pre-processed data set is processed by adding an instance to obtain a function graph tree according to the tree control, wherein the tree control can use QTreeWidget control, and the tree node is composed of QTreeWidgetItem control. QTreeWidget control is a tree control, which can display the inclusion relationship between data (or files) in a tree structure, and it is customary to refer to each piece of data in the tree structure as a node. In the QTreeWidget control, each node is an instance object of the QTreeWidgetItem class. That is to say, the QTreeWidget object represents the entire tree control, and the QTreeWidgetItem object represents the node in the tree control. Therefore, the process of building a function graphic tree is actually the process of continuously adding QTreeWidgetItem instances to the tree, extracting the fields in the preprocessed data set filtered out by the preprocessing, and then creating QTreeWidgetItem instances one by one, and setting some control properties for these instances, such as icon path, whether dragging is allowed, whether other nodes can be included, etc. When creating a tree node instance, you need to pass in the corresponding parent node instance to automatically establish the binding relationship between the parent and child nodes without manual processing. When all function nodes are created recursively, the function graphic tree is constructed, such as Figure 2 As shown, Figure 2 is a schematic diagram of a function graph tree provided in an embodiment of the present application, Figure 2 In the figure, reference numeral 201 indicates a primary classification, reference numeral 202 indicates a secondary classification, and reference numeral 203 indicates a tertiary classification.
[0081] One of the above technical solutions has the following advantages or beneficial effects: the embodiment of the present application obtains a function graphic tree by performing a graphic tree construction process on the code logic table, and can display the function in the form of a graphic tree, thereby facilitating subsequent visualization operations, and can quickly state the corresponding code according to the function graphic tree, thereby improving the code generation efficiency.
[0082] In some embodiments, the sorting of the table data structure objects to obtain a preprocessed data set includes the following steps:
[0083] Performing hierarchical processing on the table data structure objects according to the serial numbers to obtain hierarchical data;
[0084] Sub-category search and sequence number sorting are performed on the hierarchical data to obtain the pre-processed data set.
[0085] In an embodiment of the present application, the table data structure object is preprocessed to construct a tree structure, which needs to be constructed layer by layer, starting from the trunk and then extending to the branches and leaves. First, the first-level classification table data structure objects with a parent_id of 0 are screened out and sorted according to the serial number. The smaller the serial number, the closer the classification is displayed in the tree. After completing the data screening, proceed to the next step of building a tree node. After processing the first-level classification, search for the corresponding subclass based on the id of the first-level classification. The search logic is: the parent_id of the subclass is equal to the id of the parent class. Then, sort the subclass data and build the corresponding tree nodes. Repeat this process until all the data of the three-level classifications are processed and the preprocessed data set is obtained.
[0086] One of the above technical solutions has the following advantages or beneficial effects: the embodiment of the present application can quickly match and generate corresponding instances for subsequent graphic tree construction by sorting the table data structure objects, thereby improving the efficiency of generating function graphic trees.
[0087] In step S104 of some embodiments, in response to the target operation instruction, programming the nodes of the function graph tree in the programming canvas to generate an extensible markup language file includes the following steps:
[0088] In response to a drag operation instruction for the function graphic tree, dragging a tree node of the function graphic tree to the programming canvas;
[0089] In response to a click operation instruction on the tree node, displaying a function parameter panel in the editing interface;
[0090] In response to an editing operation instruction for the function parameter panel, parameter editing processing is performed on the function parameter panel to generate the extensible markup language file.
[0091] In the embodiments of this application, please refer to Figure 3 , Figure 3In the figure, reference numeral 301 represents a function graph tree, reference numeral 302 represents a programming canvas, and reference numeral 303 represents a function parameter panel. In response to the drag operation instruction of the function graph tree, the tree node of the function graph tree is dragged to the programming canvas. Specifically, the user only needs to press and hold the left mouse button to generate a drag operation instruction, and drag the node in the tree structure to the programming canvas on the right to complete the operation. This method greatly reduces the complexity of programming and makes function calls more intuitive. Then in response to the click operation instruction of the tree node, the function parameter panel is displayed in the editing interface. When the user clicks the node in the canvas, that is, clicks the corresponding function, the function parameter panel will be displayed. The function parameter panel is used to display the parameters required for the function. Among them, the function parameter panel needs to be created in advance, and can be specifically designed by the PyQt5 interface editor. In response to the editing operation instruction of the function parameter panel, the function parameter panel is processed by parameter editing to generate an extensible markup language file. The user can enter the necessary parameters for the function according to the actual situation. For example, for the function of "opening a browser", the parameters that must be entered include the website (URL) and the browser type.
[0092] One of the above technical solutions has the following advantages or beneficial effects: The embodiment of the present application helps developers quickly select and reuse existing function libraries through visual drag-and-drop operations and modular design, avoiding reinventing the wheel, thereby simplifying the code writing process. It also allows developers to complete the construction of complex functions through interface operations without having to deeply understand the underlying code logic, thereby improving the efficiency and reliability of project development, while minimizing code redundancy, reducing maintenance costs, and improving code generation efficiency.
[0093] In some embodiments, the step of performing parameter editing processing on the function parameter panel to generate the extensible markup language file includes the following steps:
[0094] Perform parameter editing processing on the function parameter panel to obtain a tree control object;
[0095] Perform parameter transfer processing on the root node of the tree control object to obtain a document object;
[0096] The document object is saved according to the write function to generate the extensible markup language file.
[0097] In an embodiment of the present application, a program compiled with a canvas will be saved as an XML (Extensible Markup Language) file. Specifically, a tree control object can be obtained by editing the parameters of the function parameter panel. It exists in the form of a QTreeWidget object. A QTreeWidget object contains many QTreeWidgetItem objects (i.e., functions), which are converted into an XML file by the QTreeWidget object. It should be noted that a required check mark field (required) is stored in the QTreeWidgetItem object. If it is empty, it is not required. If it is 1, it is required. A third-party Python library, such as the Element object of the lxml library, is used to generate a root element as the root node of this XML file. Among them, the Element object corresponds to the HTML tag element of the web page. Each HTML tag element will be converted into an Element node object on the DOM tree. Write a recursive method, pass the root node of the QTreeWidget object and the root node of the XML file as parameters to this recursive method, this method will generate a complete XML document object, the XML document object has a write function (write method), you can save the document object as an XML file, enter the save path and call the write function to generate an extensible markup language file. Specifically, the code of the recursive method is as follows:
[0098]
[0099]
[0100] One of the above technical solutions has the following advantages or beneficial effects: The embodiment of the present application generates an extensible markup language file in the programming canvas by performing parameter editing processing in the function parameter panel, which can significantly simplify the function calling process through a graphical operation interface and greatly improve development efficiency.
[0101] In some embodiments, the code generation process is performed on the extensible markup language file to obtain the target code, including the following steps:
[0102] Reading and processing the extensible markup language file to obtain an element node object;
[0103] Performing attribute parsing on the element node object to obtain a function name and function parameters;
[0104] The function name and the function parameters are subjected to code concatenation processing to generate the target code.
[0105] In the embodiment of the present application, the XML file of the flowchart is read out using the python third-party library lxml to obtain an operable Element object, that is, an element node object. Then, the element node object is subjected to attribute parsing processing. <action>The code attribute of the element can get the function name, and then <action>Child elements of an element <attrs>Also read, in the child element <attrs>It also contains many <attr>element, <attr>Elements are function parameters. After obtaining the function name and function parameters, the function name and parameters can be spliced into Python code. Since these functions are already written, the Python code can be run directly. In the embodiment of the present application, the running results of the code can be displayed in the programming canvas.
[0106] One of the above technical solutions has the following advantages or beneficial effects: the embodiment of the present application generates an extensible markup language file through graphical programming, and then converts the extensible markup language file into target code, which can simplify the code writing process and improve the code generation efficiency.
[0107] The following is a detailed description of the embodiments of the present invention with reference to specific application examples:
[0108] The embodiment of the present application can be applied to the field of computer technology, and is suitable for the generation scenario of the code project. The developer needs to edit and generate the code. By pre-building a graphical function tree, the function graphical tree and the programming canvas are displayed in the editing interface. The developer only needs to drag the required function to the programming canvas, and then click Save to generate an executable code file. This method is not only suitable for professional software developers, but also for ordinary users. The embodiment of the present application simplifies the function call process through graphical operations, significantly improves development efficiency, and reduces the repetition of writing the same code. Functions can also be centrally managed and updated, and functions can be quickly and accurately modified synchronously in the project without modifying the calling code one by one. In addition, the embodiment of the present application simplifies the project development process through a visual development method, so that users only need to drag and configure parameters to complete the project, which greatly reduces the difficulty of development.
[0109] See also Figure 4 The embodiment of the present application also provides a code generation system, which can implement the above code generation method, and the system includes:
[0110] The first module 401 is used to obtain a function configuration table and convert the function configuration table into a code logic table;
[0111] The second module 402 is used to perform a graphic tree construction process on the code logic table to obtain a function graphic tree;
[0112] The third module 403 is used to display an editing interface, wherein the editing interface includes the function graph tree and a programming canvas;
[0113] The fourth module 404 is used to program the nodes of the function graph tree in the programming canvas in response to the target operation instruction to generate an extensible markup language file;
[0114] The fifth module 405 is used to perform code generation processing on the extensible markup language file to obtain target code.
[0115] It can be understood that the contents of the above method embodiments are all applicable to the present system embodiments, the functions specifically implemented by the present system embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0116] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above code generation method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0117] It can be understood that the contents of the above method embodiments are all applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0118] See also Figure 5 , Figure 5 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0119] The processor 501 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0120] The memory 502 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 502 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 502, and the processor 501 calls and executes the code generation method of the embodiment of this application;
[0121] Input / output interface 503, used to implement information input and output;
[0122] Communication interface 504, used to realize communication interaction between the device and other devices, which can be realized by wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.);
[0123] A bus 505 that transmits information between the various components of the device (e.g., the processor 501, the memory 502, the input / output interface 503, and the communication interface 504);
[0124] The processor 501 , the memory 502 , the input / output interface 503 and the communication interface 504 are connected to each other in communication within the device via the bus 505 .
[0125] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned code generation method is implemented.
[0126] It can be understood that the contents of the above method embodiments are all applicable to the present storage medium embodiments, the functions specifically implemented by the present storage medium embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0127] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0128] The embodiment of the present application provides a code generation method, system, electronic device and storage medium. The scheme obtains a function configuration table, converts the function configuration table into a code logic table; performs a graphic tree construction process on the code logic table to obtain a function graphic tree; displays an editing interface, the editing interface includes a function graphic tree and a programming canvas; responds to a target operation instruction, performs programming processing on the nodes of the function graphic tree in the programming canvas to generate an extensible markup language file; performs code generation processing on the extensible markup language file to obtain a target code. The embodiment of the present application can simplify the function calling process and quickly generate code through visual operation and modular design, reduce the workload of developers, and improve the efficiency of code generation.
[0129] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0130] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0131] The system embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0132] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0133] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0134] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or plural.
[0135] In the several embodiments provided in the present application, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or units, which can be electrical, mechanical or other forms.
[0136] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0137] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0138] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0139] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.< / attr> < / attr> < / attrs> < / attrs> < / action> < / action>
Claims
1. A code generation method, characterized in that: The method comprises the following steps: Obtain a function configuration table, and convert the function configuration table into a code logic table; Performing a graphic tree construction process on the code logic table to obtain a function graphic tree; Display an editing interface, the editing interface including the function graph tree and a programming canvas; In response to the target operation instruction, programming the nodes of the function graph tree in the programming canvas to generate an extensible markup language file; The extensible markup language file is subjected to code generation processing to obtain a target code.
2. The method according to claim 1, characterized in that: The step of converting the function configuration table into a code logic table comprises the following steps: Classify the function configuration table according to function functions and application scenarios to obtain a classification configuration table; The classification configuration table is numbered and subjected to control logic conversion processing to obtain the code logic table.
3. The method according to claim 1, characterized in that The process of constructing a graphic tree for the code logic table to obtain a function graphic tree comprises the following steps: Performing object conversion processing on the code logic table to obtain a table data structure object; Sorting the table data structure object to obtain a preprocessed data set; The preprocessed data set is subjected to instance adding processing according to the tree control to obtain the function graphic tree.
4. The method according to claim 3, characterized in that The process of sorting the table data structure objects to obtain a preprocessed data set includes the following steps: Performing hierarchical processing on the table data structure objects according to the serial numbers to obtain hierarchical data; Sub-category search and sequence number sorting are performed on the hierarchical data to obtain the pre-processed data set.
5. The method according to claim 1, characterized in that In response to the target operation instruction, programming the nodes of the function graph tree in the programming canvas to generate an extensible markup language file includes the following steps: In response to a drag operation instruction for the function graphic tree, dragging a tree node of the function graphic tree to the programming canvas; In response to a click operation instruction on the tree node, displaying a function parameter panel in the editing interface; In response to an editing operation instruction for the function parameter panel, parameter editing processing is performed on the function parameter panel to generate the extensible markup language file.
6. The method according to claim 5, characterized in that The step of performing parameter editing processing on the function parameter panel to generate the extensible markup language file comprises the following steps: Perform parameter editing processing on the function parameter panel to obtain a tree control object; Perform parameter transfer processing on the root node of the tree control object to obtain a document object; The document object is saved according to the write function to generate the extensible markup language file.
7. The method according to any one of claims 1 to 5, characterized in that: The code generation process of the extensible markup language file to obtain the target code comprises the following steps: Reading and processing the extensible markup language file to obtain an element node object; Performing attribute parsing on the element node object to obtain a function name and function parameters; The function name and the function parameters are subjected to code concatenation processing to generate the target code.
8. A code generation system, characterized in that: The system comprises: The first module is used to obtain a function configuration table and convert the function configuration table into a code logic table; The second module is used to perform a graphic tree construction process on the code logic table to obtain a function graphic tree; A third module is used to display an editing interface, wherein the editing interface includes the function graph tree and a programming canvas; A fourth module is used for, in response to a target operation instruction, programming the nodes of the function graph tree in the programming canvas to generate an extensible markup language file; The fifth module is used to perform code generation processing on the extensible markup language file to obtain the target code.
9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Low-code development method and device, equipment and storage medium
CN115712413A
Visualization method for dynamic function call
CN115952230A
Test case editing method, electronic equipment and readable storage medium
CN117194227A
Cloud-based indexing for integrated development environments
US8667456B1