Source code processing method and device, electronic equipment and storage medium

By synchronizing the processing of source code and comment information, the problem of inconsistency between comment information and actual functionality is solved, thereby improving the maintainability and efficiency of the source code.

CN114756279BActive Publication Date: 2026-01-16LENOVO (BEIJING) LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210473801.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-29
Publication Date
2026-01-16
Estimated Expiration
2042-04-29

AI Technical Summary

Technical Problem

In existing technologies, when the source code function is not implemented or the function requirements change, the comment information is inconsistent with the actual function, which makes the source code difficult to maintain and prone to execution errors.

Method used

By displaying the source code and comment information, processing operations can be obtained, and the target code snippet and the target second-level comment content can be processed synchronously or sequentially to ensure the correspondence between the two and achieve the corresponding modifications.

Benefits of technology

It improves the maintainability of the source code, reduces the error rate caused by inconsistencies between code snippets and comments, and improves maintenance efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114756279B_ABST
    Figure CN114756279B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a source code processing method, comprising: displaying source code and annotation information of the source code; wherein the source code comprises at least one code block, each code block comprises at least one code segment; the annotation information comprises first-level annotation content corresponding to each code block and second-level annotation content corresponding to each code segment; obtaining a processing operation; synchronously or sequentially executing the processing operation on a first content block and a second content block; the first content block is one of a target code segment and target second-level annotation content; the second content block is the other of the target code segment and the target second-level annotation content; and the target second-level annotation content and the target code segment have a corresponding relationship. Embodiments of the present application also provide a source code processing device, an electronic device and a storage medium.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of electronic devices, and relates to, but is not limited to, a source code processing method and device, an electronic device, and a storage medium. BACKGROUND

[0002] The annotation information can be used to describe the function of the source code, and at least includes first-level annotation content and second-level annotation content. The first-level annotation content can describe the function to be implemented by a code block in the source code. The second-level annotation content can describe the function to be implemented by a code segment in the code block. In the process of implementing a complex function, first, the complex function is decomposed into a plurality of different sub-functions. Then, the first-level annotation content is used to describe the implementation steps and implementation logic of the sub-functions. Finally, the code block is written according to the implementation steps and implementation logic to implement the function of the source code. However, in the case that the function of the source code is not implemented or the function requirement is changed, the implementation logic will be adjusted, and the actual function will be inconsistent with the annotation information, thereby causing the difficulty in maintaining the source code and even the problem of execution error. SUMMARY

[0003] Embodiments of the present application provide a source code processing method and device, an electronic device, and a storage medium.

[0004] The technical solution of the embodiments of the present application is as follows:

[0005] In a first aspect, the embodiments of the present application provide a source code processing method, which includes:

[0006] displaying a source code and annotation information of the source code; wherein the source code includes at least one code block, each code block includes at least one code segment; the annotation information includes first-level annotation content corresponding to each code block and second-level annotation content corresponding to each code segment;

[0007] obtaining a processing operation;

[0008] synchronously or sequentially executing the processing operation on a first content block and a second content block; the first content block is one of a target code segment and target second-level annotation content; the second content block is the other of the target code segment and the target second-level annotation content; the target second-level annotation content and the target code segment have a corresponding relationship.

[0009] In a second aspect, the embodiments of the present application provide a source code processing device, which includes:

[0010] The display module is configured to display source code and annotation information of the source code; the source code comprises at least one code block, each code block comprises at least one code segment; and the annotation information comprises first-level annotation content corresponding to each code block and second-level annotation content corresponding to each code segment.

[0011] The acquisition module is configured to acquire a processing operation.

[0012] The processing module is configured to synchronously or sequentially execute the processing operation on the first content block and the second content block; the first content block is one of a target code segment and target second-level annotation content; the second content block is the other of the target code segment and the target second-level annotation content; and the target second-level annotation content has a corresponding relationship with the target code segment.

[0013] In a third aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, the memory stores a computer program capable of running on the processor, and the processor implements the steps in the above method when executing the program.

[0014] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the steps in the above method.

[0015] The technical scheme provided by the embodiments of the present application has at least the following beneficial effects:

[0016] In the embodiments of the present application, the processing operation is synchronously or sequentially executed on the first content block and the second content block; the first content block is one of a target code segment and target second-level annotation content; the second content block is the other of the target code segment and the target second-level annotation content; and the target second-level annotation content has a corresponding relationship with the target code segment. In this way, the corresponding modification of the target code segment and the target second-level annotation content can be realized through the synchronous or sequential processing of the target code segment and the target second-level annotation content, the consistency of the target code segment and the target second-level annotation content is improved, and the maintainability of the source code is improved. BRIEF DESCRIPTION OF DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.

[0018] Figure 1 A flowchart of a source code processing method provided by an embodiment of the present application is shown in the figure.

[0019] Figure 2A A flowchart of a source code processing method provided for an embodiment of the present application is shown in FIG. 1.

[0020] Figure 2B A flowchart of a source code processing method provided for an embodiment of the present application is shown in FIG. 1.

[0021] Figure 3 A flowchart of a source code processing method provided for an embodiment of the present application is shown in FIG. 1.

[0022] Figure 4 A flowchart of a source code processing method provided for an embodiment of the present application is shown in FIG. 1.

[0023] Figure 5 A flowchart of a source code processing method provided for an embodiment of the present application is shown in FIG. 1.

[0024] Figure 6A An application scenario diagram of a source code processing method provided for an embodiment of the present application is shown in FIG. 1.

[0025] Figure 6B An application scenario diagram of a source code processing method provided for an embodiment of the present application is shown in FIG. 1.

[0026] Figure 6C An application scenario diagram of a source code processing method provided for an embodiment of the present application is shown in FIG. 1.

[0027] Figure 7 A composition structure diagram of a source code processing device provided for an embodiment of the present application is shown in FIG. 1.

[0028] Figure 8 A hardware entity diagram of an electronic device provided for an embodiment of the present application is shown in FIG. 1. DETAILED DESCRIPTION

[0029] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some embodiments of the present application but not all embodiments of the present application. The following embodiments are used to explain the present application but not to limit the scope of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.

[0030] In the following description, “some embodiments” are described, which describe a subset of all possible embodiments, but it can be understood that “some embodiments” can be the same subset or different subsets of all possible embodiments and can be combined with each other without conflict.

[0031] It should be noted that the terms "first", "second", "third" involved in the embodiments of the present application are only to distinguish similar objects, and do not represent a specific order of the objects. It can be understood that the "first", "second", "third" can be interchanged in a specific order or sequence as allowed, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0032] Those skilled in the art can understand that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those skilled in the art to which the embodiments of the present application belong. It should also be understood that terms such as those defined in a general dictionary should be understood to have meanings consistent with meanings in the context of the prior art, and should not be interpreted to have idealized or overly formal meanings unless specifically defined as such herein.

[0033] Figure 1 A flowchart of a source code processing method provided by the embodiments of the present application is shown in FIG. 1. As shown in FIG. 1, the method comprises at least the following steps: Figure 1

[0034] Step S101, display source code and annotation information of the source code; wherein the source code comprises at least one code block, each code block comprises at least one code segment; the annotation information comprises first-level annotation content corresponding to each code block and second-level annotation content corresponding to each code segment;

[0035] Here, the source code can be an uncompiled text file written according to the writing specification of different types of programming languages. The different types of programming languages can be object-oriented programming (OOP) type programming languages, or procedure-oriented (PO) type programming languages. The OOP type programming language can be JAVA programming language, etc. The PO type programming language can be C programming language, etc. When the programming language is JAVA, the source file storing the source code has a.java suffix. When the programming language is C, the source file storing the source code has a.cpp suffix.

[0036] ​Here, the identification information of the annotation information is different in different programming languages. For example, in the C programming language, the annotation information is any one of the following: 1) a block comment starting with / * and ending with * / ; 2) a line comment starting with / / and ending with a line feed. For example, in the JAVA programming language, in addition to the two types in the C programming language, the annotation information also includes a javadoc comment starting with / ** and ending with * / .

[0037] Here, the code block has different forms in different programming languages. For example, in the JAVA programming language, the code block includes at least one of the following: 1) a normal code block: the method body of a method in a JAVA class; 2) a construction code block: a construction block is called when an object is created, and is called every time an object is created, and is executed before the class constructor; 3) a static code block: a code block wrapped with the keyword static{}, which is executed only once; 4) a synchronization code block: a code block wrapped with the keyword synchronized(). For example, as shown in Figure 6B The code block is the method body 62 of the createSchool method.

[0038] Here, the code block can be split into at least one code snippet by the identification information of the code snippet, which can include at least one of the following: a blank line, a punctuation mark, and a keyword. For example, as shown in Figure 6B The code block can be split by the keyword of the if condition and the colon to obtain code snippets 621, 622, and 623.

[0039] Here, the first-level annotation content is annotation content used to describe the implementation function of the code block. Here, the second-level annotation content is annotation content used to describe the implementation function of the code snippet. For example, as shown in Figure 6B The createSchool describing the function of the code block 62 is the first-level annotation content; S601 to S603 describing the code snippets 621, 622, and 623 are the second-level annotation content.

[0040] Step S102, obtaining a processing operation;

[0041] Here, the processing operation can include at least one of the following: a delete operation, a modify operation, a copy operation, and an insert operation.

[0042] S103, synchronously or sequentially performing the processing operation on the first content block and the second content block; the first content block is one of the target code segment and the target secondary annotation content; the second content block is the other of the target code segment and the target secondary annotation content; the target secondary annotation content has a corresponding relationship with the target code segment.

[0043] In an implementable manner, the processing operation is sequentially performed on the first content block and the second content block, including: in response to the processing operation, performing the processing operation on the first content block in the display interface displaying the source code and the annotation information; displaying the edited first content block; jumping the display interface from the first content block to the second content block; performing the processing operation on the second content block, and displaying the edited second content block.

[0044] In another implementable manner, the processing operation is sequentially performed on the first content block and the second content block, including: in response to the processing operation, performing the processing operation on the first content block and the second content block in the display interface, and synchronously displaying the edited first content block and the second content block.

[0045] In the above embodiment, the processing operation is synchronously or sequentially performed on the first content block and the second content block; the first content block is one of the target code segment and the target secondary annotation content; the second content block is the other of the target code segment and the target secondary annotation content; the target secondary annotation content has a corresponding relationship with the target code segment. In this way, the corresponding modification of the target code segment and the target secondary annotation content can be realized by synchronously or sequentially processing the target code segment and the target secondary annotation content, the consistency of the target code segment and the target secondary annotation content is improved, and the maintainability of the source code is improved.

[0046] Figure 2A A flowchart of a source code processing method provided by an embodiment of the present application is shown in FIG. 1, which includes the following steps: Figure 2A

[0047] S201, displaying source code and annotation information of the source code; the source code includes at least one code block, and each code block includes at least one code segment; the annotation information includes first-level annotation content corresponding to each code block and second-level annotation content corresponding to each code segment;

[0048] S202, obtaining a processing operation;

[0049] ​In step S203, a first editing operation is performed on the first content block and the second content block synchronously or sequentially, the first editing operation being used to adjust the content of the first content block and the second content block, the first content block being one of a target code segment and a target secondary annotation content, the second content block being the other of the target code segment and the target secondary annotation content, and the target secondary annotation content having a corresponding relationship with the target code segment.

[0050] Here, the first editing operation includes at least one of a deletion operation and a modification operation. In the process of performing the first editing operation, no new code segment and annotation content are added in the source code and the annotation information.

[0051] In the above embodiment, by performing a first editing operation on the first content block and the second content block synchronously or sequentially, the first editing operation being used to adjust the content of the first content block and the second content block, the first content block being one of a target code segment and a target secondary annotation content, the second content block being the other of the target code segment and the target secondary annotation content, and the target secondary annotation content having a corresponding relationship with the target code segment. In this way, the target code segment and the target secondary annotation content can be modified correspondingly without adding new target code segments and target secondary annotation contents, thereby reducing the problem of inconsistency between the code segment and the annotation content in the process of modifying the target code segment or the target secondary annotation content alone, and thus reducing the time cost of finding the code segment with errors by the user in the process of maintaining the source code and improving the efficiency of maintaining the source code.

[0052] Figure 2B A flowchart of a source code processing method provided by an embodiment of the present application is shown in FIG. 2. As shown in FIG. 2, the method includes at least the following steps: Figure 2B

[0053] In step S210, a source code and annotation information of the source code are displayed, the source code including at least one code block, each code block including at least one code segment, and the annotation information including primary annotation content corresponding to each code block and secondary annotation content corresponding to each code segment.

[0054] In step S220, a processing operation is obtained.

[0055] ​In step S230, a second editing operation is performed on the first content block and the second content block synchronously or sequentially; the second editing operation is used to add a third content block in the source code and the annotation information based on the first content block; the third content block and the first content block have a reference relationship; a fourth content block is added in the source code and the annotation information based on the second content block; the fourth content block and the second content block have a reference relationship; the third content block and the fourth content block have a corresponding relationship; the first content block is one of a target code segment and a target secondary annotation content; the second content block is the other of the target code segment and the target secondary annotation content; the target secondary annotation content and the target code segment have a corresponding relationship.

[0056] Here, the second editing operation can include at least one of a copy operation and an insertion operation. After the second editing operation is performed, new code segments and annotation contents are added in the source code and the annotation information.

[0057] In an implementable manner, when the processing operation is a copy operation, a reference relationship is established between the target secondary annotation content and the copied secondary annotation content; a reference relationship is established between the target code segment and the copied code segment; the copied secondary annotation content and the copied code segment have a corresponding relationship. The copied secondary annotation content is used to describe the copied code segment.

[0058] In an implementable manner, the method further includes: performing the first editing operation on the third content block and the fourth content block.

[0059] For example, when the target secondary annotation content is modified, the corresponding target code segment, the copied secondary annotation content and the copied code segment are modified.

[0060] For example, when the target code segment is modified, the corresponding secondary annotation content, the copied secondary annotation content and the copied code segment are modified.

[0061] In an implementable manner, the first editing operation includes at least one of a deletion operation and a modification operation; the second editing operation includes at least one of a copy operation and an insertion operation; and step S230 includes at least one of the following:

[0062] The first content block and the second content block are synchronously or sequentially copied;

[0063] The first content block and the second content block are synchronously or sequentially inserted;

[0064] Correspondingly, the first editing operation is performed on the third content block and the fourth content block, at least one of the following is included:

[0065] synchronously or sequentially deleting the third content block and the fourth content block;

[0066] synchronously or sequentially modifying the third content block and the fourth content block.

[0067] In the above embodiment, on the one hand, the second editing operation is performed on the first content block and the second content block synchronously or sequentially; wherein the second editing operation is used to add a third content block in the source code and the annotation information based on the first content block; and add a fourth content block in the source code and the annotation information based on the second content block. In this way, in the case of adding a target code segment, the target secondary annotation content corresponding to the added target code segment can be added; in the case of adding a target secondary annotation content, the target code segment corresponding to the added target secondary annotation content can be added, and in the case of adding a code segment or adding annotation content, the consistency of the code segment and the annotation content is improved, and the problem of missing or incomplete code segment or annotation content is reduced.

[0068] On the other hand, the third content block and the fourth content block are synchronously or sequentially deleted; the third content block and the fourth content block are synchronously or sequentially modified; the third content block and the first content block have a reference relationship; and the fourth content block and the second content block have a reference relationship. In this way, the reference relationship between the content blocks can be realized, and in the case of modifying the content blocks, the content blocks with reference relationship are synchronously or sequentially modified, one place is modified, and everywhere is synchronized, and for the target code segment and the target secondary annotation content with reference relationship, the inconsistency problem caused by modification is reduced, thereby reducing the probability of code error.

[0069] Figure 3 A flowchart of a source code processing method provided by an embodiment of the present application is shown in FIG. 1, which includes the following steps: Figure 3

[0070] In step S301, the source code and the annotation information of the source code are displayed; wherein the source code includes at least one code block, each code block includes at least one code segment; and the annotation information includes first-level annotation content corresponding to each code block and second-level annotation content corresponding to each code segment;

[0071] In step S302, a processing operation is obtained;

[0072] ​S303, synchronously or sequentially performing the processing operation on the first content block and the second content block; the first content block is one of the target code segment and the target secondary annotation content; the second content block is the other of the target code segment and the target secondary annotation content; the target secondary annotation content has a corresponding relationship with the target code segment;

[0073] S304, in response to the operation of adding the secondary annotation content, obtaining the input character;

[0074] S305, searching the character in at least one of the secondary annotation contents, and determining at least one piece of secondary annotation content which is identical to the character or has the same semantic as the character;

[0075] S306, in response to the selection operation on any of the secondary annotation contents, determining the added secondary annotation content.

[0076] In an implementable manner, the step S303 of synchronously or sequentially performing the processing operation on the first content block and the second content block comprises:

[0077] In the case that the added secondary annotation content is the target secondary annotation content, the target secondary annotation content and the target code segment are synchronously or sequentially added into the annotation information and the source code respectively.

[0078] Exemplarily, when writing new annotation information, the secondary annotation content in the annotation information can be searched through the input character or the semantic of the character, and in the case of determining the inserted secondary annotation content, the code segment associated with the secondary annotation content is inserted.

[0079] Exemplarily, in the source file as shown in Figure 6B the newly added code block is used to create another school, and the code segment of inserting the school record in the database also needs to be added in the newly added code block. The input character is obtained: insert, and the interface displays two pieces of secondary annotation content: insert school record and insert student and teacher record. In response to the selection operation on the insert school record, the secondary annotation content of the code segment of inserting the school record in the database and the corresponding code segment are inserted into the newly added code block.

[0080] In the above embodiment, the character is searched in the at least one secondary annotation content, it is determined that at least one piece of secondary annotation content is same as the character, or the semantic of the character is same; in response to the selection operation of any secondary annotation content, it is determined that the added secondary annotation content; in the case that the added secondary annotation content is the target secondary annotation content, the target secondary annotation content and the target code segment are respectively synchronized or sequentially added to the annotation information and the source code. In this way, in the process of adding secondary annotation content, the same secondary annotation content is searched through the input character or the semantic of the character, and the corresponding target code segment is inserted, so that the efficiency of writing annotation information and writing source code is improved.

[0081] Figure 4 A flowchart of a source code processing method provided by the embodiment of the application is shown in Figure 4 The method comprises the following steps:

[0082] In step S401, the source code and the annotation information of the source code are displayed; the source code comprises at least one code block, each code block comprises at least one code segment; the annotation information comprises primary annotation content corresponding to each code block and secondary annotation content corresponding to each code segment;

[0083] In step S402, a processing operation is acquired;

[0084] In step S403, the processing operation is synchronously or sequentially executed on a first content block and a second content block; the first content block is one of a target code segment and a target secondary annotation content; the second content block is the other of the target code segment and the target secondary annotation content; the target secondary annotation content and the target code segment have a corresponding relationship;

[0085] In step S404, a parsing operation or a compiling operation on the source code is acquired;

[0086] In step S405, a log output code is generated in the process of executing the parsing operation or the compiling operation; the log output code is used to output the secondary annotation content corresponding to the code segment in the case of capturing a running exception.

[0087] For example, as shown in Figure 6B the code segment generating a running exception is 621, and the secondary annotation content corresponding to the code segment 621 is output in the log file: in step S601, permission verification, the administrator can operate.

[0088] In an implementable manner, the method further comprises:

[0089] display prompt information; wherein the prompt information comprises: a first matching degree between each of the primary annotation content and a corresponding code block, a completion degree of each of the code blocks, a second matching degree between each of the secondary annotation content and a corresponding code segment, and a completion degree of each of the code segments.

[0090] Exemplarily, as shown in the following table, a school is created in an unfinished state, and the matching degree is 70%. Figure 6B

[0091] In the above embodiment, on the one hand, by outputting the secondary annotation content corresponding to the code segment generating the running exception in the case of capturing the running exception, the user can understand the function of the code segment generating the running exception, and the efficiency of repairing errors is improved.

[0092] On the other hand, the prompt information is displayed; wherein the prompt information comprises: a first matching degree between each of the primary annotation content and a corresponding code block, a completion degree of each of the code blocks, a second matching degree between each of the secondary annotation content and a corresponding code segment, and a completion degree of each of the code segments. In this way, the matching degree displayed can assist the user in decision-making to determine whether to select the current processing operation.

[0093] The annotation information can be used to describe the function of the source code, and at least includes primary annotation content and secondary annotation content, wherein the primary annotation content can describe the function to be implemented by the code block in the source code; and the secondary annotation content can describe the function to be implemented by the code segment in the code block. In the process of implementing a complex function, first, the complex function is decomposed into a plurality of different sub-functions; then, the primary annotation content is used to describe the implementation steps and implementation logic of the sub-function; finally, the code block is written according to the implementation steps and implementation logic to implement the function of the source code.

[0094] However, in the case that the function of the source code is not implemented or the function requirement is changed, the implementation logic will be adjusted, and the actual function will be inconsistent with the annotation information, thereby causing the difficulty in maintaining the source code and even the problem of executing errors. Moreover, the annotation method and the source code editing tool in the related art cannot accurately reflect the relationship between the annotation information and the code block, the user cannot know the completion degree of the code block through the annotation information, and the source code cannot be modified in a targeted manner.

[0095] To solve the above problems, the present application provides a source code processing method, which comprises:

[0096] Step S501, processing the annotation information to obtain primary annotation content;

[0097] ​In an implementable manner, a natural language processing (NLP) technique is used to identify semantics in the annotation information and extract function keywords in the annotation information.

[0098] As shown in Figure 6A the annotation information content includes: creating a school: 1, permission verification, administrator can operate; 2, insert school record in the database; 3, insert teacher and teaching information in the database.

[0099] As an example, the annotation information is processed by step S501, the NLP technique is used to identify the semantics in the annotation information, and the verb-noun group in the annotation information is extracted to obtain the following function keywords in the annotation information: creating a school; permission verification; inserting a school; inserting teacher and teaching information.

[0100] In an implementable manner, in the case that the annotation information includes a hierarchical relationship, the obtained function keywords also include a hierarchical relationship; based on the hierarchical relationship of the function keywords, the hierarchical relationship of the annotation information is determined to obtain primary annotation content and secondary annotation content.

[0101] As an example, the function of creating a school is implemented by the sub-function of permission verification, so the primary function keyword is: creating a school; the secondary function keyword is: permission verification. Therefore, based on the hierarchical relationship of the function keywords, it can be obtained that the primary annotation content is creating a school, and the secondary annotation content is permission verification, and the administrator can operate.

[0102] Step S502, source code structure analysis, to obtain at least one code block;

[0103] In an implementable manner, the source code can be split into at least one functionally independent code block by step S502.

[0104] In an implementable manner, each of the code blocks can be implemented by at least one code segment.

[0105] As shown in Figure 6A the code block 61 for implementing the function of creating a school includes three different code segments, which are respectively used to implement the permission verification function, the school insertion function, and the teacher insertion and teaching information insertion function in the secondary annotation content.

[0106] In an implementable manner, the code block can be split into at least one code segment by the identification information of the code segment, and the identification information can at least include one of the following: line feed, punctuation mark, and keyword. For example, the code block can be split into at least one code segment by the keywords of for loop and while loop.

[0107] Step S503, matching the at least one code block with the primary annotation content to obtain a first matching degree and a first association relationship;

[0108] Here, the first matching degree can be determined by the context in the source code.

[0109] In an implementable manner, the method further comprises: determining a second matching degree between the secondary annotation content and the code segment in combination with the context; establishing the first association relationship between the primary annotation content and the code block; and the second association relationship between the secondary annotation content and the code segment.

[0110] In an implementable manner, the first matching degree is determined by the context in the source code, comprising: dividing the content into N steps, and determining the percentage of the number of completed steps in the total number of steps according to the number of steps completed in real time.

[0111] Exemplarily, as shown in Figure 6B , creating a school comprises: step S601, permission check, which can be operated by an administrator; step S602, inserting a school record in a database; and step S603, inserting teacher and teaching information in the database. Among them, step S603 is in an unfinished state, so the creation of the school is in an unfinished state, and the matching degree is 70%.

[0112] In an implementable manner, as shown in Figure 6C , the first association relationship is obtained by matching the at least one code block with the primary annotation content, comprising: step S610, inputting historical source code and annotated annotation information file into a model for training to obtain a trained model; and step S620, inputting the at least one code block and the primary annotation content into the trained model to obtain the first association relationship.

[0113] In an implementable manner, the method further comprises: inputting the at least one code segment and the secondary annotation content into the trained model to obtain a second association relationship.

[0114] Step S504, determining a processing operation on the source code based on the first matching degree;

[0115] Here, the processing operation can include one of the following: a deletion operation, a modification operation, a copy operation, and an insertion operation.

[0116] Exemplarily, in the case that the creation of the school is in an unfinished state and the matching degree is 70%, the user can choose not to perform the copy operation, thereby reducing the error rate of the source code.

[0117] In step S505, the source code is processed based on the processing operation and the first association relationship.

[0118] In an implementable manner, the processing of the source code at least further includes one of the following: in the case of deleting the target secondary comment content, deleting the target code segment; in the case of copying the target secondary comment content, copying the target code segment; in the case of modifying the target secondary comment content, modifying the target code segment; in the case of inserting the target secondary comment content, inserting the target code segment.

[0119] In an implementable manner, in the case where the processing operation is a copying operation, a reference relationship is established between the target secondary comment content and the copied secondary comment content; a reference relationship is established between the target code segment and the copied code segment; the copied secondary comment content and the copied code segment have a corresponding relationship. The copied secondary comment content is used to describe the copied code segment.

[0120] In an implementable manner, in the case of modifying the target secondary comment content, the corresponding target code segment, the copied secondary comment content and the copied code segment are modified.

[0121] In an implementable manner, in the case of modifying the target code segment, the corresponding secondary comment content, the copied secondary comment content and the copied code segment are modified.

[0122] In an implementable manner, the method further includes: in the case of writing new comment information, searching for secondary comment content in the comment information through input characters or semantics of the characters; in the case of determining to insert the secondary comment content, inserting a code segment associated with the secondary comment content.

[0123] In an implementable manner, the method further includes: in the process of performing the parsing operation or the compiling operation, generating a log output code; the log output code is used to output secondary comment content corresponding to a code segment that produces a running exception in the case of capturing the running exception.

[0124] In the above embodiment, on the one hand, the first matching degree and the first association relationship are obtained by matching the at least one code block with the primary comment content; and the source code is processed based on the processing operation and the first association relationship. In this way, corresponding modification of the code block and the comment content can be realized, the consistency of the code block and the comment content is improved, and the maintainability of the source code is improved.

[0125] In another aspect, a processing operation on the source code is determined based on the first matching degree. In this way, the user can be assisted in decision-making to determine whether to select the current processing operation by displaying the matching degree.

[0126] In still another aspect, the secondary annotation content corresponding to the code segment generating the running exception is outputted in the case of capturing a running exception, so that the user can easily understand the function of the code segment generating the running exception, and the efficiency of error repair is improved.

[0127] Based on the foregoing embodiments, the embodiments of the present application further provide a source code processing device. The control device includes various modules and units included in the modules, and can be implemented by a processor in an electronic device. Of course, it can also be implemented by a specific logic circuit. In the implementation process, the processor can be a central processing unit (CPU), a micro processing unit (MPU), a digital signal processor (DSP), or a field programmable gate array (FPGA).

[0128] Figure 7 The composition structure of a source code processing device provided by the embodiments of the present application is shown in FIG. 7. Figure 7 As shown in FIG. 7, the device 700 includes a display module 701, an acquisition module 702, and a processing module 703, wherein:

[0129] The display module 701 is configured to display source code and annotation information of the source code. The source code includes at least one code block, and each code block includes at least one code segment. The annotation information includes first annotation content corresponding to each code block and second annotation content corresponding to each code segment.

[0130] The acquisition module 702 is configured to acquire a processing operation.

[0131] The processing module 703 is configured to synchronously or sequentially execute the processing operation on a first content block and a second content block. The first content block is one of a target code segment and target second annotation content. The second content block is the other of the target code segment and the target second annotation content. The target second annotation content and the target code segment have a corresponding relationship.

[0132] In some possible embodiments, the processing module 703 is further configured to: synchronously or sequentially perform a first editing operation on the first content block and the second content block; the first editing operation is configured to adjust the content of the first content block and the second content block.

[0133] In some possible embodiments, the processing module 703 is further configured to: synchronously or sequentially perform a second editing operation on the first content block and the second content block; the second editing operation is configured to add a third content block based on the first content block in the source code and the annotation information; the third content block and the first content block have a reference relationship; add a fourth content block based on the second content block in the source code and the annotation information; the fourth content block and the second content block have a reference relationship; the third content block and the fourth content block have a corresponding relationship; and perform the first editing operation on the third content block and the fourth content block.

[0134] In some possible embodiments, the first editing operation includes at least one of the following: a deletion operation and a modification operation; the second editing operation includes at least one of the following: a copy operation and an insertion operation; the processing module 703 is further configured to: synchronously or sequentially copy the first content block and the second content block; synchronously or sequentially insert the first content block and the second content block; synchronously or sequentially delete the third content block and the fourth content block; and synchronously or sequentially modify the third content block and the fourth content block.

[0135] In some possible embodiments, the obtaining module is further configured to: in response to an operation of adding secondary annotation content, obtain an input character; the apparatus 700 further includes a determination module configured to: search for the character in at least one of the secondary annotation content, and determine at least one piece of secondary annotation content that is identical to the character or has the same semantic as the character; and in response to a selection operation on any of the secondary annotation content, determine the added secondary annotation content.

[0136] In some possible embodiments, the processing module 703 is further configured to: in a case where the added secondary annotation content is the target secondary annotation content, synchronously or sequentially add the target secondary annotation content and the target code segment to the annotation information and the source code, respectively.

[0137] In some possible embodiments, the obtaining module is further configured to: obtain a parsing operation or a compiling operation on the source code; the apparatus 700 further includes an encoding module configured to: generate log output code in a process of performing the parsing operation or the compiling operation; the log output code is configured to: output the secondary annotation content corresponding to the code segment that causes the running exception in a case that the running exception is captured.

[0138] In some possible embodiments, the apparatus 700 further includes a display module configured to: display prompt information; and the prompt information includes: the first matching degree between each first annotation content and a corresponding code block, the completion degree of each code block, the second matching degree between each secondary annotation content and a corresponding code segment, and the completion degree of each code segment.

[0139] It should be noted that the above description of the apparatus embodiments is similar to the description of the above method embodiments, and has similar beneficial effects to the method embodiments. For technical details not disclosed in the apparatus embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.

[0140] It should be noted that, in the embodiments of the present application, if the above-mentioned source code processing method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present application can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a plurality of instructions for causing an electronic device to execute all or part of the method described in the embodiments of the present application. The storage medium mentioned above includes: a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk, and various media that can store program codes. Thus, the embodiments of the present application are not limited to any specific hardware and software combination.

[0141] Correspondingly, the embodiments of the present application provide a computer-readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the steps of the source code processing method in any of the above embodiments.

[0142] Correspondingly, in the embodiments of the present application, a chip is also provided, which includes a programmable logic circuit and / or program instructions, and when the chip is running, it is used to implement the steps of the source code processing method in any of the above embodiments.

[0143] Correspondingly, the embodiment of the present application also provides a computer program product, when the computer program product is executed by a processor of an electronic device, the computer program product is used to implement the steps in the source code processing method in any of the above-mentioned embodiments.

[0144] Based on the same technical concept, the embodiment of the present application provides an electronic device for implementing the source code processing method described in the above method embodiments. Figure 8 A hardware entity schematic diagram of an electronic device provided by the embodiment of the present application is shown in Figure 8 The electronic device 800 includes a memory 810 and a processor 820, the memory 810 stores a computer program executable on the processor 820, and the processor 820 implements the steps in any of the source code processing methods of the embodiments of the present application when executing the program.

[0145] The memory 810 is configured to store instructions and applications executable by the processor 820, and can also cache data to be processed by the processor 820 and each module in the electronic device, and can be implemented by a FLASH or a random access memory (RAM).

[0146] The processor 820 implements the steps of any of the source code processing methods when executing the program. The processor 820 generally controls the overall operation of the electronic device 800.

[0147] The above processor can be at least one of an application specific integrated circuit (application specific integrated circuit, ASIC), a digital signal processor (digital signal processor, DSP), a digital signal processing device (digital signal processing device, DSPD), a programmable logic device (programmable logic device, PLD), a field programmable gate array (field programmable gate array, FPGA), a central processing unit (central processing unit, CPU), a controller, a microcontroller, and a microprocessor. It can be understood that the electronic device realizing the function of the above processor can also be other, and the embodiment of the present application does not make specific limitation.

[0148] The computer storage medium / memory can be a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), a Ferromagnetic Random Access Memory (FRAM), a Flash Memory, a magnetic surface storage, an optical disc, a Compact Disc Read-Only Memory (CD-ROM), or the like memory; or can be various electronic devices including one or any combination of the above memories, such as a personal computer, etc.

[0149] It should be noted that the above description of the storage medium and device embodiments is similar to the description of the above method embodiments, and has similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium and device embodiments of the present application, please refer to the description of the method embodiments of the present application for understanding.

[0150] It should be understood that the "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily mean the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of each process does not mean the order of execution, and the execution order of each process should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The above sequence number of the embodiments of the present application is only for description, not representing the advantages and disadvantages of the embodiments.

[0151] It should be noted that in this document, the term "comprising" or "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of other identical elements in the process, method, article or device including the element.

[0152] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other manners. The above described device embodiments are merely schematic, for example, the division of the units is only a logical function division, and there can be another division manner in actual implementation, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed coupling, or direct coupling or communication connection between the components can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or in other forms.

[0153] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units; they can be located in one place, or distributed on a plurality of network units; and part or all of the units can be selected according to actual needs to achieve the purpose of the embodiments of the present application.

[0154] In addition, each functional unit in the embodiments of the present application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be realized in the form of hardware, or in the form of hardware plus software functional units.

[0155] Alternatively, the integrated units of the present application, if implemented in the form of software functional modules and sold or used as independent products, can also be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application can be embodied in the form of a software product, and the computer software product is stored in a storage medium, and includes several instructions for causing the device under test to execute all or part of the methods described in the embodiments of the present application. The storage medium mentioned above includes: mobile storage devices, ROM, magnetic disks or optical disks, and various media that can store program codes.

[0156] The methods disclosed in the several method embodiments of the present application can be combined arbitrarily without conflict to obtain new method embodiments.

[0157] The features disclosed in the several method or device embodiments of the present application can be combined arbitrarily without conflict to obtain new method embodiments or device embodiments.

[0158] The above merely provides the implementation of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of the change or replacement within the technical range disclosed by the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A source code processing method, comprising: displaying a source code and annotation information of the source code; wherein the source code comprises at least one code block, each of the code blocks comprises at least one code snippet; the annotation information comprises first-level annotation content corresponding to each of the code blocks and second-level annotation content corresponding to each of the code snippets; obtaining a processing operation; synchronously or sequentially executing the processing operation on a first content block and a second content block; the first content block is one of a target code snippet and a target second-level annotation content; the second content block is the other of the target code snippet and the target second-level annotation content; there is a corresponding relationship between the target second-level annotation content and the target code snippet; wherein the method further comprises: displaying prompt information; wherein the prompt information comprises a first matching degree between each of the first-level annotation content and a corresponding code block, a completion degree of each of the code blocks, a second matching degree between each of the second-level annotation content and a corresponding code snippet, and a completion degree of each of the code snippets. 2.The method of claim 1, wherein the synchronously or sequentially executing the processing operation on the first content block and the second content block comprises: synchronously or sequentially executing a first editing operation on the first content block and the second content block; wherein the first editing operation is used to adjust the content of the first content block and the second content block. 3.The method of claim 1, wherein the synchronously executing the processing operation on the first content block and the second content block comprises: synchronously or sequentially executing a second editing operation on the first content block and the second content block; wherein the second editing operation is used to add a third content block in the source code and the annotation information based on the first content block; there is a reference relationship between the third content block and the first content block; add a fourth content block in the source code and the annotation information based on the second content block; there is a reference relationship between the fourth content block and the second content block; there is a corresponding relationship between the third content block and the fourth content block; correspondingly, the method further comprises: executing the first editing operation on the third content block and the fourth content block.

4. The method of claim 3, the first edit operation comprising at least one of: a delete operation and a modification operation. The second editing operation comprises at least one of the following: a copy operation and an insertion operation; the synchronously or sequentially executing the second editing operation on the first content block and the second content block comprises at least one of the following: synchronously or sequentially copying the first content block and the second content block; synchronously or sequentially inserting the first content block and the second content block; correspondingly, the executing the first editing operation on the third content block and the fourth content block comprises at least one of the following: synchronously or sequentially deleting the third content block and the fourth content block; synchronously or sequentially modifying the third content block and the fourth content block. 5.The method of claim 1, further comprising: in response to an operation of adding second-level annotation content, obtaining an input character. searching the character in at least one of the secondary annotation contents, and determining at least one piece of secondary annotation content identical to the character or having the same semantic meaning as the character; in response to a selection operation on any of the secondary annotation contents, determining an added secondary annotation content.

6. The method of claim 5, wherein the processing operation is performed synchronously or sequentially on the first content block and the second content block, including: in a case where the added secondary annotation content is the target secondary annotation content, synchronously or sequentially adding the target secondary annotation content and the target code segment into the annotation information and the source code, respectively.

7. The method of any one of claims 1 to 6, further comprising: obtaining a parsing operation or a compiling operation on the source code; generating a log output code during execution of the parsing operation or the compiling operation; the log output code is configured to output a secondary annotation content corresponding to a code segment causing a running exception in a case where the running exception is captured.

8. A source code processing apparatus, comprising: a display module configured to display a source code and annotation information of the source code; wherein the source code comprises at least one code block, each of the code blocks comprises at least one code segment; and the annotation information comprises primary annotation contents corresponding to each of the code blocks and secondary annotation contents corresponding to each of the code segments; an obtaining module configured to obtain a processing operation; a processing module configured to perform the processing operation synchronously or sequentially on a first content block and a second content block; the first content block is one of a target code segment and a target secondary annotation content; the second content block is the other of the target code segment and the target secondary annotation content; and the target secondary annotation content and the target code segment have a corresponding relationship; a display module configured to display prompt information; wherein the prompt information comprises a first matching degree between each of the primary annotation contents and a corresponding code block, a completion degree of each of the code blocks, a second matching degree between each of the secondary annotation contents and a corresponding code segment, and a completion degree of each of the code segments.

9. An electronic device, comprising a memory and a processor, the memory storing a computer program capable of running on the processor, and the processor implements steps in the method of any one of claims 1 to 7 when executing the program.

Citation Information

Patent Citations

  • Annotation adding method and device

    CN105824794A

  • Annotation information processing method, device, computer equipment and storage medium

    CN110471694A