CN111274127B - Code jumping method, device, equipment and medium in code evaluation - Google Patents
Code jumping method, device, equipment and medium in code evaluation Download PDFInfo
- Publication number
- CN111274127B CN111274127B CN202010038881.1A CN202010038881A CN111274127B CN 111274127 B CN111274127 B CN 111274127B CN 202010038881 A CN202010038881 A CN 202010038881A CN 111274127 B CN111274127 B CN 111274127B
- Authority
- CN
- China
- Prior art keywords
- code
- code element
- jump
- review
- information
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/362—Debugging of software
- G06F11/3636—Debugging of software by tracing the execution of the program
- G06F11/364—Debugging of software by tracing the execution of the program tracing values on a bus
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3604—Analysis of software for verifying properties of programs
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Stored Programmes (AREA)
Abstract
本申请公开了一种代码评审中的代码跳转方法、装置、设备和介质,涉及代码评审技术。具体实现方案为:解析待评审代码的变更代码文件,获取其中存在跳转的至少一个代码元素的代码元素信息,并存储在数据库,其中,所述代码元素信息至少包括代码元素的位置信息、语法信息和签名信息;显示所述变更代码文件,并对所述至少一个代码元素进行标注;响应于针对标注的代码元素中任意目标代码元素的跳转请求,根据目标代码元素的签名信息从数据库中查询目标代码元素对应的跳转代码元素及其在变更代码文件中的位置信息;根据所述跳转代码元素的位置信息进行跳转,显示所述跳转代码元素所在的页面。本申请实施例提供代码评审中的代码跳转功能,提高开发效率。
The present application discloses a code jump method, device, equipment and medium in code review, and relates to code review technology. The specific implementation plan is: analyze the changed code file of the code to be reviewed, obtain the code element information of at least one code element that has a jump therein, and store it in the database, wherein the code element information includes at least the position information of the code element, the syntax information and signature information; display the changed code file, and mark the at least one code element; in response to a jump request for any target code element in the marked code element, from the database according to the signature information of the target code element Query the jump code element corresponding to the target code element and its position information in the changed code file; perform a jump according to the position information of the jump code element, and display the page where the jump code element is located. The embodiment of the present application provides a code jump function in code review to improve development efficiency.
Description
技术领域technical field
本申请涉及计算机技术领域,尤其涉及一种代码评审技术,具体涉及一种代码评审中的代码跳转方法、装置、设备和介质。The present application relates to the field of computer technology, in particular to a code review technology, in particular to a code jump method, device, device and medium in code review.
背景技术Background technique
代码评审(Code review)是现代程序开发过程中保证软件质量的重要方法之一。通过进行代码评审,既能提高代码质量,避免技术债,又能让团队成员对自己侧重业务和领域之外的知识有所了解,还能保证团队规范的执行。Code review (Code review) is one of the important methods to ensure software quality in the modern program development process. Code review can not only improve code quality, avoid technical debt, but also allow team members to understand knowledge outside their business and domain, and ensure the implementation of team norms.
代码跳转是软件开发过程中最常使用的功能之一,是指从一个代码片段(如函数、类、变量、方法等)跳转到另一个代码片段的过程,以函数为例,可以从函数的使用位置直接跳转到函数的定义位置,也可以从函数的定义位置查找所有使用该函数的代码片段。在代码评审过程中,代码跳转的功能可以方便开发者更好的理解代码,加快开发效率。Code jump is one of the most commonly used functions in the software development process. It refers to the process of jumping from one code segment (such as function, class, variable, method, etc.) The use position of the function jumps directly to the definition position of the function, and you can also find all the code fragments that use the function from the definition position of the function. During the code review process, the code jump function can facilitate developers to better understand the code and speed up development efficiency.
现有的源码托管平台如Github、微软Azure等都能提供代码评审的功能,可以显示一次代码提交过程中代码变更的部分,方便评审人对修改的代码进行评审。然而,在这些代码评审工具中,只能显示代码变更的部分,并不能实现代码跳转的功能,而这些功能恰恰是代码开发及评审过程中必不可少的。缺少这些代码跳转的功能,会导致评审人难以理解变更的代码,使得代码评审变得费时费力,更不能达到期望的保证代码质量的效果。Existing source code hosting platforms such as Github and Microsoft Azure can provide code review functions, which can display code changes during a code submission process, making it easier for reviewers to review the modified code. However, in these code review tools, only the changed part of the code can be displayed, and the function of code jump cannot be realized, and these functions are precisely necessary in the process of code development and review. The lack of these code jump functions will make it difficult for reviewers to understand the changed code, making code review time-consuming and laborious, let alone achieving the desired effect of ensuring code quality.
发明内容Contents of the invention
本申请实施例提供一种代码评审中的代码跳转方法、装置、设备和介质,以在代码评审过程中提供代码跳转的能力,方便开发者更好的理解代码,加快开发效率。Embodiments of the present application provide a code jump method, device, device, and medium in code review, so as to provide code jump capability during code review, so as to facilitate developers to better understand code and speed up development efficiency.
第一方面,本申请实施例提供了一种代码评审中的代码跳转方法,包括:In the first aspect, the embodiment of the present application provides a code jump method in code review, including:
解析待评审代码的变更代码文件,获取其中存在跳转的至少一个代码元素的代码元素信息,并将所述代码元素信息存储在数据库,其中,所述代码元素信息至少包括代码元素的位置信息、语法信息和签名信息;Analyzing the changed code file of the code to be reviewed, obtaining code element information of at least one code element that has a jump therein, and storing the code element information in a database, wherein the code element information includes at least the location information of the code element, syntax information and signature information;
显示所述变更代码文件,并对所述至少一个代码元素进行标注;displaying the change code file, and marking the at least one code element;
响应于针对所述标注的代码元素中任意目标代码元素的跳转请求,根据所述目标代码元素的签名信息从所述数据库中查询所述目标代码元素对应的跳转代码元素及其在所述变更代码文件中的位置信息;In response to a jump request for any target code element in the marked code elements, query the database for the jump code element corresponding to the target code element and its content in the target code element according to the signature information of the target code element. Change the location information in the code file;
根据所述跳转代码元素的位置信息进行跳转,显示所述跳转代码元素所在的页面。Jump according to the location information of the jump code element, and display the page where the jump code element is located.
上述申请中的一个实施例具有如下优点或有益效果:在源码托管平台提供的评审功能基础上,增加了跳转功能,通过对变更代码文件进行解析得到存在跳转的至少一个代码元素及其代码元素信息,并存储在数据库,在显示变更代码文件时,还会将这些存在跳转的至少一个代码元素标注出来,以便于评审人员进行点击,当获取到针对标注中的任意目标代码元素的跳转请求时,则可以从数据库中查询得到目标代码元素对应的跳转代码元素及其位置信息,从而实现跳转,因而避免了评审人员进行手工查询,缩减了评审时间,提高了评审效率,并且有效保证代码质量,且不受语言类型的限制,可以适用于任何语言。An embodiment of the above application has the following advantages or beneficial effects: on the basis of the review function provided by the source code hosting platform, a jump function is added, and at least one code element and its code that has a jump can be obtained by parsing the changed code file Element information, and stored in the database, when displaying the changed code file, at least one code element with a jump will be marked out, so that the reviewer can click, when the jump to any target code element in the markup is obtained When the request is forwarded, the jump code element and its location information corresponding to the target code element can be queried from the database, so as to realize the jump, thus avoiding manual query by the reviewers, reducing the review time, improving the review efficiency, and It effectively guarantees the code quality, and is not limited by the language type, and can be applied to any language.
可选的,在所述解析待评审代码的变更代码文件之前,所述方法还包括:Optionally, before the parsing of the changed code file of the code to be reviewed, the method further includes:
根据当前代码评审请求中的评审标识信息,创建当前代码评审目录,从代码库中下载待评审代码至所述当前代码评审目录,并获取所述待评审代码的变更代码文件;Create a current code review directory according to the review identification information in the current code review request, download the code to be reviewed from the code library to the current code review directory, and obtain the changed code file of the code to be reviewed;
相应的,所述解析待评审代码的变更代码文件,包括:Correspondingly, the parsing of the changed code file of the code to be reviewed includes:
在所述当前代码评审目录下,解析所述待评审代码的变更代码文件。Under the current code review directory, the changed code file of the code to be reviewed is parsed.
可选的,在所述当前代码评审目录下,将首次获取的变更代码文件作为基准代码;Optionally, under the current code review directory, use the changed code file obtained for the first time as the benchmark code;
相应的,所述方法还包括:Correspondingly, the method also includes:
如果在所述当前代码评审请求下存在不同版本的评审请求,则在所述当前代码评审目录下,创建不同版本的评审目录,每个版本的评审目录中的变更代码文件是通过拷贝所述基准代码而来,并且不同版本的评审目录的数量不超过预设阈值。If there are different versions of review requests under the current code review request, then under the current code review directory, create different versions of the review directory, and the changed code files in the review directory of each version are obtained by copying the benchmark code, and the number of review directories of different versions does not exceed the preset threshold.
上述申请中的一个实施例具有如下优点或有益效果:针对不同的评审创建不同的目录,并分别在各个目录下进行代码解析,相互不受影响。同理,针对一次评审中不同版本的评审,也会创建各自的目录,并且,后面创建的目录中的代码是通过拷贝基准代码而得来,也就是说只下载一份代码即可,节省了下载代码的时间,提高了评审效率。An embodiment of the above application has the following advantages or beneficial effects: different directories are created for different reviews, and code analysis is performed in each directory without mutual influence. Similarly, for reviews of different versions in one review, their own directories will also be created, and the codes in the directories created later are obtained by copying the benchmark code, that is to say, only one copy of the code can be downloaded, which saves The time to download the code improves the review efficiency.
可选的,所述解析待评审代码的变更代码文件,获取其中存在跳转的至少一个代码元素的代码元素信息,包括:Optionally, the parsing of the changed code file of the code to be reviewed to obtain code element information of at least one code element in which there is a jump includes:
利用代码解析器解析待评审代码的变更代码文件,获取所述变更代码文件的抽象语法树;Using a code parser to parse the changed code file of the code to be reviewed, and obtain the abstract syntax tree of the changed code file;
对所述抽象语法树进行分析,获取其中各代码元素的代码元素信息;Analyzing the abstract syntax tree to obtain code element information of each code element therein;
根据预设的跳转规则和各代码元素的语法信息,从各代码元素中获取存在跳转的至少一个代码元素及其代码元素信息。At least one code element with a jump and its code element information are obtained from each code element according to a preset jump rule and syntax information of each code element.
可选的,在所述解析待评审代码的变更代码文件之前,所述方法还包括:Optionally, before the parsing of the changed code file of the code to be reviewed, the method further includes:
获取所述变更代码文件所使用的外部依赖类,并下载依赖包;Obtain the external dependent class used by the changed code file, and download the dependent package;
遍历所述变更代码文件,按照预设的过滤规则对所述变更代码文件进行过滤;Traverse the changed code file, and filter the changed code file according to preset filtering rules;
根据所述依赖包和经过滤的变更代码文件进行解析。Parsing is performed according to the dependency package and the filtered changed code files.
上述申请中的一个实施例具有如下优点或有益效果:根据依赖包和经过滤的变更代码文件进行解析,从而实现增量索引,无需解析整个代码库,只对变更文件及其关联文件进行解析,其他文件的变动也不会影响当前评审的代码文件和解析结果,不仅提高了解析效率,也能保证解析结果的正确性。An embodiment of the above application has the following advantages or beneficial effects: parsing is performed according to dependent packages and filtered changed code files, thereby realizing incremental indexing, without parsing the entire code base, only parsing changed files and their associated files, Changes in other files will not affect the currently reviewed code files and analysis results, which not only improves the analysis efficiency, but also ensures the correctness of the analysis results.
可选的,所述语法信息中至少包括代码元素类型,所述代码元素类型包括引用和定义。Optionally, the syntax information includes at least a code element type, and the code element type includes a reference and a definition.
可选的,所述跳转请求是基于对查看引用按钮或查看定义按钮的触发操作而生成;Optionally, the jump request is generated based on a trigger operation on the view reference button or view definition button;
其中,所述查看引用按钮和查看定义按钮是根据目标代码元素的代码元素类型而生成。Wherein, the View Reference button and View Definition button are generated according to the code element type of the target code element.
上述申请中的一个实施例具有如下优点或有益效果:实现对引用或定义这两种跳转情形的查询,对于存在引用的代码元素提供查看引用按钮,对于存在定义的代码元素提供查看定义按钮,以供评审人员根据需要通过点击按钮而发出请求。An embodiment of the above application has the following advantages or beneficial effects: realize the query of the two jump situations of reference or definition, provide a view reference button for code elements with references, and provide a view definition button for code elements with definitions, For reviewers to make requests by clicking a button as needed.
可选的,所述根据所述目标代码元素的签名信息从所述数据库中获取所述目标代码元素对应的跳转代码元素及其在所述变更代码文件中的位置信息,包括:Optionally, the obtaining the jump code element corresponding to the object code element and its position information in the changed code file from the database according to the signature information of the object code element includes:
根据所述数据库中的代码元素信息,查询与所述目标代码元素的签名信息相同,并且代码元素类型是引用或定义的代码元素,作为所述目标代码元素对应的跳转代码元素;According to the code element information in the database, the query is the same as the signature information of the target code element, and the code element type is a referenced or defined code element as the jump code element corresponding to the target code element;
获取所述跳转代码元素在所述变更代码文件中的位置信息。Acquiring position information of the jump code element in the changed code file.
上述申请中的一个实施例具有如下优点或有益效果:在源码托管平台提供的评审功能基础上,增加了跳转功能,通过对变更代码文件进行解析得到存在跳转的至少一个代码元素及其代码元素信息,并存储在数据库,在显示变更代码文件时,还会将这些存在跳转的至少一个代码元素标注出来,以便于评审人员进行点击,当获取到针对标注中的任意目标代码元素的跳转请求时,则可以从数据库中查询得到目标代码元素对应的跳转代码元素及其位置信息,从而实现跳转,实现对代码元素定义或引用的查询,因而避免了评审人员进行手工查询,缩减了评审时间,提高了评审效率,并且,通过多评审处理机制和增量索引,能够进一步提高评审效率,有效保证了代码质量,且不受语言类型的限制,可以适用于任何语言。An embodiment of the above application has the following advantages or beneficial effects: on the basis of the review function provided by the source code hosting platform, a jump function is added, and at least one code element and its code that has a jump can be obtained by parsing the changed code file Element information, and stored in the database, when displaying the changed code file, at least one code element with a jump will be marked out, so that the reviewer can click, when the jump to any target code element in the markup is obtained When the transfer request is requested, the jump code element and its location information corresponding to the target code element can be obtained from the database, so as to realize the jump and realize the query of the definition or reference of the code element, thus avoiding manual query by the reviewers and reducing the The review time is shortened, the review efficiency is improved, and, through the multi-review processing mechanism and incremental indexing, the review efficiency can be further improved, the code quality can be effectively guaranteed, and it is not limited by the language type, and can be applied to any language.
第二方面,本申请实施例还提供了一种代码评审中的代码跳转装置,包括:In the second aspect, the embodiment of the present application also provides a code jumping device in code review, including:
解析模块,用于解析待评审代码的变更代码文件,获取其中存在跳转的至少一个代码元素的代码元素信息,并将所述代码元素信息存储在数据库,其中,所述代码元素信息至少包括代码元素的位置信息、语法信息和签名信息;The parsing module is configured to parse the changed code file of the code to be reviewed, obtain the code element information of at least one code element in which there is a jump, and store the code element information in a database, wherein the code element information includes at least the code Element location information, syntax information, and signature information;
标注模块,用于显示所述变更代码文件,并对所述至少一个代码元素进行标注;An annotation module, configured to display the changed code file, and annotate the at least one code element;
查询模块,用于响应于针对所述标注的代码元素中任意目标代码元素的跳转请求,根据所述目标代码元素的签名信息从所述数据库中查询所述目标代码元素对应的跳转代码元素及其在所述变更代码文件中的位置信息;A query module, configured to, in response to a jump request for any target code element in the marked code elements, query the jump code element corresponding to the target code element from the database according to the signature information of the target code element and its location information in said change code file;
跳转模块,用于根据所述跳转代码元素的位置信息进行跳转,显示所述跳转代码元素所在的页面。A jump module, configured to perform a jump according to the location information of the jump code element, and display the page where the jump code element is located.
第三方面,本申请实施例还提供了一种电子设备,包括:In a third aspect, the embodiment of the present application also provides an electronic device, including:
至少一个处理器;以及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, and the instructions are executed by the at least one processor, so that the at least one processor can perform the code review described in any embodiment of the present application. The code jump method.
第四方面,本申请实施例还提供了一种存储有计算机指令的非瞬时计算机可读存储介质,所述计算机指令用于使所述计算机执行本申请任意实施例所述的代码评审中的代码跳转方法。In the fourth aspect, the embodiments of the present application also provide a non-transitory computer-readable storage medium storing computer instructions, the computer instructions are used to make the computer execute the code in the code review described in any embodiment of the present application jump method.
上述可选方式所具有的其他效果将在下文中结合具体实施例加以说明。Other effects of the above optional manner will be described below in conjunction with specific embodiments.
附图说明Description of drawings
附图用于更好地理解本方案,不构成对本申请的限定。其中:The accompanying drawings are used to better understand the solution, and do not constitute a limitation to the application. in:
图1a是根据本申请第一实施例的代码评审中的代码跳转方法的流程示意图;Fig. 1a is a schematic flowchart of a code jump method in code review according to the first embodiment of the present application;
图1b是根据本申请第一实施例的代码评审中的代码跳转方法的另一种流程示意图;Fig. 1b is another schematic flowchart of a code jump method in code review according to the first embodiment of the present application;
图2是根据本申请第二实施例的代码评审中的代码跳转方法的流程示意图;FIG. 2 is a schematic flowchart of a code jump method in code review according to a second embodiment of the present application;
图3是根据本申请第三实施例的代码评审中的代码跳转方法的流程示意图;FIG. 3 is a schematic flowchart of a code jump method in code review according to a third embodiment of the present application;
图4是根据本申请第四实施例的代码评审中的代码跳转装置的结构示意图;FIG. 4 is a schematic structural diagram of a code jumping device in code review according to a fourth embodiment of the present application;
图5是用来实现本申请实施例的代码评审中的代码跳转方法的电子设备的框图。Fig. 5 is a block diagram of an electronic device used to implement the code jump method in the code review of the embodiment of the present application.
具体实施方式Detailed ways
以下结合附图对本申请的示范性实施例做出说明,其中包括本申请实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本申请的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present application are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present application to facilitate understanding, and they should be regarded as exemplary only. Accordingly, those 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 application. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
图1a是根据本申请第一实施例的代码评审中的代码跳转方法的流程示意图,本实施例可适用于在评审人员进行代码评审的过程中提供代码跳转的功能,让评审人员可以方便的查看当前代码元素的定义,或查看引用了当前代码元素的代码元素的情况。该方法可由一种代码评审中的代码跳转装置来执行,该装置采用软件和/或硬件的方式实现,优选是配置于电子设备中,例如服务器或计算机设备等。如图1a所示,该方法具体包括如下:Figure 1a is a schematic flow chart of the code jump method in code review according to the first embodiment of the present application. This embodiment is applicable to provide the function of code jump during the process of code review by reviewers, so that reviewers can conveniently View the definition of the current code element, or view the status of code elements that reference the current code element. The method can be implemented by a code jumping device in code review, which is implemented in software and/or hardware, and is preferably configured in electronic equipment, such as a server or computer equipment. As shown in Figure 1a, the method specifically includes the following:
S101、解析待评审代码的变更代码文件,获取其中存在跳转的至少一个代码元素的代码元素信息,并将所述代码元素信息存储在数据库,其中,所述代码元素信息至少包括代码元素的位置信息、语法信息和签名信息。S101. Parse the changed code file of the code to be reviewed, obtain code element information of at least one code element in which there is a jump, and store the code element information in a database, wherein the code element information includes at least the location of the code element information, syntax information, and signature information.
所述变更代码文件可以是利用Git工具提供的diff功能获取到的待评审代码的变更代码文件。而所述待评审代码可以是根据评审消息中携带的库名、分支、Commit ID(代码评审编号)等信息,从Git仓库中下载的代码。The changed code file may be a changed code file of the code to be reviewed obtained by using the diff function provided by the Git tool. The code to be reviewed can be code downloaded from the Git warehouse according to information such as library name, branch, Commit ID (code review number) carried in the review message.
代码中的代码元素有些是存在跳转的,跳转是指从一个代码片段跳转到另一个代码片段的过程,至少包括引用和定义。因此,若具备代码跳转功能,则可以实现让评审人员方便的查看代码元素的定义或引用。本申请实施例利用代码解析技术,通过对变更代码文件进行解析,从而获取其中存在跳转的至少一个代码元素的代码元素信息,并将所述代码元素信息存储在数据库。这样,当存在查看某代码元素的定义或引用的需求时,则可以直接通过查询数据库来确定该代码元素的定义或引用在代码中的位置,从而实现跳转。Some code elements in the code have jumps, and jumps refer to the process of jumping from one code segment to another, including at least references and definitions. Therefore, if the code jump function is available, reviewers can easily view the definition or reference of code elements. In this embodiment of the present application, code element information of at least one code element that has a jump is obtained by parsing the changed code file by using the code analysis technology, and storing the code element information in the database. In this way, when there is a need to view the definition or reference of a certain code element, the location of the definition or reference of the code element in the code can be determined directly by querying the database, so as to realize the jump.
可选的,所述解析待评审代码的变更代码文件,获取其中存在跳转的至少一个代码元素的代码元素信息,包括:Optionally, the parsing of the changed code file of the code to be reviewed to obtain code element information of at least one code element in which there is a jump includes:
利用代码解析器解析待评审代码的变更代码文件,获取所述变更代码文件的抽象语法树;Using a code parser to parse the changed code file of the code to be reviewed, and obtain the abstract syntax tree of the changed code file;
对所述抽象语法树进行分析,获取其中各代码元素的代码元素信息;Analyzing the abstract syntax tree to obtain code element information of each code element therein;
根据预设的跳转规则和各代码元素的语法信息,从各代码元素中获取存在跳转的至少一个代码元素及其代码元素信息。At least one code element with a jump and its code element information are obtained from each code element according to a preset jump rule and syntax information of each code element.
其中,抽象语法树可以描述代码文件内各个代码元素的关系,因此,获取抽象语法树后,即可通过对其进行二次分析来获取代码元素信息。所述代码元素信息至少包括代码元素的位置信息、语法信息和签名信息。所述位置信息即代码元素在变更代码文件中的位置,例如起止行、列、在文件内的偏移、所在的文件名、分支名和库名等;所述语法信息中至少包括代码元素类型和名称等,所述代码元素类型包括引用和定义;所述签名信息是用来唯一标识一个代码元素的签名信息,例如可以设置为代码元素的文件名与起始地址组合成的字符串的哈希值,本申请实施例对该签名信息的设置不做任何限定,只要能起到唯一标识代码元素的作用即可。Among them, the abstract syntax tree can describe the relationship of each code element in the code file. Therefore, after the abstract syntax tree is obtained, the code element information can be obtained by performing secondary analysis on it. The code element information includes at least location information, syntax information and signature information of the code element. The position information is the position of the code element in the changed code file, such as start and end lines, columns, offset in the file, file name, branch name and library name, etc.; the syntax information includes at least the code element type and Name, etc., the code element type includes reference and definition; the signature information is the signature information used to uniquely identify a code element, for example, it can be set as the hash of the string composed of the file name and the start address of the code element value, the embodiment of the present application does not impose any limitation on the setting of the signature information, as long as it can uniquely identify the code element.
获取到各代码元素的代码元素信息之后,就可以根据预设的跳转规则和各代码元素的语法信息,从各代码元素中获取存在跳转的至少一个代码元素及其代码元素信息。具体的,所述跳转规则是指代码编写语言的跳转规则,以Java语言为例,可以将类、函数、符号、枚举等类型视为定义,其他的元素类型视为引用,其他代码编写语言类似。因此,根据代码元素的类型,也即代码元素信息中的语法信息,结合跳转规则,即可推断出代码元素是定义还是引用。After the code element information of each code element is obtained, at least one code element with a jump and its code element information can be obtained from each code element according to the preset jump rule and the syntax information of each code element. Specifically, the jump rule refers to the jump rule of the code writing language. Taking the Java language as an example, types such as classes, functions, symbols, and enumerations can be regarded as definitions, and other element types can be regarded as references. The writing language is similar. Therefore, according to the type of the code element, that is, the syntax information in the code element information, combined with the jump rules, it can be deduced whether the code element is a definition or a reference.
此外,解析出来的代码元素信息可以将其格式化为规范格式的对象,存储到数据库中,以方便后续的查询。In addition, the parsed code element information can be formatted into an object in a standardized format and stored in the database to facilitate subsequent queries.
S102、显示所述变更代码文件,并对所述至少一个代码元素进行标注。S102. Display the change code file, and mark the at least one code element.
显示变更代码文件时,不仅显示本次代码中变更的部分,还会对存在跳转的至少一个代码元素进行标注,例如,采用下划线的方式进行标注,目的是告知评审人员该代码元素存在跳转,若评审人员需要查看引用或定义,则可以通过点击等方式触发请求。本申请实施例对代码元素的标注方式不做任何限定。When displaying the changed code file, it will not only display the changed part of the code, but also mark at least one code element that has a jump, for example, mark it with an underline to inform the reviewers that the code element has a jump , if reviewers need to view references or definitions, they can trigger the request by clicking, etc. The embodiment of the present application does not impose any limitation on the labeling manner of the code elements.
S103、响应于针对所述标注的代码元素中任意目标代码元素的跳转请求,根据所述目标代码元素的签名信息从所述数据库中查询所述目标代码元素对应的跳转代码元素及其在所述变更代码文件中的位置信息。S103. In response to a jump request for any target code element in the marked code elements, query the database for the jump code element corresponding to the target code element and its location according to the signature information of the target code element The location information in the change code file.
S104、根据所述跳转代码元素的位置信息进行跳转,显示所述跳转代码元素所在的页面。S104. Jump according to the location information of the jump code element, and display the page where the jump code element is located.
可选的,所述跳转请求是基于对查看引用按钮或查看定义按钮的触发操作而生成;其中,所述查看引用按钮和查看定义按钮是根据目标代码元素的代码元素类型而生成。Optionally, the jump request is generated based on the trigger operation of the view reference button or view definition button; wherein, the view reference button and view definition button are generated according to the code element type of the target code element.
具体的,由于已经获取到存在跳转的至少一个代码元素的代码元素信息,也就已经获知当前评审人员要查看的目标代码元素的跳转类型是定义还是引用,继而可以生成查看引用按钮和查看定义按钮。例如,当评审人员将光标移动到标注的目标代码元素周围时,即可出现该按钮,或者鼠标右键点击后即可出现该按钮。当评审人员点击查看引用按钮或查看定义按钮,则触发所述跳转请求。本申请实施例对跳转请求的触发方式不做任何限定。Specifically, since the code element information of at least one code element that has a jump has been obtained, it is already known whether the jump type of the target code element that the current reviewer wants to view is definition or reference, and then the view reference button and the view reference button can be generated. Define the button. For example, the button can appear when a reviewer moves the cursor around an annotated object code element, or after a right mouse click. When the reviewer clicks the View Reference button or the View Definition button, the jump request is triggered. The embodiment of the present application does not set any limitation on the triggering mode of the jump request.
进一步的,响应于跳转请求,根据目标代码元素的签名信息,即可从数据库中查询目标代码元素对应的跳转代码元素及其在变更代码文件中的位置信息。其中,签名信息能够唯一标识一个代码元素,而目标代码元素的定义或引用的代码也具有该相同的签名信息,因此,依据签名信息即可从数据库中查询出目标代码元素对应的跳转代码元素,即定义或引用的代码元素,而根据其位置即可实现跳转。Further, in response to the jump request, according to the signature information of the target code element, the jump code element corresponding to the target code element and its location information in the changed code file can be queried from the database. Among them, the signature information can uniquely identify a code element, and the definition or referenced code of the target code element also has the same signature information, so the jump code element corresponding to the target code element can be queried from the database according to the signature information , that is, the defined or referenced code element, and the jump can be realized according to its position.
因此,可选的,所述根据所述目标代码元素的签名信息从所述数据库中获取所述目标代码元素对应的跳转代码元素及其在所述变更代码文件中的位置信息,包括:Therefore, optionally, the acquiring the jump code element corresponding to the object code element and its position information in the changed code file from the database according to the signature information of the object code element includes:
根据所述数据库中的代码元素信息,查询与所述目标代码元素的签名信息相同,并且代码元素类型是引用或定义的代码元素,作为所述目标代码元素对应的跳转代码元素;According to the code element information in the database, the query is the same as the signature information of the target code element, and the code element type is a referenced or defined code element as the jump code element corresponding to the target code element;
获取所述跳转代码元素在所述变更代码文件中的位置信息。Acquiring position information of the jump code element in the changed code file.
图1b是根据本申请第一实施例的代码评审中的代码跳转方法的另一种流程示意图。如图所示,本实施例中包括两个部分,第一部分是索引端,第二部分是在线端。索引端和在线端可以在一台电子设备上,也可以在不同的电子设备上。索引端用于从Git仓库下载代码文件,并利用Git解析器获取其变更文件,利用代码解析器获取代码元素信息并存储于数据库集群。在线端通过浏览器打开变更代码文件,从而可以查看其中发生变更的代码元素,同时通过向数据库请求符号,即获取存在跳转的代码元素,从而对其进行标注,当评审人员发出查看定义或引用的请求,索引端通过数据库即可查询出定义或引用的跳转代码元素,并作为结果返回在线端实现跳转。Fig. 1b is another schematic flowchart of a code jump method in code review according to the first embodiment of the present application. As shown in the figure, this embodiment includes two parts, the first part is the index end, and the second part is the online end. The index end and the online end can be on one electronic device, or on different electronic devices. The index end is used to download code files from the Git warehouse, and use the Git parser to obtain its changed files, and use the code parser to obtain code element information and store it in the database cluster. Open the changed code file through the browser on the online side, so that the code elements that have changed can be viewed. At the same time, by requesting symbols from the database, that is, to obtain the code elements that have jumps, so as to mark them. When the reviewer issues a view definition or reference request, the index end can query the defined or referenced jump code elements through the database, and return the result to the online end to realize the jump.
本申请实施例的技术方案,在源码托管平台提供的评审功能基础上,增加了跳转功能,通过对变更代码文件进行解析得到存在跳转的至少一个代码元素及其代码元素信息,并存储在数据库,在显示变更代码文件时,还会将这些存在跳转的至少一个代码元素标注出来,以便于评审人员进行点击,当获取到针对标注中的任意目标代码元素的跳转请求时,则可以从数据库中查询得到目标代码元素对应的跳转代码元素及其位置信息,从而实现跳转。而现有技术中若要查看定义或引用,只能是在每个变更的文件页中,用浏览器自带的文本搜索功能搜索代码元素的关键字,查看其中是否存在想要的结果,费时费力。因此,本申请实施例避免了评审人员进行手工查询,缩减了评审时间,提高了评审效率,并且有效保证代码质量,且不受语言类型的限制,可以适用于任何语言。In the technical solution of the embodiment of the present application, on the basis of the review function provided by the source code hosting platform, a jump function is added. By analyzing the changed code file, at least one code element and its code element information that has a jump are obtained, and stored in The database, when displaying the changed code file, will also mark at least one code element that has a jump, so that the reviewer can click. When a jump request for any target code element in the mark is obtained, you can The jump code element corresponding to the target code element and its position information are obtained by querying from the database, so as to realize the jump. However, in the prior art, if you want to view definitions or references, you can only use the browser’s built-in text search function to search for the keywords of code elements in each changed file page to check whether there are desired results, which is time-consuming. strenuous. Therefore, the embodiment of the present application avoids manual query by reviewers, reduces review time, improves review efficiency, and effectively guarantees code quality, and is not limited by language types, and can be applied to any language.
图2是根据本申请第二实施例的代码评审中的代码跳转方法的流程示意图,本实施例在上述实施例的基础上进一步进行优化。如图2所示,该方法具体包括如下:FIG. 2 is a schematic flowchart of a code jump method in code review according to a second embodiment of the present application. This embodiment is further optimized on the basis of the above-mentioned embodiments. As shown in Figure 2, the method specifically includes the following:
S201、根据当前代码评审请求中的评审标识信息,创建当前代码评审目录,从代码库中下载待评审代码至所述当前代码评审目录,并获取所述待评审代码的变更代码文件。S201. Create a current code review directory according to the review identification information in the current code review request, download the code to be reviewed from the code library to the current code review directory, and obtain a changed code file of the code to be reviewed.
其中,评审标识信息例如可以是唯一标识一次评审的编号等信息,创建的当前代码评审目录的目录名则可以是该评审标识信息。因此,当存在多次评审时,每次评审都可以对应一个评审目录,相应的,下载的代码以及该代码的变更代码文件都存储在该目录下。该目录例如可以创建在索引端的硬盘上。Wherein, the review identification information may be, for example, information such as a number that uniquely identifies a review, and the directory name of the created current code review directory may be the review identification information. Therefore, when there are multiple reviews, each review can correspond to a review directory, and correspondingly, the downloaded code and the changed code files of the code are all stored in the directory. This directory can be created on the hard disk of the index side, for example.
S202、在所述当前代码评审目录下,解析所述待评审代码的变更代码文件,获取其中存在跳转的至少一个代码元素的代码元素信息,并将所述代码元素信息存储在所述数据库,其中,所述代码元素信息至少包括代码元素的位置信息、语法信息和签名信息。S202. Under the current code review directory, parse the changed code file of the code to be reviewed, obtain code element information of at least one code element that has a jump therein, and store the code element information in the database, Wherein, the code element information includes at least location information, syntax information and signature information of the code element.
创建的目录下,除了存储变更代码文件之外,还存储解析到的代码元素信息,也即,每次评审都在各自的目录下进行,以示区分,并且互不影响。In the created directory, in addition to storing the changed code files, the parsed code element information is also stored, that is, each review is carried out in its own directory to distinguish and does not affect each other.
当一次评审下存在多个版本的评审时,可以在该次评审的目录下以每个版本的评审标识为名再新建目录,并分别下载代码到目录下,用于不同版本的评审的处理。而为了节省下载代码的时间,对于同一个评审中的多个版本的评审,可以在一个目录内同时处理。When there are multiple versions of reviews under one review, you can create a new directory under the review directory under the name of the review logo of each version, and download the codes to the directories respectively for processing different versions of reviews. In order to save the time of downloading the code, the reviews of multiple versions in the same review can be processed in one directory at the same time.
因此,可选的,在当前代码评审目录下,将首次获取的变更代码文件作为基准代码;相应的,所述方法还包括:如果在所述当前代码评审请求下存在不同版本的评审请求,则在所述当前代码评审目录下,创建不同版本的评审目录,每个版本的评审目录中的变更代码文件是通过拷贝所述基准代码而来,并且不同版本的评审目录的数量不超过预设阈值。Therefore, optionally, under the current code review directory, the changed code file obtained for the first time is used as the benchmark code; correspondingly, the method further includes: if there are review requests of different versions under the current code review request, then Under the current code review directory, create different versions of the review directory, the changed code files in each version of the review directory are copied from the benchmark code, and the number of different versions of the review directory does not exceed the preset threshold .
具体的,如果每个不同版本的评审都从代码库下载代码,必然会增加代码下载的时间,影响评审效率,因此,本申请实施例采取直接拷贝基准代码的方式,则可以大大节省代码下载时间,提高评审效率。同时,这样也可以避免多个版本的评审同时处理时造成正在解析的文件发生变更,导致解析失败。Specifically, if the code is downloaded from the code library for each version of the review, it will inevitably increase the code download time and affect the review efficiency. Therefore, the embodiment of this application adopts the method of directly copying the benchmark code, which can greatly save the code download time , improve review efficiency. At the same time, this can also avoid changes in the file being parsed when multiple versions of the review are processed at the same time, resulting in parsing failure.
此外,为了达到节约存储空间的目的,可以设定拷贝基准代码的份数上限值,也即,不同版本的评审目录的数量不超过预设阈值,例如n,那么,同时处理的不同版本评审则不超过n个。而当短时间内到达的版本评审请求多于n时,可以通过设置信号量保证并发,前n个达到的版本评审同时处理,其余的保持等待,当n个中的某一个版本评审解析完成后,释放其资源,从而保证每个版本评审在获取到释放的资源后才能进行解析。In addition, in order to achieve the purpose of saving storage space, the upper limit of the number of copies of the copy reference code can be set, that is, the number of review directories of different versions does not exceed the preset threshold, such as n, then, the different versions of the reviews processed at the same time then no more than n. And when there are more than n version review requests arriving in a short period of time, you can set the semaphore to ensure concurrency. The first n version reviews that arrive are processed at the same time, and the rest are kept waiting. When one of the n version review resolutions is completed , to release its resources, so as to ensure that each version review can only be parsed after obtaining the released resources.
S203、显示所述变更代码文件,并对所述至少一个代码元素进行标注。S203. Display the change code file, and mark the at least one code element.
S204、响应于针对所述标注的代码元素中任意目标代码元素的跳转请求,根据所述目标代码元素的签名信息从所述数据库中查询所述目标代码元素对应的跳转代码元素及其在所述变更代码文件中的位置信息。S204. In response to a jump request for any target code element in the marked code elements, query the database for the jump code element corresponding to the target code element and its location according to the signature information of the target code element The location information in the change code file.
S205、根据所述跳转代码元素的位置信息进行跳转,显示所述跳转代码元素所在的页面。S205. Jump according to the location information of the jump code element, and display the page where the jump code element is located.
本申请实施例的技术方案,在源码托管平台提供的评审功能基础上,增加了跳转功能,通过对变更代码文件进行解析得到存在跳转的至少一个代码元素及其代码元素信息,并存储在数据库,在显示变更代码文件时,还会将这些存在跳转的至少一个代码元素标注出来,以便于评审人员进行点击,当获取到针对标注中的任意目标代码元素的跳转请求时,则可以从数据库中查询得到目标代码元素对应的跳转代码元素及其位置信息,从而实现跳转,因而避免了评审人员进行手工查询,缩减了评审时间,提高了评审效率,并且有效保证代码质量,且不受语言类型的限制,可以适用于任何语言。In the technical solution of the embodiment of the present application, on the basis of the review function provided by the source code hosting platform, a jump function is added. By analyzing the changed code file, at least one code element and its code element information that has a jump are obtained, and stored in The database, when displaying the changed code file, will also mark at least one code element that has a jump, so that the reviewer can click. When a jump request for any target code element in the mark is obtained, you can Query the jump code element and its location information corresponding to the target code element from the database, so as to realize the jump, thus avoiding manual query by reviewers, reducing review time, improving review efficiency, and effectively ensuring code quality, and It is not limited by language type and can be applied to any language.
同时,针对不同的评审创建不同的目录,并分别在各个目录下进行代码解析,相互不受影响。同理,针对一次评审中不同版本的评审,也会创建各自的目录,并且,后面创建的目录中的代码是通过拷贝基准代码而得来,也就是说只下载一份代码即可,节省了下载代码的时间,提高了评审效率。At the same time, different directories are created for different reviews, and code analysis is performed in each directory separately, without affecting each other. Similarly, for reviews of different versions in one review, their own directories will also be created, and the codes in the directories created later are obtained by copying the benchmark code, that is to say, only one copy of the code can be downloaded, which saves The time to download the code improves the review efficiency.
图3是根据本申请第三实施例的代码评审中的代码跳转方法的流程示意图,本实施例在上述实施例的基础上进一步进行优化。如图3所示,该方法具体包括如下:Fig. 3 is a schematic flowchart of a code jump method in code review according to a third embodiment of the present application, and this embodiment is further optimized on the basis of the above-mentioned embodiments. As shown in Figure 3, the method specifically includes the following:
S301、获取变更代码文件所使用的外部依赖类,并下载依赖包。S301. Obtain the external dependency class used by the changed code file, and download the dependency package.
S302、遍历所述变更代码文件,按照预设的过滤规则对所述变更代码文件进行过滤。S302. Traverse the change code files, and filter the change code files according to preset filtering rules.
其中,所述过滤规则可以根据不同的代码编写语言来确定。例如,在有些代码编写语言中,测试文件可以作为不必要的文件,那么则可以将过滤测试文件作为所述过滤规则。Wherein, the filtering rules may be determined according to different coding languages. For example, in some coding languages, test files can be regarded as unnecessary files, then filtering test files can be used as the filtering rule.
S303、根据所述依赖包和经过滤的变更代码文件进行解析,获取其中存在跳转的至少一个代码元素的代码元素信息,并将所述代码元素信息存储在数据库,其中,所述代码元素信息至少包括代码元素的位置信息、语法信息和签名信息。S303. Perform parsing according to the dependency package and the filtered changed code file, obtain code element information of at least one code element in which there is a jump, and store the code element information in a database, wherein the code element information Include at least location information, syntax information, and signature information of code elements.
具体实现时,可以将依赖包的下载路径和过滤后的源码文件的路径发送给代码解析器,由代码解析器根据依赖包和经过滤的变更代码文件进行解析,从而实现对部分文件的单独解析。In the specific implementation, the download path of the dependent package and the path of the filtered source code file can be sent to the code parser, and the code parser can analyze it according to the dependent package and the filtered changed code file, so as to realize the separate parsing of some files .
需要说明的是,解析一个代码库内的所有代码文件的时间与库内文件个数以及代码量有关。对于包含上万个文件的代码库,完整解析一次的时间往往需要数小时甚至更多,而一次代码评审从提交到评审人完成评审,很可能在分钟级别内就会完成。因而,为了支持代码评审中的代码跳转,就不能重新解析整个代码库,而只解析变更文件及其有关联的文件。因此,本申请实施例只对经过滤后的变更代码文件和与之有关的依赖包进行解析,从而实现增量索引,而且与对完整代码库进行解析的结果相同,但却可以大大节省索引时间,对于变更几个到几十个文件的评审,采用增量索引技术可以在提交评审分钟级别时间内就可以进行代码跳转查询,从而提高评审效率。It should be noted that the time for parsing all code files in a code library is related to the number of files in the library and the amount of code. For a code base containing tens of thousands of files, it often takes hours or more to complete a complete analysis, while a code review is likely to be completed within minutes from submission to reviewer's completion of the review. Thus, to support code jumps in code reviews, it is not possible to reparse the entire code base, but only the changed files and their associated files. Therefore, the embodiment of the present application only parses the filtered changed code files and related dependent packages, so as to realize incremental indexing, and the result is the same as parsing the complete code base, but it can greatly save indexing time , for the review of changing several to dozens of files, the incremental indexing technology can be used to perform code jump query within minutes of submitting the review, thereby improving the review efficiency.
S304、显示所述变更代码文件,并对所述至少一个代码元素进行标注。S304. Display the change code file, and mark the at least one code element.
S305、响应于针对所述标注的代码元素中任意目标代码元素的跳转请求,根据所述目标代码元素的签名信息从所述数据库中查询所述目标代码元素对应的跳转代码元素及其在所述变更代码文件中的位置信息。S305. In response to a jump request for any target code element in the marked code elements, query the database for the jump code element corresponding to the target code element and its location according to the signature information of the target code element The location information in the change code file.
S306、根据所述跳转代码元素的位置信息进行跳转,显示所述跳转代码元素所在的页面。S306. Jump according to the location information of the jump code element, and display the page where the jump code element is located.
本申请实施例的技术方案,在源码托管平台提供的评审功能基础上,增加了跳转功能,通过对变更代码文件进行解析得到存在跳转的至少一个代码元素及其代码元素信息,并存储在数据库,在显示变更代码文件时,还会将这些存在跳转的至少一个代码元素标注出来,以便于评审人员进行点击,当获取到针对标注中的任意目标代码元素的跳转请求时,则可以从数据库中查询得到目标代码元素对应的跳转代码元素及其位置信息,从而实现跳转,因而避免了评审人员进行手工查询,缩减了评审时间,提高了评审效率,并且有效保证代码质量,且不受语言类型的限制,可以适用于任何语言。In the technical solution of the embodiment of the present application, on the basis of the review function provided by the source code hosting platform, a jump function is added. By analyzing the changed code file, at least one code element and its code element information that has a jump are obtained, and stored in The database, when displaying the changed code file, will also mark at least one code element that has a jump, so that the reviewer can click. When a jump request for any target code element in the mark is obtained, you can Query the jump code element and its location information corresponding to the target code element from the database, so as to realize the jump, thus avoiding manual query by reviewers, reducing review time, improving review efficiency, and effectively ensuring code quality, and It is not limited by language type and can be applied to any language.
同时,根据依赖包和经过滤的变更代码文件进行解析,从而实现增量索引,无需解析整个代码库,只对变更文件及其关联文件进行解析,其他文件的变动也不会影响当前评审的代码文件和解析结果,不仅提高了解析效率,也能保证解析结果的正确性。At the same time, parsing is performed according to dependent packages and filtered changed code files, so as to realize incremental indexing, without parsing the entire code base, only the changed files and their associated files are parsed, and changes in other files will not affect the currently reviewed code The files and analysis results not only improve the analysis efficiency, but also ensure the correctness of the analysis results.
图4是根据本申请第四实施例的代码评审中的代码跳转装置的结构示意图,本实施例可适用于的在评审人员进行代码评审的过程中提供代码跳转的功能,让评审人员可以方便的查看当前代码元素的定义,或查看引用了当前代码元素的代码元素的情况。该装置可实现本申请任意实施例所述的代码评审中的代码跳转方法。如图4所示,该装置400具体包括:Fig. 4 is a schematic structural diagram of a code jump device in code review according to the fourth embodiment of the present application. This embodiment is applicable to provide a code jump function during the process of code review by reviewers, so that reviewers can It is convenient to view the definition of the current code element, or view the status of the code element that references the current code element. The device can implement the code jumping method in code review described in any embodiment of the present application. As shown in Figure 4, the
解析模块401,用于解析待评审代码的变更代码文件,获取其中存在跳转的至少一个代码元素的代码元素信息,并将所述代码元素信息存储在数据库,其中,所述代码元素信息至少包括代码元素的位置信息、语法信息和签名信息。The
标注模块402,用于显示所述变更代码文件,并对所述至少一个代码元素进行标注。An
查询模块403,用于响应于针对所述标注的代码元素中任意目标代码元素的跳转请求,根据所述目标代码元素的签名信息从所述数据库中查询所述目标代码元素对应的跳转代码元素及其在所述变更代码文件中的位置信息。The
跳转模块404,用于根据所述跳转代码元素的位置信息进行跳转,显示所述跳转代码元素所在的页面。The
可选的,所述装置还包括:Optionally, the device also includes:
目录创建模块,用于在所述解析模块解析待评审代码的变更代码文件之前,根据当前代码评审请求中的评审标识信息,创建当前代码评审目录,从代码库中下载待评审代码至所述当前代码评审目录,并获取所述待评审代码的变更代码文件;The directory creation module is used to create a current code review directory according to the review identification information in the current code review request before the parsing module parses the changed code file of the code to be reviewed, and download the code to be reviewed from the code library to the current Code review directory, and obtain the changed code file of the code to be reviewed;
相应的,所述解析模块具体用于在所述当前代码评审目录下,解析所述待评审代码的变更代码文件。Correspondingly, the parsing module is specifically configured to parse the changed code file of the code to be reviewed under the current code review directory.
可选的,在所述当前代码评审目录下,将首次获取的变更代码文件作为基准代码;Optionally, under the current code review directory, use the changed code file obtained for the first time as the benchmark code;
相应的,所述目录创建模块还用于:Correspondingly, the directory creation module is also used for:
如果在所述当前代码评审请求下存在不同版本的评审请求,则在所述当前代码评审目录下,创建不同版本的评审目录,每个版本的评审目录中的变更代码文件是通过拷贝所述基准代码而来,并且不同版本的评审目录的数量不超过预设阈值。If there are different versions of review requests under the current code review request, then under the current code review directory, create different versions of the review directory, and the changed code files in the review directory of each version are obtained by copying the benchmark code, and the number of review directories of different versions does not exceed the preset threshold.
可选的,所述解析模块包括:Optionally, the parsing module includes:
抽象语法树获取单元,用于利用代码解析器解析待评审代码的变更代码文件,获取所述变更代码文件的抽象语法树;An abstract syntax tree acquisition unit, configured to use a code parser to parse the changed code file of the code to be reviewed, and obtain the abstract syntax tree of the changed code file;
代码元素信息获取单元,用于对所述抽象语法树进行分析,获取其中各代码元素的代码元素信息;a code element information acquisition unit, configured to analyze the abstract syntax tree, and acquire code element information of each code element therein;
跳转元素获取单元,用于根据预设的跳转规则和各代码元素的语法信息,从各代码元素中获取存在跳转的至少一个代码元素及其代码元素信息。The jump element acquisition unit is configured to acquire at least one code element that has a jump and its code element information from each code element according to a preset jump rule and syntax information of each code element.
可选的,所述装置还包括:Optionally, the device also includes:
过滤模块,用于在所述解析模块解析待评审代码的变更代码文件之前,获取所述变更代码文件所使用的外部依赖类,并下载依赖包;遍历所述变更代码文件,按照预设的过滤规则对所述变更代码文件进行过滤;根据所述依赖包和经过滤的变更代码文件进行解析。The filtering module is used to obtain the external dependency class used by the changed code file and download the dependent package before the parsing module parses the changed code file of the code to be reviewed; traverse the changed code file and filter according to the preset The rule filters the changed code file; and analyzes according to the dependent package and the filtered changed code file.
可选的,所述语法信息中至少包括代码元素类型,所述代码元素类型包括引用和定义。Optionally, the syntax information includes at least a code element type, and the code element type includes a reference and a definition.
可选的,所述跳转请求是基于对查看引用按钮或查看定义按钮的触发操作而生成;Optionally, the jump request is generated based on a trigger operation on the view reference button or view definition button;
其中,所述查看引用按钮和查看定义按钮是根据目标代码元素的代码元素类型而生成。Wherein, the View Reference button and View Definition button are generated according to the code element type of the target code element.
可选的,所述查询模块包括:Optionally, the query module includes:
查询单元,用于根据所述数据库中的代码元素信息,查询与所述目标代码元素的签名信息相同,并且代码元素类型是引用或定义的代码元素,作为所述目标代码元素对应的跳转代码元素;A query unit, configured to query, according to the code element information in the database, that the signature information of the target code element is the same as that of the target code element, and the code element type is a reference or defined code element, as the jump code corresponding to the target code element element;
位置获取单元,用于获取所述跳转代码元素在所述变更代码文件中的位置信息。A position acquiring unit, configured to acquire position information of the jump code element in the changed code file.
本申请实施例提供的代码评审中的代码跳转装置400可执行本申请任意实施例提供的代码评审中的代码跳转方法,具备执行方法相应的功能模块和有益效果。本实施例中未详尽描述的内容可以参考本申请任意方法实施例中的描述。The
根据本申请的实施例,本申请还提供了一种电子设备和一种可读存储介质。According to the embodiments of the present application, the present application also provides an electronic device and a readable storage medium.
如图5所示,是根据本申请实施例的代码评审中的代码跳转方法的电子设备的框图。电子设备旨在表示各种形式的数字计算机,诸如,膝上型计算机、台式计算机、工作台、个人数字助理、服务器、刀片式服务器、大型计算机、和其它适合的计算机。电子设备还可以表示各种形式的移动装置,诸如,个人数字处理、蜂窝电话、智能电话、可穿戴设备和其它类似的计算装置。本文所示的部件、它们的连接和关系、以及它们的功能仅仅作为示例,并且不意在限制本文中描述的和/或者要求的本申请的实现。As shown in FIG. 5 , it is a block diagram of an electronic device according to a code jump method in code review according to an embodiment of the present application. Electronic device is intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other suitable computers. Electronic devices may also represent various forms of mobile devices, such as personal digital processing, cellular telephones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are by way of example only, and are not intended to limit implementations of the applications described and/or claimed herein.
如图5所示,该电子设备包括:一个或多个处理器501、存储器502,以及用于连接各部件的接口,包括高速接口和低速接口。各个部件利用不同的总线互相连接,并且可以被安装在公共主板上或者根据需要以其它方式安装。处理器可以对在电子设备内执行的指令进行处理,包括存储在存储器中或者存储器上以在外部输入/输出装置(诸如,耦合至接口的显示设备)上显示GUI的图形信息的指令。在其它实施方式中,若需要,可以将多个处理器和/或多条总线与多个存储器和多个存储器一起使用。同样,可以连接多个电子设备,各个设备提供部分必要的操作(例如,作为服务器阵列、一组刀片式服务器、或者多处理器系统)。图5中以一个处理器501为例。As shown in FIG. 5 , the electronic device includes: one or
存储器502即为本申请所提供的非瞬时计算机可读存储介质。其中,所述存储器存储有可由至少一个处理器执行的指令,以使所述至少一个处理器执行本申请所提供的代码评审中的代码跳转方法。本申请的非瞬时计算机可读存储介质存储计算机指令,该计算机指令用于使计算机执行本申请所提供的代码评审中的代码跳转方法。The
存储器502作为一种非瞬时计算机可读存储介质,可用于存储非瞬时软件程序、非瞬时计算机可执行程序以及模块,如本申请实施例中的代码评审中的代码跳转方法对应的程序指令/模块(例如,附图4所示的解析模块401、标注模块402、查询模块403和跳转模块404)。处理器501通过运行存储在存储器502中的非瞬时软件程序、指令以及模块,从而执行服务器的各种功能应用以及数据处理,即实现上述方法实施例中的代码评审中的代码跳转方法。The
存储器502可以包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需要的应用程序;存储数据区可存储根据实现本申请实施例的代码评审中的代码跳转方法的电子设备的使用所创建的数据等。此外,存储器502可以包括高速随机存取存储器,还可以包括非瞬时存储器,例如至少一个磁盘存储器件、闪存器件、或其他非瞬时固态存储器件。在一些实施例中,存储器502可选包括相对于处理器501远程设置的存储器,这些远程存储器可以通过网络连接至实现本申请实施例的代码评审中的代码跳转方法的电子设备。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。The
实现本申请实施例的代码评审中的代码跳转方法的电子设备还可以包括:输入装置503和输出装置504。处理器501、存储器502、输入装置503和输出装置504可以通过总线或者其他方式连接,图5中以通过总线连接为例。The electronic device implementing the code jumping method in the code review of the embodiment of the present application may further include: an
输入装置503可接收输入的数字或字符信息,以及产生与实现本申请实施例的代码评审中的代码跳转方法的电子设备的用户设置以及功能控制有关的键信号输入,例如触摸屏、小键盘、鼠标、轨迹板、触摸板、指示杆、一个或者多个鼠标按钮、轨迹球、操纵杆等输入装置。输出装置504可以包括显示设备、辅助照明装置(例如,LED)和触觉反馈装置(例如,振动电机)等。该显示设备可以包括但不限于,液晶显示器(LCD)、发光二极管(LED)显示器和等离子体显示器。在一些实施方式中,显示设备可以是触摸屏。The
此处描述的系统和技术的各种实施方式可以在数字电子电路系统、集成电路系统、专用ASIC(专用集成电路)、计算机硬件、固件、软件、和/或它们的组合中实现。这些各种实施方式可以包括:实施在一个或者多个计算机程序中,该一个或者多个计算机程序可在包括至少一个可编程处理器的可编程系统上执行和/或解释,该可编程处理器可以是专用或者通用可编程处理器,可以从存储系统、至少一个输入装置、和至少一个输出装置接收数据和指令,并且将数据和指令传输至该存储系统、该至少一个输入装置、和该至少一个输出装置。Various implementations of the systems and techniques described herein can be implemented in digital electronic circuitry, integrated circuit systems, application specific ASICs (application specific integrated circuits), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include being implemented in one or more computer programs executable and/or interpreted on a programmable system including at least one programmable processor, the programmable processor Can be special-purpose or general-purpose programmable processor, can receive data and instruction from storage system, at least one input device, and at least one output device, and transmit data and instruction to this storage system, this at least one input device, and this at least one output device an output device.
这些计算程序(也称作程序、软件、软件应用、或者代码)包括可编程处理器的机器指令,并且可以利用高级过程和/或面向对象的编程语言、和/或汇编/机器语言来实施这些计算程序。如本文使用的,术语“机器可读介质”和“计算机可读介质”指的是用于将机器指令和/或数据提供给可编程处理器的任何计算机程序产品、设备、和/或装置(例如,磁盘、光盘、存储器、可编程逻辑装置(PLD)),包括,接收作为机器可读信号的机器指令的机器可读介质。术语“机器可读信号”指的是用于将机器指令和/或数据提供给可编程处理器的任何信号。These computing programs (also referred to as programs, software, software applications, or codes) include machine instructions for a programmable processor and may be implemented using high-level procedural and/or object-oriented programming languages, and/or assembly/machine language calculation program. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and/or means for providing machine instructions and/or data to a programmable processor ( For example, magnetic disks, optical disks, memories, programmable logic devices (PLDs), including machine-readable media that receive machine instructions as machine-readable signals. The term "machine-readable signal" refers to any signal used to provide machine instructions and/or data to a programmable processor.
为了提供与用户的交互,可以在计算机上实施此处描述的系统和技术,该计算机具有:用于向用户显示信息的显示装置(例如,CRT(阴极射线管)或者LCD(液晶显示器)监视器);以及键盘和指向装置(例如,鼠标或者轨迹球),用户可以通过该键盘和该指向装置来将输入提供给计算机。其它种类的装置还可以用于提供与用户的交互;例如,提供给用户的反馈可以是任何形式的传感反馈(例如,视觉反馈、听觉反馈、或者触觉反馈);并且可以用任何形式(包括声输入、语音输入或者、触觉输入)来接收来自用户的输入。To provide for interaction with the user, the systems and techniques described herein 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 the user. ); and a keyboard and pointing device (eg, a mouse or a trackball) through which a user can provide input to the computer. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and can be in any form (including Acoustic input, speech input or, tactile input) to receive input from the user.
可以将此处描述的系统和技术实施在包括后台部件的计算系统(例如,作为数据服务器)、或者包括中间件部件的计算系统(例如,应用服务器)、或者包括前端部件的计算系统(例如,具有图形用户界面或者网络浏览器的用户计算机,用户可以通过该图形用户界面或者该网络浏览器来与此处描述的系统和技术的实施方式交互)、或者包括这种后台部件、中间件部件、或者前端部件的任何组合的计算系统中。可以通过任何形式或者介质的数字数据通信(例如,通信网络)来将系统的部件相互连接。通信网络的示例包括:局域网(LAN)、广域网(WAN)、互联网和区块链网络。The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., as a a user computer having a graphical user interface or web browser through which a user can interact with embodiments of the systems and techniques described herein), or including such backend components, middleware components, Or any combination of front-end components in a computing system. The components of the system can be interconnected by any form or medium of digital data communication, eg, a communication network. Examples of communication networks include: local area networks (LANs), wide area networks (WANs), the Internet, and blockchain networks.
计算机系统可以包括客户端和服务器。客户端和服务器一般远离彼此并且通常通过通信网络进行交互。通过在相应的计算机上运行并且彼此具有客户端-服务器关系的计算机程序来产生客户端和服务器的关系。A computer system may include clients and servers. Clients and servers are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by computer programs running on the respective computers and having a client-server relationship to each other.
根据本申请实施例的技术方案,在源码托管平台提供的评审功能基础上,增加了跳转功能,通过对变更代码文件进行解析得到存在跳转的至少一个代码元素及其代码元素信息,并存储在数据库,在显示变更代码文件时,还会将这些存在跳转的至少一个代码元素标注出来,以便于评审人员进行点击,当获取到针对标注中的任意目标代码元素的跳转请求时,则可以从数据库中查询得到目标代码元素对应的跳转代码元素及其位置信息,从而实现跳转,实现对代码元素定义或引用的查询,因而避免了评审人员进行手工查询,缩减了评审时间,提高了评审效率,并且,通过多评审处理机制和增量索引,能够进一步提高评审效率,有效保证了代码质量,且不受语言类型的限制,可以适用于任何语言。According to the technical solution of the embodiment of the application, on the basis of the review function provided by the source code hosting platform, a jump function is added, and at least one code element and its code element information that has a jump are obtained by parsing the changed code file, and stored In the database, when displaying the changed code file, at least one code element with a jump will be marked, so that the reviewer can click. When a jump request for any target code element in the mark is obtained, then The jump code element and its location information corresponding to the target code element can be queried from the database, so as to realize the jump and realize the query of the definition or reference of the code element, thereby avoiding manual query by the reviewers, reducing the review time, and improving It improves the review efficiency, and through the multi-review processing mechanism and incremental index, the review efficiency can be further improved, the code quality can be effectively guaranteed, and it is not limited by the language type, and can be applied to any language.
应该理解,可以使用上面所示的各种形式的流程,重新排序、增加或删除步骤。例如,本发申请中记载的各步骤可以并行地执行也可以顺序地执行也可以不同的次序执行,只要能够实现本申请公开的技术方案所期望的结果,本文在此不进行限制。It should be understood that steps may be reordered, added or deleted using the various forms of flow shown above. For example, the steps described in the present application may be executed in parallel, sequentially, or in a different order, as long as the desired result of the technical solution disclosed in the present application can be achieved, no limitation is imposed herein.
上述具体实施方式,并不构成对本申请保护范围的限制。本领域技术人员应该明白的是,根据设计要求和其他因素,可以进行各种修改、组合、子组合和替代。任何在本申请的精神和原则之内所作的修改、等同替换和改进等,均应包含在本申请保护范围之内。The above specific implementation methods are not intended to limit the protection scope of the present application. It should be apparent to those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of this application shall be included within the protection scope of this application.
Claims (18)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010038881.1A CN111274127B (en) | 2020-01-14 | 2020-01-14 | Code jumping method, device, equipment and medium in code evaluation |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010038881.1A CN111274127B (en) | 2020-01-14 | 2020-01-14 | Code jumping method, device, equipment and medium in code evaluation |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111274127A CN111274127A (en) | 2020-06-12 |
CN111274127B true CN111274127B (en) | 2023-04-07 |
Family
ID=70998712
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010038881.1A Active CN111274127B (en) | 2020-01-14 | 2020-01-14 | Code jumping method, device, equipment and medium in code evaluation |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111274127B (en) |
Families Citing this family (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113805856B (en) * | 2021-01-18 | 2025-05-16 | 北京沃东天骏信息技术有限公司 | Functional module intercommunication method, device, readable storage medium and electronic device |
CN114840204A (en) * | 2021-02-02 | 2022-08-02 | 华为技术有限公司 | Function jump method and device for non-homonymous symbols and computer readable storage medium |
CN112860565A (en) * | 2021-02-24 | 2021-05-28 | 北京皮尔布莱尼软件有限公司 | Code evaluation method, system, computing device and storage medium |
CN113282282B (en) * | 2021-05-31 | 2022-05-06 | 深圳赛安特技术服务有限公司 | Business requirement form publishing method and device, electronic equipment and storage medium |
CN114693116A (en) * | 2022-03-30 | 2022-07-01 | 北京百度网讯科技有限公司 | Method and device for detecting code review validity and electronic equipment |
CN115509938A (en) * | 2022-10-24 | 2022-12-23 | 平安银行股份有限公司 | Code viewing method, device and computer readable storage medium |
CN116795340A (en) * | 2023-01-29 | 2023-09-22 | 重庆市绝学网络科技有限责任公司 | Code reading system, method and storage medium |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107015911A (en) * | 2017-04-07 | 2017-08-04 | 广东亿迅科技有限公司 | The code review method and device of continuous integrating |
CN107092475A (en) * | 2016-12-21 | 2017-08-25 | 阿里巴巴集团控股有限公司 | The call method and device of a kind of interactive controls |
CN108536577A (en) * | 2017-03-02 | 2018-09-14 | 北京嘀嘀无限科技发展有限公司 | program code information processing method and device |
WO2019005351A1 (en) * | 2017-06-29 | 2019-01-03 | Microsoft Technology Licensing, Llc | Code review rebase diffing |
CN109976793A (en) * | 2019-03-15 | 2019-07-05 | 北京字节跳动网络技术有限公司 | A kind of operation method of application program, device, equipment and medium |
CN109992519A (en) * | 2019-04-11 | 2019-07-09 | 睿驰达新能源汽车科技(北京)有限公司 | A kind of methods, devices and systems that information is shown |
CN110286938A (en) * | 2019-07-03 | 2019-09-27 | 北京百度网讯科技有限公司 | Method and device for outputting evaluation information for users |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8739150B2 (en) * | 2010-05-28 | 2014-05-27 | Smartshift Gmbh | Systems and methods for dynamically replacing code objects via conditional pattern templates |
US9721615B2 (en) * | 2014-10-27 | 2017-08-01 | Cisco Technology, Inc. | Non-linear video review buffer navigation |
-
2020
- 2020-01-14 CN CN202010038881.1A patent/CN111274127B/en active Active
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107092475A (en) * | 2016-12-21 | 2017-08-25 | 阿里巴巴集团控股有限公司 | The call method and device of a kind of interactive controls |
CN108536577A (en) * | 2017-03-02 | 2018-09-14 | 北京嘀嘀无限科技发展有限公司 | program code information processing method and device |
CN107015911A (en) * | 2017-04-07 | 2017-08-04 | 广东亿迅科技有限公司 | The code review method and device of continuous integrating |
WO2019005351A1 (en) * | 2017-06-29 | 2019-01-03 | Microsoft Technology Licensing, Llc | Code review rebase diffing |
CN109976793A (en) * | 2019-03-15 | 2019-07-05 | 北京字节跳动网络技术有限公司 | A kind of operation method of application program, device, equipment and medium |
CN109992519A (en) * | 2019-04-11 | 2019-07-09 | 睿驰达新能源汽车科技(北京)有限公司 | A kind of methods, devices and systems that information is shown |
CN110286938A (en) * | 2019-07-03 | 2019-09-27 | 北京百度网讯科技有限公司 | Method and device for outputting evaluation information for users |
Non-Patent Citations (2)
Title |
---|
傅仰耿 等.基于证据推理面向生命周期的可信软件评估.《南京师大学报(自然科学版)》.2013,第36卷(第01期),第133-141页. * |
张迅珍 等.RV32I控制单元设计与实现.《微电子学与计算机》.2018,第35卷(第03期),第74-78页. * |
Also Published As
Publication number | Publication date |
---|---|
CN111274127A (en) | 2020-06-12 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111274127B (en) | Code jumping method, device, equipment and medium in code evaluation | |
KR102497463B1 (en) | Mini-program execution method, mini-program execution device, electronic device and storage medium | |
US9009664B2 (en) | Structural search of source code | |
US9058360B2 (en) | Extensible language framework using data cartridges | |
CN111666206A (en) | Method, device, equipment and storage medium for acquiring influence range of change code | |
US9619449B2 (en) | Compact encoding of node locations | |
CN111143577B (en) | Data labeling method, device and system | |
US9930113B2 (en) | Data retrieval via a telecommunication network | |
CN112015468B (en) | Interface document processing method and device, electronic equipment and storage medium | |
US10228913B2 (en) | Functional rule and component storage | |
US9311077B2 (en) | Identification of code changes using language syntax and changeset data | |
US20210209526A1 (en) | Landing page processing method, device and medium | |
CN111831320A (en) | Plug-in management method, device, electronic device and storage medium | |
CN116028028B (en) | Request function generation method, device, equipment and storage medium | |
CN112181429B (en) | Information processing method and device and electronic equipment | |
CN112000690B (en) | Method and device for analyzing structured operation statement | |
CN111880778A (en) | Interface document generation method and device, electronic equipment and storage medium | |
CN114168119B (en) | Code file editing method, device, electronic equipment and storage medium | |
CN117453221A (en) | Low code conversion method, device, readable storage medium and equipment | |
EP4160395A1 (en) | Storage structure for pattern mining | |
CN116069755A (en) | mapper file processing method and related equipment | |
CN113254405A (en) | File conversion method, device, equipment and medium | |
Srivastava et al. | Elasticsearch 7 Quick Start Guide: Get up and running with the distributed search and analytics capabilities of Elasticsearch | |
CN111506268B (en) | Code file storage method, device and electronic equipment | |
CN113495753B (en) | Method and device for acquiring label of item, electronic 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 |