A code generation method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202310152269.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-14
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2043-02-14
AI Technical Summary
在开发平台内往往会出现同一份逻辑代码需要在不同的类中重新编写的情况,任何需求变化都需要修改代码,代码的重用率较低,这就导致在后续修改维护和扩展代码时,需要耗费大量的精力
[0020]响应于在低代码开发平台中添加第一类并为第一类选择包括嵌套类的第一父类进行继承的操作,生成第一特定领域语言DSL声明语句;第一DSL声明语句包括第一类的类信息和第一嵌套字段,第一嵌套字段中包括第一嵌套类的类信息,第一嵌套类为第一类继承自第一父类的嵌套类,根据第一DSL声明语句中的第一类的类信息,生成第一类的声明代码。即通过上述步骤可以实现根据在低代码开发平台中添加第一类并为第一类选择包括嵌套类的第一父类进行继承的操作,生成第一特定领域语言DSL声明语句,接着根据第一DSL声明语句中的第一类的类信息生成第一类的声明代码。然后,检测第一DSL声明语句中是否存在包括嵌套类的类信息的嵌套字段,当检测第一DSL声明语句中存在包括第一嵌套类的类信息的第一嵌套字段时,根据第一嵌套类的类信息,生成相对于第一类的声明代码缩进的第一嵌套类的声明代码,这样,就生成了带嵌套类的声明代码。
Smart Images

Figure CN116107569B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and more specifically to a code generation method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] In the field of front-end web development, low-code development platforms (LCDPs) are development platforms that allow for the rapid generation of applications with little or no code. Visual front-end development enables developers of varying experience levels to create web pages using drag-and-drop components and model-driven logic through a graphical user interface. However, this low-code development approach is typically used for pages with simple layouts and uncomplicated component interactions, such as marketing campaign pages, forms, tables, and reports. For projects with more complex logic flows, such as game server development or large-scale software development, code development is usually required.
[0003] In low-code products, data organization and functionality are often based on classes (or objects and entities). Within the development platform, the same logic code often needs to be rewritten in different classes. Any change in requirements necessitates code modification, resulting in low code reusability. This leads to significant effort required for subsequent modifications, maintenance, and expansions. Furthermore, code writing, such as Python code, typically has strict syntax and logic, demanding a high level of expertise from developers. Syntax or logical errors can cause program malfunctions, potentially leading to crashes and extending development time, thus impacting development efficiency. Summary of the Invention
[0004] This application provides a code generation method, apparatus, electronic device, and computer-readable storage medium. When a user adds a class on a low-code platform, they select a parent class (including nested classes) for inheritance. This generates corresponding nested class DSL statements with inheritance relationships. Based on these DSL statements, code containing nested classes is generated. By using class inheritance, the same logic code is avoided from being rewritten in different classes, improving code reusability. Furthermore, by first generating DSL statements with nested classes based on user actions, and then generating code from these statements, users are not required to directly write code with strict syntax and logic, reducing the demands on developers, shortening development time, and improving development efficiency.
[0005] In a first aspect, embodiments of this application provide a code generation method, the method comprising:
[0006] In response to the operation of adding a first class in the low-code development platform and selecting a first parent class including nested classes for inheritance of the first class, a first domain-specific language (DSL) declaration statement is generated; the first DSL declaration statement includes class information of the first class and a first nested field, the first nested field including class information of the first nested class, the first nested class being a nested class that the first class inherits from the first parent class;
[0007] Based on the class information of the first class in the first DSL declaration statement, generate the declaration code for the first class;
[0008] Detect whether the first DSL declaration statement contains nested fields that include class information of nested classes;
[0009] When a first nested field containing class information of the first nested class is detected in the first DSL declaration statement, the declaration code of the first nested class, which is indented relative to the declaration code of the first class, is generated based on the class information of the first nested class.
[0010] Secondly, embodiments of this application provide a code generation apparatus, the apparatus comprising:
[0011] A generation unit is configured to generate a first domain-specific language (DSL) declaration statement in response to an operation of adding a first class in a low-code development platform and selecting a first parent class including nested classes for inheritance of the first class; the first DSL declaration statement includes class information of the first class and a first nesting field, the first nesting field including class information of the first nested class, the first nested class being a nested class inherited by the first class from the first parent class;
[0012] The generation unit is further configured to generate declaration code for the first class based on the class information of the first class in the first DSL declaration statement;
[0013] The detection unit is used to detect whether there is a nested field in the first DSL declaration statement that includes class information of nested classes;
[0014] The generation unit is further configured to, when the detection unit detects that the first DSL declaration statement contains a first nested field including class information of the first nested class, generate declaration code of the first nested class that is indented relative to the declaration code of the first class, based on the class information of the first nested class.
[0015] Thirdly, embodiments of this application provide an electronic device, including:
[0016] Processor; and
[0017] The memory is used to store a data processing program, which, when the electronic device is powered on and runs through the processor, executes the code generation method as described in the first aspect.
[0018] Fourthly, embodiments of this application provide a computer-readable storage medium storing a data processing program that is executed by a processor to perform the method described in the first aspect.
[0019] Compared with the prior art, this application has the following advantages:
[0020] In response to the operation of adding a first class in the low-code development platform and selecting a first parent class including nested classes for inheritance, a first Domain-Specific Language (DSL) declaration statement is generated. The first DSL declaration statement includes class information for the first class and a first nested field. The first nested field includes class information for the first nested class, which is a nested class inherited by the first class from the first parent class. Based on the class information of the first class in the first DSL declaration statement, declaration code for the first class is generated. That is, through the above steps, the operation of adding a first class in the low-code development platform and selecting a first parent class including nested classes for inheritance can generate a first DSL declaration statement, and then generate declaration code for the first class based on the class information in the first DSL declaration statement. Then, it is checked whether a nested field including class information of a nested class exists in the first DSL declaration statement. When a first nested field including class information of a nested class is detected, declaration code for the first nested class, indented relative to the declaration code of the first class, is generated based on the class information of the nested class. Thus, declaration code with nested classes is generated.
[0021] The code generation method provided in this application generates corresponding nested class DSL statements based on the user's selection of a parent class (including nested classes) for inheritance when adding a class in a low-code platform. Then, it generates code containing nested classes based on these DSL statements. By using class inheritance, the method avoids rewriting the same logic in different classes, improving code reusability. Furthermore, by first generating the nested class DSL statements based on user actions, and then generating code from these statements, the method eliminates the need for users to directly write code with strict syntax and logic, reducing the demands on developers, shortening development time, and improving development efficiency. Attached Figure Description
[0022] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 A flowchart illustrating a code generation method provided in an embodiment of this application;
[0024] Figure 2A , 2B This application provides an embodiment of an operation diagram illustrating the addition of a class in a low-code development platform.
[0025] Figure 3 This application provides a schematic diagram of a process for adding custom functionality to a first nested class in a low-code development platform, as illustrated in an embodiment of the present application.
[0026] Figure 4A , 4B This application provides an embodiment of an operation diagram illustrating the addition of custom functionality to the first nested class of a class in a low-code development platform.
[0027] Figure 5 A flowchart illustrating another code generation method provided in an embodiment of this application;
[0028] Figure 6 A flowchart illustrating another code generation method provided in an embodiment of this application;
[0029] Figure 7 This is a schematic diagram of the structure of a code generation device provided in an embodiment of this application;
[0030] Figure 8 A structural block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0031] Many specific details are set forth in the following description to provide a full understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this application; therefore, this application is not limited to the specific embodiments disclosed below.
[0032] It should be noted that the terms "first," "second," "third," etc., in the claims, specification, and drawings of this application are used to distinguish similar objects and are not used to describe a specific order or sequence. Such data are interchangeable where appropriate so that the embodiments of this application described herein can be implemented in a sequence other than that shown or described herein. Furthermore, the terms "comprising," "having," and their variations are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or apparatuses.
[0033] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, or in one or more software-hardened modules, or in different network and / or processor devices and / or microcontroller devices.
[0034] Before detailing the implementation methods of this application, the relevant technologies will be further introduced first.
[0035] A Domain-Specific Language (DSL) is a language specifically tailored for a particular application, service, framework, or domain. It is written solely based on the concepts and characteristics of that domain and can only be parsed by that domain. Therefore, a DSL is a syntax that describes how programs are generated, their flow structure, and their decision logic within a specific domain. It is easy to understand and can be edited without requiring general programming knowledge. By customizing syntax specifically for a particular program domain, DSLs provide unique productivity, helping users quickly understand certain usages. For example, the operation syntax in MySQL and the query syntax in Elastic Search are based on DSLs, making them easy to learn and use.
[0036] In object-oriented languages, a class is used to describe objects of the same type that share similar behaviors and attributes. Regular classes or top-level classes can be created and exist independently. Nested classes, however, represent objects that depend on and are specific to an outer class. The most important reason for defining nested classes is their independence from each other and the influence of the outer class. Nested classes offer numerous advantages for object-oriented languages: 1. They allow access to all methods and attributes of the outer class, providing greater flexibility and convenience. 2. The implementation of the inner class is hidden from the outside world, concealing details that users don't need to know. 3. They reduce coupling between classes and increase cohesion.
[0037] In the field of front-end web development, low-code development platforms (LCDPs) are development platforms that allow for the rapid generation of applications with little or no code. Visual front-end development enables developers of varying experience levels to create web pages using drag-and-drop components and model-driven logic through a graphical user interface. However, this low-code development approach is typically used for pages with simple layouts and uncomplicated component interactions, such as marketing campaign pages, forms, tables, and reports. For projects with more complex logic flows, such as game server development or large-scale software development, code development is usually required.
[0038] Currently, low-code products often organize data and build functionality based on classes (or objects and entities). Within the development platform, the same logic code often needs to be rewritten in different classes. Any change in requirements necessitates code modification, resulting in low code reusability. This leads to significant effort required for subsequent modifications, maintenance, and expansions. Furthermore, coding, such as Python code, typically has strict syntax and logic, demanding a high level of expertise from developers. Syntax or logical errors can cause program malfunctions, potentially leading to crashes and extending development time, thus impacting efficiency.
[0039] To address the aforementioned problems, this application provides a code generation method, apparatus, electronic device, and storage medium. When a user adds a class in a low-code platform, they select a parent class that includes nested classes for inheritance. This generates corresponding nested class DSL statements with inheritance relationships. Based on these DSL statements, code containing nested classes is generated. By using class inheritance, the same logic code is avoided from being rewritten in different classes, improving code reusability. Furthermore, by first generating DSL statements with nested classes based on user actions, and then generating code from these statements, users are not required to directly write code with strict syntax and logic, reducing the demands on developers, shortening development time, and improving development efficiency. The methods, apparatus, electronic devices, and computer-readable storage media described in this application will be further described in detail below with reference to specific embodiments and accompanying drawings.
[0040] First Embodiment
[0041] Figure 1This is a flowchart illustrating a code generation method provided in an embodiment of this application. It should be noted that the steps shown in this flowchart can be executed in a computer system such as a set of computer-executable instructions, and in some cases, the steps shown can be executed in a logical order different from that shown in the flowchart.
[0042] like Figure 1 As shown, this code generation method includes the following steps:
[0043] 101. In response to the operation of adding a first class in the low-code development platform and selecting a first parent class including nested classes for inheritance, generate a first domain-specific language (DSL) declaration statement.
[0044] In low-code products, data organization and functionality are often built using classes as the basic unit. Users add a first class in the low-code platform and choose a first parent class (including nested classes) to inherit from. Understandably, the first class inherits from the first parent class, and since the first parent class includes nested classes, the first class inherits from the nested classes of the first parent class.
[0045] For example, such as Figure 2A , 2B As shown, Figure 2A , 2B This is a schematic diagram illustrating the operation of adding a class in a low-code development platform provided in an embodiment of this application. Figure 2A In the low-code development platform shown, the user selects entity column 201 on the data page, clicks the operation menu 202 of entity column 201, and the "Add Entity" control 203 appears. This control is user-operable; clicking the "Add Entity" control 203 adds the first type of Actor1 to the low-code platform, such as... Figure 2B As shown, in the drop-down menu, select the first parent class Agent containing nested classes for Actor1. Agent includes two nested classes: recognition and policy. Understandably, when the first class Actor1 inherits from the first parent class Agent, it inherits the two nested classes recognition and policy under the first parent class Agent.
[0046] In response to a user adding a first class in the low-code development platform and selecting a first parent class (including nested classes) for inheritance, a first Domain-Specific Language (DSL) declaration statement is generated. This first DSL declaration statement includes class information for the first class and a first nested field. The first nested field further includes class information for the first nested class, which is a nested class that the first class inherits from the first parent class.
[0047] The first type of class information includes identification information used to describe the first type, such as uid information describing the class id, type information describing the class type, and name information describing the class name, etc.
[0048] The first nested field includes the class identifier and class information of the first nested class. For example, the class identifier of the nested field is the children field, which contains the class information of the first nested class. The class information of the first nested class includes identification information used to describe the first nested class, such as uid information describing the id of the first nested class, type information describing the type of the first nested class, name information describing the class name of the first nested class, etc.
[0049] For example, in the above example, when the first class Actor1 inherits from the first parent class Agent, it inherits the two nested classes cognition and policy from the first parent class Agent. The generated DSL declaration statement can then include the following:
[0050]
[0051] In this example, the first DSL declaration statement includes class information for the first class Actor1 and a first nested field. The class information for Actor1 is uid and name. The first nested field includes the class identifier and class information of the first nested classes recognition and policy. The first nested class is indicated by a nested field, which is the children field. The class information of the first nested class is the uid and name of recognition and policy.
[0052] 102. Generate the declaration code for the first class based on the class information of the first class in the first DSL declaration statement.
[0053] In step 101, a first domain-specific language (DSL) declaration statement is generated, which includes class information of the first class. Next, based on the class information of the first class in the first DSL declaration statement, the declaration code of the first class is generated.
[0054] Understandably, user operations on low-code platforms must be translated into code that computers can execute. The first type of declaration code is computer-executable code, which can be any language that computers can recognize and execute; no restrictions are made here.
[0055] In this embodiment, the declaration code of the first type is illustrated using Python code.
[0056] In Python code, the format for inheritance is:
[0057] class subclass name(parent class name):
[0058] In the example above, if the user adds a first class, Actor1, to the low-code platform and selects Agent, which contains nested classes, as the first parent class, the Python declaration code for generating the first class, Actor1, would be as follows:
[0059] classActor1(Agent):
[0060] 103. Check if there are nested fields in the first DSL declaration statement that include class information of nested classes.
[0061] During the generation of the declaration code for the first class, it is necessary to check whether there is a nested field in the first DSL declaration statement that includes class information of the nested class. In other words, it is necessary to check whether the first DSL declaration statement contains a nested class, which is indicated by the nested field, namely the children field, which includes the class information of the nested class.
[0062] In the example above, the system checks whether the first type of Actor1 inherits from the parent class Agent in the DSL declaration statement generated by the first parent class Agent. Specifically, it checks whether the DSL declaration statement under Actor1 contains the children field and whether the children field contains the class information of the nested class.
[0063] 104. When a first nested field containing class information of a first nested class is detected in the first DSL declaration statement, the declaration code of the first nested class with indentation relative to the declaration code of the first class is generated based on the class information of the first nested class.
[0064] When a first nested field containing class information of the first nested class is detected in the first DSL declaration statement, that is, the first class inherits from the first parent class to the nested class, then the declaration code of the first nested class with indentation relative to the declaration code of the first class is generated based on the class information of the first nested class.
[0065] The declaration code of the first nested class is indented relative to the declaration code of the first class. This is because Python's indentation rules are as follows: for class definitions, function definitions, flow control statements, exception handling statements, etc., the colon at the end of the line and the indentation of the next line indicate the beginning of the next code block, while the end of the indentation indicates the end of this code block. Usually, 4 spaces are used as an indentation amount, and the indentation amount of code blocks at the same level must be the same.
[0066] Using the example above, the detection method for the first type of Actor1, which inherits from the first parent class Agent, includes a `children` field in its DSL declaration statement. This `children` field contains class information for the nested class, specifically the `uid` and `name` of both `cognition` and `policy`. Therefore, the Python declaration code for the first nested class, indented relative to the Python declaration code of the first type of Actor1, could include the following:
[0067] classActor1(Agent):
[0068] classcognition(Agent.cognition)
[0069] class policy(Agent.policy)
[0070] As can be seen in the example above, the indentation of the nested classes `cognition` and `policy` relative to the Python declaration code of the first type `Actor1` is the same. This is because `cognition` and `policy` are both nested classes of the first type `Actor1`, and they are two nested classes at the same level under the first type `Actor1`. Python's code indentation rules stipulate that the indentation of code blocks at the same level must be the same. Therefore, the indentation of the nested classes `cognition` and `policy` relative to the Python declaration code of the first type `Actor1` is the same.
[0071] If the first DSL declaration statement does not contain a first nested field that includes class information for the first nested class (meaning the first class does not inherit from the parent class (i.e., the parent class does not contain the nested class), then the step of generating the nested class declaration line is not executed. Instead, in response to other user operations on the low-code development platform, and if other DSL statements are generated based on these operations, then corresponding code is generated based on these DSL statements, such as code defining class properties and methods.
[0072] In the code generation method provided in this application, in response to the operation of adding a first class in a low-code development platform and selecting a first parent class including nested classes for inheritance, a first domain-specific language (DSL) declaration statement is generated. The first DSL declaration statement includes class information of the first class and a first nested field. The first nested field includes class information of the first nested class, which is a nested class inherited by the first class from the first parent class. Based on the class information of the first class in the first DSL declaration statement, the declaration code of the first class is generated. That is, through the above steps, the operation of adding a first class in a low-code development platform and selecting a first parent class including nested classes for inheritance can be implemented to generate a first domain-specific language (DSL) declaration statement, and then generate the declaration code of the first class based on the class information of the first class in the first DSL declaration statement. Then, it is detected whether there is a nested field including class information of the nested class in the first DSL declaration statement. When a first nested field including class information of the first nested class is detected in the first DSL declaration statement, the declaration code of the first nested class, indented relative to the declaration code of the first class, is generated based on the class information of the first nested class. In this way, the declaration code with nested classes is generated.
[0073] The code generation method provided in this application generates corresponding nested class DSL statements based on the user's selection of a parent class (including nested classes) for inheritance when adding a class in a low-code platform. Then, it generates code containing nested classes based on these DSL statements. By using class inheritance, the method avoids rewriting the same logic in different classes, improving code reusability. Furthermore, by first generating the nested class DSL statements based on user actions, and then generating code from these statements, the method eliminates the need for users to directly write code with strict syntax and logic, reducing the demands on developers, shortening development time, and improving development efficiency.
[0074] In conjunction with the above embodiments, after generating the declaration code for the first nested class in response to the operation of adding a first class in the low-code development platform and selecting a first parent class including nested classes for inheritance, the following describes how to add custom functionality to the first nested class in the low-code development platform. Figure 3 This application provides a flowchart illustrating the process of adding custom functionality to a first nested class in a low-code development platform, as shown in the embodiments of this application. Figure 3 As shown, after step 104 in the above embodiment, adding custom functionality to the first nested class in the low-code development platform includes the following steps:
[0075] 301. In response to the operation of adding custom functionality to the first nested class in the low-code development platform, add a second nested field to the class information of the first nested class in the first nested field of the first DSL declaration statement.
[0076] When a user adds custom functionality to the first nested class of a class in a low-code platform, a second nested field is added to the class information of the first nested class in the first nested field of the first DSL declaration statement.
[0077] For example, such as Figure 4A , 4B As shown, Figure 4A , 4B This is a schematic diagram illustrating the operation of adding custom functionality to the first nested class of a class in a low-code development platform provided in this application embodiment. Figure 4A In the low-code development platform shown, the user can access the "Add Capability" control 403 by clicking the operation menu 402 of the first nested class cognition of class Actor1. This control is user-operable; clicking the "Add Capability" control 403 allows the user to add a custom function cap1 to the first nested class cognition of class Actor1 in the low-code platform. Figure 4B As shown. A second nested field is added to the first nested field, cognition. That is, the second nested class is then shown as a nested field, as mentioned before, the nested field is the children field.
[0078] 302. Add a second DSL declaration statement to the second nested field.
[0079] Add a second DSL declaration statement to the added second nested field. The second DSL declaration statement includes the class information of the second nested class corresponding to the custom function. The second nested class is a nested class of the first nested class.
[0080] The class information of the second nested class includes identification information used to describe the second nested class, such as uid information describing the id of the second nested class, type information describing the type of the nested class, name information describing the class name of the nested class, etc.
[0081] The second nested class corresponding to the custom function includes a second logic nested class for defining the implementation logic of the custom function, a second input nested class for defining the input parameters of the custom function, and a second output nested class for defining the output parameters of the custom function.
[0082] For example, in a low-code platform, a user adds a custom function `cap1` to the first nested class `cognition` of class `Actor1`, along with a second nested logic class defining the logic of the custom function `cap1`, a second nested input class defining the input parameters of the custom function, and a second nested output class defining the output parameters of the custom function. The generated second DSL declaration statement can then include the following:
[0083]
[0084]
[0085] 303. Based on the second DSL declaration statement, generate the declaration code of the second nested class that is indented relative to the declaration code of the first nested class.
[0086] Based on the class information of the second nested class in the second DSL declaration statement, and the nesting relationship between the second nested class and the first nested class, the declaration code of the second logical nested class with indentation relative to the declaration code of the first nested class is generated.
[0087] Generate the declaration code of the second input nested class, indented relative to the declaration code of the first nested class.
[0088] Generates the declaration code of the second output nested class, indented relative to the declaration code of the first nested class.
[0089] Among them, the declaration code of the second logical nested class, the declaration code of the second input nested class, and the declaration code of the second output nested class have the same indentation relative to the declaration code of the first nested class, because the three nested classes of the second logical nested class, the second input nested class, and the second output nested class all belong to the first nested class and are three nested classes of the same level under the first nested class.
[0090] In the example above, the Python declaration code generated when a user adds custom functionality to the first nested class `cognition` of class `Actor1` in a low-code platform might include the following:
[0091]
[0092] Understandably, if the second logical nested class, second input nested class, and second output nested class of the custom function cap1 need to add more nested classes, then a third nested field is added within each of the second nested classes. A third DSL declaration statement is added to the third nested field. The third DSL declaration statement includes the class information of the third nested class. Based on the third DSL declaration statement, the declaration code of the third nested class with indentation relative to the declaration code of the second nested class is generated, and so on.
[0093] Additionally, it should be noted that the DSL statements and Python code mentioned in this application are for illustrative purposes only and are not the actual executable DSL statements and Python code used to implement this application.
[0094] As can be seen, when adding custom functionality to the first nested class in a low-code development platform, the custom functionality is treated as a nested class of the first nested class, and the declaration code is generated based on the nesting relationship. In this way, the relationship between classes can be expressed through nesting. When generating code, appropriate indentation is applied according to the nesting relationship, making the hierarchy and relationships between classes clear.
[0095] Furthermore, in response to the operation of referencing a nested class through a first target class in a low-code development platform, embodiments of this application provide another code generation method. Figure 5 This is a flowchart illustrating another code generation method provided in an embodiment of this application.
[0096] like Figure 5 As shown, this code generation method includes the following steps:
[0097] 501. In response to an operation in a low-code development platform that references a nested class through a first target class, generate a DSL reference statement for the nested class.
[0098] DSL reference statements include the class identifier of the nested class, and a reference identifier that indicates the reference type to the nested class.
[0099] There are two ways for the first target class to reference a nested class:
[0100] Method 1: The first target class directly references the nested class.
[0101] Method 2: Use an instance of the nested class as an attribute of the first target class to reference the nested class.
[0102] Based on the relationship between the first target class and the nested class, generate a DSL reference statement for the nested class, including a reference identifier, in the following two cases:
[0103] 1. The first target class is the outer class of the nested class.
[0104] In Method 1, when the first target class directly references the nested class, if the first target class is the outer class of the nested class, in response to the operation of referencing the nested class through the first target class in the low-code development platform, a DSL reference statement for the nested class including an internal reference identifier is generated. The internal reference identifier is used to indicate that the reference type to the nested class is an internal reference.
[0105] In Method 2, when an instance of a nested class is used as an attribute of the first target class to reference the nested class, if the first target class is the outer class of the nested class, in response to the operation of using an instance of a nested class as an attribute of the first target class to reference the nested class in the low-code development platform, a DSL reference statement for the nested class including an inner reference identifier is generated.
[0106] 2. The first target class is not the outer class of a nested class.
[0107] In Method 1, when the first target class directly references the nested class, if the first target class is not the outer class of the nested class, a DSL reference statement for the nested class is generated in response to the operation of referencing the nested class through the first target class in the low-code development platform. This DSL reference statement includes an outer reference identifier. The outer reference identifier indicates that the reference type to the nested class is an outer reference. The DSL reference statement also includes a classpath, which includes class identifiers at each level from the outermost class of the nested class to the outer class of the nested class.
[0108] In Method 2, when an instance of a nested class is used as an attribute of the first target class to reference the nested class, if the first target class is not the outer class of the nested class, in response to the operation of using an instance of a nested class as an attribute of the first target class to reference the nested class in the low-code development platform, a DSL reference statement for the nested class including an outer reference identifier is generated.
[0109] 502. Determine the search scope based on the type of the reference identifiers included in the DSL reference statement.
[0110] The search scope varies depending on the type of the reference identifier.
[0111] 1. The reference identifier is an internal reference.
[0112] When a DSL reference statement includes an internal reference identifier, the search scope is determined to be the nested fields in each DSL declaration statement.
[0113] 2. The reference identifier is an external reference.
[0114] When a DSL reference statement includes an external reference identifier, the search scope is determined to be each DSL declaration statement. Based on the classpath, the search proceeds level by level from the outermost class of the nested class to the outermost class of the nested class in each DSL declaration statement.
[0115] 503. From each DSL declaration statement, find the class name of the nested class corresponding to the class identifier of the nested class, and generate the reference code of the nested class.
[0116] In Method 1, when the first target class directly references a nested class, if the DSL reference statement includes an internal reference identifier, the search scope is determined to be each nested field in each DSL declaration statement. From each nested field in each DSL declaration statement, the class name of the nested class corresponding to the class identifier of the nested class is searched, and reference code for the nested class including the class name of the nested class is generated.
[0117] In Method 2, when an instance of a nested class is used as an attribute of the first target class to reference the nested class, if the first target class is the outer class of the nested class, the implementation of generating the reference code of the nested class including the class name of the nested class is as follows: through the attribute decorator, the attribute name of the target attribute is defined as the class name of the nested class in the first target class, and an instance of the nested class is created in the target attribute.
[0118] In Method 1, when the first target class directly references a nested class, if the DSL reference statement includes an outer reference identifier, the search scope is determined to be each DSL declaration statement. Based on the classpath, the search proceeds level by level from the outermost class of the nested class to its outermost class within each DSL declaration statement. From each DSL declaration statement, the search finds the class name of the nested class corresponding to its class identifier, generating reference code for the nested class that includes the class names from the outermost class to its outermost class, as well as the nested class's name.
[0119] In Method 2, when an instance of a nested class is used as an attribute of the first target class to reference the nested class, if the first target class is not the outer class of the nested class, the code that generates the reference code for the nested class, including the class names of each level from the outermost class of the nested class to the outer class of the nested class, and the class name of the nested class, is generated as follows: through an attribute decorator, the attribute name of the target attribute in the first target class is defined as a sequential combination of the class names of each level from the outermost class of the nested class to the outer class of the nested class and the class name of the nested class, and an instance of the nested class is created in the target attribute.
[0120] As can be seen, in response to the operation of referencing a nested class through a first target class in a low-code development platform, a DSL reference statement for the nested class is generated. The DSL reference statement includes the class identifier of the nested class and a reference identifier used to indicate the reference type of the nested class. Based on the DSL reference statement, reference code for the nested class is generated.
[0121] Furthermore, in response to the operation of enabling a second target class to inherit from a nested class in a low-code development platform, embodiments of this application provide another code generation method. Figure 6 This is a flowchart illustrating another code generation method provided in an embodiment of this application.
[0122] like Figure 6 As shown, this code generation method includes the following steps:
[0123] 601. In response to an operation that causes a second target class to inherit from a nested class in a low-code development platform, generate a DSL inheritance statement for the second target class to inherit from the nested class.
[0124] The DSL inheritance statement includes a class identifier for the second target class and inheritance fields, which include a class identifier for the nested class and a reference identifier for indicating the reference type of the nested class.
[0125] Based on the relationship between the second target class and the nested class, generate the DSL inheritance statement where the second target class inherits from the nested class, in the following two cases:
[0126] 1. The second target class and the nested class belong to the same outer class.
[0127] When the second target class and the nested class belong to the same outer class, in response to the operation of making the second target class inherit the nested class in the low-code development platform, a DSL inheritance statement is generated for the second target class to inherit the nested class, including an internal reference identifier, which is used to indicate that the reference type to the nested class is an internal reference.
[0128] 2. The second target class and the nested class belong to different outer classes.
[0129] When the second target class and the nested class belong to different outer classes, in response to the operation of making the second target class inherit the nested class in the low-code development platform, a DSL inheritance statement for inheriting the nested class is generated, which includes an outer reference identifier to indicate that the reference type of the nested class is an outer reference. The inheritance field also includes a class path, which includes class identifiers of each level from the outermost class of the nested class to the outer class of the nested class.
[0130] 602. Determine the search scope based on the type of the reference identifiers included in the DSL reference statement.
[0131] When the DSL inheritance statement includes an internal reference identifier, the search scope is determined to be the nested fields in each DSL declaration statement.
[0132] When an external reference identifier is included in a DSL inheritance statement, the search scope is determined to be each DSL declaration statement.
[0133] 603. Based on the DSL inheritance statement, generate the inheritance code for the second target class to inherit from the nested class.
[0134] When the DSL inheritance statement includes an internal reference identifier, the class name of the nested class corresponding to the class identifier of the nested class is found from each nested field in each DSL declaration statement. The class name of the nested class is then added to the parent class indicator position after the class name of the second target class in the declaration code of the second target class, thus obtaining the inheritance code of the second target class inheriting from the nested class.
[0135] When the DSL inheritance statement includes an external reference identifier, according to the classpath, the class names of each level from the outermost class of the nested class to the outer class of the nested class are searched level by level from each DSL declaration statement. The class name of the nested class corresponding to the class identifier of the nested class is searched from each DSL declaration statement. At the parent class indicator position after the class name of the second target class in the declaration code of the second target class, the class names of each level from the outermost class of the nested class to the outer class of the nested class, as well as the class name of the nested class, are added level by level to obtain the inheritance code of the second target class inheriting from the nested class.
[0136] As can be seen, in response to the operation of making the second target class inherit from the nested class in the low-code development platform, a DSL inheritance statement is generated for the second target class to inherit from the nested class. The DSL inheritance statement includes the class identifier of the second target class and inheritance fields. The inheritance fields include the class identifier of the nested class and a reference identifier used to indicate the reference type of the nested class. Based on the DSL inheritance statement, the inheritance code for the second target class to inherit from the nested class is generated.
[0137] Figure 7 This is a schematic diagram of a code generation device provided in an embodiment of this application. The following is in conjunction with... Figure 7 The embodiments described below are described in detail. The embodiments described below are used to explain the technical solutions of this application and are not intended to limit actual use.
[0138] The code generation device includes:
[0139] The generation unit 701 is used to generate a first domain-specific language (DSL) declaration statement in response to the operation of adding a first class in the low-code development platform and selecting a first parent class including nested classes for inheritance of the first class; the first DSL declaration statement includes class information of the first class and a first nested field, the first nested field including class information of the first nested class, the first nested class being a nested class that the first class inherits from the first parent class;
[0140] The generation unit 701 is also used to generate declaration code for the first class based on the class information of the first class in the first DSL declaration statement;
[0141] The detection unit 702 is used to detect whether there is a nested field in the first DSL declaration statement that includes class information of a nested class;
[0142] The generation unit 701 is further configured to, when the detection unit detects that there is a first nested field in the first DSL declaration statement that includes class information of the first nested class, generate declaration code of the first nested class with indentation relative to the declaration code of the first class based on the class information of the first nested class.
[0143] In an optional implementation, the code generation apparatus further includes an adding unit 703.
[0144] Add unit 703 to respond to the operation of adding custom functionality to the first nested class in the low-code development platform. Add a second nested field to the class information of the first nested class in the first nested field of the first DSL declaration statement. Add a second DSL declaration statement to the second nested field. The second DSL declaration statement includes the class information of the second nested class corresponding to the custom functionality. The second nested class is a nested class of the first nested class.
[0145] The generation unit 701 is also configured to generate declaration code for a second nested class that is indented relative to the declaration code of the first nested class, based on the second DSL declaration statement.
[0146] In an optional implementation, the second nested class corresponding to the custom function includes a second logic nested class for defining the implementation logic of the custom function, a second input nested class for defining the input parameters of the custom function, and a second output nested class for defining the output parameters of the custom function.
[0147] The generation unit 701 is further configured to, based on the class information of the second nested class in the second DSL declaration statement and the nesting relationship between the second nested class and the first nested class, generate declaration code for a second logical nested class that is indented relative to the declaration code of the first nested class; generate declaration code for a second input nested class that is indented relative to the declaration code of the first nested class; and generate declaration code for a second output nested class that is indented relative to the declaration code of the first nested class. The indentation of the declaration code for the second logical nested class, the declaration code for the second input nested class, and the declaration code for the second output nested class relative to the declaration code of the first nested class is the same.
[0148] In an optional implementation, generation unit 701 is further configured to generate a DSL reference statement for the nested class in response to an operation that references the nested class through a first target class in a low-code development platform; the DSL reference statement includes a class identifier of the nested class and a reference identifier for indicating the reference type of the nested class; and generate reference code for the nested class based on the DSL reference statement.
[0149] In an optional implementation, the code generation apparatus further includes a determining unit 704 and a searching unit 705.
[0150] The generation unit 701 is further configured to, in the case that the first target class is the outer class of the nested class, generate a DSL reference statement of the nested class including an internal reference identifier in response to an operation of referencing the nested class through the first target class in the low-code development platform; the internal reference identifier is used to indicate that the reference type of the nested class is an internal reference.
[0151] The determination unit 704 is used to determine the search scope as each nested field in each DSL declaration statement when the DSL reference statement includes an internal reference identifier.
[0152] The lookup unit 705 is used to look up the class name of the nested class corresponding to the class identifier of the nested class from each nested field in each DSL declaration statement.
[0153] The generation unit 701 is also used to generate reference code for nested classes, including the class name of the nested class.
[0154] In one optional implementation,
[0155] The generation unit 701 is further configured to, in response to an operation in which the first target class is referenced to the nested class through the first target class in the low-code development platform, generate a DSL reference statement for the nested class that includes an external reference identifier, when the first target class is not the outer class of the nested class; the external reference identifier is used to indicate that the reference type to the nested class is an external reference, and the DSL reference statement also includes a class path, which includes class identifiers at each level from the outermost class of the nested class to the outer class of the nested class.
[0156] The determining unit 704 is also used to determine the search scope as each DSL declaration statement when the DSL reference statement includes an external reference identifier.
[0157] The lookup unit 705 is also used to search for the class names of each level from the outermost class to the outer class of the nested class in each DSL declaration statement according to the class path; and to search for the class name of the nested class corresponding to the class identifier of the nested class in each DSL declaration statement.
[0158] The generation unit 701 is also used to generate class names at all levels, including the outermost class of the nested class to the outer class of the nested class, and reference code of the nested class of the nested class name.
[0159] In an optional implementation, the code generation apparatus further includes a processing unit 706.
[0160] The generation unit 701 is further configured to, in the case where the first target class is the outer class of the nested class, generate a DSL reference statement for the nested class that includes an inner reference identifier, in response to an operation in the low-code development platform to reference the nested class by using an instance of the nested class as an attribute of the first target class.
[0161] Processing unit 706 is used to define the attribute name of the target attribute in the first target class as the class name of the nested class through an attribute decorator, and to create an instance of the nested class in the target attribute.
[0162] In one optional implementation,
[0163] The generation unit 701 is further configured to, in the case that the first target class is not the outer class of the nested class, generate a DSL reference statement for the nested class that includes an outer reference identifier, in response to an operation in the low-code development platform to reference the nested class by using an instance of the nested class as an attribute of the first target class.
[0164] The processing unit 706 is further configured to define, in the first target class, the attribute name of the target attribute as a sequential combination of the class names of each level from the outermost class of the nested class to the outer class of the nested class and the class name of the nested class, and to create an instance of the nested class in the target attribute.
[0165] In one optional implementation,
[0166] The generation unit 701 is further configured to, in response to an operation in a low-code development platform that causes a second target class to inherit from a nested class, generate a DSL inheritance statement for the second target class to inherit from the nested class; the DSL inheritance statement includes a class identifier of the second target class and an inheritance field, the inheritance field including a class identifier of the nested class and a reference identifier for indicating a reference type to the nested class; and generate inheritance code for the second target class to inherit from the nested class based on the DSL inheritance statement.
[0167] In one optional implementation,
[0168] The generation unit 701 is further configured to, in response to an operation in the low-code development platform that causes the second target class to inherit from the nested class, generate a DSL inheritance statement for the second target class to inherit from the nested class, including an internal reference identifier, when the second target class and the nested class belong to the same outer class; the internal reference identifier is used to indicate that the reference type to the nested class is an internal reference.
[0169] The determination unit 704 is also used to determine the search scope as each nested field in each DSL declaration statement when the DSL inheritance statement includes an internal reference identifier.
[0170] The lookup unit 705 is also used to look up the class name of the nested class corresponding to the class identifier of the nested class from each nested field in each DSL declaration statement.
[0171] Adding unit 703 is also used to add the class name of the nested class at the parent class indicator position after the class name of the second target class in the declaration code of the second target class, so as to obtain the inheritance code of the second target class inheriting the nested class.
[0172] In one optional implementation,
[0173] The generation unit 701 is further configured to, in response to the operation of making the second target class inherit the nested class in the low-code development platform, generate a DSL inheritance statement for inheriting the nested class, including an external reference identifier, when the second target class and the nested class belong to different outer classes; the external reference identifier is used to indicate that the reference type of the nested class is an external reference, and the inheritance field also includes a class path, which includes class identifiers of each level from the outermost class of the nested class to the outer class of the nested class.
[0174] The determination unit 704 is also used to determine the search scope as each DSL declaration statement when the DSL inheritance statement includes an external reference identifier.
[0175] The lookup unit 705 is also used to search for the class names of each level from the outermost class to the outer class of the nested class in each DSL declaration statement according to the class path; and to search for the class name of the nested class corresponding to the class identifier of the nested class in each DSL declaration statement.
[0176] Adding unit 703 is also used to add the class names of each level of the nested class, from the outermost class to the outermost class of the nested class, and the class name of the nested class, at the parent class indicator position after the class name of the second target class in the declaration code of the second target class, so as to obtain the inheritance code of the second target class inheriting the nested class.
[0177] Third Embodiment
[0178] Corresponding to the code generation method provided in the first embodiment of this application, the third embodiment of this application also provides an electronic device for processing code, such as... Figure 8 As shown, the electronic device includes: a processor 801; and a memory 802 for storing a program for the code generation method. After the device is powered on and the program for the code generation method is run by the processor, the following steps are performed:
[0179] In response to the operation of adding a first class in the low-code development platform and selecting a first parent class including nested classes for inheritance of the first class, a first domain-specific language (DSL) declaration statement is generated; the first DSL declaration statement includes class information of the first class and a first nested field, the first nested field including class information of the first nested class, the first nested class being a nested class that the first class inherits from the first parent class;
[0180] Based on the class information of the first class in the first DSL declaration statement, generate the declaration code for the first class;
[0181] Detect whether the first DSL declaration statement contains nested fields that include class information of nested classes;
[0182] When a first nested field containing class information of the first nested class is detected in the first DSL declaration statement, the declaration code of the first nested class, which is indented relative to the declaration code of the first class, is generated based on the class information of the first nested class.
[0183] Fourth embodiment
[0184] Corresponding to the code generation method provided in the first embodiment of this application, the fourth embodiment of this application also provides a computer-readable storage medium storing a program for the code generation method, which is executed by a processor to perform the following steps:
[0185] In response to the operation of adding a first class in the low-code development platform and selecting a first parent class including nested classes for inheritance of the first class, a first domain-specific language (DSL) declaration statement is generated; the first DSL declaration statement includes class information of the first class and a first nested field, the first nested field including class information of the first nested class, the first nested class being a nested class that the first class inherits from the first parent class;
[0186] Based on the class information of the first class in the first DSL declaration statement, generate the declaration code for the first class;
[0187] Detect whether the first DSL declaration statement contains nested fields that include class information of nested classes;
[0188] When a first nested field containing class information of the first nested class is detected in the first DSL declaration statement, the declaration code of the first nested class, which is indented relative to the declaration code of the first class, is generated based on the class information of the first nested class.
[0189] It should be noted that for detailed descriptions of the code generation apparatus, electronic device, and computer-readable storage medium provided in the second, third, and fourth embodiments of this application, please refer to the relevant description of the first embodiment of this application, which will not be repeated here.
[0190] Although this application discloses preferred embodiments as described above, it is not intended to limit this application. Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of this application. Therefore, the scope of protection of this application should be determined by the scope defined in the claims of this application.
[0191] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0192] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0193] 1. Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include non-transitory computer-readable media, such as modulated data signals and carrier waves.
[0194] 2. Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0195] Although this application discloses preferred embodiments as described above, it is not intended to limit this application. Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of this application. Therefore, the scope of protection of this application should be determined by the scope defined in the claims of this application.
Claims
1. A code generation method, characterized in that, include: In response to the operation of adding a first class in the low-code development platform and selecting a first parent class including nested classes for inheritance of the first class, a first DSL declaration statement is generated; the first DSL declaration statement includes class information of the first class and a first nesting field, the first nesting field includes class information of the first nested class, the first nested class is a nested class that the first class inherits from the first parent class; Based on the class information of the first class in the first DSL declaration statement, generate the declaration code for the first class; Detect whether the first DSL declaration statement contains nested fields that include class information of nested classes; When a first nested field containing class information of the first nested class is detected in the first DSL declaration statement, the declaration code of the first nested class with indentation relative to the declaration code of the first class is generated based on the class information of the first nested class. In response to the operation of making a second target class inherit a nested class in the low-code development platform, a DSL inheritance statement is generated in which the second target class inherits the nested class; the DSL inheritance statement includes a class identifier of the second target class and an inheritance field, the inheritance field including a class identifier of the nested class and a reference identifier for indicating a reference type to the nested class; Based on the DSL inheritance statement, generate the inheritance code for the second target class to inherit from the nested class; The step of generating a DSL inheritance statement for the second target class to inherit from the nested class in response to an operation in the low-code development platform includes: When the second target class and the nested class belong to the same outer class, in response to the operation of making the second target class inherit the nested class in the low-code development platform, a DSL inheritance statement for the second target class to inherit the nested class is generated, including an internal reference identifier; the internal reference identifier is used to indicate that the reference type of the nested class is an internal reference. When the second target class and the nested class belong to different outer classes, in response to the operation of making the second target class inherit the nested class in the low-code development platform, a DSL inheritance statement for inheriting the nested class is generated, including an outer reference identifier; the outer reference identifier is used to indicate that the reference type of the nested class is an outer reference, and the inheritance field also includes a class path, which includes class identifiers at each level from the outermost class of the nested class to the outer class of the nested class; The step of generating inheritance code for the second target class to inherit from the nested class based on the DSL inheritance statement includes: When the DSL inheritance statement includes the internal reference identifier, the search scope is determined to be each nested field in each DSL declaration statement; from each nested field in each DSL declaration statement, the class name of the nested class corresponding to the class identifier of the nested class is searched; at the parent class indicator position after the class name of the second target class in the declaration code of the second target class, the class name of the nested class is added to obtain the inheritance code of the second target class inheriting the nested class; When the DSL inheritance statement includes the external reference identifier, the search scope is determined to be each DSL declaration statement; according to the class path, from each DSL declaration statement, the class names of each level from the outermost class of the nested class to the outer class of the nested class are searched level by level; from each DSL declaration statement, the class name of the nested class corresponding to the class identifier of the nested class is searched; at the parent class indicator position after the class name of the second target class in the declaration code of the second target class, the class names of each level from the outermost class of the nested class to the outer class of the nested class, as well as the class name of the nested class, are added level by level to obtain the inheritance code of the second target class inheriting the nested class.
2. The method according to claim 1, characterized in that, The method further includes: In response to the operation of adding custom functionality to the first nested class in the low-code development platform, a second nested field is added to the class information of the first nested class in the first nested field of the first DSL declaration statement; Add a second DSL declaration statement to the second nested field; the second DSL declaration statement includes the class information of the second nested class corresponding to the custom function, and the second nested class is a nested class of the first nested class; Based on the second DSL declaration statement, generate the declaration code of the second nested class, which is indented relative to the declaration code of the first nested class.
3. The method according to claim 2, characterized in that, The second nested class corresponding to the custom function includes a second logic nested class for defining the implementation logic of the custom function, a second input nested class for defining the input parameters of the custom function, and a second output nested class for defining the output parameters of the custom function. The step of generating declaration code for the second nested class, indented relative to the declaration code of the first nested class, based on the second DSL declaration statement, includes: Based on the class information of the second nested class in the second DSL declaration statement, and the nesting relationship between the second nested class and the first nested class, the declaration code of the second logical nested class with indentation relative to the declaration code of the first nested class is generated; Generate declaration code for the second input nested class that is indented relative to the declaration code of the first nested class; Generate the declaration code of the second output nested class, indented relative to the declaration code of the first nested class; The declaration codes of the second logical nested class, the second input nested class, and the second output nested class all have the same indentation relative to the declaration code of the first nested class.
4. The method according to claim 1, characterized in that, The method further includes: In response to an operation in the low-code development platform that references a nested class through a first target class, a DSL reference statement for the nested class is generated; the DSL reference statement includes a class identifier of the nested class and a reference identifier for indicating the reference type of the nested class. Based on the DSL reference statement, the reference code for the nested class is generated.
5. The method according to claim 4, characterized in that, The step of generating a DSL reference statement for the nested class in response to an operation in the low-code development platform that references the nested class through a first target class includes: When the first target class is the outer class of the nested class, in response to the operation of referencing the nested class through the first target class in the low-code development platform, a DSL reference statement of the nested class including an internal reference identifier is generated; the internal reference identifier is used to indicate that the reference type of the nested class is an internal reference. The step of generating the reference code for the nested class based on the DSL reference statement includes: When the internal reference identifier is included in the DSL reference statement, the search scope is determined to be each nested field in each DSL declaration statement; From each of the nested fields in each of the DSL declaration statements, find the class name of the nested class corresponding to the class identifier of the nested class; Generate reference code for the nested class, including the class name of the nested class.
6. The method according to claim 4, characterized in that, The step of generating a DSL reference statement for the nested class in response to an operation in the low-code development platform that references the nested class through a first target class includes: If the first target class is not the outer class of the nested class, in response to the operation of referencing the nested class through the first target class in the low-code development platform, a DSL reference statement for the nested class including an external reference identifier is generated; the external reference identifier is used to indicate that the reference type of the nested class is an external reference, and the DSL reference statement also includes a class path, which includes class identifiers at each level from the outermost class of the nested class to the outer class of the nested class; The step of generating the reference code for the nested class based on the DSL reference statement includes: When the external reference identifier is included in the DSL reference statement, the search scope is determined to be each DSL declaration statement; Based on the class path, the class names of each level from the outermost class of the nested class to the outermost class of the nested class are searched level by level from each of the DSL declaration statements; From each of the DSL declaration statements, find the class name of the nested class corresponding to the class identifier of the nested class; Generate the class names of each level from the outermost class of the nested class to the outer class of the nested class, and the reference code of the nested class with the class name of the nested class.
7. The method according to claim 5, characterized in that, In the case where the first target class is the outer class of the nested class, in response to an operation in the low-code development platform that references the nested class through the first target class, a DSL reference statement for the nested class including an internal reference identifier is generated, including: In the case where the first target class is the outer class of the nested class, in response to the operation of using an instance of the nested class as an attribute of the first target class in the low-code development platform to reference the nested class, a DSL reference statement of the nested class including an internal reference identifier is generated. The step of generating the reference code for the nested class, which includes the class name of the nested class, includes: Using an attribute decorator, the attribute name of the target attribute is defined as the class name of the nested class in the first target class, and an instance of the nested class is created in the target attribute.
8. The method according to claim 6, characterized in that, In the case that the first target class is not the outer class of the nested class, in response to an operation in the low-code development platform that references the nested class through the first target class, a DSL reference statement for the nested class including an outer reference identifier is generated, including: If the first target class is not the outer class of the nested class, in response to the operation of using an instance of the nested class as an attribute of the first target class in the low-code development platform to reference the nested class, a DSL reference statement of the nested class including an outer reference identifier is generated. The step of generating the reference code for the nested class, which includes the class names of each level from the outermost class of the nested class to the outer class of the nested class, and the class name of the nested class, includes: Using an attribute decorator, the attribute name of the target attribute in the first target class is defined as a sequential combination of the class names of each level from the outermost class to the outer class of the nested class and the class name of the nested class, and an instance of the nested class is created in the target attribute.
9. A code generation device, characterized in that, The device includes: A generation unit is used to generate a first DSL declaration statement in response to the operation of adding a first class in a low-code development platform and selecting a first parent class including nested classes for inheritance of the first class; the first DSL declaration statement includes class information of the first class and a first nesting field, the first nesting field including class information of the first nested class, the first nested class being a nested class that the first class inherits from the first parent class; The generation unit is further configured to generate declaration code for the first class based on the class information of the first class in the first DSL declaration statement; The detection unit is used to detect whether there is a nested field in the first DSL declaration statement that includes class information of nested classes; The generation unit is further configured to, when the detection unit detects that there is a first nested field in the first DSL declaration statement that includes class information of the first nested class, generate declaration code of the first nested class that is indented relative to the declaration code of the first class based on the class information of the first nested class; The generation unit is further configured to, in response to an operation in the low-code development platform to cause a second target class to inherit from a nested class, generate a DSL inheritance statement for the second target class to inherit from the nested class; the DSL inheritance statement includes a class identifier of the second target class and an inheritance field, the inheritance field including a class identifier of the nested class and a reference identifier for indicating a reference type to the nested class; and generate inheritance code for the second target class to inherit from the nested class according to the DSL inheritance statement. The generation unit is further configured to, in response to an operation in the low-code development platform that causes the second target class to inherit from the nested class, generate a DSL inheritance statement for the second target class to inherit from the nested class, including an internal reference identifier, when the second target class and the nested class belong to the same outer class; the internal reference identifier is used to indicate that the reference type to the nested class is an internal reference. The generation unit is further configured to, in response to an operation in the low-code development platform to make the second target class inherit the nested class when the second target class and the nested class belong to different outer classes, generate a DSL inheritance statement for inheriting the nested class, including an external reference identifier; the external reference identifier is used to indicate that the reference type of the nested class is an external reference, and the inheritance field also includes a class path, which includes class identifiers at each level from the outermost class of the nested class to the outer class of the nested class; The determining unit is configured to determine the search scope as each nested field in each DSL declaration statement when the DSL inheritance statement includes the internal reference identifier; and to determine the search scope as each DSL declaration statement when the DSL inheritance statement includes the external reference identifier. The lookup unit is configured to, when the DSL inheritance statement includes the internal reference identifier, search for the class name of the nested class corresponding to the class identifier of the nested class from each of the nested fields in each of the DSL declaration statements; and to, when the DSL inheritance statement includes the external reference identifier, search for the class names of each level from the outermost class to the outer class of the nested class in each of the DSL declaration statements according to the class path, and to search for the class name of the nested class corresponding to the class identifier of the nested class in each of the DSL declaration statements. The addition unit is configured to, when the DSL inheritance statement includes the internal reference identifier, add the class name of the nested class at the parent class indicator position after the class name of the second target class in the declaration code of the second target class, to obtain the inheritance code of the second target class inheriting from the nested class; and to, when the DSL inheritance statement includes the external reference identifier, add the class names of each level from the outermost class of the nested class to the outer class of the nested class, as well as the class name of the nested class, at the parent class indicator position, to obtain the inheritance code of the second target class inheriting from the nested class.
10. An electronic device, characterized in that, include: processor; as well as A memory for storing a data processing program, which, when powered on and run by the processor, executes the method as described in any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, The system contains a data processing program that is executed by a processor to perform the method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Front-end code generation method and device and computer equipment
CN113805871A