CN113050953A - Method, device and storage medium for generating code based on annotation - Google Patents

Method, device and storage medium for generating code based on annotation Download PDF

Info

Publication number
CN113050953A
CN113050953A CN202110430668.XA CN202110430668A CN113050953A CN 113050953 A CN113050953 A CN 113050953A CN 202110430668 A CN202110430668 A CN 202110430668A CN 113050953 A CN113050953 A CN 113050953A
Authority
CN
China
Prior art keywords
target class
class
annotation tag
annotation
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110430668.XA
Other languages
Chinese (zh)
Inventor
梁明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Puhui Enterprise Management Co Ltd
Original Assignee
Ping An Puhui Enterprise Management Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN202110430668.XA priority Critical patent/CN113050953A/en
Publication of CN113050953A publication Critical patent/CN113050953A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Abstract

The application discloses a method, a device and a storage medium for generating codes based on annotations, which relate to the technical field of research and development management, and the method comprises the following steps: acquiring an interface document to be converted into a code; determining a first target class to be converted in an interface document, and determining a second target class; setting a first annotation label and a second annotation label for the first target class, wherein the first annotation label is used for indicating that the first target class is a class to be converted, and the second annotation label is used for indicating that the first target class is converted into a second target class; converting the first target class into the second target class according to the second annotation tag; and compiling the interface document by the first annotation tag, the second annotation tag, the first target class and the second target class to obtain a source code file corresponding to the interface document. According to the scheme, an additional auxiliary class is not required to be written to help generate the conversion code, the introduction dependence is reduced, the loss caused by dependence of each link of testing and deployment is reduced, and meanwhile the burden of the virtual machine during operation is reduced.

Description

Method, device and storage medium for generating code based on annotation
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, and a storage medium for generating a code based on annotations.
Background
A Data Transfer Object (DTO) is a software application that transfers Data between design modes, i.e., a DTO is an Object responsible for passing Data between an application layer and a presentation layer. Often the data transfer objective is for a data access object to retrieve data from a database. The difference between data transfer objects and data interaction objects or data access objects is that one does not have any behavior except for stored and retrieved data (access and accessors), while DTO is used to encapsulate data into common JavaBeans, transferred between multiple layers of J2 EE.
In database technology, Data Transfer Object (DTO) is typically used to express the in-and out-references of Object interfaces, and Entity (Entity) or other similar concepts are used to express persistent objects of a database. In many scenarios, the database-based processing flow spans multiple layers, and because the attributes of the DTO and the Entity have many similarities, two java objects, namely the DTO and the Entity, need to be converted between the layers.
Currently, an annotation processor-based mapping tool (such as selma) is mainly used to realize that two java objects, namely DTO and Entity, need to be converted between layers. Specifically, a special object interface is written based on selma of the annotation processor, an implementation class is generated during compiling, and two java objects, namely DTO and Entity, need to be converted between layers based on implementation class implementation. However, a special object interface needs to be written for selma, and DTO and Entity cannot be converted directly.
Disclosure of Invention
The embodiment of the application provides a method, a device and a storage medium for generating a code based on annotations, and aims to solve the problem that DTO and Entity cannot be directly converted in the prior art.
In a first aspect, an embodiment of the present application provides a method for generating a code based on an annotation, which includes:
acquiring an interface document to be converted into a code;
determining a first target class to be converted in the interface document and determining a second target class;
setting a first annotation tag and a second annotation tag for the first target class, wherein the first annotation tag is used for indicating that the first target class is a class to be converted, and the second annotation tag is used for indicating that the first target class is converted into the second target class;
converting the first target class to the second target class according to the second annotation tag;
compiling the interface document by the first annotation tag, the second annotation tag, the first target class and the second target class to obtain a source code file corresponding to the interface document. .
In a second aspect, an embodiment of the present application provides a code generation apparatus, which includes:
the acquisition module is used for acquiring an interface document to be converted into a code;
the processing module is used for determining a first target class to be converted in the interface document acquired by the acquisition module and determining a second target class; setting a first annotation tag and a second annotation tag for the first target class, wherein the first annotation tag is used for indicating that the first target class is a class to be converted, and the second annotation tag is used for indicating that the first target class is converted into the second target class; converting the first target class to the second target class according to the second annotation tag; compiling the interface document by the first annotation tag, the second annotation tag, the first target class and the second target class to obtain a source code file corresponding to the interface document.
In a third aspect, an embodiment of the present application further provides a computer device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, and when the processor executes the computer program, the processor implements the method for generating a code based on an annotation according to the first aspect.
In a fourth aspect, this application further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and the computer program, when executed by a processor, causes the processor to execute the method for generating code based on annotations according to the first aspect.
The embodiment of the application provides a method, a device, equipment and a storage medium for generating codes based on annotations, wherein a first annotation label and a second annotation label are set for a class in a data transmission object between layers under a scene spanning multiple layers, then a first object class is converted into a second object class according to the first annotation label, and then an interface document is compiled according to the first annotation label, the second annotation label, the first object class and the second object class so as to obtain a source code file corresponding to the interface document. Because of the use of custom annotation tags, no additional auxiliary classes need to be written to help generate the translation code. In addition, because the user-defined annotation tag is adopted to help generate the conversion code, an additional special object interface is not required to be written, so that the dependence is hardly introduced, the loss caused by dependence of testing and deploying links is reduced, and the burden of the virtual machine during operation is reduced.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a flowchart illustrating a method for generating code based on annotations according to an embodiment of the present disclosure;
FIG. 2 is a diagram illustrating a first target class being converted into a second target class according to an embodiment of the present disclosure;
FIG. 3 is a schematic block diagram of a code generation apparatus provided by an embodiment of the present application;
fig. 4 is a schematic block diagram of a computer device provided in an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the present application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in the specification of the present application and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
Referring to fig. 1, fig. 1 is a schematic flowchart illustrating a method for generating a code based on a comment according to an embodiment of the present application, where the method for generating a code based on a comment is applied to a server, and the method is executed by application software installed in the server. As shown in fig. 1, the method includes steps S101 to S105.
S101, obtaining an interface document to be converted into a code.
The interface document refers to a document for transmitting data between the application layer and the presentation layer, that is, a document required when an interface is called in a software project development process to complete corresponding software design, and may also be referred to as a code. In an embodiment of the present application, the interface document may be a DTO. Interaction is carried out between the presentation layer and the application layer through DTO, the DTO is a POCO object without behaviors, the purpose is to carry out data encapsulation on the field object and realize data transmission between the layers, namely the DTO pays attention to data and directly exposes the behaviors of the field object to the presentation layer, and the DTO faces to an interface UI.
In the embodiment of the application, the interface document can be used for communication and development of a unified file for front-end and back-end engineers in the project development process, and can be used in project maintenance or project personnel change, so that later-stage personnel can conveniently check and maintain the interface document. The interface document may also perform interface verification. Specifically, the front-end and back-end are used with the interfaces corresponding to the test. Because the front end and the back end of the development of the program are separated, the direct data transmission and interaction of the front end and the back end are operated through an interface. .
Front end: and carrying out Ajax design through an interface document given by a back-end person, sending a request to a service through an interface, acquiring response data, and then carrying out next page jumping and displaying through the returned data.
A rear end: and providing a channel for interaction with the server and the data request for the front end through the programming interface. Writing corresponding interfaces, parameters to be transferred, parameter types and the like. And then generating an interface document, sharing the interface document to the front end, and writing the corresponding Ajax according to the interface document.
And (3) testing: interface verification can be carried out through interface documents, whether an interface developed at the back end corresponds to Ajax written by the front end or not and whether an error interface exists or not can be checked, and whether the interfaces between the whole system correspond or not, whether the interfaces are not aligned or not can be known through interface flow testing.
The interfaces are generally divided into interfaces inside the program and interfaces outside the system. The following are introduced separately:
external interface of system: for example, resources or information are to be acquired from other websites or servers, and the other websites or servers do not share the database, but only provide a written method to acquire data, so that personnel who are not the websites or servers need to refer to the interface provided by the website or server to use the written method, thereby achieving the purpose of data sharing.
Interfaces inside the program: the method comprises the steps that interaction between modules is carried out between the methods, interfaces thrown out from the interior of a program are carried out, for example, a certain forum system is provided with a login module and a posting module, if the forum system is required to post, the forum system needs to log in first, interaction is required between the login module and the posting module, and therefore the forum system throws out an interface for the interior system to call.
S102, determining a first target class to be converted in the interface document, and determining a second target class.
The first target class is a class needing conversion, and the second target class is a converted target class. The first target class may be at least one, and the specific number is not limited in the embodiments of the present application.
S103, setting a first annotation tag and a second annotation tag for the first target class.
The first annotation tag is used for indicating that the first target class is a class to be converted, the first annotation tag is associated with a corresponding trigger event, and the trigger event is an event for triggering the conversion of the first target class into the second target class. The second annotation tag is to indicate a conversion of the first target class to the second target class.
Specifically, since there are many classes involved in the unit test, only some classes need to be converted into other classes, in order to implement the automatic test and improve the test efficiency, it may be determined that the first target class is a trigger event to be converted into other classes according to the test requirement, and after it is determined that the class to be converted from the first target class is the second target class, it may be determined that the first target class satisfies the preset annotation tag setting condition. Then, a first annotation tag and a second annotation tag may be added to the first target class, so that in the subsequent compilation process, when the second target class is traversed, a trigger event associated with the first annotation tag may be triggered, that is, an event for converting the first target class into the second target class is triggered.
In some embodiments, in order to further facilitate data interaction and improve data processing efficiency, a data object DTO may be organized as needed, and only a target field required by an interface document page is organized, so that on one hand, transmission of a field of the entire table is avoided, and thus, security is improved, and on the other hand, transmission efficiency is improved.
Specifically, the DTO class inheritance entity class may be used, a specific service field is placed in a specific DTP class (these specific DTO classes do not need to be converted into other classes), corresponding usage methods (for example, including a get method and a set method) are correspondingly provided, and third comment tags are respectively set for these specific service fields, and the functions of these specific service fields are equivalent to the functions of the preprocessed database fields in the database. When fields which do not exist in the database are used at the business logic layer or the interaction layer, such specific business fields can be identified through the third comment tag, and then data interaction is carried out by using the specific business fields.
In some implementations, the first annotation tag and the second annotation tag can be written in a javadoc format on the first target class. In this case, the first annotation tag and the second annotation tag are both custom annotation tags.
In other embodiments, auxiliary information may be further set for the first target class, and the first code may be generated according to the auxiliary information. For example, some extra information may be appended to assist in generating other non-essential information.
In the embodiment of the present application, the setting of the first annotation tag and the second annotation tag for the first target class may also be regarded as performing document annotation on an interface document. Among them, the document annotation is only responsible for describing class (class), interface (interface), method (method), constructor (constructor), and member field (field). Accordingly, document annotations must be written in front of class, interface, method, constructor, member fields, and written elsewhere, such as inside functions, are invalid document annotations. The document annotation is written by using HTML grammar rules, supports HTML marks (tag), and has some additional auxiliary marks, and the marks are used for better generating a final document by a javadoc tool.
And S104, converting the first target class into the second target class according to the second annotation label.
Specifically, the same fields in the first target class and the second target class are transformed, and the fields (or attributes) a in the second target class can be unified and assigned to the fields (or attributes) a in the first target class. In some embodiments, if the first target class and the second target class have the same structure and different class names, the first target class may be converted into the second target class by using a copyProperties method of beans, which may be specifically referred to as the schematic diagram of converting the first target class into the second target class shown in fig. 2. Or, the json tool is adopted to firstly convert the first target class into the json string, and then the json string is converted into the second target class.
S105, compiling the interface document by the first annotation tag, the second annotation tag, the first target class and the second target class to obtain a source code file corresponding to the interface document.
In some embodiments, S105 may be implemented based on a generator, for example, the generator may be started, and after the generator compiles the interface document into a source code file, the source code file may be output to a specified directory, and the test code may be output to a specified test directory.
In some embodiments, after obtaining the source code file corresponding to the interface document, the method further includes:
adding the source code file to a target directory and adding a test code to a test directory;
and performing unit test on the source code file based on the test code to test the correctness of the source code file.
For example, by running unit tests, i.e. by automatically generating unit test classes, the correctness of the generated code is guaranteed. Such as whether the type is correctly translated, whether the name mapping is correct, and whether it is a deep copy. This provides a great convenience for the verification after modification.
The unit test includes an interface test, which is not distinguished in the present application. The interface test is mainly used for interaction points between external systems and between internal subsystems, defines specific interaction points, and then performs interaction between data through the interaction points and through some special rules, namely protocols.
In some embodiments, to further ensure conversion of classes to power, prior to said converting the first target class to the second target class according to the second annotation tag, the method further comprises:
(1) detecting a current application environment;
(2) when a test item with a specific dependency relationship in the application environment is detected, a specific conversion class is generated.
Specifically, if a specific dependency exists in the application environment, a specific transformation class corresponding to the specific dependency is generated, for example, the specific transformation class may include a specific transformation class integrating spring elements.
Wherein, the specific dependency relationship refers to the usage relationship between two classes, and the usage of one class must be operated based on the generation class. For example, a specific dependency relationship means that a class a uses another class B, and the usage relationship is accidental, temporary and very weak, but a change of the class B affects the class a, which is embodied in a code level, so that the class B is used as a parameter by the class a in a certain method. If there is no corresponding generation class during compiling, an error is reported and the operation is interrupted.
(3) Injecting the particular conversion class into the interface document.
For example, after a specific conversion class integrating spring elements is generated, the specific conversion class is injected into the interface document.
Accordingly, (4) starting the generator based on the specific conversion class.
For example, when a specific dependency is found, a corresponding specific code may be generated, for example, a transformation class integrating spring elements may be generated, and since the spring framework supports constructor parameter injection and setter method attribute injection, interface injection is not required, and when a test item with a specific dependency exists in the interface document, the interface injection may not be relied on, but attribute injection may be implemented based on the specific transformation class, so that an error may not be reported when compiling, and when running, the test item may correctly run due to injection of the spring framework.
Therefore, in the process of compiling the interface document by the first annotation tag, the second annotation tag, the first target class and the second target class, if the generation class does not exist, the specific conversion class is called to execute the operation of converting the first target class into the second target class.
Therefore, through the specific conversion class, no extra interface needs to be written, the dependence is hardly introduced, the loss caused by the dependence of each link of testing and deployment is reduced, and the load of the running virtual machine is reduced.
In some embodiments, to help the generator generate the source code file more correctly, the field in the first target class may be further marked, and specifically, before the interface document is compiled by the first annotation tag, the second annotation tag, the first target class, and the second target class to obtain the source code file corresponding to the interface document, the application further includes:
determining a target service field in the first target class which meets a preset annotation condition;
and generating a comment mark field for the target service field.
For example, some fields in the first target class need to be ignored, or some fields are inconsistent in names of the two classes (for example, the field a in the first target class is inconsistent in names of the first target class and the third target class), or the corresponding field types are inconsistent, in order to improve the accuracy of the source code file, when such a situation occurs, additional marks need to be performed on the first target class, and the additional marks can help the generator to generate the source code file more correctly.
In the embodiment of the application, a first annotation tag and a second annotation tag are set for a class in a data transmission object between layers in a scene spanning multiple layers, a first object class is converted into a second object class according to the first annotation tag, and then the interface document is compiled according to the first annotation tag, the second annotation tag, the first object class and the second object class, so that a source code file corresponding to the interface document is obtained. In one aspect, because custom annotation tags are employed, no additional auxiliary classes need to be written to help generate the translation code. Because the user-defined annotation tag is adopted to help generate the conversion code, an additional interface is not required to be written, so that the dependence is hardly introduced, the loss caused by the dependence of testing and deploying links is reduced, and the burden of the running virtual machine is reduced.
On the other hand, the method can intelligently detect the application environment, generate corresponding special codes when finding specific dependencies, for example, generate a conversion class integrating spring elements, and because the spring framework supports constructor parameter injection and setter method attribute injection, interface injection is not needed, so that when a test item with a specific dependency relationship exists in the interface document, the interface injection is not relied on, and the attribute injection is realized based on the specific conversion class, so that when compiling does not exist, a fault is not reported to cause compiling interruption, that is, when a test item with a specific dependency relationship exists in the interface document, the compiling is correctly executed due to the injection of the spring framework, and therefore, high cohesion and low coupling can be achieved. And generating a source code file seamlessly integrated with the code of the application. Therefore, the source code file obtained by the method has testability and readability. Wherein, the testability is shown as follows: the automatically generated test classes ensure correctness while eliminating the burden of developers. Readability is then reflected in: the written comments increase the readability of the code, and the comments, namely the code, conform to the autonomous principle in development and design.
The embodiment of the application also provides a code generation device, and the code generation device is used for executing any embodiment of the method for generating the code based on the annotation. Specifically, referring to fig. 3, fig. 3 is a schematic block diagram of a code generation apparatus 30 according to an embodiment of the present application. The code generation apparatus 30 may be configured in a server.
As shown in fig. 3, the code generation apparatus 30 includes: an acquisition module 301 and a processing module 302.
An obtaining module 301, configured to obtain an interface document to be converted into a code;
a processing module 302, configured to determine a first target class to be converted in the interface document, and determine a second target class; setting a first annotation tag and a second annotation tag for the first target class, wherein the first annotation tag is used for indicating that the first target class is a class to be converted, and the second annotation tag is used for indicating that the first target class is converted into the second target class; converting the first target class to the second target class according to the second annotation tag; compiling the interface document by the first annotation tag, the second annotation tag, the first target class and the second target class to obtain a source code file corresponding to the interface document.
In an embodiment, after obtaining the source code file corresponding to the interface document, the processing module 302 is further configured to:
adding the source code file to a target directory and adding a test code to a test directory;
and performing unit test on the source code file based on the test code to test the correctness of the source code file.
In an embodiment, the first annotation tag and the second annotation tag are both custom annotation tags; before the processing module 302 sets the first annotation tag and the second annotation tag for the first target class, the processing module is further configured to:
if the first target class is determined to be the trigger event of class conversion to be carried out according to the test requirement, and the class to be converted from the first target class is determined to be the second target class, determining that the first target class meets the preset annotation label setting condition;
setting the first annotation tag and the second annotation tag for the first target class;
binding the first annotation tag with a trigger event, wherein the trigger event is the conversion of the first target class into the second target class;
when traversing to the second target class, triggering a triggering event associated with the first annotation tag to convert the first target class to the second target class according to the second annotation tag.
In an embodiment, the processing module 302, prior to the converting the first target class into the second target class according to the second annotation tag, is further configured to:
detecting a current application environment;
when detecting that the test item with the specific dependency relationship exists in the application environment, generating a specific conversion class;
injecting the particular conversion class into the interface document;
starting the generator based on the specific conversion class.
In an embodiment, the processing module 302 is further configured to:
putting a specific service field in the specific conversion class, and configuring a using method of the specific service field;
setting a third annotation label for the specific service field, so that the function of the specific service field simulates the function of a preprocessed database field in a database;
identifying the particular business field by the third annotation tag when a field not present in the database is used at a business logic layer or an interaction layer;
and performing data interaction by using the specific service field.
In some embodiments, before the processing module 302 compiles the interface document with the first annotation tag, the second annotation tag, the first target class, and the second target class to obtain a source code file corresponding to the interface document, the processing module is further configured to:
determining a target service field in the first target class which meets a preset annotation condition;
and generating a comment mark field for the target service field.
In some embodiments, before the processing module 302 converts the first target class into the second target class according to the second annotation tag, the processing module is further configured to:
setting auxiliary information for the first target class;
and generating a first code according to the auxiliary information.
The code generation device 30 does not need to write additional auxiliary classes to help generate the conversion codes, can hardly introduce dependence, reduces the loss caused by dependence of testing and deploying links, and reduces the burden of the running virtual machine.
The code generation apparatus 30 described above may be implemented in the form of a computer program that can be run on a computer device as shown in fig. 4.
Referring to fig. 4, fig. 4 is a schematic block diagram of a computer device according to an embodiment of the present application. The computer device 400 is a server, which may be an independent server or a server cluster composed of a plurality of servers.
Referring to fig. 4, the computer device 400 includes a processor 402, memory, and a network interface 405 connected by a system bus 401, where the memory may include a non-volatile storage medium 403 and an internal memory 404.
The non-volatile storage medium 403 may store an operating system 4031 and computer programs 4032. The computer program 4032, when executed, may cause the processor 402 to perform a method of generating code based on annotations.
The processor 402 is used to provide computing and control capabilities that support the operation of the overall computer device 400.
The memory 404 provides an environment for the operation of the computer program 4032 in the non-volatile storage medium 403, which computer program 4032, when executed by the processor 402, may cause the processor 402 to perform a method of generating code based on annotations.
The network interface 405 is used for network communication, such as providing transmission of data information. Those skilled in the art will appreciate that the configuration shown in fig. 4 is a block diagram of only a portion of the configuration associated with the present application and does not constitute a limitation of the computing device 400 to which the present application is applied, and that a particular computing device 400 may include more or less components than those shown, or combine certain components, or have a different arrangement of components.
The processor 402 is configured to run the computer program 4032 stored in the memory to implement the method for generating code based on annotations disclosed in the embodiments of the present application.
Those skilled in the art will appreciate that the embodiment of a computer device illustrated in fig. 4 does not constitute a limitation on the specific construction of the computer device, and that in other embodiments a computer device may include more or fewer components than those illustrated, or some components may be combined, or a different arrangement of components. For example, in some embodiments, the computer device may only include a memory and a processor, and in such embodiments, the structures and functions of the memory and the processor are consistent with those of the embodiment shown in fig. 4, and are not described herein again.
It should be understood that in the embodiment of the present Application, the Processor 402 may be a Central Processing Unit (CPU), and the Processor 402 may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, and the like. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
In another embodiment of the present application, a computer-readable storage medium is provided. The computer readable storage medium may be a non-volatile computer readable storage medium. The computer readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the method for generating code based on annotations disclosed in embodiments of the present application.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses, devices and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus, device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only a logical division, and there may be other divisions when the actual implementation is performed, or units having the same function may be grouped into one unit, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may also be an electric, mechanical or other form of connection.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiments of the present application.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a storage medium. Based on such understanding, the technical solution of the present application may be substantially or partially contributed by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-only memory (ROM), a magnetic disk, or an optical disk.
While the invention has been described with reference to specific embodiments, the scope of the invention is not limited thereto, and those skilled in the art can easily conceive various equivalent modifications or substitutions within the technical scope of the invention. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A method for generating code based on annotations, the method comprising:
acquiring an interface document to be converted into a code;
determining a first target class to be converted in the interface document and determining a second target class;
setting a first annotation tag and a second annotation tag for the first target class, wherein the first annotation tag is used for indicating that the first target class is a class to be converted, and the second annotation tag is used for indicating that the first target class is converted into the second target class;
converting the first target class to the second target class according to the second annotation tag;
compiling the interface document by the first annotation tag, the second annotation tag, the first target class and the second target class to obtain a source code file corresponding to the interface document.
2. The method according to claim 1, wherein after obtaining the source code file corresponding to the interface document, the method further comprises:
adding the source code file to a target directory and adding a test code to a test directory;
and performing unit test on the source code file based on the test code to test the correctness of the source code file.
3. The method of claim 2, wherein the first annotation tag and the second annotation tag are both custom annotation tags; before the setting the first annotation tag and the second annotation tag for the first target class, the method further includes:
if the first target class is determined to be the trigger event of class conversion to be carried out according to the test requirement, and the class to be converted from the first target class is determined to be the second target class, determining that the first target class meets the preset annotation label setting condition; then the process of the first step is carried out,
the setting a first annotation tag and a second annotation tag for the first target class includes:
setting the first annotation tag and the second annotation tag for the first target class;
binding the first annotation tag with a trigger event, wherein the trigger event is the conversion of the first target class into the second target class;
the converting the first target class to the second target class according to the second annotation tag comprises:
when traversing to the second target class, triggering a triggering event associated with the first annotation tag to convert the first target class to the second target class according to the second annotation tag.
4. The method of any of claims 1-3, wherein prior to said converting the first target class to the second target class according to the second annotation tag, the method further comprises:
detecting a current application environment;
when detecting that the test item with the specific dependency relationship exists in the application environment, generating a specific conversion class;
injecting the particular conversion class into the interface document;
starting a generator based on the particular conversion class.
5. The method of claim 4, wherein after the setting the first annotation tag and the second annotation tag for the first target class, the method further comprises:
putting a specific service field in the specific conversion class, and configuring a using method of the specific service field;
setting a third annotation label for the specific service field, so that the function of the specific service field simulates the function of a preprocessed database field in a database;
after the source code file corresponding to the interface document is obtained, the method further includes:
identifying the particular business field by the third annotation tag when a field not present in the database is used at a business logic layer or an interaction layer;
and performing data interaction by using the specific service field.
6. The method of claim 4, wherein before compiling the first annotation tag, the second annotation tag, the first target class, and the second target class into the interface document to obtain a source code file corresponding to the interface document, the method further comprises:
determining a target service field in the first target class which meets a preset annotation condition;
and generating a comment mark field for the target service field.
7. The method of any of claims 1-3, wherein prior to said converting the first target class to the second target class according to the second annotation tag, the method further comprises:
setting auxiliary information for the first target class;
and generating a first code according to the auxiliary information.
8. A code generation apparatus, characterized in that the code generation apparatus comprises:
the acquisition module is used for acquiring an interface document to be converted into a code;
the processing module is used for determining a first target class to be converted in the interface document acquired by the acquisition module and determining a second target class; setting a first annotation tag and a second annotation tag for the first target class, wherein the first annotation tag is used for indicating that the first target class is a class to be converted, and the second annotation tag is used for indicating that the first target class is converted into the second target class; converting the first target class to the second target class according to the second annotation tag; compiling the interface document by the first annotation tag, the second annotation tag, the first target class and the second target class to obtain a source code file corresponding to the interface document.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the method of generating code based on annotations according to any of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program which, when executed by a processor, causes the processor to carry out the method of generating code based on annotations according to any of claims 1 to 7.
CN202110430668.XA 2021-04-21 2021-04-21 Method, device and storage medium for generating code based on annotation Pending CN113050953A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110430668.XA CN113050953A (en) 2021-04-21 2021-04-21 Method, device and storage medium for generating code based on annotation

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110430668.XA CN113050953A (en) 2021-04-21 2021-04-21 Method, device and storage medium for generating code based on annotation

Publications (1)

Publication Number Publication Date
CN113050953A true CN113050953A (en) 2021-06-29

Family

ID=76519896

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110430668.XA Pending CN113050953A (en) 2021-04-21 2021-04-21 Method, device and storage medium for generating code based on annotation

Country Status (1)

Country Link
CN (1) CN113050953A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113791979A (en) * 2021-09-16 2021-12-14 平安国际智慧城市科技股份有限公司 Dynamic debugging method and device of software product, computer equipment and storage medium
CN115599388A (en) * 2022-10-17 2023-01-13 中航信移动科技有限公司(Cn) API (application programming interface) document generation method, storage medium and electronic equipment
CN116431108A (en) * 2023-03-16 2023-07-14 北京百度网讯科技有限公司 Object type processing method and device, electronic equipment and storage medium
CN116663502A (en) * 2023-06-01 2023-08-29 上海同星智能科技有限公司 Method and system for converting text codes and graphic codes for automobile development
CN117172203A (en) * 2023-09-07 2023-12-05 芯华章科技股份有限公司 Method for processing script command, electronic device and storage medium
CN117032467B (en) * 2023-10-08 2024-01-09 成都卓拙科技有限公司 Method, device, electronic equipment and storage medium for interaction with chat robot

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109117131A (en) * 2018-08-16 2019-01-01 杭州云纪网络科技有限公司 Code generating method and device, storage medium and electric terminal
CN112230904A (en) * 2020-10-16 2021-01-15 蜂助手股份有限公司 Code generation method and device based on interface document, storage medium and server
CN112667240A (en) * 2020-12-23 2021-04-16 平安普惠企业管理有限公司 Program code conversion method and related device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109117131A (en) * 2018-08-16 2019-01-01 杭州云纪网络科技有限公司 Code generating method and device, storage medium and electric terminal
CN112230904A (en) * 2020-10-16 2021-01-15 蜂助手股份有限公司 Code generation method and device based on interface document, storage medium and server
CN112667240A (en) * 2020-12-23 2021-04-16 平安普惠企业管理有限公司 Program code conversion method and related device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
毒绣: "Dto与Entity相互转换的工具类", pages 1, Retrieved from the Internet <URL:https://blog.csdn.net/qq_38571996/article/details/833052451> *

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113791979A (en) * 2021-09-16 2021-12-14 平安国际智慧城市科技股份有限公司 Dynamic debugging method and device of software product, computer equipment and storage medium
CN113791979B (en) * 2021-09-16 2023-12-22 平安国际智慧城市科技股份有限公司 Dynamic debugging method and device for software product, computer equipment and storage medium
CN115599388A (en) * 2022-10-17 2023-01-13 中航信移动科技有限公司(Cn) API (application programming interface) document generation method, storage medium and electronic equipment
CN115599388B (en) * 2022-10-17 2023-07-21 中航信移动科技有限公司 API (application program interface) document generation method, storage medium and electronic equipment
CN116431108A (en) * 2023-03-16 2023-07-14 北京百度网讯科技有限公司 Object type processing method and device, electronic equipment and storage medium
CN116431108B (en) * 2023-03-16 2024-03-22 北京百度网讯科技有限公司 Object type processing method and device, electronic equipment and storage medium
CN116663502A (en) * 2023-06-01 2023-08-29 上海同星智能科技有限公司 Method and system for converting text codes and graphic codes for automobile development
CN116663502B (en) * 2023-06-01 2023-11-28 上海同星智能科技有限公司 Method and system for converting text codes and graphic codes for automobile development
CN117172203A (en) * 2023-09-07 2023-12-05 芯华章科技股份有限公司 Method for processing script command, electronic device and storage medium
CN117032467B (en) * 2023-10-08 2024-01-09 成都卓拙科技有限公司 Method, device, electronic equipment and storage medium for interaction with chat robot

Similar Documents

Publication Publication Date Title
CN113050953A (en) Method, device and storage medium for generating code based on annotation
CN106919434B (en) Code generation method and device
US8473902B2 (en) Identifying source code elements for refactoring
US9134966B2 (en) Management of mixed programming languages for a simulation environment
US7577946B2 (en) Program product, method, and system for testing consistency of machine code files and source files
US8584104B2 (en) Compile-time management of polyphasic modules
US11386154B2 (en) Method for generating a graph model for monitoring machinery health
EP3623948B1 (en) Method and system for code analysis to identify causes of code smells
CN110704064B (en) Method and device for compiling and executing intelligent contract
ITTO980722A1 (en) PROCEDURE FOR INSTALLING AND / OR VERIFYING THE SOFTWARE FOR A COMPUTER SYSTEM MADE TO ORDER, AND COMPUTER SYSTEM FOR
ITTO980720A1 (en) PROCEDURE FOR INSTALLING AND VERIFYING THE SOFTWARE FOR A CUSTOM MADE COMPUTER SYSTEM.
CN110704063A (en) Method and device for compiling and executing intelligent contract
US10120776B2 (en) Documents for human readable documentation and runtime validation
US9304893B1 (en) Integrated software development and test case management system
Chen et al. Extracting and studying the Logging-Code-Issue-Introducing changes in Java-based large-scale open source software systems
EP2141587A1 (en) Method and system for generating of a control flow graph for representing a program code
Dong et al. Orplocator: Identifying read points of configuration options via static analysis
CN103186463A (en) Method and system for determining testing range of software
US11099978B2 (en) Modeling system for software-implemented testing using domain specific profiles to translate tests for a subset of paths included in a UML test model
US8719766B1 (en) System and method for identifying and adding files to a project manifest
US7194658B2 (en) Various methods and apparatuses for interfacing of a protocol monitor to protocol checkers and functional checkers
Pirkelbauer et al. Source code rejuvenation is not refactoring
US9396239B2 (en) Compiling method, storage medium and compiling apparatus
Nguyen et al. Verifying implementation of uml sequence diagrams using java pathfinder
CN112256554B (en) Method and equipment for testing based on scene test cases

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination