CN114168119B - Code file editing method, device, electronic equipment and storage medium - Google Patents

Code file editing method, device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114168119B
CN114168119B CN202111487940.4A CN202111487940A CN114168119B CN 114168119 B CN114168119 B CN 114168119B CN 202111487940 A CN202111487940 A CN 202111487940A CN 114168119 B CN114168119 B CN 114168119B
Authority
CN
China
Prior art keywords
attribute
interface
information
code file
code
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
Application number
CN202111487940.4A
Other languages
Chinese (zh)
Other versions
CN114168119A (en
Inventor
田泽润
魏嘉汛
覃耀辉
张聪
董敏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN202111487940.4A priority Critical patent/CN114168119B/en
Publication of CN114168119A publication Critical patent/CN114168119A/en
Priority to PCT/CN2022/111304 priority patent/WO2023103432A1/en
Application granted granted Critical
Publication of CN114168119B publication Critical patent/CN114168119B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting

Abstract

The disclosure provides a code file editing method, a device, electronic equipment and a storage medium, relates to the technical field of computers, in particular to the technical field of text processing, and can be applied to scenes such as code file editing. The specific implementation scheme is as follows: when the code file is detected to be edited, a first code text before the code file is edited and a second code text after the code file is edited are obtained; comparing the interface definition information in the first code text and the second code text to obtain interface attribute change information; and updating the attribute information in the corresponding function definition component of the code file based on the interface attribute change information under the condition that the interface attribute change information indicates that the interface attribute of the code file is changed. The method can automatically update the attribute information in the related function definition component when the attribute in the code file is determined to be modified, and the workload of a developer is obviously reduced.

Description

Code file editing method, device, electronic equipment and storage medium
Technical Field
The disclosure relates to the technical field of computers, in particular to the technical field of text processing, and can be applied to scenes such as code file editing.
Background
When a developer writes a function definition component, the developer usually defines the interface type of the function definition component, where the interface type includes attribute information of the interface. In the process of editing a code file, when the attribute of a certain interface needs to be modified, a developer usually defines the code part modification attribute of the interface type, and then the corresponding attribute needs to be manually updated synchronously in the code part of the related function definition component, and the synchronous operation is not related to the core logic of development, although the synchronous operation is necessary, the workload of the developer is certainly increased, and the code writing efficiency is affected.
Disclosure of Invention
The disclosure provides a code file editing method, a code file editing device, electronic equipment and a storage medium.
According to a first aspect of the present disclosure, there is provided a code file editing method including:
when the code file is detected to be edited, a first code text before the code file is edited and a second code text after the code file is edited are obtained;
comparing the interface definition information in the first code text and the second code text to obtain interface attribute change information, wherein the interface attribute change information is used for indicating the change condition of the attribute of the corresponding interface in the code file;
And updating the attribute information in the corresponding function definition component of the code file based on the interface attribute change information under the condition that the interface attribute change information indicates that the interface attribute of the code file is changed.
According to a second aspect of the present disclosure, there is provided a code file editing apparatus comprising:
the text acquisition module is used for acquiring a first code text before the code file is edited and a second code text after the code file is edited when the code file is detected to be edited;
the attribute comparison module is used for comparing the interface definition information in the first code text and the second code text to obtain interface attribute change information, wherein the interface attribute change information is used for indicating the change condition of the attribute of the corresponding interface in the code file;
and the attribute updating module is used for updating the attribute information in the corresponding function definition component of the code file based on the interface attribute change information under the condition that the interface attribute change information indicates that the interface attribute of the code file is changed.
According to a third aspect of the present disclosure, there is provided an electronic device comprising:
at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the code file editing method described above.
According to a fourth aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium storing computer instructions for causing the computer to execute the above-described code file editing method.
According to a fifth aspect of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements the code file editing method described above.
It should be understood that the description in this section is not intended to identify key or critical features of the embodiments of the disclosure, nor is it intended to be used to limit the scope of the disclosure. Other features of the present disclosure will become apparent from the following specification.
The beneficial effects that this disclosure provided technical scheme brought are:
in the technical scheme of the disclosure, whether the attribute in the interface definition information is modified after the code file is edited can be determined, when the attribute is determined to be modified, the attribute information in the related function definition assembly is automatically updated, the attribute information in the function definition assembly is not required to be manually modified one by a developer, and the workload of the developer is remarkably reduced.
Drawings
The drawings are for a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
fig. 1 is a schematic flow chart of a code file editing method according to an embodiment of the disclosure;
fig. 2 illustrates a schematic diagram of attribute information change before and after editing of a first code file according to an embodiment of the present disclosure;
fig. 3 is a schematic diagram showing attribute information change before and after editing of a second code file according to an embodiment of the present disclosure;
fig. 4 is a schematic diagram showing attribute information change before and after editing of a third code file according to an embodiment of the present disclosure;
FIG. 5 is a schematic diagram of a code file editing apparatus provided by an embodiment of the present disclosure;
FIG. 6 illustrates a schematic block diagram of an example electronic device that may be used to implement the code file editing methods provided by embodiments of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present disclosure to facilitate understanding, and should be considered as merely exemplary. Accordingly, one of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
When a developer writes a function definition component, the developer usually defines the interface type of the function definition component, where the interface type includes attribute information of the interface. In the process of editing a code file, when the attribute of a certain interface needs to be modified, a developer usually defines the code part modification attribute of the interface type, and then the corresponding attribute needs to be manually updated synchronously in the code part of the related function definition component, and the synchronous operation is unnecessary, but is irrelevant to the core logic of development, and certainly the workload of the developer influences the code writing efficiency.
The embodiment of the disclosure provides a code file editing method, a device, an electronic device and a storage medium, which aim to solve at least one of the above technical problems in the prior art.
Fig. 1 shows a flow chart of a code file editing method provided by an embodiment of the disclosure, and as shown in fig. 1, the method mainly includes the following steps:
s110: when the code file is detected to be edited, a first code text before the code file is edited and a second code text after the code file is edited are acquired.
In the embodiment of the disclosure, when the code file is in an opened state, an editing operation for the code file may be detected in real time, and the editing operation may include operations of adding a code, deleting a code, replacing a code, and the like. When one editing operation for a code file is detected, a text containing the content before the code file is edited may be regarded as a first code text, and a text containing the content after the code file is edited may be regarded as a second code text.
It will be appreciated that editing operations on a code file may cause the contents of the code file to change, for example, may result in changes to the properties of the interface in the code file. When the content of the code file is changed for the editing operation of the code file, the content of the first code text and the second code text may be different; when the editing operation for the code file does not change the content of the code file, the content of the first code text and the second code text are identical.
S120: and comparing the interface definition information in the first code text and the second code text to obtain the interface attribute change information.
As indicated above, editing operations for a code file may cause changes in the properties of interfaces in the code file, where interface property change information is used to indicate changes in the properties of the corresponding interfaces in the code file. In some scenarios, when a developer writes a function definition component, it generally defines an interface type of the function definition component, where the interface type includes attribute information of the interface. For example, when a developer may write a reaction function definition component in TypeScript, interface is often used to define the Interface type of the reaction function definition component, commonly referred to as the component tips type. In the embodiment of the present disclosure, a code segment for defining an interface type of a function definition component is referred to as interface definition information.
The editing operation for the code file may include a modification operation for interface definition information of the code file, and the developer may modify the attribute of the interface in the interface definition information of the code file, thereby changing the attribute of the interface. It will be appreciated that the interface-to-attribute may be identified in the interface definition information, and thus, by comparing the interface definition information in the first code text and the second code text, the interface attribute change information of each interface of the code file after editing may be obtained.
S130: and updating the attribute information in the corresponding function definition component of the code file based on the interface attribute change information under the condition that the interface attribute change information indicates that the interface attribute of the code file is changed.
As described above, the interface attribute change information is used to indicate the change condition of the attribute of the corresponding interface in the code file, for example, the interface attribute change information may indicate whether the attribute of the corresponding interface changes and the specific change content. The attributes of the interface may include that some of the attributes of the interface are deleted, that the interface has a new attribute added, that some of the attributes of the interface have been replaced with new attributes, and so on.
Generally, when modifying an attribute of an interface in a code file, a developer needs to modify the attribute of the interface in the interface definition information, and at this time, the attribute in the corresponding function definition component is not modified, so when the interface attribute change information indicates that the interface attribute of the code file is changed, it may be determined that the function definition component corresponding to the modified attribute is determined based on the interface attribute change information, and the attribute information in the function definition component is updated, and the developer is not required to manually modify the attribute information in the function definition component.
It can be appreciated that, after step S120, in the case where the interface attribute change information indicates that the interface attribute of the code file has not changed, the embodiment of the disclosure may end the update procedure of the attribute information in the function definition component for the code file this time, thereby saving computing resources. When it is again detected that the code file is edited, the above-described method is re-executed.
According to the code file editing method provided by the embodiment of the disclosure, whether the attribute in the interface definition information is modified after the code file is edited can be determined, when the attribute is determined to be modified, the attribute information in the related function definition component is automatically updated, a developer does not need to manually modify the attribute information in the function definition component one by one, the workload of the developer is obviously reduced, the developer can concentrate on writing core logic, and the code writing efficiency is improved.
Optionally, in step S120, embodiments of the present disclosure may parse at least one first interface definition information from the first code text, identify first interface attribute information based on each first interface definition information; parsing at least one second interface definition information from the second code text, identifying second interface attribute information based on each second interface definition information; and comparing the first interface attribute information with the second interface attribute information to obtain interface attribute change information.
It should be noted that, for convenience of understanding and description, the code file includes at least one interface, where the first code text refers to the interface in the code file as a first interface, and the second code text refers to the interface in the code file as a second interface, and it is understood that, in a case where a new interface is not added in the code file, the first interface in the first code text and the second interface in the second code text are generally in one-to-one correspondence. According to the embodiment of the disclosure, interface attribute information in a first code text is called first interface attribute information, interface attribute information in a second code text is called second interface attribute information, the interface attribute information can describe related information of attributes, and whether the attributes change or not can be determined by comparing the corresponding first interface attribute information with the corresponding second interface attribute information.
Optionally, when parsing at least one first interface definition information from the first code text, the embodiments of the present disclosure may construct a first abstract syntax tree based on the first code text, and parse first interface attribute information from the first abstract syntax tree. Likewise, when parsing at least one second interface definition information from the second code text, a second abstract syntax tree may be constructed based on the second code text, from which second interface attribute information is parsed. Here, the abstract syntax tree is a tree representation of an abstract syntax structure of source code written in a programming language. Each node of the tree represents a construct that occurs in the source code. The grammar is "abstract" in that it does not represent every detail that appears in the real grammar, but rather is merely structural, content-related details. Code content belonging to interface attribute information in codes can be rapidly and accurately identified through the abstract syntax tree, and the attribute updating efficiency of subsequent steps is improved.
Alternatively, the first interface attribute information may include a name of the first interface, a name of the first attribute of the first interface, a location of the first attribute in the code file, and the second interface attribute information includes a name of the second interface, a name of the second attribute of the second interface, and a location of the second attribute in the code file. For ease of understanding and presentation, the attributes of the first interface are referred to as first attributes in the first code text and the attributes of the second interface are referred to as second attributes in the second code text. In the embodiment of the disclosure, the attribute of all the first interfaces in the first code text can be recorded as a 1 ,A 2 ,…,A k ,…,A n The method comprises the steps of carrying out a first treatment on the surface of the The attributes of all the second interfaces in the second code text can be recorded as B 1 ,B 2 ,…,B k ,…B n . In A way k And B k For example, A k And interface attribute information representing a kth attribute in the first code text, including a name of the first interface to which the kth attribute belongs, a name of the kth attribute, and a position of the kth attribute in the code file; b (B) k And interface attribute information representing a kth attribute in the second code text, which contains a name of the second interface to which the kth attribute belongs, a name of the kth attribute, and a position of the kth attribute in the code file.
Typically, each attribute of the interface is edited in a single line when the code is edited, so the number of lines of the attribute in the code file can be used to represent its position in the code file. Here, A as described above may be 1 ,A 2 ,…,A k ,…,A n Converted into L p P represents the number of lines in the code file where the first attribute is located, e.g., L 3 Interface attribute information indicating an attribute of line 3 in a code file before editing, L 11 Representing code files before editingInterface attribute information for the attributes of line 11. The above B can be used 1 ,B 2 ,…,B k ,…,B n Converted into R p P represents the number of lines in the code file where the second attribute is located, e.g. R 3 Interface attribute information indicating the attribute of line 3 in the edited code file, R 11 Interface attribute information indicating an attribute of line 11 in the edited code file.
Optionally, when comparing the first interface attribute information and the second interface attribute information, the first interface attribute information and the second interface attribute information may be compared based on the position of the interface in the code file, so as to obtain each first interface attribute information and/or each interface attribute change information corresponding to each second interface attribute information. Here, it may be determined whether there is a difference between the first interface attribute information and the second interface attribute information having the same priority comparison position and specific difference content, so as to obtain corresponding attribute change information. It will be appreciated that the attribute change information may be dependent on the number of first interface attribute information and second interface attribute information, and for one attribute change information may be related to only one first attribute, only one second attribute, or a pair of corresponding first and second attributes.
In an embodiment of the present disclosure, the interface attribute change information includes at least one of interface attribute removal information, interface attribute replacement information, and interface attribute new addition information. The interface attribute removing information is used for indicating that the corresponding first attribute is removed from the edited code file, the interface attribute replacing information is used for indicating that the corresponding first attribute is replaced by a second attribute with the same position in the code file, and the interface attribute newly-added information is used for indicating that the corresponding second attribute is the newly-added attribute after the code file is edited.
The process of obtaining the interface attribute change information is described below by taking the first attribute as a comparison object:
alternatively, in comparing the first interface attribute information and the second interface attribute information, it is possible to determine, for each first attribute,retrieving a second attribute that is the same as the first attribute in position; and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result. Specifically, for one L p Search for whether there is a corresponding R p . For example, L 3 Interface attribute information indicating the attribute of line 3 in the code file before editing, and searching for whether there is a corresponding R 3 Wherein R is 3 Interface attribute information indicating an attribute of line 3 in the edited code file. For having corresponding R p Is not corresponding to R p Different interface attribute change information may be generated.
In the embodiment of the present disclosure, when the search case is that the second attribute identical to the first attribute is not searched, the interface attribute removal information for the first attribute may be generated. For example for L 3 When no corresponding R is retrieved 3 When generating the interface attribute removal information for the attribute of line 3 in the code file before editing, the interface attribute removal information may include the L 3 The name of the first interface to which the first attribute belongs, the name of the first attribute, the location (e.g., the number of lines) of the first attribute in the code file, and information indicating that the first attribute needs to be deleted are included.
It should be noted that, the editing operation for the code file may change the information such as the number of lines and the position of the code in the file, so that the interfaces corresponding to the first attribute and the second attribute with the same position may be different, and thus the generated interface attribute removal information may be inaccurate, and thus, further filtering needs to be performed on each interface attribute removal information.
In the embodiment of the disclosure, when the search condition is that the second attribute identical to the position of the first attribute is searched, interface attribute removal information for the first attribute is generated when the second attribute identical to the position of the first attribute is not searched. And determining a second interface which is the same as the name of the first interface to which the first attribute belongs, and comparing the names of the first attribute and the second attributes of the second interface. Deleting interface attribute removal information when it is determined that the first attribute is the same as a name of a second attribute of the second interface; and when the first attribute and any second attribute of the second interface are determined to be different in name, retaining interface attribute removal information. Through the screening mode, the accuracy of the attribute removal information of each interface can be ensured.
Specifically, for one L p Search for whether there is a corresponding R p . For example, L 3 Interface attribute information indicating the attribute of line 3 in the code file before editing, and searching for whether there is a corresponding R 3 Wherein R is 3 Interface attribute information indicating an attribute of line 3 in the edited code file. For L 3 When no corresponding R is retrieved 3 When generating the interface attribute removal information for the attribute of line 3 in the code file before editing, the interface attribute removal information may include the L 3 The name of the first interface to which the first attribute belongs, the name of the first attribute, the location (e.g., the number of lines) of the first attribute in the code file, and information indicating that the first attribute needs to be deleted are included. Then, regardless of the location of the attribute, search and L 3 The second interfaces with the same names of the first interfaces are included, and all R containing the names of the second interfaces are determined p In determining these R p One of R p Name and L of the second attribute contained in the file 3 Deleting L when names of the first attributes contained are the same 3 Interface attribute removal information of the first attribute included; in determining these R p Any one R of p Name and L of the second attribute contained in the file 3 When the names of the first attributes are different, L is reserved 3 Interface attribute removal information of the first attribute is included.
In the embodiment of the disclosure, when the search condition is that the second attribute which is the same as the position of the first attribute is searched, the names of the second attribute which is the same as the position of the first attribute can be compared; when it is determined that the names of the first attribute and the second attribute identical to the position are not identical, interface attribute replacement information for the first attribute and the second attribute identical to the position of the first attribute is generated.
Specifically, for one L p Search for whether there is a corresponding R p . For example, L 3 Interface attribute information indicating the attribute of line 3 in the code file before editing, and searching for whether there is a corresponding R 3 Wherein R is 3 Interface attribute information indicating an attribute of line 3 in the edited code file. For L 3 When the corresponding R is retrieved 3 At this time, L can be compared 3 Name and R of first attribute 3 Whether the names of the second attributes contained are the same, and when the names are determined to be different, generating a target L 3 First attribute included, R 3 Interface attribute replacement information for the second attribute is included. The interface attribute replacement information may include the L 3 The name of the first interface to which the first attribute belongs, the name of the first attribute, the position (such as the number of lines) of the first attribute in the code file, R 3 The name of the second interface to which the second attribute belongs, the name of the second attribute, the location of the second attribute in the code file (e.g., the number of lines), and information indicating that the first attribute needs to be replaced by the second attribute are included.
It should be noted that, the editing operation for the code file may change the information such as the number of lines and the position of the code in the file, so that the interfaces corresponding to the first attribute and the second attribute with the same position may be different, and thus the generated interface attribute replacement information may be inaccurate, and thus, further filtering needs to be performed on each interface attribute replacement information.
In the embodiment of the disclosure, when the search condition is that the second attribute which is the same as the position of the first attribute is searched, comparing the names of the second attribute which is the same as the position of the first attribute; when it is determined that the names of the first attribute and the second attribute identical to the position are not identical, interface attribute replacement information for the first attribute and the second attribute identical to the position of the first attribute is generated.
After the interface attribute replacement information is generated, a second interface which is the same as the name of the first interface to which the first attribute belongs can be determined, and the names of the first attribute and the second attributes of the second interface are compared; when the first attribute is determined to be different from the name of any one of the second interfaces, retaining interface attribute replacement information; and deleting the interface attribute replacement information when the first attribute is determined to be the same as the name of one second interface of the second interfaces, and generating interface attribute newly-added information for the second attribute which is the same as the position of the first attribute. By the screening method, accuracy of the replacement information of each interface attribute can be ensured.
Specifically, for one L p Search for whether there is a corresponding R p . For example, L 3 Interface attribute information indicating the attribute of line 3 in the code file before editing, and searching for whether there is a corresponding R 3 Wherein R is 3 Interface attribute information indicating an attribute of line 3 in the edited code file. For L 3 When the corresponding R is retrieved 3 At this time, L can be compared 3 Name and R of first attribute 3 Whether the names of the second attributes contained are the same, and when the names are determined to be different, generating a target L 3 First attribute included, R 3 Interface attribute replacement information for the second attribute is included. The interface attribute replacement information may include the L 3 The name of the first interface to which the first attribute belongs, the name of the first attribute, the position (such as the number of lines) of the first attribute in the code file, R 3 The name of the second interface to which the second attribute belongs, the name of the second attribute, the location of the second attribute in the code file (e.g., the number of lines), and information indicating that the first attribute needs to be replaced by the second attribute are included.
After the interface attribute replacement information is generated, the search and L are carried out without considering the position of the attribute 3 The second interfaces with the same names of the first interfaces are included, and all R containing the names of the second interfaces are determined p . Determination of these R' s p One of R p Of a second attribute contained thereinName and L 3 Deleting the interface attribute replacement information when the names of the contained first attributes are the same, and generating R p Interface attribute newly-added information of the second attribute; in determining these R p Any one R of p Name and L of the second attribute contained in the file 3 And when the names of the contained first attributes are different, retaining the interface attribute replacement information.
In the embodiment of the disclosure, when the search condition is that the second attribute which is the same as the position of the first attribute is searched, comparing the names of the second attribute which is the same as the position of the first attribute; when it is determined that the names of the first attribute and the second attribute identical to the position are not identical, interface attribute replacement information for the first attribute and the second attribute identical to the position of the first attribute is generated.
After the interface attribute replacement information is generated, a first interface which is the same as the name of a second interface to which the second attribute belongs can be determined, and the names of the second attribute and each second attribute of the first interface are compared; when the second attribute is determined to be different from the name of any one of the first interfaces, retaining interface attribute replacement information; when it is determined that the second attribute is the same as the name of one of the first interfaces, the interface attribute replacement information is deleted, and interface attribute deletion information for the first attribute that is the same as the name of the second attribute is generated.
Specifically, for one L p Search for whether there is a corresponding R p . For example, L 3 Interface attribute information indicating the attribute of line 3 in the code file before editing, and searching for whether there is a corresponding R 3 Wherein R is 3 Interface attribute information indicating an attribute of line 3 in the edited code file. For L 3 When the corresponding R is retrieved 3 At this time, L can be compared 3 Name and R of first attribute 3 Whether the names of the second attributes contained are the same, and when the names are determined to be different, generating a target L 3 First attribute included, R 3 Interface attribute replacement information for the second attribute is included. The interface attribute replacement information may beTo include the L 3 The name of the first interface to which the first attribute belongs, the name of the first attribute, the position (such as the number of lines) of the first attribute in the code file, R 3 The name of the second interface to which the second attribute belongs, the name of the second attribute, the location of the second attribute in the code file (e.g., the number of lines), and information indicating that the first attribute needs to be replaced by the second attribute are included.
After the interface attribute replacement information is generated, the R and R are retrieved regardless of the location of the attribute 3 The first interfaces with the same names of the second interfaces are included, and all L containing the names of the first interfaces are determined p . Determination of these L p One of L p Name and R of the first attribute contained in the list 3 Deleting the interface attribute replacement information when the names of the contained second attributes are the same, and generating L p Interface attribute newly-added information of the first attribute; in determining these L p Any one L of p Name and R of the first attribute contained in the list 3 And when the names of the contained second attributes are different, retaining the interface attribute replacement information.
The process of obtaining the interface attribute change information is described below by taking the second attribute as a comparison object:
alternatively, when comparing the first interface attribute information and the second interface attribute information, the first attribute identical to the position of each second attribute may be retrieved for each second attribute; and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result.
Specifically, for one R p Search for whether there is a corresponding L p . For example, R 3 Interface attribute information indicating the attribute of line 3 in the edited code file, and searching for a corresponding L 3 Wherein L is 3 Interface attribute information indicating an attribute of line 3 in the code file before editing. For having corresponding L p Is not corresponding to L p Different interface attribute change information may be generated.
In the embodiment of the disclosure, when the search condition is that the second attribute which is the same as the position of the first attribute is not searched, the interface attribute newly-added information for the second attribute can be generated for the first attribute when the first attribute which is the same as the position of the second attribute is not searched. For example for R 3 When no corresponding L is retrieved 3 When generating the interface attribute newly-added information for the attribute of the 3 rd line in the edited code file, the interface attribute newly-added information can comprise the R 3 The name of the second interface to which the second attribute belongs, the name of the second attribute, the location of the second attribute in the code file (e.g., the number of lines) and information indicating that the second attribute needs to be added are included.
It should be noted that, the editing operation for the code file may change the information such as the number of lines and the position of the code in the file, so that the interfaces corresponding to the first attribute and the second attribute with the same position may be different, and thus the generated new information of the interface attribute may be inaccurate, and thus, further screening needs to be performed on each new information of the interface attribute.
In the embodiment of the disclosure, when the search condition is that the first attribute which is the same as the second attribute in position is not searched, the interface attribute newly-added information aiming at the second attribute is generated. After generating new information of interface attribute, determining a first interface with the same name as the second interface to which the second attribute belongs, and comparing the names of the second attribute and each first attribute of the first interface; deleting the interface attribute newly-added information when the second attribute is determined to be the same as the name of one first attribute of the first interface; and when the second attribute is determined to be different from any first attribute of the first interface, reserving interface attribute newly-added information. Through the screening mode, the accuracy of the newly added information of each interface attribute can be ensured.
For example for R 3 When no corresponding L is retrieved 3 Generating interface attribute newly-added information for the attribute of the 3 rd line in the edited code file, wherein the interface attribute newly-added information can be used forTo include the R 3 The name of the second interface to which the second attribute belongs, the name of the second attribute, the location of the second attribute in the code file (e.g., the number of lines) and information indicating that the second attribute needs to be added are included. After generating the new information of the interface attribute, searching and R is carried out without considering the position of the attribute 3 The first interfaces with the same names of the second interfaces are included, and all L containing the names of the first interfaces are determined p . Determination of these L p One of L p Name and R of the first attribute contained in the list 3 Deleting the new information of the interface attribute when the names of the second attributes are the same; in determining these L p Any one L of p Name and R of the first attribute contained in the list 3 And when the names of the contained second attributes are different, reserving the newly-added information of the interface attributes.
As described above, the interface attribute change information includes at least one of interface attribute removal information, interface attribute replacement information, and interface attribute new-addition information. For different types of interface attribute change information, step S130 may perform different sub-steps, as follows:
When the interface attribute change information includes interface attribute removal information, a first attribute in the attribute removal information is identified, a first function definition component containing a first interface to which the first attribute belongs is determined from the code file, and the first attribute is removed from the first function definition component.
Fig. 2 shows a schematic diagram of attribute information change before and after editing of a first code file provided in an embodiment of the present disclosure, and as shown in fig. 2, before the code file is edited, two attributes foo and bar are included in interface attribute definition information of an interface of the code file, and a function definition component referencing the interface also has the two attributes of the interface. After the code file is edited, the developer deletes the attribute foo in the interface attribute definition information of the above interface of the code file, so step S130 may automatically delete the attribute foo in the corresponding function definition component.
When the interface attribute change information comprises interface attribute replacement information, a first attribute and a second attribute in the attribute removal information are identified, a second function definition component containing a first interface corresponding to the first attribute is determined from the code file, and the first attribute is replaced by the second attribute in the second function definition component.
Fig. 3 is a schematic diagram showing attribute information change before and after editing of a second code file according to an embodiment of the present disclosure, where, as shown in fig. 3, before the code file is edited, an attribute of bar is included in interface attribute definition information of an interface of the code file, and a function definition component referencing the interface also includes the attribute of the interface. After the code file is edited, the developer modifies bar to baz at the interface attribute definition information of the above interface of the code file, so step S130 may automatically modify bar to baz in the corresponding function definition component.
When the interface attribute change information comprises the interface attribute newly-added information, a second attribute in the interface attribute newly-added information is identified, a third function definition component containing a first interface corresponding to the second attribute is determined from the code file, and the second attribute is added into the third function definition component.
Fig. 4 shows a schematic diagram of attribute information change before and after editing of a third code file provided in an embodiment of the present disclosure, where before the code file is edited, an attribute is not configured in interface attribute definition information of an interface of the code file, and a function definition component referencing the interface does not have an attribute of the interface, as shown in fig. 4. After the code file is edited, the developer adds the attribute foo to the interface attribute definition information of the above interface of the code file, so step S130 may automatically add the attribute foo to the corresponding function definition component.
Based on the same principle as the code file editing method described above, the embodiment of the present disclosure further provides a code file editing apparatus, and fig. 5 shows a schematic diagram of the code file editing apparatus provided by the embodiment of the present disclosure, and as shown in fig. 5, the code file editing apparatus 500 includes a text obtaining module 510, an attribute comparing module 520, and an attribute updating module 530.
The text obtaining module 510 is configured to obtain, when it is detected that the code file is edited, a first code text before the code file is edited, and a second code text after the code file is edited.
The attribute comparison module 520 is configured to compare the interface definition information in the first code text and the second code text to obtain interface attribute change information, where the interface attribute change information is used to indicate a change condition of an attribute of a corresponding interface in the code file.
The attribute updating module 530 is configured to update the attribute information in the corresponding function definition component of the code file based on the interface attribute change information when the interface attribute change information indicates that the interface attribute of the code file changes.
The code file editing device provided by the embodiment of the disclosure can determine whether the attribute in the interface definition information is modified after the code file is edited, and automatically update the attribute information in the related function definition components when the attribute is modified, so that a developer does not need to manually modify the attribute information in the function definition components one by one, the workload of the developer is obviously reduced, the developer can concentrate on writing core logic, and the code writing efficiency is improved.
In the embodiment of the present disclosure, the attribute comparison module 520 is specifically configured to, when configured to compare the interface definition information in the first code text and the second code text to obtain the interface attribute change information:
parsing at least one first interface definition information from the first code text, and identifying first interface attribute information based on each first interface definition information;
parsing at least one second interface definition information from the second code text, identifying second interface attribute information based on each second interface definition information;
and comparing the first interface attribute information with the second interface attribute information to obtain interface attribute change information.
In the embodiment of the disclosure, the first interface attribute information includes a name of the first interface, a name of a first attribute of the first interface, and a position of the first attribute in the code file, and the second interface attribute information includes a name of the second interface, a name of a second attribute of the second interface, and a position of the second attribute in the code file;
the attribute comparison module 520 is configured to compare the first interface attribute information and the second interface attribute information to obtain interface attribute change information, and is specifically configured to:
and comparing the first interface attribute information with the second interface attribute information based on the position of the interface in the code file to obtain interface attribute change information corresponding to each first interface attribute information and/or each second interface attribute information.
In the embodiment of the present disclosure, the attribute comparison module 520 is configured to compare the first interface attribute information and the second interface attribute information based on the position of the interface in the code file, so as to obtain the interface attribute change information corresponding to each first interface attribute information and/or each second interface attribute information, where the attribute comparison module is specifically configured to:
for each first attribute, retrieving a second attribute that is the same as the first attribute in position;
and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result.
In an embodiment of the present disclosure, the interface attribute change information includes interface attribute removal information, where the interface attribute removal information is used to indicate that the corresponding first attribute is removed in the edited code file;
the attribute comparison module 520, when configured to generate the interface attribute change information of each first attribute and/or second attribute according to the search result, is specifically configured to:
when a second attribute identical to the first attribute in position is not retrieved, interface attribute removal information for the first attribute is generated.
In an embodiment of the present disclosure, the interface attribute change information includes interface attribute removal information, where the interface attribute removal information is used to indicate that the corresponding first attribute is removed in the edited code file;
The attribute comparison module 520, when configured to generate the interface attribute change information of each first attribute and/or second attribute according to the search result, is specifically configured to:
generating interface attribute removal information for the first attribute when the second attribute identical to the first attribute in position is not retrieved;
determining a second interface with the same name as the first interface to which the first attribute belongs, and comparing the names of the first attribute and each second attribute of the second interface;
deleting interface attribute removal information when it is determined that the first attribute is the same as a name of a second attribute of the second interface;
and when the first attribute and any second attribute of the second interface are determined to be different in name, retaining interface attribute removal information.
In an embodiment of the present disclosure, the interface attribute change information includes interface attribute replacement information, where the interface attribute replacement information is used to indicate that a corresponding first attribute is replaced in the code file by a second attribute with the same position;
the attribute comparison module 520, when configured to generate the interface attribute change information of each first attribute and/or second attribute according to the search result, is specifically configured to:
when a second attribute identical to the position of the first attribute is retrieved, comparing the names of the second attribute identical to the position of the first attribute;
When it is determined that the names of the first attribute and the second attribute identical to the position are not identical, interface attribute replacement information for the first attribute and the second attribute identical to the position of the first attribute is generated.
In the embodiment of the disclosure, the interface attribute change information includes interface attribute replacement information and interface attribute newly-added information, the interface attribute replacement information is used for indicating that the corresponding first attribute is replaced by a second attribute with the same position in the code file, and the interface attribute newly-added information is used for indicating that the corresponding second attribute is newly-added attribute after the code file is edited;
the attribute comparison module 520, when configured to generate the interface attribute change information of each first attribute and/or second attribute according to the search result, is specifically configured to:
when a second attribute identical to the position of the first attribute is retrieved, comparing the names of the second attribute identical to the position of the first attribute;
when it is determined that the names of the first attribute and the second attribute identical to the position are different, generating interface attribute replacement information for the first attribute and the second attribute identical to the position of the first attribute;
determining a second interface with the same name as the first interface to which the first attribute belongs, and comparing the names of the first attribute and each second attribute of the second interface;
When the first attribute is determined to be different from the name of any one of the second interfaces, retaining interface attribute replacement information;
and deleting the interface attribute replacement information when the first attribute is determined to be the same as the name of one second interface of the second interfaces, and generating interface attribute newly-added information for the second attribute which is the same as the position of the first attribute.
In an embodiment of the present disclosure, the interface attribute change information includes interface attribute replacement information and interface attribute removal information, the interface attribute replacement information is used to indicate that the corresponding first attribute is replaced by a second attribute with the same position in the code file, and the interface attribute removal information is used to indicate that the corresponding first attribute is removed in the edited code file;
the attribute comparison module 520, when configured to generate the interface attribute change information of each first attribute and/or second attribute according to the search result, is specifically configured to:
when a second attribute identical to the position of the first attribute is retrieved, comparing the names of the second attribute identical to the position of the first attribute;
when it is determined that the names of the first attribute and the second attribute identical to the position are different, generating interface attribute replacement information for the first attribute and the second attribute identical to the position of the first attribute;
Determining a first interface with the same name as the second interface to which the second attribute belongs, and comparing the names of the second attribute and each second attribute of the first interface;
when the second attribute is determined to be different from the name of any one of the first interfaces, retaining interface attribute replacement information;
when it is determined that the second attribute is the same as the name of one of the first interfaces, the interface attribute replacement information is deleted, and interface attribute deletion information for the first attribute that is the same as the name of the second attribute is generated.
In the embodiment of the present disclosure, the attribute comparison module 520 is configured to compare the first interface attribute information and the second interface attribute information based on the position of the interface in the code file, so as to obtain the interface attribute change information corresponding to each first interface attribute information and/or each second interface attribute information, where the attribute comparison module is specifically configured to:
for each second attribute, retrieving the first attribute that is the same as the location of the second attribute;
and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result.
In the embodiment of the disclosure, the interface attribute change information includes interface attribute newly-added information, where the interface attribute newly-added information is used to indicate that the corresponding second attribute is an attribute newly added after the code file is edited;
The attribute comparison module 520, when configured to generate the interface attribute change information of each first attribute and/or second attribute according to the search result, is specifically configured to:
when the first attribute which is the same as the second attribute in position is not retrieved, interface attribute newly-added information for the second attribute is generated.
In the embodiment of the disclosure, the interface attribute change information includes interface attribute newly-added information, where the interface attribute newly-added information is used to indicate that the corresponding second attribute is an attribute newly added after the code file is edited;
the attribute comparison module 520, when configured to generate the interface attribute change information of each first attribute and/or second attribute according to the search result, is specifically configured to:
generating interface attribute newly-added information for the second attribute when the first attribute which is the same as the second attribute in position is not searched;
determining a first interface with the same name as the second interface to which the second attribute belongs, and comparing the names of the second attribute and each first attribute of the first interface;
deleting the interface attribute newly-added information when the second attribute is determined to be the same as the name of one first attribute of the first interface;
and when the second attribute is determined to be different from any first attribute of the first interface, reserving interface attribute newly-added information.
In the embodiment of the present disclosure, the attribute comparison module 520, when configured to parse at least one first interface definition information from a first code text, is specifically configured to: constructing a first abstract syntax tree based on the first code text, and analyzing first interface attribute information from the first abstract syntax tree.
In the embodiment of the present disclosure, the attribute comparison module 520, when configured to parse at least one second interface definition information from the second code text, is specifically configured to: and constructing a second abstract syntax tree based on the second code text, and analyzing second interface attribute information from the second abstract syntax tree.
In the disclosed embodiment, the attribute comparison module 520 is further configured to: and ending the updating flow of the attribute information in the function definition component aiming at the code file when the interface attribute change information indicates that the interface attribute of the code file is not changed.
In an embodiment of the present disclosure, the interface attribute change information includes at least one of interface attribute removal information, interface attribute replacement information, and interface attribute new addition information;
the attribute updating module 530 is specifically configured to, when defining attribute information in a component for a corresponding function of a code file based on the interface attribute change information when the interface attribute change information indicates that an interface attribute of the code file changes:
When the interface attribute change information comprises interface attribute removal information, identifying a first attribute in the attribute removal information, determining a first function definition component containing a first interface to which the first attribute belongs from a code file, and removing the first attribute from the first function definition component;
when the interface attribute change information comprises interface attribute replacement information, identifying a first attribute and a second attribute in the attribute removal information, determining a second function definition component containing a first interface corresponding to the first attribute from a code file, and replacing the first attribute with the second attribute in the second function definition component;
when the interface attribute change information comprises the interface attribute newly-added information, a second attribute in the interface attribute newly-added information is identified, a third function definition component containing a first interface corresponding to the second attribute is determined from the code file, and the second attribute is added into the third function definition component.
It is understood that each of the above modules of the code file editing apparatus in the embodiments of the present disclosure has a function of implementing the corresponding steps of the above-described code file editing method. The functions can be realized by hardware, and can also be realized by executing corresponding software by hardware. The hardware or software includes one or more modules corresponding to the functions described above. The modules may be software and/or hardware, and each module may be implemented separately or may be implemented by integrating multiple modules. For the functional description of each module of the code file editing apparatus, reference may be specifically made to the corresponding description of the code file editing method, which is not described herein.
In the technical scheme of the disclosure, the related processes of collecting, storing, using, processing, transmitting, providing, disclosing and the like of the personal information of the user accord with the regulations of related laws and regulations, and the public order colloquial is not violated.
According to embodiments of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
FIG. 6 illustrates a schematic block diagram of an example electronic device that may be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 6, the apparatus 600 includes a computing unit 601 that can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM) 602 or a computer program loaded from a storage unit 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 may also be stored. The computing unit 601, ROM 602, and RAM 603 are connected to each other by a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
Various components in the device 600 are connected to the I/O interface 605, including: an input unit 606 such as a keyboard, mouse, etc.; an output unit 607 such as various types of displays, speakers, and the like; a storage unit 608, such as a magnetic disk, optical disk, or the like; and a communication unit 609 such as a network card, modem, wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
The computing unit 601 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of computing unit 601 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 601 performs the respective methods and processes described above, such as a code file editing method. For example, in some embodiments, the code file editing method may be implemented as a computer software program tangibly embodied on a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program may be loaded and/or installed onto the device 600 via the ROM 602 and/or the communication unit 609. When the computer program is loaded into the RAM 603 and executed by the computing unit 601, one or more steps of the code file editing method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform the code file editing method by any other suitable means (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for carrying out methods of the present disclosure may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the processor or controller, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and pointing device (e.g., a mouse or trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), and the internet.
The computer system may include a client and a server. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server may be a cloud server, a server of a distributed system, or a server incorporating a blockchain.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps recited in the present disclosure may be performed in parallel, sequentially, or in a different order, provided that the desired results of the disclosed aspects are achieved, and are not limited herein.
The above detailed description should not be taken as limiting the scope of the present disclosure. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives are possible, depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present disclosure are intended to be included within the scope of the present disclosure.

Claims (16)

1. A code file editing method comprising:
when the code file is detected to be edited, a first code text before the code file is edited and a second code text after the code file is edited are obtained;
comparing the interface definition information in the first code text and the second code text to obtain interface attribute change information, wherein the interface attribute change information is used for indicating the change condition of the attribute of the corresponding interface in the code file;
Updating attribute information in a corresponding function definition component of the code file based on the interface attribute change information under the condition that the interface attribute change information indicates that the interface attribute of the code file is changed;
the comparing the interface definition information in the first code text and the second code text to obtain interface attribute change information comprises the following steps:
parsing at least one first interface definition information from the first code text, and identifying first interface attribute information based on each first interface definition information;
parsing at least one second interface definition information from the second code text, and identifying second interface attribute information based on each second interface definition information;
comparing the first interface attribute information with the second interface attribute information to obtain interface attribute change information;
the first interface attribute information comprises a name of a first interface, a name of a first attribute of the first interface and a position of the first attribute in the code file, and the second interface attribute information comprises a name of a second interface, a name of a second attribute of the second interface and a position of the second attribute in the code file;
The comparing the first interface attribute information and the second interface attribute information to obtain interface attribute change information includes:
for each first attribute, retrieving the second attribute which is the same as the first attribute in position;
and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result.
2. The method of claim 1, wherein the interface attribute change information includes interface attribute removal information indicating that the corresponding first attribute is removed in the edited code file;
and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result, wherein the interface attribute change information comprises:
when the second attribute identical to the first attribute in position is not retrieved, interface attribute removal information for the first attribute is generated.
3. The method of claim 1, wherein the interface attribute change information includes interface attribute removal information indicating that the corresponding first attribute is removed in the edited code file;
And generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result, wherein the interface attribute change information comprises:
generating interface attribute removal information for the first attribute when the second attribute which is the same as the first attribute in position is not retrieved;
determining the second interfaces with the same names as the first interfaces to which the first attributes belong, and comparing the names of the first attributes with the names of the second attributes of the second interfaces;
deleting the interface attribute removal information when the first attribute is determined to be the same as the name of one of the second attributes of the second interface;
and when the first attribute and the names of any second attribute of the second interface are different, retaining the interface attribute removal information.
4. The method of claim 1, the interface attribute change information comprising interface attribute replacement information indicating that the corresponding first attribute is replaced in the code file by the second attribute having the same position;
and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result, wherein the interface attribute change information comprises:
When the second attribute which is the same as the position of the first attribute is retrieved, comparing the names of the second attribute which is the same as the position of the first attribute;
when it is determined that the names of the first attribute and the second attribute identical to the position are not identical, the interface attribute replacement information for the first attribute and the second attribute identical to the position of the first attribute is generated.
5. The method of claim 1, the interface attribute change information including interface attribute replacement information for indicating that the corresponding first attribute is replaced in the code file by the second attribute having the same position, and interface attribute addition information for indicating that the corresponding second attribute is an attribute newly added after the code file is edited;
and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result, wherein the interface attribute change information comprises:
when the second attribute which is the same as the position of the first attribute is retrieved, comparing the names of the second attribute which is the same as the position of the first attribute;
generating the interface attribute replacement information for the first attribute and the second attribute identical to the first attribute when the first attribute is determined to be different from the second attribute identical to the first attribute in name;
Determining the second interfaces with the same names as the first interfaces to which the first attributes belong, and comparing the names of the first attributes with the names of the second attributes of the second interfaces;
when the first attribute is determined to be different from the name of any second interface of the second interfaces, retaining the interface attribute replacement information;
and deleting the interface attribute replacement information when the first attribute is determined to be the same as the name of one second interface of the second interfaces, and generating the interface attribute newly-added information for the second attribute which is the same as the position of the first attribute.
6. The method of claim 1, wherein the interface attribute change information includes interface attribute replacement information for indicating that the corresponding first attribute is replaced in the code file by the second attribute having the same position, and interface attribute removal information for indicating that the corresponding first attribute is removed in the edited code file;
and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result, wherein the interface attribute change information comprises:
When the second attribute which is the same as the position of the first attribute is retrieved, comparing the names of the second attribute which is the same as the position of the first attribute;
generating the interface attribute replacement information for the first attribute and the second attribute identical to the first attribute when the first attribute is determined to be different from the second attribute identical to the first attribute in name;
determining the first interfaces with the same names as the second interfaces to which the second attributes belong, and comparing the names of the second attributes with the names of the second attributes of the first interfaces;
when the second attribute is determined to be different from the name of any one of the first interfaces, retaining the interface attribute replacement information;
and deleting the interface attribute replacement information when the second attribute is determined to be the same as the name of one of the first interfaces of the first interface, and generating the interface attribute deletion information for the first attribute which is the same as the name of the second attribute.
7. The method according to claim 1, wherein comparing the first interface attribute information and the second interface attribute information based on the position of the interface in the code file, to obtain each first interface attribute information and/or each interface attribute change information corresponding to the second interface attribute information, includes:
For each second attribute, retrieving the first attribute which is the same as the second attribute in position;
and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result.
8. The method of claim 7, wherein the interface attribute change information includes interface attribute newly-added information indicating that the corresponding second attribute is an attribute newly added after the code file is edited;
and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result, wherein the interface attribute change information comprises:
and when the first attribute which is the same as the second attribute in position is not retrieved, generating the interface attribute newly-added information aiming at the second attribute.
9. The method of claim 8, wherein the interface attribute change information includes interface attribute newly-added information indicating that the corresponding second attribute is an attribute newly added after the code file is edited;
and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result, wherein the interface attribute change information comprises:
Generating the interface attribute newly-added information for the second attribute when the first attribute which is the same as the second attribute in position is not retrieved;
determining the first interfaces with the same names as the second interfaces to which the second attributes belong, and comparing the names of the second attributes with the names of the first attributes of the first interfaces;
deleting the interface attribute newly-added information when the second attribute is determined to be the same as the name of one first attribute of the first interface;
and when the second attribute is determined to be different from any first attribute of the first interface, reserving the new information of the interface attribute.
10. The method of claim 1, wherein,
the parsing at least one first interface definition information from the first code text includes: constructing a first abstract syntax tree based on the first code text, and analyzing first interface attribute information from the first abstract syntax tree;
said parsing at least one second interface definition information from said second code text comprises: constructing a second abstract syntax tree based on the second code text, and analyzing second interface attribute information from the second abstract syntax tree.
11. The method of claim 1, further comprising, after said comparing interface definition information in said first code text and said second code text to obtain interface attribute change information:
and ending the updating flow of the attribute information in the function definition component aiming at the code file when the interface attribute change information indicates that the interface attribute of the code file is not changed.
12. The method of claim 1, the interface attribute change information comprising at least one of interface attribute removal information, interface attribute replacement information, and interface attribute addition information;
and defining attribute information in a component for a corresponding function of the code file based on the interface attribute change information when the interface attribute change information indicates that the interface attribute of the code file is changed, wherein the attribute information comprises:
when the interface attribute change information comprises the interface attribute removal information, identifying a first attribute in the attribute removal information, determining a first function definition component containing a first interface to which the first attribute belongs from the code file, and removing the first attribute from the first function definition component;
When the interface attribute change information comprises the interface attribute replacement information, identifying a first attribute and a second attribute in the attribute removal information, determining a second function definition component containing a first interface corresponding to the first attribute from the code file, and replacing the first attribute with the second attribute in the second function definition component;
when the interface attribute change information comprises interface attribute newly-added information, a second attribute in the interface attribute newly-added information is identified, a third function definition component containing a first interface corresponding to the second attribute is determined from the code file, and the second attribute is added into the third function definition component.
13. A code file editing apparatus comprising:
the text acquisition module is used for acquiring a first code text before the code file is edited and a second code text after the code file is edited when the code file is detected to be edited;
the attribute comparison module is used for comparing the interface definition information in the first code text and the second code text to obtain interface attribute change information, wherein the interface attribute change information is used for indicating the change condition of the attribute of the corresponding interface in the code file;
The attribute updating module is used for updating the attribute information in the corresponding function definition component of the code file based on the interface attribute change information under the condition that the interface attribute change information indicates that the interface attribute of the code file is changed;
the attribute comparison module is specifically configured to parse at least one first interface definition information from the first code text, and identify first interface attribute information based on each first interface definition information; parsing at least one second interface definition information from the second code text, and identifying second interface attribute information based on each second interface definition information; comparing the first interface attribute information with the second interface attribute information to obtain interface attribute change information;
the first interface attribute information comprises a name of a first interface, a name of a first attribute of the first interface and a position of the first attribute in the code file, and the second interface attribute information comprises a name of a second interface, a name of a second attribute of the second interface and a position of the second attribute in the code file;
The attribute comparison module is specifically configured to, for each first attribute, retrieve the second attribute that is the same as the first attribute in position; and generating interface attribute change information of each first attribute and/or each second attribute according to the condition of the search result.
14. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-12.
15. A non-transitory computer readable storage medium storing computer instructions for causing the computer to perform the method of any one of claims 1-12.
16. A computer program product comprising a computer program which, when executed by a processor, implements the method of any of claims 1-12.
CN202111487940.4A 2021-12-07 2021-12-07 Code file editing method, device, electronic equipment and storage medium Active CN114168119B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202111487940.4A CN114168119B (en) 2021-12-07 2021-12-07 Code file editing method, device, electronic equipment and storage medium
PCT/CN2022/111304 WO2023103432A1 (en) 2021-12-07 2022-08-10 Code file editing method and apparatus, electronic device, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111487940.4A CN114168119B (en) 2021-12-07 2021-12-07 Code file editing method, device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN114168119A CN114168119A (en) 2022-03-11
CN114168119B true CN114168119B (en) 2024-04-05

Family

ID=80484134

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111487940.4A Active CN114168119B (en) 2021-12-07 2021-12-07 Code file editing method, device, electronic equipment and storage medium

Country Status (2)

Country Link
CN (1) CN114168119B (en)
WO (1) WO2023103432A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114168119B (en) * 2021-12-07 2024-04-05 北京百度网讯科技有限公司 Code file editing method, device, electronic equipment and storage medium

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP2498155A1 (en) * 2011-03-11 2012-09-12 Siemens Aktiengesellschaft Method for recognition of SW-interface modifications and for automatical adaptation of said interfaces in an automation program
CN105117233A (en) * 2015-09-14 2015-12-02 百度在线网络技术(北京)有限公司 API calling method and device
CN108268253A (en) * 2017-05-05 2018-07-10 平安科技(深圳)有限公司 Interface code generation method and terminal device
CN108595200A (en) * 2018-04-19 2018-09-28 北京微播视界科技有限公司 Code update method, figure update method, device, storage medium and terminal
CN111221521A (en) * 2019-12-31 2020-06-02 奇安信科技集团股份有限公司 Method and device for generating log code, computer system and readable storage medium
CN111367547A (en) * 2020-02-27 2020-07-03 平安国际智慧城市科技股份有限公司 Automatic interface code synchronization method, device and storage medium
CN111708563A (en) * 2020-06-24 2020-09-25 北京冰封互娱科技有限公司 Method and device for updating UI control in game
CN112286557A (en) * 2020-11-05 2021-01-29 苏州帝博信息技术有限公司 Method and device for updating code content in non-covering mode
CN112579146A (en) * 2019-09-29 2021-03-30 北京国双科技有限公司 Interface change detection method and device

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TWI467481B (en) * 2010-05-31 2015-01-01 Ibm Method, system, and computer program product for hierarchical program source management
US10509642B2 (en) * 2018-03-30 2019-12-17 International Business Machines Corporation Intelligent discovery and application of API changes for application migration
CN114168119B (en) * 2021-12-07 2024-04-05 北京百度网讯科技有限公司 Code file editing method, device, electronic equipment and storage medium

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP2498155A1 (en) * 2011-03-11 2012-09-12 Siemens Aktiengesellschaft Method for recognition of SW-interface modifications and for automatical adaptation of said interfaces in an automation program
CN105117233A (en) * 2015-09-14 2015-12-02 百度在线网络技术(北京)有限公司 API calling method and device
CN108268253A (en) * 2017-05-05 2018-07-10 平安科技(深圳)有限公司 Interface code generation method and terminal device
CN108595200A (en) * 2018-04-19 2018-09-28 北京微播视界科技有限公司 Code update method, figure update method, device, storage medium and terminal
CN112579146A (en) * 2019-09-29 2021-03-30 北京国双科技有限公司 Interface change detection method and device
CN111221521A (en) * 2019-12-31 2020-06-02 奇安信科技集团股份有限公司 Method and device for generating log code, computer system and readable storage medium
CN111367547A (en) * 2020-02-27 2020-07-03 平安国际智慧城市科技股份有限公司 Automatic interface code synchronization method, device and storage medium
CN111708563A (en) * 2020-06-24 2020-09-25 北京冰封互娱科技有限公司 Method and device for updating UI control in game
CN112286557A (en) * 2020-11-05 2021-01-29 苏州帝博信息技术有限公司 Method and device for updating code content in non-covering mode

Also Published As

Publication number Publication date
CN114168119A (en) 2022-03-11
WO2023103432A1 (en) 2023-06-15

Similar Documents

Publication Publication Date Title
CN113342345A (en) Operator fusion method and device of deep learning framework
CN113868273B (en) Metadata snapshot method and device
CN114168119B (en) Code file editing method, device, electronic equipment and storage medium
CN108694172B (en) Information output method and device
CN116185389A (en) Code generation method and device, electronic equipment and medium
CN116361591A (en) Content auditing method, device, electronic equipment and computer readable storage medium
CN113127357B (en) Unit test method, apparatus, device, storage medium, and program product
CN113868254B (en) Method, device and storage medium for removing duplication of entity node in graph database
CN115328736A (en) Probe deployment method, device, equipment and storage medium
CN115329150A (en) Method and device for generating search condition tree, electronic equipment and storage medium
CN115469849A (en) Service processing system, method, electronic device and storage medium
CN114817223A (en) Service data extraction method and device, electronic equipment and storage medium
CN112989066A (en) Data processing method and device, electronic equipment and computer readable medium
CN112783507B (en) Data stream guiding playback method and device, electronic equipment and readable storage medium
CN113835893B (en) Data processing method, device, equipment, storage medium and program product
CN117251196A (en) Data maintenance method, device, equipment and storage medium
CN113378524A (en) Method, device, equipment and storage medium for updating storage information of document
CN115981657A (en) Code generation method and device, electronic equipment and readable medium
CN115454977A (en) Data migration method, device, equipment and storage medium
CN116009847A (en) Code generation method, device, electronic equipment and storage medium
CN117610580A (en) Instruction identification method and device based on large model, electronic equipment and storage medium
CN117873990A (en) DDL analysis method, device, equipment and storage medium based on WAL log
CN115687141A (en) Application program testing method and device, electronic equipment and storage medium
CN116400956A (en) Code merging information determining method and device, electronic equipment and storage medium
CN113836291A (en) Data processing method, device, equipment and storage medium

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