CN112286557A - Method and device for updating code content in non-covering mode - Google Patents
Method and device for updating code content in non-covering mode Download PDFInfo
- Publication number
- CN112286557A CN112286557A CN202011220746.5A CN202011220746A CN112286557A CN 112286557 A CN112286557 A CN 112286557A CN 202011220746 A CN202011220746 A CN 202011220746A CN 112286557 A CN112286557 A CN 112286557A
- Authority
- CN
- China
- Prior art keywords
- syntax tree
- modification
- code
- updated
- type
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 56
- 230000004048 modification Effects 0.000 claims abstract description 137
- 238000012986 modification Methods 0.000 claims abstract description 137
- 238000012217 deletion Methods 0.000 claims abstract description 22
- 230000037430 deletion Effects 0.000 claims abstract description 22
- 238000006243 chemical reaction Methods 0.000 claims description 7
- 238000012544 monitoring process Methods 0.000 claims description 7
- 238000004590 computer program Methods 0.000 claims description 6
- 238000004458 analytical method Methods 0.000 claims description 3
- 230000018109 developmental process Effects 0.000 description 14
- 230000008859 change Effects 0.000 description 11
- 230000006870 function Effects 0.000 description 11
- 238000011161 development Methods 0.000 description 7
- 238000010586 diagram Methods 0.000 description 6
- 230000008569 process Effects 0.000 description 6
- 238000012545 processing Methods 0.000 description 3
- 230000003252 repetitive effect Effects 0.000 description 3
- 230000005540 biological transmission Effects 0.000 description 2
- 230000003068 static effect Effects 0.000 description 2
- 230000009471 action Effects 0.000 description 1
- 238000003491 array Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000004806 packaging method and process Methods 0.000 description 1
- 230000008929 regeneration Effects 0.000 description 1
- 238000011069 regeneration method Methods 0.000 description 1
- 230000000717 retained effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/60—Software deployment
- G06F8/65—Updates
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Stored Programmes (AREA)
Abstract
The invention provides a method and a device for updating code content in a non-overlay mode. The method comprises the following steps: acquiring attribute definition information of an object of a code file to be updated; obtaining a modification type and a modification field when attribute definition information of an object is modified; generating a temporary new code file based on the modified attribute definition information of the object, a code generation tool and a code generation template; respectively obtaining syntax trees of a code to be updated and a temporary new code, extracting syntax tree nodes of modification fields of a deletion type from the syntax tree of the code to be updated, and extracting syntax tree nodes of modification fields of a new addition type and an update type from the syntax tree of the temporary new code; deleting the syntax tree nodes of the modification fields of the update type and the deletion type from the syntax tree of the code to be updated, and adding the syntax tree nodes of the modification fields of the new addition and the update type extracted from the syntax tree of the temporary new code into the syntax tree of the code to be updated; the updated syntax tree is converted into code to update the code.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for updating code content in a non-overlay mode.
Background
In the development process of a software program, a lot of repetitive work can be involved in code writing, the repetitive code writing work is tedious physical labor, and code generation by means of a code generator is one of the effective modes which are generally adopted in the industry and used for reducing software development intensity, reducing repetitive code writing and improving development efficiency. However, the existing code generator in the industry only has code generation capability, which results in limited use range of the code generator, and the code generator is only suitable for the initial stage of software project start, namely, the code generated after the data structure is designed based on the existing requirements is generated uniformly; for the middle and later stages of software project development, the requirement generates a changed scene, and because the code generator can only regenerate the code, when the code is updated, the regenerated code directly and comprehensively covers the previous old code, wherein the old code comprises the old code which is manually modified or newly added by a developer. This direct overlay code regeneration may result in developers manually modifying or newly added content being overwritten and removed, which may result in a large number of BUGs being present and some functions not being able to run. Therefore, the code generation function of the code generator is not suitable for use in a scenario where requirements or data structures change during software development.
When the code modification and update caused by the requirement in the software development process or the change of the data structure are completely modified manually by software programmers, the code modification or update accuracy is not high and the working efficiency is low due to the large workload and the easy error of the code modification.
Disclosure of Invention
The present invention aims to provide a method and apparatus for non-overlay updating code content to improve the above problems.
A first embodiment of the present invention provides a method for non-overlay updating code content, which includes:
s1, acquiring attribute definition information of the object in the code file to be updated;
s2, when the obtained attribute definition information of the object is modified, obtaining a modification type made to the current object and a corresponding modification field, the modification type including: new addition, update, and deletion;
s3, using the modified attribute definition information of the object as an input parameter, and generating a temporary new code file by using a code generation tool and a code generation template;
s4, respectively obtaining a syntax tree of a code file to be updated and a syntax tree of the temporary new code file, extracting syntax tree nodes corresponding to the modification fields of the deletion type from the syntax tree of the code file to be updated, and extracting syntax tree nodes corresponding to the modification fields of the addition type and syntax tree nodes corresponding to the modification fields of the update type from the syntax tree of the temporary new code file;
s5, deleting the syntax tree node corresponding to the modification field of the update type and the syntax tree node corresponding to the modification field of the deletion type from the syntax tree of the code file to be updated, and adding the syntax tree node corresponding to the modification field of the new addition type and the syntax tree node corresponding to the modification field of the update type, which are extracted from the syntax tree of the temporary new code file, into the syntax tree of the code file to be updated;
s6, converting the syntax tree of the updated code file to be updated into codes so as to update the codes to be updated.
Wherein: in step S1, attribute definition information of the object is obtained by reading the data source to which the code file to be updated is connected.
And before the obtained attribute definition information of the object is modified, converting the attribute definition information of the object into a JSON format.
Wherein: the step of obtaining the type of modification made to the current object and the corresponding modification field comprises:
comparing the attribute definition information of the object before modification with the attribute definition information of the object after modification to obtain the modification type and the corresponding modification field of the current object; or
The type of modification made and the corresponding modification field are monitored and recorded directly by a monitoring record function.
A second embodiment of the present invention provides an apparatus for non-overlay updating code content, comprising:
the object information acquisition module is used for acquiring attribute definition information of an object in the code file to be updated;
a modification content obtaining module, configured to obtain a modification type and a corresponding modification field made to the current object when the obtained attribute definition information of the object is modified, where the modification type includes: new addition, update, and deletion;
the code generation module is used for generating a code file to be updated by using the code generation template with the modified attribute definition information of the object as an input parameter;
the syntax tree analysis module is used for obtaining a syntax tree of a code file to be updated and a syntax tree of the temporary new code file;
a node extracting module, configured to extract a syntax tree node corresponding to the modification field of the deletion type from the syntax tree of the to-be-updated code file, and extract a syntax tree node corresponding to the modification field of the addition type and a syntax tree node corresponding to the modification field of the update type from the syntax tree of the temporary new code file;
a syntax tree merging module, configured to delete a syntax tree node corresponding to the modification field of the update type and a syntax tree node corresponding to the modification field of the deletion type from a syntax tree of the code file to be updated, and add, to the syntax tree of the code file to be updated, a syntax tree node corresponding to the modification field of the new addition type and a syntax tree node corresponding to the modification field of the update type, which are extracted from the syntax tree of the temporary new code file;
and the syntax tree conversion code module is used for converting the syntax tree of the updated code file to be updated into codes so as to update the codes to be updated.
Wherein: the object information acquisition module is used for acquiring the attribute definition information of the object by reading the data source connected with the code file to be updated.
The device also comprises a format conversion module which is used for converting the attribute definition information of the object into the JSON format before the obtained attribute definition information of the object is modified.
Wherein: the modified content acquisition module performs the following operations:
comparing the attribute definition information of the object before modification with the attribute definition information of the object after modification to obtain the modification type and the corresponding modification field of the current object; or
The type of modification made and the corresponding modification field are monitored and recorded directly by a monitoring record function.
A third embodiment of the present invention provides a computer-readable storage medium, wherein a computer program that, when executed by a processor, implements the method of the first embodiment and its preferred embodiments is recorded on the computer-readable storage medium.
A fourth embodiment of the present invention provides a computing device comprising a storage unit and a processor, wherein the storage unit has stored therein a set of computer-executable instructions which, when executed by the processor, cause the processor to perform the method as described in the first embodiment and its preferred embodiment.
According to the method and the device for updating the code content in the non-covering manner, the grammar tree of the code file to be updated is analyzed and updated, and the updated grammar tree is converted into the novel method for updating the code content, so that the code content added by a developer in a modification or customization manner is not touched, and is reserved but not covered, namely, code change information or customized code information in the previous version of the developer can be reserved and is not covered or cleared, and the non-covering updating of the code content is realized. Therefore, the method and the device for updating the code content in a non-covering mode can be used in a code generator, so that the code generator has the capability of providing the non-covering mode to update the code, the code generator can be suitable for the whole period of software project development (the primary stage of new requirements and the middle and later stages of requirement change), the code updating is automatically completed through the process, the software development efficiency is improved, omission and errors caused by manual modification are avoided, and the code quality is improved.
Drawings
FIG. 1 is a flow chart of a method for non-overlay updating code content according to a first embodiment of the present invention;
FIG. 2 is a flowchart of a non-overlay code content updating method according to a second embodiment of the present invention;
FIG. 3 is a schematic block diagram of a non-overlay update code content apparatus provided by a third embodiment of the present invention;
fig. 4 is a schematic block diagram of a non-overlay code content updating apparatus according to a fourth embodiment of the present invention.
Detailed Description
The technical solutions proposed by the present invention will be clearly and completely described below with reference to specific embodiments and the accompanying drawings, and it is to be understood that the described exemplary embodiments are for illustrative purposes only and are not limiting.
Fig. 1 is a flowchart of a method for non-overlay updating code content according to a first embodiment of the present invention. As shown in fig. 1, a method for non-overlay updating code content according to a first embodiment of the present invention includes:
s1 obtains attribute definition information of the object in the code file to be updated.
The code file to be updated is an old version of the code file with contents needing to be updated. For example, an old version of a code file that has at least a portion of code to be modified due to requirements or data structure changes during software development.
The attribute definition information of the object in the code file to be updated may be obtained by reading a data source to which the code file to be updated is connected. A data source is a place where data is stored, such as a database, which is a data source. The code normally runs and is generally connected to a data source, for example, the code normally runs and needs to be connected with a database. Attribute definition information of an object is obtained by reading a saving position of attribute information of the object defined in the program code.
Different data sources have corresponding implementations. Taking a common relational database as an example, the field definition of an object (for the database, the object mapped with the code is a data table) can be obtained through query SQL of the database. For example, MySQL may be queried by a SQL statement of "SHOW FULL COLUMNS FROM table _ name" to get the field definitions of the table. What is obtained at this time is a database query result, such as the following example of a user table query result:
Field | Type | Null | Key | Default | Extra | Comment |
Id | bigint | NO | PMI | auto_increment | ID primary key | |
Realname | varchar(100) | NO | Nickname | |||
Age | int | NO | Age (age) |
S2, when the obtained attribute definition information of the object is modified, obtaining a modification type made to the current object and a corresponding modification field, the modification type including: add, update, and delete.
Here, the obtained attribute definition information of the object may be modified by a code generation tool, and the code generation tool may be any known code generator, a UI interface, a command line, or the like for generating a code. Based on the change of the requirement, a developer or a user of the code generation tool can use the code generation tool to modify the attribute definition information of the corresponding object, so that the modification type and the corresponding modification field made to the current object can be obtained. For example, based on the above example, the modification operations made by the developer or the user of the code generation tool according to the change in demand are as follows:
1 'new type', modifying the field 'birthdate', the type is 'Date', the remark is 'birth Date';
1 'update type', modifying field 'realname', remarking to 'real name';
1 "delete type", modify field "age".
The following examples of user table query results:
Field | Type | Null | Key | Default | Extra | Comment |
id | bigint | NO | PMI | auto_increment | ID primary key | |
realname | varchar(100) | NO | Real name | |||
birthdate | Date | NO | Date of birth |
Further, the step of obtaining the type of modification made to the current object and the corresponding modified field includes:
comparing the attribute definition information of the object before modification with the attribute definition information of the object after modification to obtain the modification type and the corresponding modification field of the current object; or
The type of modification made and the corresponding modification field are monitored and recorded directly by a monitoring record function.
That is, the type of modification made to the current object and the corresponding modification field may be obtained in two ways. The first way is to compare the attribute definition information of the object before modification with the attribute definition information of the object after modification, so as to know which fields are modified and the modified type, i.e. the new type, the updated type or the deleted type. The second way is to set a monitoring record function to directly monitor and record the modification action made on the current object, i.e. directly monitor and record the modification type and corresponding modification field made.
S3 generates a temporary new code file using the code generation tool and the code generation template, using the modified attribute definition information of the object as an input parameter.
The code generation tool may be the same as the code generation tool described above. The code generation template may be a template of the code generation tool itself, or may be a custom template pre-written by a developer or a user of the code generation tool using a template language such as Freemarker, Velocity, Thymeleaf, etc., which is common in the art.
S4, respectively obtaining the abstract syntax tree of the code file to be updated and the abstract syntax tree of the temporary new code file, extracting the syntax tree node corresponding to the modification field of the deletion type from the abstract syntax tree of the code file to be updated, and extracting the syntax tree node corresponding to the modification field of the addition type and the syntax tree node corresponding to the modification field of the update type from the abstract syntax tree of the temporary new code file.
A syntax tree parsing engine such as JavaParser can be used to perform syntax tree parsing on the code file to be updated and the temporary new code file respectively, so as to obtain an abstract syntax tree of the code file to be updated and an abstract syntax tree of the temporary new code file respectively, and thus node definition information of the target field about the syntax tree can be obtained.
Taking JavaParser as an example, the following functions can be implemented:
CompilationUnit compilationUnit=StaticJavaParser.parse(code);
any type of node data may be obtained and the set of attribute definitions for all fields in the code may be obtained using the functions listed below.
List<FieldDeclaration>fieldDeclarationList=compilationUnit.findAll(Field Declaration.class)。
However, those skilled in the art will recognize that parsing a code file into a concrete syntax tree using a syntax tree parsing engine is also applicable here and is not limited to abstract syntax trees.
Based on the field information obtained in the step S2, the required syntax tree node definition information can be extracted from the abstract syntax tree of the temporary new code file. For example:
the attribute definition node and the method definition node related to the 'newly added' field birthdate;
the associated attribute definition node and method definition node of the "update" field realname.
Syntax tree node definition information of fields to be deleted can also be extracted from the abstract syntax tree of the code file to be updated, for example:
the relevant attribute definition node and method definition node of the "delete" field age.
The above examples are for illustrative purposes only, and the requirement or the change of the data structure during the software development process may occur in the new type, the update type, and the delete type at the same time, or only some types, for example, only the new type, or the update type, or both the new type and the delete type, or both the new type and the update type, or both the update type and the delete type, which occurs based on the actual needs.
S5 deletes the syntax tree node corresponding to the modification field of the update type and the syntax tree node corresponding to the modification field of the deletion type from the abstract syntax tree of the to-be-updated code file, and adds the syntax tree node corresponding to the modification field of the new addition type and the syntax tree node corresponding to the modification field of the update type extracted from the abstract syntax tree of the temporary new code file to the abstract syntax tree of the to-be-updated code file.
Based on the syntax tree node information obtained in step S4, i.e., the syntax tree node corresponding to the modified field of the delete type in the abstract syntax tree of the code file to be updated, and the syntax tree node corresponding to the modified field of the add type and the syntax tree node corresponding to the modified field of the update type in the abstract syntax tree of the temporary new code file, the relevant syntax tree nodes (attribute definition node and method definition node, etc.) for the "delete" field and the relevant syntax tree nodes (attribute definition node and method definition node, etc.) for the "update" field are removed from the abstract syntax tree of the code file to be updated; and respectively adding relevant syntax tree nodes (attribute definition nodes, method definition nodes and the like) of 'new added' fields extracted from the abstract syntax tree of the temporary new code file and relevant syntax tree nodes (attribute definition nodes, method definition nodes and the like) of 'updated' fields in the abstract syntax tree of the code file to be updated. The specific operation method is well known to those skilled in the art, and continuing to take JavaParser as an example, the removal operation can be realized by nodelist. Add operation may be implemented by nodelist.
S6, the abstract syntax tree of the updated code file to be updated is converted into codes so as to update the codes to be updated.
The corresponding operation of converting the updated abstract syntax tree into code content can be implemented using existing known methods. Continuing with the JavaParser example, the conversion of the syntax tree into code content can be achieved through the componentional unit.
The method for updating the code to be updated is usually to write the new code content back to the code file to be updated, which can be implemented by, for example, a FileWriter object in Java language or some kind of packaging tool such as fileutilils.
Fig. 2 is a flowchart of a non-overlay code content updating method according to a second embodiment of the present invention. As shown in fig. 2, the method for non-overlay updating code content provided by the second embodiment is to add step S12 to the method provided by the first embodiment, that is, before the obtained attribute definition information of the object is modified, the attribute definition information of the object is converted into JSON format. The method comprises the following specific steps:
s1, acquiring attribute definition information of the object in the code file to be updated;
s12, converting the attribute definition information of the object into a JSON format;
s2, when the obtained attribute definition information of the object is modified, obtaining a modification type made to the current object and a corresponding modification field, the modification type including: new addition, update, and deletion;
s3, using the modified attribute definition information of the object as an input parameter, and generating a temporary new code file by using a code generation tool and a code generation template;
s4, respectively obtaining an abstract syntax tree of a code file to be updated and an abstract syntax tree of the temporary new code file, extracting syntax tree nodes corresponding to the modification fields of the deletion type from the abstract syntax tree of the code file to be updated, and extracting syntax tree nodes corresponding to the modification fields of the addition type and syntax tree nodes corresponding to the modification fields of the update type from the abstract syntax tree of the temporary new code file;
s5, deleting the syntax tree node corresponding to the modification field of the update type and the syntax tree node corresponding to the modification field of the deletion type from the abstract syntax tree of the code file to be updated, and adding the syntax tree node corresponding to the modification field of the new addition type and the syntax tree node corresponding to the modification field of the update type, which are extracted from the abstract syntax tree of the temporary new code file, into the abstract syntax tree of the code file to be updated;
s6, the abstract syntax tree of the updated code file to be updated is converted into codes so as to update the codes to be updated.
Here, step S12 will be described as an example. Examples of JSON data are as follows:
{
“className”:“User”,
“columns”:[
{ "field": "id", "type": "Long", "isNull": false, "isprimary key": true, "comment": an "ID primary key" },
{ "field": "realname", "type": String "," isNull ": false, "isprimary key": false, "comment": a "nickname" },
{ "field": "age", "type": "Integer", "isNull": false, "isprimary key": false, "comment": "age" }
]
}
Continuing with the example, in step S2, after the attribute definition information of the obtained object is modified, the new JSON data at this time is:
{
“className”:“User”,
“columns”:[
{ "field": ID "," type ": Long", "isNull": false "," isprimary Key ": true", "comment": ID Primary Key "},
{ "field": realname "," type ": String", "isNull": false "," isPrimaryKey ": false", "comment": real name "},
{ "field": birthdate "," type ": Date", "isNull": false "," isPrimaryKey ": false", "comment": birth Date "}
]
}
Continuing with the example, here is given a custom example of the code generation template mentioned in step S3:
in addition, the explanation contents of the respective steps of the first embodiment also apply to the corresponding steps of the second embodiment, and the example given in the second embodiment also applies to the first embodiment.
Although syntax tree parsing of a code file using a syntax tree parsing engine to obtain an abstract syntax tree is described in the first and second embodiments, parsing the code file into a concrete syntax tree is also applicable here.
Based on the first embodiment and the second embodiment, the invention adopts a novel method for analyzing and updating the abstract syntax tree of the code file to be updated and converting the updated syntax tree into the updated code content, so that the manual modification content or the custom-added code content of the code by a developer can not be touched, and the code can be kept and not covered, i.e. the code change information or the custom-added code information manually executed by the developer in the previous version can be kept and not covered or removed, thereby realizing the non-covering update of the code content, leading the code generator to be suitable for the whole period of software project development (the primary stage of new requirements and the middle and later stages of requirement change), automatically completing the code update through the flow, improving the development efficiency of software, avoiding omission and errors caused by manual modification, the code quality is improved.
The following continues to illustrate the advantageous effects of the solution provided by the present invention by means of a specific routine.
Assume that the code content to be updated is as follows:
using the prior art overlay code update method, the developer manually adds new code content: private static String STATUS _ a is "incumbent"; and
private String getStatus(){
…}
the cover will be removed.
By using the method for updating the code content in a non-covering manner provided by the invention, the updated code content is as follows:
therefore, the developer manually adds the code content: private static String STATUS _ a is "incumbent"; and
private String getStatus(){
…}
can be retained and not be covered or cleared.
Fig. 3 is a schematic block diagram of a non-overlay code content updating apparatus according to a third embodiment of the present invention. As shown in fig. 3, an apparatus for non-overlay updating code content according to a third embodiment of the present invention includes:
the object information acquisition module 1 is used for acquiring attribute definition information of an object in a code file to be updated;
a modification content obtaining module 2, configured to, when the obtained attribute definition information of the object is modified, obtain a modification type made to the current object and a corresponding modification field, where the modification type includes: new addition, update, and deletion;
the code generation module 3 is used for generating a code file to be updated by using the code generation template with the modified attribute definition information of the object as an input parameter;
a syntax tree analysis module 4, configured to obtain an abstract syntax tree of a code file to be updated and an abstract syntax tree of the temporary new code file;
a node extracting module 5, configured to extract a syntax tree node corresponding to the modified field of the deletion type from the abstract syntax tree of the to-be-updated code file, and extract a syntax tree node corresponding to the modified field of the addition type and a syntax tree node corresponding to the modified field of the update type from the abstract syntax tree of the temporary new code file;
a syntax tree merging module 6, configured to delete syntax tree nodes corresponding to the modification fields of the update type and syntax tree nodes corresponding to the modification fields of the deletion type from the abstract syntax tree of the to-be-updated code file, and add syntax tree nodes corresponding to the modification fields of the new addition type and syntax tree nodes corresponding to the modification fields of the update type, which are extracted from the abstract syntax tree of the temporary new code file, to the abstract syntax tree of the to-be-updated code file;
and the syntax tree conversion code module 7 is used for converting the abstract syntax tree of the updated code file to be updated into codes so as to update the codes to be updated.
Wherein: the object information acquisition module is used for acquiring the attribute definition information of the object by reading the data source connected with the code file to be updated.
Wherein: the modified content acquisition module performs the following operations:
comparing the attribute definition information of the object before modification with the attribute definition information of the object after modification to obtain the modification type and the corresponding modification field of the current object; or
The type of modification made and the corresponding modification field are monitored and recorded directly by a monitoring record function.
Fig. 4 is a schematic block diagram of a non-overlay code content updating apparatus according to a fourth embodiment of the present invention. As shown in fig. 4, the non-overlay code content updating apparatus further includes a format conversion module 11, configured to convert the attribute definition information of the object into JSON format before the obtained attribute definition information of the object is modified.
It is clear to those skilled in the art that for the convenience and brevity of description, the specific operation of the apparatus described in the third embodiment above can be explained by referring to the corresponding process in the first embodiment, the example and the related description listed in the first embodiment and the corresponding preferred embodiment, and the operation of the apparatus described in the third embodiment is also applicable, and will not be repeated herein.
Similarly, the specific operation of the device described in the fourth embodiment can refer to the corresponding process in the second embodiment, and the example and the related description listed in the second embodiment and the corresponding preferred embodiment are also applicable to explain the operation of the device described in the fourth embodiment, and the description is not repeated here.
Based on the third embodiment and the fourth embodiment, the non-overlay code content updating device provided by the invention adopts a novel method for analyzing and updating the abstract syntax tree of the code file to be updated and converting the updated syntax tree into the updated code content, so that the code content added by a developer in a modification or customization mode can not be touched and can be reserved but not be overlaid, namely, the code change information or the customized code information made by the developer in the previous version can be reserved and can not be overlaid or cleared, thereby realizing the non-overlay updating of the code content, enabling the code generator to be suitable for the whole period of software project development (the primary stage of new requirements and the middle and later stages of requirement change), automatically completing the code updating through the flow, and further improving the software development efficiency, omission and errors caused by manual modification are avoided, and the code quality is improved.
A method and apparatus for non-overriding updating of code content according to exemplary embodiments of the present application has been described above with reference to fig. 1 to 4. However, it should be understood that: the apparatuses and unit modules thereof shown in fig. 3 and 4 may be respectively configured as software, hardware, firmware, or any combination thereof to perform a specific function. For example, these means or unit modules may correspond to dedicated integrated circuits, to pure software code, or to a combination of software and hardware. Furthermore, one or more functions implemented by these means or unit modules may also be uniformly executed by components in a physical entity device (e.g., processor, client or server, etc.).
Further, the above-mentioned method of non-overlay updating code content may be implemented by a program recorded on a computer readable medium, for example, according to the exemplary embodiments of the present application, a computer readable storage medium may be provided, on which a computer program is recorded that, when executed by a processor, implements the method as described in the first embodiment or a combination thereof with the respective preferred embodiments. Furthermore, a computer-readable storage medium may also be provided, wherein a computer program is recorded on the computer-readable storage medium, which when executed by a processor implements the method according to the second embodiment or the combination thereof with the respective preferred embodiments.
The computer program in the computer-readable storage medium may be executed in an environment deployed in a computer device such as a client, a host, a proxy device, a server, etc., and it should be noted that the computer program may also be used to perform additional steps other than or in addition to the above steps, and the content of the additional steps and further processing is mentioned in the description of the related method with reference to fig. 1 and 2, and thus will not be described again here to avoid repetition.
Further, the above-described method of non-overriding updating the code content may also be realized by a program recorded on a computing device. The computing device comprises a storage means and a processor, the storage means having stored therein a set of computer-executable instructions which, when executed by the processor, perform the method steps as described in the first embodiment or in combination with the respective preferred embodiments; or to carry out the method steps as described in the second embodiment or a combination thereof with the respective preferred embodiments.
In particular, the computing devices may be deployed in servers or clients, as well as on node devices in a distributed network environment. Further, the computing device may be a PC computer, tablet device, personal digital assistant, smart phone, web application, or other device capable of executing the set of instructions described above.
The computing device need not be a single computing device, but can be any device or collection of circuits capable of executing the instructions (or sets of instructions) described above, individually or in combination. The computing device may also be part of an integrated control system or system manager, or may be configured as a portable electronic device that interfaces with local or remote (e.g., via wireless transmission).
In the computing device, the processor may include a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a programmable logic device, a special purpose processor system, a microcontroller, or a microprocessor. By way of example, and not limitation, processors may also include analog processors, digital processors, microprocessors, multi-core processors, processor arrays, network processors, and the like.
Some of the operations described in the method according to the exemplary embodiments of the present application may be implemented by software, some of the operations may be implemented by hardware, and furthermore, the operations may be implemented by a combination of hardware and software.
The processor may execute instructions or code stored in one of the memory components, which may also store data. Instructions and data may also be transmitted and received over a network via a network interface device, which may employ any known transmission protocol.
The memory component may be integral to the processor, e.g., having RAM or flash memory disposed within an integrated circuit microprocessor or the like. Further, the storage component may comprise a stand-alone device, such as an external disk drive, storage array, or any other storage device usable by a database system. The storage component and the processor may be operatively coupled or may communicate with each other, such as through an I/O port, a network connection, etc., so that the processor can read files stored in the storage component.
Further, the computing device may also include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, mouse, touch input device, etc.). All components of the computing device may be connected to each other via a bus and/or a network.
The operations involved in the methods according to the exemplary embodiments of the present application may be described as various interconnected or coupled functional blocks or functional diagrams. However, these functional blocks or functional diagrams may be equally integrated into a single logic device or operated on by non-exact boundaries.
While exemplary embodiments of the present application are described above, it should be understood that: the above description is exemplary only and not exhaustive. The present application is not limited to the disclosed exemplary embodiments, and many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the application. Therefore, the protection scope of the present application shall be subject to the scope of the claims.
Claims (10)
1. A method of non-overriding update code content, comprising:
s1, acquiring attribute definition information of the object in the code file to be updated;
s2, when the obtained attribute definition information of the object is modified, obtaining a modification type made to the current object and a corresponding modification field, the modification type including: new addition, update, and deletion;
s3, using the modified attribute definition information of the object as an input parameter, and generating a temporary new code file by using a code generation tool and a code generation template;
s4, respectively obtaining a syntax tree of a code file to be updated and a syntax tree of the temporary new code file, extracting syntax tree nodes corresponding to the modification fields of the deletion type from the syntax tree of the code file to be updated, and extracting syntax tree nodes corresponding to the modification fields of the addition type and syntax tree nodes corresponding to the modification fields of the update type from the syntax tree of the temporary new code file;
s5, deleting the syntax tree node corresponding to the modification field of the update type and the syntax tree node corresponding to the modification field of the deletion type from the syntax tree of the code file to be updated, and adding the syntax tree node corresponding to the modification field of the new addition type and the syntax tree node corresponding to the modification field of the update type, which are extracted from the syntax tree of the temporary new code file, into the syntax tree of the code file to be updated;
s6, converting the syntax tree of the updated code file to be updated into codes so as to update the codes to be updated.
2. The method of claim 1, wherein: in step S1, attribute definition information of the object is obtained by reading the data source to which the code file to be updated is connected.
3. The method according to claim 1, wherein before the obtained attribute definition information of the object is modified, the attribute definition information of the object is converted into a JSON format.
4. The method of claim 1, wherein: the step of obtaining the type of modification made to the current object and the corresponding modification field comprises:
comparing the attribute definition information of the object before modification with the attribute definition information of the object after modification to obtain the modification type and the corresponding modification field of the current object; or
The type of modification made and the corresponding modification field are monitored and recorded directly by a monitoring record function.
5. A device for non-overlay updating code content, comprising:
the object information acquisition module is used for acquiring attribute definition information of an object in the code file to be updated;
a modification content obtaining module, configured to obtain a modification type and a corresponding modification field made to the current object when the obtained attribute definition information of the object is modified, where the modification type includes: new addition, update, and deletion;
the code generation module is used for generating a code file to be updated by using the code generation template with the modified attribute definition information of the object as an input parameter;
the syntax tree analysis module is used for obtaining a syntax tree of a code file to be updated and a syntax tree of the temporary new code file;
a node extracting module, configured to extract a syntax tree node corresponding to the modification field of the deletion type from the syntax tree of the to-be-updated code file, and extract a syntax tree node corresponding to the modification field of the addition type and a syntax tree node corresponding to the modification field of the update type from the syntax tree of the temporary new code file;
a syntax tree merging module, configured to delete a syntax tree node corresponding to the modification field of the update type and a syntax tree node corresponding to the modification field of the deletion type from a syntax tree of the code file to be updated, and add, to the syntax tree of the code file to be updated, a syntax tree node corresponding to the modification field of the new addition type and a syntax tree node corresponding to the modification field of the update type, which are extracted from the syntax tree of the temporary new code file;
and the syntax tree conversion code module is used for converting the syntax tree of the updated code file to be updated into codes so as to update the codes to be updated.
6. The apparatus of claim 5, wherein: the object information acquisition module is used for acquiring the attribute definition information of the object by reading the data source connected with the code file to be updated.
7. The apparatus of claim 5, further comprising a format conversion module for converting the attribute definition information of the object into the JSON format before the obtained attribute definition information of the object is modified.
8. The apparatus of claim 5, wherein: the modified content acquisition module performs the following operations:
comparing the attribute definition information of the object before modification with the attribute definition information of the object after modification to obtain the modification type and the corresponding modification field of the current object; or
The type of modification made and the corresponding modification field are monitored and recorded directly by a monitoring record function.
9. A computer-readable storage medium, wherein a computer program is recorded on the computer-readable storage medium, which when executed by a processor implements the method of any of claims 1 to 4.
10. A computing device comprising a storage component and a processor, wherein the storage component has stored therein a set of computer-executable instructions that, when executed by the processor, cause the processor to perform the method of any of claims 1 to 4.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011220746.5A CN112286557B (en) | 2020-11-05 | 2020-11-05 | Method and device for updating code content in non-coverage mode |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011220746.5A CN112286557B (en) | 2020-11-05 | 2020-11-05 | Method and device for updating code content in non-coverage mode |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112286557A true CN112286557A (en) | 2021-01-29 |
CN112286557B CN112286557B (en) | 2024-03-22 |
Family
ID=74351489
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011220746.5A Active CN112286557B (en) | 2020-11-05 | 2020-11-05 | Method and device for updating code content in non-coverage mode |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112286557B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113110832A (en) * | 2021-04-08 | 2021-07-13 | 北京联创新天科技有限公司 | Intelligent efficient code generation method and device and storage medium |
CN114168119A (en) * | 2021-12-07 | 2022-03-11 | 北京百度网讯科技有限公司 | Code file editing method and device, electronic equipment and storage medium |
Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
AU2001294531A1 (en) * | 2000-09-25 | 2002-04-08 | Acuabiotec Llc | Method, system and computer program product for technical management and biocontrol of disease in animal production systems |
US20130159964A1 (en) * | 2011-12-15 | 2013-06-20 | The Mathworks, Inc. | System and method for systematic error injection in generated code |
CN103645986A (en) * | 2013-11-29 | 2014-03-19 | 北京广利核系统工程有限公司 | Generation method and reconstruction method of visualization syntax tree of compiler |
CN104657140A (en) * | 2015-02-10 | 2015-05-27 | 广州华多网络科技有限公司 | Code generating method and device |
CN107015813A (en) * | 2017-04-19 | 2017-08-04 | 网易(杭州)网络有限公司 | Method, device and electronic equipment that code is repaired |
CN107402746A (en) * | 2016-05-20 | 2017-11-28 | 阿里巴巴集团控股有限公司 | A kind of method and device of automatic code generating file |
CN109032662A (en) * | 2018-06-19 | 2018-12-18 | 上海陆家嘴国际金融资产交易市场股份有限公司 | Code file generation method, device, computer equipment and storage medium |
CN111142862A (en) * | 2019-11-20 | 2020-05-12 | 苏州帝博信息技术有限公司 | System and method for automatically generating code |
CN111209022A (en) * | 2020-01-03 | 2020-05-29 | 支付宝(杭州)信息技术有限公司 | Resource publishing and acquiring method, device and equipment |
CN111625230A (en) * | 2020-05-19 | 2020-09-04 | 北京计算机技术及应用研究所 | System for unifying front-end JavaScript coding specifications |
-
2020
- 2020-11-05 CN CN202011220746.5A patent/CN112286557B/en active Active
Patent Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
AU2001294531A1 (en) * | 2000-09-25 | 2002-04-08 | Acuabiotec Llc | Method, system and computer program product for technical management and biocontrol of disease in animal production systems |
US20130159964A1 (en) * | 2011-12-15 | 2013-06-20 | The Mathworks, Inc. | System and method for systematic error injection in generated code |
CN103645986A (en) * | 2013-11-29 | 2014-03-19 | 北京广利核系统工程有限公司 | Generation method and reconstruction method of visualization syntax tree of compiler |
CN104657140A (en) * | 2015-02-10 | 2015-05-27 | 广州华多网络科技有限公司 | Code generating method and device |
CN107402746A (en) * | 2016-05-20 | 2017-11-28 | 阿里巴巴集团控股有限公司 | A kind of method and device of automatic code generating file |
CN107015813A (en) * | 2017-04-19 | 2017-08-04 | 网易(杭州)网络有限公司 | Method, device and electronic equipment that code is repaired |
CN109032662A (en) * | 2018-06-19 | 2018-12-18 | 上海陆家嘴国际金融资产交易市场股份有限公司 | Code file generation method, device, computer equipment and storage medium |
CN111142862A (en) * | 2019-11-20 | 2020-05-12 | 苏州帝博信息技术有限公司 | System and method for automatically generating code |
CN111209022A (en) * | 2020-01-03 | 2020-05-29 | 支付宝(杭州)信息技术有限公司 | Resource publishing and acquiring method, device and equipment |
CN111625230A (en) * | 2020-05-19 | 2020-09-04 | 北京计算机技术及应用研究所 | System for unifying front-end JavaScript coding specifications |
Non-Patent Citations (2)
Title |
---|
MAURICIO SOTO等: "Common Statement Kind Changes to Inform Automatic Program Repair", 《2018 IEEE/ACM 15TH INTERNATIONAL CONFERENCE ON MINING SOFTWARE REPOSITORIES (MSR)》, 30 December 2018 (2018-12-30), pages 102 * |
聂佳: "一种融合代码依赖关系的基于信息检索的需求更新方法", 《CNKI优秀硕士学位论文全文库 信息科技辑》, no. 04, 15 April 2019 (2019-04-15), pages 138 - 1180 * |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113110832A (en) * | 2021-04-08 | 2021-07-13 | 北京联创新天科技有限公司 | Intelligent efficient code generation method and device and storage medium |
CN114168119A (en) * | 2021-12-07 | 2022-03-11 | 北京百度网讯科技有限公司 | Code file editing method and device, electronic equipment and storage medium |
WO2023103432A1 (en) * | 2021-12-07 | 2023-06-15 | 北京百度网讯科技有限公司 | Code file editing method and apparatus, electronic device, and storage medium |
CN114168119B (en) * | 2021-12-07 | 2024-04-05 | 北京百度网讯科技有限公司 | Code file editing method, device, electronic equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN112286557B (en) | 2024-03-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8321450B2 (en) | Standardized database connectivity support for an event processing server in an embedded context | |
US8387076B2 (en) | Standardized database connectivity support for an event processing server | |
US9009183B2 (en) | Transformation of a system change set from machine-consumable form to a form that is readily consumable by a human | |
US9646041B2 (en) | Testing of inactive design-time artifacts | |
US7254810B2 (en) | Apparatus and method for using database knowledge to optimize a computer program | |
US9141510B2 (en) | Memory allocation tracking | |
US11755614B2 (en) | Generation and graphical display of data transform provenance metadata | |
US9652220B2 (en) | Zero down-time deployment of new application versions | |
US7562342B2 (en) | Method and apparatus for incrementally processing program annotations | |
CN111414350B (en) | Service generation method and device | |
US20190114165A1 (en) | Using semantic annotations to control compatibility behaviors | |
US8918766B2 (en) | Analysis of propagated information using annotated forests | |
CN113032393B (en) | Method and device for binding associated objects | |
CN112286557B (en) | Method and device for updating code content in non-coverage mode | |
CN104598570B (en) | The grasping means of resource and device | |
CN111949693A (en) | Data processing device, data processing method, storage medium and electronic equipment | |
CN114036183A (en) | Data ETL processing method, device, equipment and medium | |
JP2018060570A (en) | Reference data segmentation from single to multiple tables | |
WO2021259290A1 (en) | Stored procedure conversion method and apparatus, and device and storage medium | |
CN115544089A (en) | Data processing method, device, equipment and storage medium | |
US20210240596A1 (en) | Source code file retrieval | |
US20170161359A1 (en) | Pattern-driven data generator | |
CN112685435A (en) | Table query method and system based on Vue and Mybatis | |
US11847448B2 (en) | Automatic generation of exporter configuration rules | |
US20240126726A1 (en) | Techniques for comprehensively supporting json schema in a rdbms |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |