CN109032662B - Code file generation method and device, computer equipment and storage medium - Google Patents
Code file generation method and device, computer equipment and storage medium Download PDFInfo
- Publication number
- CN109032662B CN109032662B CN201810629826.2A CN201810629826A CN109032662B CN 109032662 B CN109032662 B CN 109032662B CN 201810629826 A CN201810629826 A CN 201810629826A CN 109032662 B CN109032662 B CN 109032662B
- Authority
- CN
- China
- Prior art keywords
- code
- template
- file
- metadata
- code file
- 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.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/73—Program documentation
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Library & Information Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Stored Programmes (AREA)
Abstract
The application relates to a code file generation method, a code file generation device, computer equipment and a storage medium. The method comprises the following steps: acquiring metadata of an object to be operated; loading at least one group of code templates matched with the extracted metadata, wherein each group of code templates defines the set operation logic of the object to be operated; and combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated. By adopting the method, flexible customization of various operation logic codes can be realized.
Description
Technical Field
The present application relates to the field of computer technologies, and in particular, to a code file generation method and apparatus, a computer device, and a storage medium.
Background
With the development of internet technology, the software system has been the soul of the internet, and in order to meet the increasing computer software service requirements of people, software developers need to continuously develop and innovate computer programs.
A computer program is composed of a series of codes and is capable of expressing specific mathematical logic. The conventional way of generating the above-mentioned series of codes includes: developers manually type code and automatically generate code through a code generation tool. The method that developers write codes purely manually has the defect that a large amount of codes are written repeatedly, and time and labor are wasted. However, because the conventional code generation tools mostly perform code generation for a specific scenario, one code generation tool can only generate codes for a specific scenario (e.g., database operation). When the operation codes under various scenes are generated, various code generation tools are needed, the code generation efficiency is low, and the flexibility is poor.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a code generation file method, apparatus, computer device, and storage medium, which can implement flexible customization of various operation logic codes and have higher code generation efficiency.
A method of code file generation, the method comprising:
acquiring metadata of an object to be operated;
loading at least one group of code templates matched with the extracted metadata, wherein each group of code templates defines the set operation logic of the object to be operated;
and combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated.
In one embodiment, the obtaining metadata of the operation object includes:
acquiring a source code file of an object to be operated;
analyzing the source code file, and determining a data extraction strategy corresponding to the source code file according to a preset corresponding relation between the type of the source code file and the data extraction strategy;
and loading the data extraction strategy, and extracting metadata from the source code file through the data extraction strategy.
In one embodiment, said loading at least one set of code templates matching said extracted metadata comprises:
calling at least one template processor according to the type of the metadata, wherein the template processor is a loader for setting code template combinations;
and loading a corresponding code template combination through the template processor.
In one embodiment, the combining the loaded code template and the metadata to generate at least one code file for operating the object to be operated includes:
converting the extracted metadata into a set of key-value pairs, the key-value pairs comprising variables and variable values;
acquiring the code template directory, extracting directory sub-entries in the code template directory, replacing variables in the directory sub-entries with variable values of corresponding variables in the metadata, and generating package names according to the directory sub-entries after variable replacement;
and acquiring a code template file according to the file sub-items in the code template directory, replacing variables in the code template file with variable values of corresponding variables in the metadata, and generating a code file, wherein the generated code file declares the generated package name.
In one embodiment, after the step of combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated, the method further includes:
judging whether the generated code file exists or not, if so, converting the generated code file and the existing code file into a syntax tree, circularly executing a configured merging strategy to generate a merged syntax tree, and generating the merged code file according to the merged syntax tree.
An apparatus for code file generation, the apparatus comprising:
the metadata extraction module is used for acquiring metadata of the object to be operated;
the code template loading module is used for loading at least one group of code templates matched with the extracted metadata, wherein each group of code templates defines the set operation logic of the object to be operated;
and the combination module is used for combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated.
In one embodiment, the code template loading module is further configured to invoke at least one predefined template processor according to the type of the metadata; and loading code template combinations through the template processors, and configuring the code template combinations which can be loaded for each template processor in advance.
In one embodiment, the combination module further comprises:
a format conversion module to convert the extracted metadata into a set of key-value pairs, the key-value pairs including variables and variable values;
the package name generation module is used for acquiring the code template directory, extracting directory sub-items in the code template directory, replacing variables in the directory sub-items with variable values of corresponding variables in the metadata, and generating package names according to the directory sub-items after variable replacement;
and the code file generation module is used for acquiring a code template file according to the file sub-items in the code template directory, replacing variables in the code template file with variable values of corresponding variables in the metadata, and generating a code file, wherein the generated code file declares the generated package name.
A computer device comprising a memory storing a computer program and a processor implementing the steps of the method of any one of claims 1 to 5 when the computer program is executed.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 5.
According to the code generation method, the code generation device, the computer equipment and the storage medium, the object to be operated is scanned, the metadata capable of describing the object attribute is extracted, one or more groups of code templates capable of being combined with the metadata are loaded, each group of code templates can realize the operation of a specific type in the set scene of the object to be operated, the metadata and the code templates are combined to generate the code file, the generated code file comprises the code files of various operations implemented on the object to be operated, the flexible customization of the operation codes of the object to be operated is realized by flexibly loading different code templates, and the code files of various operation logics under various scenes can be generated by one-time operation.
Drawings
FIG. 1 is a diagram illustrating an exemplary implementation of a code file generation method;
FIG. 2 is a flowchart illustrating a method for generating a code file according to an embodiment;
FIG. 3 is a schematic diagram of extracting metadata in one embodiment;
FIG. 4 is a flow diagram that illustrates the loading of at least one set of code templates that match metadata, in one embodiment;
FIG. 5 is a schematic flow diagram that illustrates the combination of metadata and code templates to generate a code file for an operand in one embodiment;
FIG. 6 is a schematic diagram of code file merging in one embodiment;
FIG. 7 is a block diagram showing the structure of a code file generating apparatus according to an embodiment;
FIG. 8 is a block diagram of a combination module in one embodiment;
FIG. 9 is a block diagram showing the construction of a code file generating apparatus in another embodiment;
FIG. 10 is a diagram showing an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The code generation method provided by the application can be applied to the application environment shown in fig. 1. Wherein the terminal 102 communicates with the server 104 via a network. The terminal 102 is configured to provide a user operation interface, monitor an object to be operated specified by a user, monitor configuration operations of the user, and send a code generation request to the server 104. The server 104 extracts the metadata of the object to be operated, loads at least one group of code templates matched with the metadata, and combines the metadata and the code templates to generate codes of at least one operation type of the object to be operated. The terminal 102 may be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, and the server 104 may be implemented by a stand-alone server or a server cluster composed of a plurality of servers.
In one embodiment, as shown in fig. 2, a code file generation method is provided, which is described by taking the application of the method to the server in fig. 1 as an example, and includes the following steps:
step S202: and acquiring metadata of the object to be operated.
The object to be operated can be a web page, an interface or a class and other program units which have relatively solidified properties and can be further operated. Metadata of an object to be operated on refers to data used to describe the properties of the object. For example, the metadata of an http interface may include interface paths, input and output parameters of the interface, and the like. The metadata of the web page may be a component id, a component type, and the like.
And scanning the source code of the object to be operated, and extracting metadata from the source code of the object to be operated. For example, JAVA engineering, by loading a class file of an object to be operated, traversing a class method (method) and a class variable (field) in the class file to obtain metadata describing the attributes in the class file.
Step S204: and loading at least one group of code templates matched with the extracted metadata, wherein each group of code templates defines the set operation logic of the object to be operated.
Abstractions code templates for manipulating various types of objects are defined for various types of manipulation logic that may be implemented for various types of objects to be manipulated. The operation logic is an abstracted operation method framework, and one type of operation logic is essentially codes capable of implementing setting operation on the same type of objects to be operated. If the operation code for implementing the call operation on the http interface is the interface call code template, the http interface is called by the user.
In this embodiment, a plurality of code templates are defined for the object to be operated, and each code template implements an operation logic of the object to be operated. If the object to be operated is an interface, the code template defined for the http interface may be a code template for calling the interface, a code template for encapsulating the interface, or the like. Combinations of multiple code templates for the same object may also be used to implement an operating logic.
In one embodiment, a tag matching an object may be added to each defined code template, and the loaded code template is a code template with a tag of an object to be operated. In another embodiment, a matching degree between the extracted metadata and the replaceable content in the code template may be calculated, and it is determined whether the code template is suitable for performing a corresponding operation on the object to be operated according to the matching degree. And the user can select the code template which needs to be loaded currently in a manual configuration mode.
In this embodiment, the loaded group code template matching the metadata may include one code template or a plurality of code templates, and one or a combination of one or a plurality of code templates can implement one operation logic of the object to be operated. Loading a set of code templates means loading a set of code templates that implement an operating logic. The embodiment focuses on loading multiple groups of code templates, and the multiple groups of code templates can realize multiple types of operation logics of objects to be operated.
Step S206: and combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated.
The template engine replaces the template content of each set of loaded code templates by using the metadata of the object to be operated, and each set of code templates after replacement can realize the set type operation logic of the object to be operated.
In this embodiment, by scanning an object to be operated, extracting metadata capable of describing attributes of the object, and loading one or more sets of code templates capable of being combined with the metadata, each set of code template may implement a specific type of operation on the object to be operated, and combining the metadata and the code templates, codes of various types of operation logics for the object to be operated may be generated. The method and the device can generate codes of various operation types of the objects to be operated in batches, and the generated codes can be flexibly customized according to needs. The code template matched with the object to be operated can be combined in a customized mode to derive a plurality of operation logics of the object to be operated.
In addition, by abstracting the code logic for a certain type of object to be operated, a large number of repeated knocks of the code in the development process is reduced.
In one embodiment, step S202: the acquiring metadata of the object to be operated comprises the following steps: acquiring a source code file of an object to be operated; analyzing the source code file, and determining a data extraction strategy corresponding to the source code file according to a corresponding relation between a pre-configured source code file type and the data extraction strategy; and loading the determined data extraction strategy, and extracting the metadata from the source code file of the object to be operated through the data extraction strategy.
Furthermore, the request can carry the identifiers of a plurality of objects to be operated, and the server loads corresponding extraction strategies for the plurality of objects to be operated in a multithreading mode and extracts the metadata of the plurality of objects to be operated at the same time.
As shown in fig. 3, the server loads two types of source code files of the object to be operated, such as a java.class file (class file) and an Html file, loads a path policy, a Method policy and a param policy configured for the java.class file in advance, loads a component policy configured for the Html file in advance, extracts and outputs metadata of the object to be operated through the loaded policy, and the output metadata is used for matching with the matched code template.
In this embodiment, different extraction strategies are defined for different types of objects to be operated, and when metadata of the objects to be operated is extracted, the extraction strategies are directly called, so that the metadata can be automatically extracted. Metadata of different types of objects to be operated can be extracted simultaneously by calling a blind extraction strategy, and the data extraction efficiency is improved.
In one embodiment, as shown in FIG. 4, step S204: loading at least one set of code templates matching the metadata, comprising the steps of:
step S402: and calling at least one template processor according to the type of the metadata, wherein the template processor is a loader for setting the code template combination.
Step S404: the corresponding code template combination is loaded by the template processor.
A plurality of template processors are predefined, and code template combinations which can be loaded by each template processor are specifically defined. Each template processor is configured with a loadable combination of code templates, and the template processor is essentially a loader that sets the combination of code templates. And establishing an association relation between the template processor and the metadata type through a code template combination which can be loaded by the template processor and the metadata type which is adapted to the code template in the code template combination. The specific implementation method comprises the following steps: and calling at least one template processor according to the type of the metadata, and loading the code template combination which can be loaded by the template processor. The multiple code templates loaded by the same template processor can realize one operation logic of the object to be operated and also can realize a series of related operation logics of the object to be operated.
In the embodiment, by defining the template processors, all the code templates matched with various objects to be processed can be combined and classified in advance, and the server can load the code templates according to the predefined combinations only by searching the matched template processors according to the types of the metadata without performing complicated code template combinations.
For example, the code templates matched with a certain type of object to be operated include a code template a, a code template B and a code template C, wherein the combination of the code template B and the code template C, and the combination of the code a, the code template B and the code template C can also realize a type of operation on the object to be operated, then 5 template processors may be defined, and the 5 template processors are defined to be sequentially the code template a, the code template B, the code template C, the combination of the code template B and the code template C, and the combination of the code a, the code template B and the code template C. Of course, if there are other combinations that can also implement operations on the object to be operated, more template processors are defined. Adding corresponding metadata type tags for defined template processors, wherein one template processor can correspond to a plurality of metadata type tags.
In one embodiment, as shown in FIG. 5, step S306: the loaded code template and the metadata are combined to generate at least one code file for operating the object to be operated, and the method comprises the following steps:
it should be noted that the following steps are given as logic for combining the metadata with one or a group of code templates, and the combination of the metadata with the multiple groups of code templates can be realized by circularly executing the following steps, or the simultaneous combination of the metadata with the multiple groups of code templates can be realized by executing the following steps in a multithread way.
Step S502: the metadata is converted into a set of key-value pairs, the key-value pairs including variables and variable values.
The metadata is converted into a ("key value") string, key being a variable and value being a variable value.
Step S504: and acquiring a directory of the code template, and replacing variables of directory sub-items in the directory with variable values in the metadata.
Recursively traversing all sub-items in the directory of the code template, judging whether the currently traversed sub-items are files or directories, if so, searching whether variables exist in the directory, if so, searching whether variable values corresponding to the variables in the directory exist in the metadata, and if so, replacing the variables in the directory with the corresponding variable values until the variables of the sub-items of each layer of the directory of the code template are replaced.
If the template directory carries $ { var } variable characters, the converted metadata is context.
Step S506: and generating the package name according to the directory sub-entry of the code template directory after replacing the variable.
Step S508: and acquiring a code template file, replacing the content in the file with metadata, generating a code file, and declaring the generated package name by the generated code file.
The code template directory comprises directory sub-entries and file sub-entries, and after variables in the directory sub-entries are replaced by variable values of the metadata, package names are generated according to set rules based on the directory sub-entries of each layer of the code template.
The file sub-item in the code template directory designates a code template file, the template engine replaces the content in the code template file with metadata, and removes the blank lines and annotations in the template to generate the code file.
In this embodiment, a package name is generated according to a directory sub-entry of the template directory, a code file is generated according to a file sub-entry in the template directory, and the generated package name is declared by the code file. When generating code, declaring a package name for the generated code file, namely creating a new namespace for the class in the code file by using the package name, and because the package creates a new namespace (namespace), no naming conflict with any name in other packages can be generated. Using a package mechanism, access control is easier to implement and locating related classes is simpler, and without using such a package mechanism declaring a package name for a newly generated code, an editing error will occur.
In one embodiment, when extracting the metadata of the object to be operated, the package name prefix is configured for the metadata. The system identifier of the system where the object to be operated is located may be searched, and the system identifier of the system where the object to be operated is located is configured as a package name prefix of the metadata of the object to be operated. And adding a package name prefix into the generated package name.
For example, the template catalog of the code template is: templates/app/appller.java, wherein/app/is a directory sub-item, and appller.java is a file sub-item, and if the configured package name prefix is com. And loading a template file based on the file sub-item, combining the template file and the metadata to generate a code file, wherein the package name corresponding to the code file is com.
When the loaded group of code templates comprises a plurality of code templates, a plurality of code files are generated according to the steps S502-S508, and each code file generates a package name correspondingly. The directory of the generated code file includes its corresponding package name.
It should be understood that although the various steps in the flowcharts of fig. 2, 4-5 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 2, 4-5 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternating with other steps or at least some of the sub-steps or stages of other steps.
In one embodiment, in step S508: acquiring the file of the code template, and replacing the content in the file with metadata to generate a code file, wherein after the generated code file declares the package name generated according to the code template directory, the method further comprises the following steps: and judging whether the generated code file exists or not, and if so, combining the code file.
Fig. 6 is a logic diagram of code merging. The method comprises the steps of firstly obtaining an existing code file and a new code file, converting the existing code and the new code into a syntax tree by using an Eclipse JDT library, loading a configured merging strategy and circularly executing the merging strategy to generate a merged syntax tree, converting the merged syntax tree into a code text, and writing the code text into a target code file.
In one embodiment, a directory and a merge of directories are also included. The method specifically comprises the following steps: and judging the type of the merging source, namely merging the directory and the directory or merging the file and the file. If the files are merged, the merging method shown in fig. 6 is adopted for merging. If the directory and the directory are merged, reading a file list in the source directory, traversing each file in the directory, obtaining a relative path between the file and the path of the source directory, obtaining a complete path of the target file according to the relative path, judging whether the target file exists, copying a code in the currently traversed code file into the target code file if the target file does not exist, and merging the source file and the target file according to the method shown in fig. 6 if the target file exists. And traversing the next source file in the source directory until all files in the source directory file list are traversed.
In this embodiment, the merging policy shown in the following table is defined in advance, and the type, name, and description of the merging policy given in table 1 specifically refer to the following table.
TABLE 1
In this embodiment, to avoid that the generated code file covers the existing code and causes the code file to be lost, a code merging policy is predefined in this embodiment, and the code file to be merged, including merging of a file and merging of a directory and a directory, is automatically searched. In the embodiment, the codes are automatically merged by circularly executing the code strategy without manual merging, and the automatic management of the codes is realized on the basis of batch generation of the codes.
In one embodiment, a code file generation method is provided, which includes the following steps:
and acquiring a source code file of the object to be operated, and extracting metadata of the object to be operated from the source code file. And storing the metadata of all the objects to be operated in the form of metadata files. When the instruction of generating the codes in batches is obtained, each metadata file is traversed recursively, metadata is read from the file, and the read metadata is converted into the Map in the recursive key-value pair format. Creating a data container, adding the metadata after format conversion into the data container by using various tool classes loaded and configured from Spring (Spring is a layered JavaSE/EE full-stack one-stop lightweight open-source framework), acquiring a configured package name prefix, and adding the entry prefix into the data container.
And configuring a template processor needing to be loaded aiming at the currently traversed metadata, and automatically loading the corresponding template processor according to the corresponding relation between the predefined template processor and the object to be operated. The code templates loaded by each template processor are predefined. Traversing all sub-items of a code template directory which can be loaded by a template processor, judging whether the currently traversed sub-item is a file or a directory, if so, searching whether a variable exists in the directory, matching key value pairs in a data container by the variable, replacing the variable by a variable value, generating a packet name by combining the current-layer directory and the previous-layer directory after replacement, traversing the sub-items of the next-layer directory, continuously updating the packet name until the traversed sub-item is the file, adding the latest packet name into the data container, and combining the packet name and the packet name prefix into a complete packet name. Loading a template code file by a template engine, calling a data container, firstly calling metadata in the data container, replacing contents in the code template with the metadata, secondly writing a packet name in the data container into a position of a declaration packet name in the code template, finally replacing template contents, removing an empty line caused by the template and a note in the template, generating and outputting a code file, declaring the packet name in the data container by the generated code file, judging whether the code file exists or not, and if so, merging the code file.
Traversing the next code template directory which can be loaded by the template processor, traversing the directory subitems to generate package names, adding the currently generated package names into the data container to replace the existing package names, loading the code template file corresponding to the current code template directory, generating code files, and declaring the replaced package names in the data container by the generated code files. And all the code templates in all the template processors corresponding to the metadata are traversed. And acquiring the next metadata file, reconstructing a data container based on the next metadata file, and traversing all the metadata files.
In the embodiment, a data container is generated based on an object to be operated, a plurality of configured code templates call the data, content replacement can be easily carried out, code files can be generated in batches, and the code file generation efficiency is higher.
In one embodiment, as shown in fig. 7, there is provided a code file generating apparatus including: a metadata extraction module 702, a code template loading module 704, and a combination module 706, wherein:
the metadata extraction module 702 obtains metadata of an object to be operated.
And a code template loading module 704, configured to load at least one group of code templates matching the extracted metadata, where each group of code templates defines a set operation logic of the object to be operated.
And the combination module 706 is configured to combine the loaded code template with the metadata to generate at least one code file for operating the object to be operated.
In an embodiment, the metadata extraction module 702 is further configured to obtain a source code file of the object to be operated; analyzing the source code file, and determining a data extraction strategy corresponding to the source code file according to a corresponding relation between a pre-configured source code file type and the data extraction strategy; and loading the determined data extraction strategy, and extracting the metadata from the source code file through the data extraction strategy.
In one embodiment, the code template loading module 704 is further configured to invoke at least one template processor according to the type of the metadata, where the template processor is a loader that sets a combination of code templates; the corresponding code template combination is loaded by the template processor.
In one embodiment, as shown in FIG. 8, the combination module 706, includes a format conversion module 802, a package name generation module 804 and a code file generation module 806, wherein:
a format conversion module 802 for converting the metadata into a set of key-value pairs, the key-value pairs including variables and variable values.
And the package name generating module 804 is configured to obtain the code template directory, extract a directory sub-entry in the code template directory, replace a variable in the directory sub-entry with a variable value of a corresponding variable in the metadata, and generate a package name according to the directory sub-entry after the variable replacement.
The code file generating module 806 is configured to obtain a code template file according to a file sub-entry in the code template directory, and replace a variable in the code template file with a variable value of a corresponding variable in the metadata to generate a code file, where the generated code file declares a generated package name.
In an embodiment, as shown in fig. 9, the code generating apparatus further includes a file merging module 708, configured to determine whether the generated code file already exists, if so, convert the generated code file and the existing code file into a syntax tree, circularly execute the configured merging policy to generate a merged syntax tree, and generate the merged code file according to the merged syntax tree.
For specific limitations of the code generation apparatus, reference may be made to the above limitations of the code generation method, which are not described herein again. The modules in the code generation apparatus can be implemented in whole or in part by software, hardware, and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as shown in fig. 10. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The database of the computer device is used for storing the generated code file. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a code file generation method.
Those skilled in the art will appreciate that the architecture shown in fig. 10 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, there is provided a computer device comprising a memory storing a computer program and a processor implementing the following steps when the processor executes the computer program: acquiring metadata of an object to be operated; loading at least one group of code templates matched with the extracted metadata, wherein each group of code templates defines the set operation logic of the object to be operated; and combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated.
In one embodiment, the processor, when executing the computer program, further performs the steps of: acquiring a source code file of an object to be operated; analyzing the source code file, and determining a data extraction strategy corresponding to the source code file according to a corresponding relation between a pre-configured source code file type and the data extraction strategy; and loading a data extraction strategy, and extracting metadata from the source code file through the data extraction strategy.
In one embodiment, the processor, when executing the computer program, further performs the steps of: calling at least one template processor according to the type of the metadata, wherein the template processor is a loader for setting code template combination; the corresponding code template combination is loaded by the template processor.
In one embodiment, the processor, when executing the computer program, further performs the steps of: converting the extracted metadata into a set of key-value pairs, the key-value pairs comprising variables and variable values; acquiring a code template directory, extracting directory sub-entries in the code template directory, replacing variables in the directory sub-entries with variable values of corresponding variables in metadata, and generating packet names according to the directory sub-entries after variable replacement; and acquiring a code template file according to the file sub-items in the code template directory, replacing variables in the code template file with variable values of corresponding variables in the metadata, and generating the code file, wherein the generated code file declares the generated package name.
In one embodiment, the processor, when executing the computer program, further performs the steps of: judging whether the generated code file exists or not, if so, converting the generated code file and the existing code file into a syntax tree, circularly executing a configured merging strategy to generate a merged syntax tree, and generating the merged code file according to the merged syntax tree.
In one embodiment, a computer-readable storage medium is provided, having a computer program stored thereon, which when executed by a processor, performs the steps of: acquiring metadata of an object to be operated; loading at least one group of code templates matched with the extracted metadata, wherein each group of code templates defines the set operation logic of the object to be operated; and combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated.
In one embodiment, the computer program when executed by the processor further performs the steps of: acquiring a source code file of an object to be operated; analyzing the source code file, and determining a data extraction strategy corresponding to the source code file according to a corresponding relation between a pre-configured source code file type and the data extraction strategy; and loading a data extraction strategy, and extracting metadata from the source code file through the data extraction strategy.
In one embodiment, the computer program when executed by the processor further performs the steps of: calling at least one template processor according to the type of the metadata, wherein the template processor is a loader for setting code template combination; the corresponding code template combination is loaded by the template processor.
In one embodiment, the computer program when executed by the processor further performs the steps of: converting the extracted metadata into a set of key-value pairs, the key-value pairs comprising variables and variable values; acquiring a code template directory, extracting directory sub-entries in the code template directory, replacing variables in the directory sub-entries with variable values of corresponding variables in metadata, and generating packet names according to the directory sub-entries after variable replacement; and acquiring a code template file according to the file sub-items in the code template directory, replacing variables in the code template file with variable values of corresponding variables in the metadata, and generating the code file, wherein the generated code file declares the generated package name.
In one embodiment, the computer program when executed by the processor further performs the steps of: judging whether the generated code file exists or not, if so, converting the generated code file and the existing code file into a syntax tree, circularly executing a configured merging strategy to generate a merged syntax tree, and generating the merged code file according to the merged syntax tree.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware related to instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, the computer program can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above examples only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.
Claims (8)
1. A method of code file generation, the method comprising:
acquiring a source code file of an object to be operated; the object to be operated comprises a Web page, an interface or a class, and is a program unit which has relative curing property and can be further operated;
analyzing the source code file, and determining a data extraction strategy corresponding to the source code file according to a preset corresponding relation between the type of the source code file and the data extraction strategy;
loading the data extraction strategy, and extracting the metadata of the object to be operated from the source code file through the data extraction strategy;
calling at least one template processor according to the type of the metadata, wherein the template processor is a loader for setting code template combinations;
loading a corresponding code template combination through the template processor to obtain at least one group of code templates matched with the extracted metadata, wherein each group of code templates defines the set operation logic of the object to be operated;
and combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated.
2. The method according to claim 1, wherein the combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated comprises:
converting the extracted metadata into a set of key-value pairs, the key-value pairs comprising variables and variable values;
acquiring a code template directory, extracting directory sub-entries in the code template directory, replacing variables in the directory sub-entries with variable values of corresponding variables in the metadata, and generating package names according to the directory sub-entries after variable replacement;
and acquiring a code template file according to the file sub-items in the code template directory, replacing variables in the code template file with variable values of corresponding variables in the metadata, and generating a code file, wherein the generated code file declares the generated package name.
3. The method according to claim 1, wherein after combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated, the method further comprises:
judging whether the generated code file exists or not, if so, converting the generated code file and the existing code file into a syntax tree, circularly executing a configured merging strategy to generate a merged syntax tree, and generating the merged code file according to the merged syntax tree.
4. An apparatus for generating a code file, the apparatus comprising:
the metadata extraction module is used for acquiring a source code file of an object to be operated, wherein the object to be operated comprises a Web page, an interface or a class, and is a program unit which has relative curing properties and can be further operated; analyzing the source code file, and determining a data extraction strategy corresponding to the source code file according to a preset corresponding relation between the type of the source code file and the data extraction strategy; loading the data extraction strategy, and extracting the metadata of the object to be operated from the source code file through the data extraction strategy;
the code template loading module is used for calling at least one predefined template processor according to the type of the metadata; loading a code template combination through the template processor to obtain at least one group of code templates matched with the extracted metadata, wherein each group of code templates defines the set operation logic of the object to be operated;
and the combination module is used for combining the loaded code template with the metadata to generate at least one code file for operating the object to be operated.
5. The apparatus of claim 4, wherein the combination module further comprises:
a format conversion module to convert the extracted metadata into a set of key-value pairs, the key-value pairs including variables and variable values;
the package name generation module is used for acquiring a code template directory, extracting directory sub-items in the code template directory, replacing variables in the directory sub-items with variable values of corresponding variables in the metadata, and generating package names according to the directory sub-items after variable replacement;
and the code file generation module is used for acquiring a code template file according to the file sub-items in the code template directory, replacing variables in the code template file with variable values of corresponding variables in the metadata, and generating a code file, wherein the generated code file declares the generated package name.
6. The apparatus of claim 4, further comprising:
and the file merging module is used for judging whether the generated code file exists or not, converting the generated code file and the existing code file into a syntax tree if the generated code file exists, circularly executing a configured merging strategy to generate a merged syntax tree, and generating the merged code file according to the merged syntax tree.
7. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor realizes the steps of the method of any one of claims 1 to 3 when executing the computer program.
8. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 3.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810629826.2A CN109032662B (en) | 2018-06-19 | 2018-06-19 | Code file generation method and device, computer equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810629826.2A CN109032662B (en) | 2018-06-19 | 2018-06-19 | Code file generation method and device, computer equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109032662A CN109032662A (en) | 2018-12-18 |
CN109032662B true CN109032662B (en) | 2021-03-23 |
Family
ID=64609599
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810629826.2A Active CN109032662B (en) | 2018-06-19 | 2018-06-19 | Code file generation method and device, computer equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109032662B (en) |
Families Citing this family (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109947431B (en) * | 2019-03-28 | 2022-09-16 | 北京字节跳动网络技术有限公司 | Code generation method, device, equipment and storage medium |
CN111045685A (en) * | 2019-11-05 | 2020-04-21 | 贝壳技术有限公司 | Code conversion method, device, storage medium and electronic equipment |
CN111061475B (en) * | 2019-12-13 | 2023-12-12 | 中国南方电网有限责任公司 | Software code generating method, device, computer equipment and storage medium |
CN112286557B (en) * | 2020-11-05 | 2024-03-22 | 苏州帝博信息技术有限公司 | Method and device for updating code content in non-coverage mode |
CN112596706A (en) * | 2020-12-15 | 2021-04-02 | 用友网络科技股份有限公司 | Patterned code generation method, device and computer readable storage medium |
CN112650529B (en) * | 2020-12-31 | 2023-06-06 | 城云科技(中国)有限公司 | System and method for configurable generation of mobile terminal APP codes |
CN112799718A (en) * | 2021-01-15 | 2021-05-14 | 亿企赢网络科技有限公司 | Enumerated document generation method and device, electronic equipment and storage medium |
CN113608726B (en) * | 2021-07-30 | 2023-08-11 | 三一专用汽车有限责任公司 | Code generation method, device, electronic equipment and storage medium |
CN113742008B (en) * | 2021-09-13 | 2024-04-02 | 挂号网(杭州)科技有限公司 | Interface calling method and device, electronic equipment and storage medium |
CN113905277B (en) * | 2021-12-09 | 2022-03-22 | 北京新片场传媒股份有限公司 | Method and device for playing video by browser and electronic equipment |
CN115048111B (en) * | 2022-08-16 | 2022-11-15 | 深圳华锐分布式技术股份有限公司 | Code generation method, device, equipment and medium based on metadata |
Family Cites Families (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
EP2433200B1 (en) * | 2009-05-21 | 2020-02-26 | Salesforce.Com, Inc. | System, method and computer program product for versioning components of an application |
CN102117202B (en) * | 2009-12-30 | 2014-03-12 | 北大方正集团有限公司 | J2EE architecture-based code generating device |
US20120317504A1 (en) * | 2011-06-13 | 2012-12-13 | Microsoft Corporation | Automated user interface object transformation and code generation |
US10417314B2 (en) * | 2012-06-14 | 2019-09-17 | Open Text Sa Ulc | Systems and methods of a script generation engine |
CN103412749A (en) * | 2013-07-29 | 2013-11-27 | 福建联迪商用设备有限公司 | Relational database based code generation method and code generator |
CN104267966B (en) * | 2014-10-15 | 2018-05-15 | 北京国双科技有限公司 | The generation method and device of the program code of software |
CN104657140B (en) * | 2015-02-10 | 2018-01-09 | 广州华多网络科技有限公司 | Code generating method and device |
CN106873949A (en) * | 2015-12-11 | 2017-06-20 | 泰康保险集团股份有限公司 | Code generating method and its device |
CA3009641A1 (en) * | 2015-12-22 | 2017-06-29 | Opera Solutions U.S.A., Llc | System and method for rapid development and deployment of reusable analytic code for use in computerized data modeling and analysis |
CN106528165B (en) * | 2016-11-11 | 2019-10-08 | 深圳中兴网信科技有限公司 | Code generating method and code generating system |
CN106843878B (en) * | 2017-01-20 | 2019-10-25 | 武汉斗鱼网络科技有限公司 | A kind of model generating method and system |
CN107291450B (en) * | 2017-05-25 | 2021-04-09 | 土巴兔集团股份有限公司 | Programming-friendly agile code automatic generation method |
-
2018
- 2018-06-19 CN CN201810629826.2A patent/CN109032662B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN109032662A (en) | 2018-12-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109032662B (en) | Code file generation method and device, computer equipment and storage medium | |
CN108446116B (en) | Application program page generation method and device, computer equipment and storage medium | |
CN110162296B (en) | Method and device for generating application programming interface document and terminal equipment | |
CN109087054B (en) | Collaborative office data stream processing method, device, computer equipment and storage medium | |
CN109814854B (en) | Project framework generation method, device, computer equipment and storage medium | |
CN111752571B (en) | Program upgrading method, device, equipment and storage medium | |
CN110968325B (en) | Applet conversion method and device | |
CN108804159B (en) | Javascript module loading method and preprocessing method and device thereof, and computer equipment | |
CN109684607B (en) | JSON data analysis method and device, computer equipment and storage medium | |
CN109062925B (en) | Method, device, computer equipment and storage medium for automatically generating insert sentences | |
CN111563220A (en) | Business website project construction method and device, computer equipment and storage medium | |
CN113835713B (en) | Source code packet downloading method, device, computer equipment and storage medium | |
CN109032631B (en) | Application program patch package obtaining method and device, computer equipment and storage medium | |
CN109597618B (en) | Program development method, program development device, computer device, and storage medium | |
CN108920691B (en) | Front-end static resource management method and device, computer equipment and storage medium | |
CN112527415A (en) | Method, device, equipment and medium for migrating applets across platforms | |
CN111008022B (en) | Relationship diagram generation method, device, computer equipment and storage medium | |
CN112380130A (en) | Application testing method and device based on call dependency relationship | |
CN111796855B (en) | Incremental version updating method and device, storage medium and computer equipment | |
CN112882782A (en) | Page generation method and device, computer equipment and storage medium | |
CN111274202A (en) | Electronic contract generating method and device, computer equipment and storage medium | |
CN112579705A (en) | Metadata acquisition method and device, computer equipment and storage medium | |
CN116185425B (en) | Event flow arrangement method, device, equipment and medium based on node combination | |
CN111984595B (en) | File processing method and device and storage medium | |
CN116466953A (en) | Modularized front-end development method, device, computer equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20200122 Address after: 200120 floor 15, 1333 Lujiazui Ring Road, China (Shanghai) pilot Free Trade Zone, Pudong New Area, Shanghai Applicant after: Weikun (Shanghai) Technology Service Co., Ltd Address before: 200120 13 floor, 1333 Lujiazui Road, Pudong New Area free trade pilot area, Shanghai. Applicant before: Lujiazui Shanghai international financial assets market Limited by Share Ltd |
|
TA01 | Transfer of patent application right | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |