WO2023155487A1 - Code refactoring method and device - Google Patents

Code refactoring method and device Download PDF

Info

Publication number
WO2023155487A1
WO2023155487A1 PCT/CN2022/129822 CN2022129822W WO2023155487A1 WO 2023155487 A1 WO2023155487 A1 WO 2023155487A1 CN 2022129822 W CN2022129822 W CN 2022129822W WO 2023155487 A1 WO2023155487 A1 WO 2023155487A1
Authority
WO
WIPO (PCT)
Prior art keywords
code
project
server
reconstruction
user
Prior art date
Application number
PCT/CN2022/129822
Other languages
French (fr)
Chinese (zh)
Inventor
梁广泰
王一凡
Original Assignee
华为云计算技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为云计算技术有限公司 filed Critical 华为云计算技术有限公司
Publication of WO2023155487A1 publication Critical patent/WO2023155487A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/34Graphical or visual programming
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring

Abstract

A code refactoring method and a device, which are applied in the field of information technology. In the method, a high-level code architecture diagram is able to be presented to a user on a user interface and a modification on a code structure by the user can be received, and the user can modify the code structure by means of an interface operation and obtain a modified code project. Consequently, code refactoring and visual display of a code structure are integrated into one, allowing a user to not need to switch between different code levels, and thereby greatly improving code refactoring efficiency. Additionally, a visual operation lowers a use barrier, and the code refactoring experience of a user is improved.

Description

代码重构方法及装置Code reconstruction method and device
本申请要求于2022年02月18日提交中国专利局、申请号为202210152592.3、申请名称为“代码重构方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202210152592.3 and the application name "code reconstruction method and device" submitted to the China Patent Office on February 18, 2022, the entire contents of which are incorporated in this application by reference.
技术领域technical field
本申请涉及信息技术(information technology,IT)领域,尤其涉及代码重构方法及装置。The present application relates to the field of information technology (IT), and in particular to a code reconstruction method and device.
背景技术Background technique
在开发过程中,为了改善代码工程的质量,经常需要对代码进行重构。代码重构(英语:Code refactoring)就是在不改变软件系统外部行为的前提下,改善它的内部结构。In the development process, in order to improve the quality of code engineering, it is often necessary to refactor the code. Code refactoring is to improve the internal structure of a software system without changing its external behavior.
在传统的代码重构过程中,开发人员往往需要先从架构层面了解整个代码结构,再基于当前不良设计来设计重构策略,最后从代码层面入手实施并完成代码重构。代码重构过程中,发现代码中的不良设计往往需要较高的层面来了解整个代码工程,但是,重构修复这个不良设计却只能从底层的代码层面着手,修改具体的代码。开发人员在重构时往往需要在不同的代码层面中进行切换,从而导致代码重构效率低。In the traditional code refactoring process, developers often need to understand the entire code structure from the architectural level, then design a refactoring strategy based on the current bad design, and finally implement and complete the code refactoring from the code level. In the process of code refactoring, it is often necessary to understand the entire code project at a higher level to find a bad design in the code. However, refactoring and repairing this bad design can only start from the underlying code level and modify the specific code. Developers often need to switch between different code levels when refactoring, resulting in low code refactoring efficiency.
发明内容Contents of the invention
本申请实施例提供了代码重构方法及装置,能够大大提升代码重构效率。The embodiment of the present application provides a code refactoring method and device, which can greatly improve code refactoring efficiency.
第一方面,本申请实施例提供一种代码重构方法,包括:In the first aspect, the embodiment of the present application provides a code reconstruction method, including:
呈现第一用户界面,所述第一用户界面用于指示第一代码工程的代码结构,所述代码结构包含包、类、类成员或底层代码中的一种或多种元素;Presenting a first user interface, the first user interface is used to indicate the code structure of the first code project, the code structure includes one or more elements in packages, classes, class members or underlying code;
接收用户在所述第一用户界面上输入的第一操作,所述第一操作用于更新所述第一代码工程的代码结构;receiving a first operation input by a user on the first user interface, where the first operation is used to update the code structure of the first code project;
基于所述第一操作向第一服务器请求重构所述第一代码工程。Refactoring of the first code project is requested from a first server based on the first operation.
本申请实施例能够在用户界面上向用户呈现代码架构图,而用户通过界面操作就能够对代码结构进行修改,并获取到修改后的代码工程。如此,将代码结构的视图展示和代码重构集成一体,使得用户无需在不同的代码层面中进行切换,从而大大提升代码重构效率。另外,可视化的操作更降低了代码重构的使用门槛,提升了用户的代码重构体验。The embodiment of the present application can present the code structure diagram to the user on the user interface, and the user can modify the code structure through interface operations and obtain the modified code project. In this way, the view display of the code structure and code refactoring are integrated, so that users do not need to switch between different code levels, thus greatly improving the efficiency of code refactoring. In addition, the visualized operation lowers the threshold for using code refactoring and improves the user's code refactoring experience.
在第一方面的一种可能的实施方式中,所述方法还包括:In a possible implementation manner of the first aspect, the method further includes:
获取经过重构的所述第一代码工程。如此,用户设备可以查看经过重构的代码工程,方便用户确认重构的结构,还可以继续对第一代码工程进行重构,提升了用户代码重构过程中的使用体验。Acquire the refactored first code project. In this way, the user device can view the refactored code project, which is convenient for the user to confirm the refactored structure, and can continue to refactor the first code project, which improves the user experience in the code refactoring process.
在第一方面的又一种可能的实施方式中,所述第一操作包含针对所述元素的移动、增加、删除、编辑等中的一项或者多项。In yet another possible implementation manner of the first aspect, the first operation includes one or more of moving, adding, deleting, editing, and the like for the element.
其中,移动操作可以更新代码结构中的元素的位置等。以移动类成员为例,用户可以将某一类成员从某一个类移动到另一个类。Wherein, the move operation may update the position of elements in the code structure and the like. Taking moving class members as an example, users can move a class member from one class to another.
增加操作可以增加元素,以增加类为例,用户可以创建新的类成员。以增加字段为例,用户可以封装新的字段。The adding operation can add elements. Taking adding a class as an example, the user can create a new class member. Taking adding fields as an example, users can encapsulate new fields.
删除操作可以移除、销毁某一元素。例如,用户可以删除包、删除类、删除类成员等。The delete operation can remove and destroy an element. For example, a user can delete a package, delete a class, delete a class member, etc.
编辑操作可以对元素进行更新。例如,用户可以变更字段的属性、修改类的名称、拆分类等等。Editing operations can update elements. For example, users can change the attributes of fields, modify the name of classes, split classes, and so on.
可选的,第一操作还包括滑动、缩放、指向、点击、长按等。其中,滑动、缩放等操作可以用于调整显示区域、页面大小等。其中,指向操作可以用于用户选择某一元素。点击操作可以用于用户选中元素、选择某一选项、或确认某一操作(如提交修改等)等。长按操作可以用于用户选中元素、移动元素、或删除元素等。Optionally, the first operation also includes sliding, zooming, pointing, clicking, long pressing, and the like. Wherein, operations such as sliding and zooming may be used to adjust a display area, a page size, and the like. Among them, the pointing operation can be used for the user to select an element. The click operation can be used for the user to select an element, select an option, or confirm an operation (such as submitting a modification, etc.). The long press operation can be used for the user to select an element, move an element, or delete an element, etc.
在第一方面的又一种可能的实施方式中,所述第一用户界面还用于指示所述第一代码工程中存在的代码架构坏味道。In yet another possible implementation manner of the first aspect, the first user interface is further used to indicate a code architecture smell existing in the first code project.
通过上述的设计,用户设备通过第一用户界面即可同时了解第一代码工程的代码架构和第一代码工程的代码架构坏味道,无需在多个窗口中切换,减少操作、节约时间。此外,通过界面来展示代码架构坏味道,使得用户无需一一排查所有元素,可以提高代码重构的效率和准确性,提升用户代码重构的体验。Through the above design, the user equipment can simultaneously understand the code structure of the first code project and the bad taste of the code structure of the first code project through the first user interface, without switching between multiple windows, reducing operations and saving time. In addition, the bad smell of the code structure is displayed through the interface, so that users do not need to check all elements one by one, which can improve the efficiency and accuracy of code refactoring, and improve the user's code refactoring experience.
在第一方面的又一种可能的实施方式中,所述第一代码工程中存在的代码架构坏味道对应于所述元素;In yet another possible implementation manner of the first aspect, the code architecture smell existing in the first code project corresponds to the element;
所述第一用户界面还用于通过颜色区分所述元素中存在代码架构坏味道的程度。The first user interface is also used to distinguish the degree of bad code structure smell in the elements by color.
这里的程度包含数量多少的程度、代码架构坏味道的严重程度或代码架构坏味道的紧急程度等中的一项或者多项。如此,通过颜色的区分,可以使得用户更快速地了解架构坏味道的分布情况,提高用户发现代码架构怪味道的效率,提升用户体验。The degree here includes one or more of the degree of quantity, the severity of the code architecture smell, or the urgency of the code architecture smell. In this way, through the distinction of colors, users can understand the distribution of bad architecture smells more quickly, improve the efficiency of users in discovering code architecture smells, and improve user experience.
在第一方面的又一种可能的实施方式中,在所述呈现第一用户界面之前,所述方法还包括:In yet another possible implementation manner of the first aspect, before presenting the first user interface, the method further includes:
接收第二服务器提供的所述第一代码工程的第一指示信息,所述第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道。Receive first indication information of the first code project provided by the second server, where the first indication information is used to indicate a code architecture smell existing in the first code project.
在上述的实施方式中,代码结构坏味道由服务器提供给用户设备。由于服务器是具有集中的计算资源的设备,通过服务器来检测代码架构坏味道,可以缩短确定代码架构坏味道的时间,提升代码重构的效率。In the above embodiments, the code structure smell is provided by the server to the user equipment. Since the server is a device with centralized computing resources, using the server to detect bad code architecture smells can shorten the time for determining bad code architecture smells and improve the efficiency of code refactoring.
可选的,第一服务器和第二服务器可能是同一个服务器,或者第一服务器和第二服务器可以包含于同一个服务器中。Optionally, the first server and the second server may be the same server, or the first server and the second server may be included in the same server.
在第一方面的又一种可能的实施方式中,所述第一用户界面还用于指示重构推荐,所述重构推荐用于提示用户针对所述第一代码工程中存在的代码架构坏味道对所述第一代码工程进行修改。In yet another possible implementation manner of the first aspect, the first user interface is further used to indicate a refactoring recommendation, and the refactoring recommendation is used to prompt the user to solve the code structure failure existing in the first code project. Flavors make modifications to the first code project.
在上述实施方式中,一方面,用户基于推荐的重构方案来重构代码,可以节省时间、提高重构效率,另一方面,将推荐的重构方案直接提供给用户,可以减少用户在代码重构时的错误调整,提高了修改代码架构坏味道的准确性。In the above implementation, on the one hand, the user refactors the code based on the recommended refactoring solution, which can save time and improve the refactoring efficiency; Error adjustments when refactoring improve the accuracy of modifying code architecture bad smells.
在第一方面的又一种可能的实施方式中,在所述呈现第一用户界面之前,所述方法还包括:In yet another possible implementation manner of the first aspect, before presenting the first user interface, the method further includes:
接收第二服务器发送的所述重构推荐。The reconstruction recommendation sent by the second server is received.
在上述实施方式中,重构推荐由服务器提供给用户设备。由于服务器是具有集中的计算资源的设备,通过服务器来确定重构推荐,可以缩短确定重构推荐的时间,提升代码重构的效率。In the above embodiments, the reconstruction recommendation is provided by the server to the user equipment. Since the server is a device with centralized computing resources, determining the refactoring recommendation through the server can shorten the time for determining the refactoring recommendation and improve the efficiency of code refactoring.
在第一方面的又一种可能的实施方式中,所述基于所述第一操作向服务器请求重构所述第一代码工程,包括:In yet another possible implementation manner of the first aspect, the requesting the server to refactor the first code project based on the first operation includes:
根据所述第一操作,得到原子重构序列,所述原子重构序列用于记录更新第一代码工程的操作顺序;According to the first operation, an atomic reconstruction sequence is obtained, and the atomic reconstruction sequence is used to record an operation sequence for updating the first code project;
向所述第一服务器发送重构请求消息,所述重构请求消息包含所述原子重构序列。sending a reconstruction request message to the first server, where the reconstruction request message includes the atomic reconstruction sequence.
在上述实施方式中,通过原子重构序列可以记录用户的操作顺序,从而使得服务器在重构代码时可以根据原子重构序列来重现用户的操作顺序,从而准确地依据用户的需求来进行代码重构。In the above implementation, the user's operation sequence can be recorded through the atomic reconstruction sequence, so that the server can reproduce the user's operation sequence according to the atomic reconstruction sequence when reconstructing the code, so as to accurately implement the code according to the user's needs. refactor.
在第一方面的又一种可能的实施方式中,所述原子重构序列包含多个原子重构操作,每个原子重构操作包含原子重构操作的标识和所述原子重构操作涉及的第一代码工程中的参数。In yet another possible implementation manner of the first aspect, the atomic reconstruction sequence includes multiple atomic reconstruction operations, and each atomic reconstruction operation includes an identifier of the atomic reconstruction operation and the Parameters in the first code project.
上述实施方式中说明了原子重构操作所包含的内容,通过原子重构操作可以使得用户的操作被对应的转换为某一格式的数据,从而服务器能够根据格式化的数据来进行代码重构,提升代码重构的效率和准确性。In the above implementation, the content of the atomic reconstruction operation is described. Through the atomic reconstruction operation, the user's operation can be converted into data in a certain format, so that the server can perform code reconstruction according to the formatted data. Improve the efficiency and accuracy of code refactoring.
在第一方面的又一种可能的实施方式中,所述呈现第一用户界面之前,所述方法还包括:In yet another possible implementation manner of the first aspect, before presenting the first user interface, the method further includes:
向第三服务器发送所述第一代码工程的第二指示信息;sending second indication information of the first code project to a third server;
接收所述第三服务器提供的所述第一代码工程的代码结构。Receive the code structure of the first code project provided by the third server.
在上述实施方式中,第一代码工程的代码结构由服务器提供给用户设备。由于服务器是具有集中的计算资源的设备,通过服务器来确定第一代码工程的代码结构,可以缩短确定代码结构的时间,提升代码重构的效率。In the above implementation manner, the code structure of the first code project is provided to the user equipment by the server. Since the server is a device with centralized computing resources, determining the code structure of the first code project through the server can shorten the time for determining the code structure and improve the efficiency of code reconstruction.
可选的,第一服务器和第三服务器可能是同一个服务器,或者第一服务器和第三服务器可以包含于同一个服务器中。进一步的,第一服务器、第二服务器和第三服务器可能是同一个服务器,或者第一服务器、第二服务器和第三服务器可以包含于同一个服务器中。Optionally, the first server and the third server may be the same server, or the first server and the third server may be included in the same server. Further, the first server, the second server and the third server may be the same server, or the first server, the second server and the third server may be included in the same server.
第二方面,本申请实施例提供一种代码重构方法,包括:In the second aspect, the embodiment of the present application provides a code reconstruction method, including:
接收来自用户设备的重构请求消息,所述重构请求消息是根据在所述第一用户界面上输入的第一操作得到的,所述第一用户界面用于指示第一代码工程的代码结构,所述代码结构包含包、类、类成员或底层代码中的一种或多种元素,所述第一操作用于更新第一代码工程的代码结构;receiving a reconstruction request message from the user equipment, the reconstruction request message is obtained according to a first operation input on the first user interface, and the first user interface is used to indicate the code structure of the first code project , the code structure includes one or more elements in package, class, class member or underlying code, and the first operation is used to update the code structure of the first code project;
根据所述重构请求消息,对所述第一代码工程进行重构。Refactor the first code project according to the refactoring request message.
在第二方面的一种可能的实施方式中,所述方法还包括:In a possible implementation manner of the second aspect, the method further includes:
向所述用户设备反馈经过重构的所述第一代码工程。Feedback the reconstructed first code project to the user equipment.
在第二方面的又一种可能的实施方式中,所述第一操作包含针对所述元素的移动、增加、删除、编辑等中的一项或者多项。In yet another possible implementation manner of the second aspect, the first operation includes one or more of moving, adding, deleting, editing, and the like for the element.
其中,移动操作可以更新代码结构中的元素的位置等。以移动类成员为例,用户可以将某一类成员从某一个类移动到另一个类。Wherein, the move operation may update the position of elements in the code structure and the like. Taking moving class members as an example, users can move a class member from one class to another.
增加操作可以增加元素,以增加类为例,用户可以创建新的类成员。以增加字段为例,用户可以封装新的字段。The adding operation can add elements. Taking adding a class as an example, the user can create a new class member. Taking adding fields as an example, users can encapsulate new fields.
删除操作可以移除、销毁某一元素。例如,用户可以删除包、删除类、删除类成员等。The delete operation can remove and destroy an element. For example, a user can delete a package, delete a class, delete a class member, etc.
编辑操作可以对元素进行更新。例如,用户可以变更字段的属性、修改类的名称、拆分类等等。Editing operations can update elements. For example, users can change the attributes of fields, modify the name of classes, split classes, and so on.
可选的,第一操作还包括滑动、缩放、指向、点击、长按等。其中,滑动、缩放等操作可以用于调整显示区域、页面大小等。指向操作可以用于用户选择某一元素。点击操作可以用于用户选中元素、选择某一选项、或确认某一操作(如提交修改等)等。长按操作可以用 于用户选中元素、移动元素、或删除元素等。Optionally, the first operation also includes sliding, zooming, pointing, clicking, long pressing, and the like. Wherein, operations such as sliding and zooming may be used to adjust a display area, a page size, and the like. A pointing operation can be used for the user to select an element. The click operation can be used for the user to select an element, select an option, or confirm an operation (such as submitting a modification, etc.). The long press operation can be used for the user to select an element, move an element, or delete an element, etc.
在第二方面的又一种可能的实施方式中,所述方法还包括:In yet another possible implementation manner of the second aspect, the method further includes:
确定所述第一代码工程中存在的代码架构坏味道;Determining the code architecture bad smell that exists in the first code project;
向所述用户设备发送第一指示信息,所述第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道。Sending first indication information to the user equipment, where the first indication information is used to indicate a code architecture smell existing in the first code project.
在第二方面的又一种可能的实施方式中,所述第一代码工程中存在的代码架构坏味道对应于所述元素;In yet another possible implementation manner of the second aspect, the code architecture smell existing in the first code project corresponds to the element;
所述第一用户界面还用于通过颜色区分所述元素中存在代码架构坏味道的程度。The first user interface is also used to distinguish the degree of bad code structure smell in the elements by color.
在第二方面的又一种可能的实施方式中,所述确定所述第一代码工程中存在的代码架构坏味道,包含:In yet another possible implementation manner of the second aspect, the determining the bad code architecture smell existing in the first code project includes:
通过架构坏味道检测模型,确定所述第一代码工程中的代码架构坏味道。The code architecture smell in the first code project is determined by using the architecture smell detection model.
可选的,架构坏味道检测模型可以是通过强化学习、深度学习、或神经网络等一种或者多种方式训练得到的。Optionally, the architecture bad smell detection model can be obtained by training in one or more ways such as reinforcement learning, deep learning, or neural network.
在上述实施方式中,服务器中可以包含架构坏味道检测模型,通过该模型可以确定所述第一代码工程中的代码架构坏味道。架构坏味道检测模型可以是通过训练数据训练得到的,可以自动检测第一代码工程中的代码架构坏味道,从而向用户提供更准确的检测结果。In the above implementation manner, the server may include an architecture smell detection model, through which the code architecture smell in the first code project can be determined. The architectural smell detection model can be obtained through training data, and can automatically detect code architectural smells in the first code project, thereby providing users with more accurate detection results.
在第二方面的又一种可能的实施方式中,所述确定所述第一代码工程中存在的代码架构坏味道,包含:In yet another possible implementation manner of the second aspect, the determining the bad code architecture smell existing in the first code project includes:
对所述第一代码工程进行代码静态分析、文本相似度计算,得到所述第一代码工程中的代码架构坏味道。Static code analysis and text similarity calculation are performed on the first code project to obtain the bad smell of the code structure in the first code project.
在上述方式中,服务器通过对代码工程进行代码静态分析、文本相似度计算,可以自动检测第一代码工程中的代码架构坏味道,从而向用户提供更准确的检测结果。In the above manner, the server can automatically detect bad code architecture smells in the first code project by performing code static analysis and text similarity calculation on the code project, thereby providing users with more accurate detection results.
在第二方面的又一种可能的实施方式中,所述方法还包括:In yet another possible implementation manner of the second aspect, the method further includes:
确定重构推荐,所述重构推荐用于提示用户针对所述第一代码工程中存在的代码架构坏味道对所述第一代码工程进行修改;Determining a refactoring recommendation, where the refactoring recommendation is used to prompt the user to modify the first code project for the bad smell of the code architecture existing in the first code project;
向所述用户设备发送所述重构推荐。Sending the reconstruction recommendation to the user equipment.
在第二方面的又一种可能的实施方式中,所述重构请求消息包含所述原子重构序列,所述原子重构序列用于记录修改更新第一代码工程的操作顺序;In yet another possible implementation manner of the second aspect, the reconstruction request message includes the atomic reconstruction sequence, and the atomic reconstruction sequence is used to record an operation sequence of modifying and updating the first code project;
所述根据所述重构请求消息,对所述第一代码工程进行重构,包括:The refactoring of the first code project according to the refactoring request message includes:
根据所述重构请求消息中的原子重构序列,对所述第一代码工程进行重构。The first code project is reconstructed according to the atomic reconstruction sequence in the reconstruction request message.
在第二方面的又一种可能的实施方式中,所述原子重构序列包含多个原子重构操作,每个原子重构操作包含原子重构操作的标识和所述原子重构操作涉及的第一代码工程中的元素。In yet another possible implementation manner of the second aspect, the atomic reconstruction sequence includes multiple atomic reconstruction operations, and each atomic reconstruction operation includes an identifier of the atomic reconstruction operation and the Elements in the first code project.
在第二方面的又一种可能的实施方式中,所述接收来自用户设备的重构请求消息之前,所述方法还包括:In yet another possible implementation manner of the second aspect, before receiving the reconfiguration request message from the user equipment, the method further includes:
接收来自所述用户设备的第一代码工程的指示信息;receiving indication information of a first code project from the user equipment;
确定所述第一代码工程的代码结构;determining the code structure of the first code project;
向用户设备提供所述第一代码工程的代码结构。The code structure of the first code project is provided to the user equipment.
第三方面,本申请实施例提供一种代码重构系统,所述代码重构系统包括用户设备和服务器,其中;In a third aspect, an embodiment of the present application provides a code reconstruction system, where the code reconstruction system includes a user equipment and a server, wherein;
所述用户设备,用于呈现第一用户界面,所述第一用户界面用于指示第一代码工程的代 码结构,所述代码结构包含包、类、类成员或底层代码中的一种或多种元素;The user equipment is configured to present a first user interface, the first user interface is used to indicate a code structure of a first code project, and the code structure includes one or more of a package, a class, a class member, or an underlying code kind of element;
所述用户设备,还用于接收用户在所述第一用户界面上输入的第一操作,所述第一操作用于更新所述第一代码工程的代码结构;The user equipment is further configured to receive a first operation input by a user on the first user interface, where the first operation is used to update the code structure of the first code project;
所述用户设备,还用于向服务器发送重构推荐消息,所述重构请求消息是根据在所述第一用户界面上输入的第一操作得到的;The user equipment is further configured to send a reconstruction recommendation message to a server, and the reconstruction request message is obtained according to a first operation input on the first user interface;
所述服务器,用于接收来自用户设备的重构请求消息;The server is configured to receive a reconstruction request message from a user equipment;
所述服务器,还用于根据所述重构请求消息,对所述第一代码工程进行重构。The server is further configured to refactor the first code project according to the refactoring request message.
在第三方面的一种可能的实施方式中,所述服务器还用于向所述用户设备反馈经过重构的所述第一代码工程;In a possible implementation manner of the third aspect, the server is further configured to feed back the reconstructed first code project to the user equipment;
所述用户设备还用于接收服务器提供的经过重构的所述第一代码工程。The user equipment is further configured to receive the reconstructed first code project provided by the server.
在第三方面的又一种可能的实施方式中,所述第一操作包含针对所述元素的移动、增加、删除、编辑中的一项或者多项。In yet another possible implementation manner of the third aspect, the first operation includes one or more of moving, adding, deleting, and editing the element.
在第三方面的又一种可能的实施方式中,所述服务器还用于:In yet another possible implementation manner of the third aspect, the server is also used for:
确定所述第一代码工程中存在的代码架构坏味道;Determining the code architecture bad smell that exists in the first code project;
向所述用户设备发送第一指示信息,所述第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道;Sending first indication information to the user equipment, where the first indication information is used to indicate a code architecture smell existing in the first code project;
所述用户设备还用于:The user equipment is also used for:
接收来自所述服务器的第一指示信息;receiving first indication information from the server;
通过所述第一用户界面指示所述第一代码工程中存在的代码架构坏味道。A bad code architecture smell existing in the first code project is indicated through the first user interface.
在第三方面的又一种可能的实施方式中,所述服务器,还用于通过架构坏味道检测模型,确定所述第一代码工程中的代码架构坏味道。In yet another possible implementation manner of the third aspect, the server is further configured to determine a code architecture smell in the first code project by using an architecture smell detection model.
在第三方面的又一种可能的实施方式中,所述服务器,还用于对所述第一代码工程进行代码静态分析、文本相似度计算,得到所述第一代码工程中的代码架构坏味道。In yet another possible implementation manner of the third aspect, the server is further configured to perform code static analysis and text similarity calculation on the first code project to obtain code structure errors in the first code project. smell.
在第三方面的又一种可能的实施方式中,所述服务器,还用于:In yet another possible implementation manner of the third aspect, the server is further configured to:
确定重构推荐,所述重构推荐用于提示用户针对所述第一代码工程中存在的代码架构坏味道对所述第一代码工程进行修改;Determining a refactoring recommendation, where the refactoring recommendation is used to prompt the user to modify the first code project for the bad smell of the code architecture existing in the first code project;
向用户设备发送所述重构推荐;sending the reconstruction recommendation to the user equipment;
所述用户设备,还用于:The user equipment is also used for:
接收服务器提供的所述重构推荐;receiving the reconstruction recommendation provided by the server;
通过所述第一用户界面指示所述重构推荐。The refactoring recommendation is indicated through the first user interface.
在第三方面的又一种可能的实施方式中,所述用户设备还用于向所述服务器发送所述第一代码工程的第二指示信息;In yet another possible implementation manner of the third aspect, the user equipment is further configured to send second indication information of the first code project to the server;
所述服务器,还用于确定所述第一代码工程的代码结构;The server is further configured to determine the code structure of the first code project;
所述服务器,还用于向所述用户设备发送所述第一代码工程的代码结构;The server is further configured to send the code structure of the first code project to the user equipment;
所述用户设备,还用于接收所述服务器提供的所述第一代码工程的代码结构;The user equipment is further configured to receive the code structure of the first code project provided by the server;
所述用户设备,还用于通过所述第一用户界面指示所述第一代码工程的代码结构。The user equipment is further configured to indicate the code structure of the first code project through the first user interface.
第四方面,本申请实施例提供一种代码重构装置,所述代码重构装置包括处理单元和通信单元,所述代码重构装置用于执行第一方面或第一方面任一种可能的实施方式所描述的方法。In a fourth aspect, an embodiment of the present application provides a code reconstruction device, the code reconstruction device includes a processing unit and a communication unit, and the code reconstruction device is used to perform any possible operation of the first aspect or the first aspect. The method described in the embodiment.
在第四方面的一种可能的实施方式中,所述处理单元,用于呈现第一用户界面,所述第 一用户界面用于指示第一代码工程的代码结构,所述代码结构包含包、类、类成员或底层代码中的一种或多种元素;In a possible implementation manner of the fourth aspect, the processing unit is configured to present a first user interface, the first user interface is used to indicate the code structure of the first code project, and the code structure includes a package, one or more elements in a class, class member, or underlying code;
所述通信单元,用于接收用户在所述第一用户界面上输入的第一操作,所述第一操作用于更新所述第一代码工程的代码结构;The communication unit is configured to receive a first operation input by a user on the first user interface, where the first operation is used to update the code structure of the first code project;
所述处理单元和通信单元,还用于基于所述第一操作向第一服务器请求重构所述第一代码工程。The processing unit and the communication unit are further configured to request the first server to reconstruct the first code project based on the first operation.
在第四方面的又一种可能的实施方式中,所述处理单元和通信单元,还用于获取经过重构的所述第一代码工程。In yet another possible implementation manner of the fourth aspect, the processing unit and the communication unit are further configured to obtain the reconstructed first code project.
在第四方面的又一种可能的实施方式中,所述第一操作包含针对所述元素的移动、增加、删除、编辑等中的一项或者多项。In yet another possible implementation manner of the fourth aspect, the first operation includes one or more of moving, adding, deleting, editing, and the like for the element.
其中,移动操作可以更新代码结构中的元素的位置等。以移动类成员为例,用户可以将某一类成员从某一个类移动到另一个类。Wherein, the move operation may update the position of elements in the code structure and the like. Taking moving class members as an example, users can move a class member from one class to another.
增加操作可以增加元素,以增加类为例,用户可以创建新的类成员。以增加字段为例,用户可以封装新的字段。The adding operation can add elements. Taking adding a class as an example, the user can create a new class member. Taking adding fields as an example, users can encapsulate new fields.
删除操作可以移除、销毁某一元素。例如,用户可以删除包、删除类、删除类成员等。The delete operation can remove and destroy an element. For example, a user can delete a package, delete a class, delete a class member, etc.
编辑操作可以对元素进行更新。例如,用户可以变更字段的属性、修改类的名称、拆分类等等。Editing operations can update elements. For example, users can change the attributes of fields, modify the name of classes, split classes, and so on.
可选的,第一操作还包括滑动、缩放、指向、点击、长按等。其中,滑动、缩放等操作可以用于调整显示区域、页面大小等。其中,指向操作可以用于用户选择某一元素。点击操作可以用于用户选中元素、选择某一选项、或确认某一操作(如提交修改等)等。长按操作可以用于用户选中元素、移动元素、或删除元素等。Optionally, the first operation also includes sliding, zooming, pointing, clicking, long pressing, and the like. Wherein, operations such as sliding and zooming may be used to adjust a display area, a page size, and the like. Among them, the pointing operation can be used for the user to select an element. The click operation can be used for the user to select an element, select an option, or confirm an operation (such as submitting a modification, etc.). The long press operation can be used for the user to select an element, move an element, or delete an element, etc.
在第四方面的又一种可能的实施方式中,所述第一用户界面还用于指示所述第一代码工程中存在的代码架构坏味道。In yet another possible implementation manner of the fourth aspect, the first user interface is further used to indicate a code architecture smell existing in the first code project.
在第四方面的又一种可能的实施方式中,所述第一代码工程中存在的代码架构坏味道对应于所述元素;In yet another possible implementation manner of the fourth aspect, the code architecture smell existing in the first code project corresponds to the element;
所述第一用户界面还用于通过颜色区分所述元素中存在代码架构坏味道的程度。The first user interface is also used to distinguish the degree of bad code structure smell in the elements by color.
在第四方面的又一种可能的实施方式中,所述通信单元,还用于:In yet another possible implementation manner of the fourth aspect, the communication unit is further configured to:
接收第二服务器提供的所述第一代码工程的第一指示信息,所述第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道。Receive first indication information of the first code project provided by the second server, where the first indication information is used to indicate a code architecture smell existing in the first code project.
在第四方面的又一种可能的实施方式中,所述第一用户界面还用于指示重构推荐,所述重构推荐用于提示用户针对所述第一代码工程中存在的代码架构坏味道对所述第一代码工程进行修改。In yet another possible implementation manner of the fourth aspect, the first user interface is further used to indicate a refactoring recommendation, and the refactoring recommendation is used to prompt the user to solve the code structure failure existing in the first code project. Flavors make modifications to the first code project.
在第四方面的又一种可能的实施方式中,所述通信单元,还用于:In yet another possible implementation manner of the fourth aspect, the communication unit is further configured to:
接收第二服务器发送的所述重构推荐。The reconstruction recommendation sent by the second server is received.
在第四方面的又一种可能的实施方式中,所述处理单元,还用于根据所述第一操作,得到原子重构序列,所述原子重构序列用于记录修改更新第一代码工程的操作顺序;In yet another possible implementation manner of the fourth aspect, the processing unit is further configured to obtain an atomic reconstruction sequence according to the first operation, and the atomic reconstruction sequence is used to record, modify and update the first code project sequence of operations;
所述通信单元,还用于向所述第一服务器发送重构请求消息,所述重构请求消息包含所述原子重构序列。The communication unit is further configured to send a reconstruction request message to the first server, where the reconstruction request message includes the atomic reconstruction sequence.
在第四方面的又一种可能的实施方式中,所述原子重构序列包含多个原子重构操作,每个原子重构操作包含原子重构操作的标识和所述原子重构操作涉及的第一代码工程中的参数。In yet another possible implementation manner of the fourth aspect, the atomic reconstruction sequence includes multiple atomic reconstruction operations, and each atomic reconstruction operation includes an identifier of the atomic reconstruction operation and the Parameters in the first code project.
在第四方面的又一种可能的实施方式中,所述通信单元,还用于:In yet another possible implementation manner of the fourth aspect, the communication unit is further configured to:
向第四服务器发送所述第一代码工程的指示信息;sending instruction information of the first code project to the fourth server;
接收所述第三服务器提供的所述第一代码工程的代码结构。Receive the code structure of the first code project provided by the third server.
第五方面,本申请实施例提供一种代码重构装置,所述代码重构装置包括处理单元和通信单元,所述代码重构装置用于执行第二方面或第二方面任一种可能的实施方式所描述的方法。In the fifth aspect, the embodiment of the present application provides a code reconstruction device, the code reconstruction device includes a processing unit and a communication unit, and the code reconstruction device is used to implement the second aspect or any possible method of the second aspect. The method described in the embodiment.
在第五方面的一种可能的实施方式中,所述通信单元,用于接收来自用户设备的重构请求消息,所述重构请求消息是根据在所述第一用户界面上输入的第一操作得到的,所述第一用户界面用于指示第一代码工程的代码结构,所述代码结构包含包、类、类成员或底层代码中的一种或多种元素,所述第一操作用于更新第一代码工程的代码结构;In a possible implementation manner of the fifth aspect, the communication unit is configured to receive a reconfiguration request message from the user equipment, where the reconfiguration request message is based on the first Obtained by the operation, the first user interface is used to indicate the code structure of the first code project, the code structure includes one or more elements in packages, classes, class members, or underlying codes, and the first operation uses for updating the code structure of the first code project;
所述处理单元,用于根据所述重构请求消息,对所述第一代码工程进行重构。The processing unit is configured to refactor the first code project according to the refactoring request message.
在第五方面的又一种可能的实施方式中,所述通信单元,还用于向所述用户设备反馈经过重构的所述第一代码工程。In yet another possible implementation manner of the fifth aspect, the communication unit is further configured to feed back the reconstructed first code project to the user equipment.
在第五方面的又一种可能的实施方式中,所述第一操作包含针对所述元素的移动、增加、删除、编辑等中的一项或者多项。In yet another possible implementation manner of the fifth aspect, the first operation includes one or more of moving, adding, deleting, editing, and the like for the element.
其中,移动操作可以更新代码结构中的元素的位置等。以移动类成员为例,用户可以将某一类成员从某一个类移动到另一个类。Wherein, the move operation may update the position of elements in the code structure and the like. Taking moving class members as an example, users can move a class member from one class to another.
增加操作可以增加元素,以增加类为例,用户可以创建新的类成员。以增加字段为例,用户可以封装新的字段。The adding operation can add elements. Taking adding a class as an example, the user can create a new class member. Taking adding fields as an example, users can encapsulate new fields.
删除操作可以移除、销毁某一元素。例如,用户可以删除包、删除类、删除类成员等。The delete operation can remove and destroy an element. For example, a user can delete a package, delete a class, delete a class member, etc.
编辑操作可以对元素进行更新。例如,用户可以变更字段的属性、修改类的名称、拆分类等等。Editing operations can update elements. For example, users can change the attributes of fields, modify the name of classes, split classes, and so on.
可选的,第一操作还包括滑动、缩放、指向、点击、长按等。其中,滑动、缩放等操作可以用于调整显示区域、页面大小等。其中,指向操作可以用于用户选择某一元素。点击操作可以用于用户选中元素、选择某一选项、或确认某一操作(如提交修改等)等。长按操作可以用于用户选中元素、移动元素、或删除元素等。Optionally, the first operation also includes sliding, zooming, pointing, clicking, long pressing, and the like. Wherein, operations such as sliding and zooming may be used to adjust a display area, a page size, and the like. Among them, the pointing operation can be used for the user to select an element. The click operation can be used for the user to select an element, select an option, or confirm an operation (such as submitting a modification, etc.). The long press operation can be used for the user to select an element, move an element, or delete an element, etc.
在第五方面的又一种可能的实施方式中,所述处理单元,还用于确定所述第一代码工程中存在的代码架构坏味道;In yet another possible implementation manner of the fifth aspect, the processing unit is further configured to determine a code architecture smell existing in the first code project;
所述通信单元,还用于向所述用户设备发送第一指示信息,所述第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道。The communication unit is further configured to send first indication information to the user equipment, where the first indication information is used to indicate a code architecture smell existing in the first code project.
在第五方面的又一种可能的实施方式中,所述第一代码工程中存在的代码架构坏味道对应于所述元素;In yet another possible implementation manner of the fifth aspect, the code architecture smell existing in the first code project corresponds to the element;
所述第一用户界面还用于通过颜色区分所述元素中存在代码架构坏味道的程度。The first user interface is also used to distinguish the degree of bad code structure smell in the elements by color.
在第五方面的又一种可能的实施方式中,所述处理单元,还用于通过架构坏味道检测模型,确定所述第一代码工程中的代码架构坏味道。In yet another possible implementation manner of the fifth aspect, the processing unit is further configured to determine a code architecture smell in the first code project by using an architecture smell detection model.
可选的,架构坏味道检测模型可以是通过强化学习、深度学习、或神经网络等一种或者多种方式训练得到的。Optionally, the architecture bad smell detection model can be obtained by training in one or more ways such as reinforcement learning, deep learning, or neural network.
在第五方面的又一种可能的实施方式中,所述处理单元,还用于对所述第一代码工程进行代码静态分析、文本相似度计算,得到所述第一代码工程中的代码架构坏味道。In yet another possible implementation manner of the fifth aspect, the processing unit is further configured to perform code static analysis and text similarity calculation on the first code project to obtain the code structure in the first code project bad taste.
在第五方面的又一种可能的实施方式中,所述处理单元还用于确定重构推荐,所述重构推荐用于提示用户针对所述第一代码工程中存在的代码架构坏味道对所述第一代码工程进行 修改;In yet another possible implementation manner of the fifth aspect, the processing unit is further configured to determine a refactoring recommendation, and the refactoring recommendation is used to prompt the user to respond to the bad code architecture smell existing in the first code project. said first code project is modified;
所述通信单元还用于向所述用户设备发送所述重构推荐。The communication unit is further configured to send the reconstruction recommendation to the user equipment.
在第五方面的又一种可能的实施方式中,所述重构请求消息包含所述原子重构序列,所述原子重构序列用于记录修改更新第一代码工程的操作顺序;In yet another possible implementation manner of the fifth aspect, the reconstruction request message includes the atomic reconstruction sequence, and the atomic reconstruction sequence is used to record an operation sequence of modifying and updating the first code project;
所述处理单元,还用于根据所述重构请求消息中的原子重构序列,对所述第一代码工程进行重构。The processing unit is further configured to reconstruct the first code project according to the atomic reconstruction sequence in the reconstruction request message.
在第五方面的又一种可能的实施方式中,所述原子重构序列包含多个原子重构操作,每个原子重构操作包含原子重构操作的标识和所述原子重构操作涉及的第一代码工程中的元素。In yet another possible implementation manner of the fifth aspect, the atomic reconstruction sequence includes multiple atomic reconstruction operations, and each atomic reconstruction operation includes an identifier of the atomic reconstruction operation and the Elements in the first code project.
在第五方面的又一种可能的实施方式中,所述通信单元,还用于接收来自所述用户设备的第一代码工程的指示信息;In yet another possible implementation manner of the fifth aspect, the communication unit is further configured to receive indication information of the first code project from the user equipment;
所述处理单元,还用于确定所述第一代码工程的代码结构;The processing unit is further configured to determine a code structure of the first code project;
所述通信单元,还用于向用户设备提供所述第一代码工程的代码结构。The communication unit is further configured to provide the code structure of the first code project to the user equipment.
第六方面,本申请实施例提供一种计算设备,该计算设备包括处理器和通信接口;所述通信接口用于接收和/或发送数据,和/或,所述通信接口用于为所述处理器提供输入和/或输出;所述处理器用于实现前述第一方面任一项、或第二方面任一项所描述的方法。In a sixth aspect, an embodiment of the present application provides a computing device, the computing device includes a processor and a communication interface; the communication interface is used to receive and/or send data, and/or the communication interface is used to provide the The processor provides input and/or output; the processor is used to implement the method described in any one of the first aspect or any one of the second aspect.
需要说明的是,上述第六方面所描述的计算设备所包含的处理器,可以是专门用于执行这些方法的处理器(便于区别称为专用处理器),也可以是通过调用计算机程序来执行这些方法的处理器,例如通用处理器。可选的,至少一个处理器还可以既包括专用处理器也包括通用处理器。It should be noted that the processor included in the computing device described in the sixth aspect above may be a processor dedicated to executing these methods (referred to as a dedicated processor for easy distinction), or it may be executed by calling a computer program Handlers for these methods, such as general-purpose handlers. Optionally, at least one processor may also include both a special-purpose processor and a general-purpose processor.
可选的,上述计算机程序可以存在存储器中。示例性的,存储器可以为非瞬时性(non-transitory)存储器,例如只读存储器(Read Only Memory,ROM),其可以与处理器集成在同一块器件上,也可以分别设置在不同的器件上,本申请实施例对存储器的类型以及存储器与处理器的设置方式不做限定。Optionally, the above computer programs may be stored in memory. Exemplarily, the memory can be a non-transitory (non-transitory) memory, such as a read-only memory (Read Only Memory, ROM), which can be integrated with the processor on the same device, or can be respectively arranged on different devices , the embodiment of the present application does not limit the type of the memory and the arrangement of the memory and the processor.
在一种可能的实施方式中,上述至少一个存储器位于上述计算设备之外。In a possible implementation manner, the at least one memory is located outside the computing device.
在又一种可能的实施方式中,上述至少一个存储器位于上述计算设备之内。In yet another possible implementation manner, the at least one memory is located within the computing device.
在又一种可能的实施方式之中,上述至少一个存储器的部分存储器位于上述计算设备之内,另一部分存储器位于上述计算设备之外。In yet another possible implementation manner, part of the memory of the at least one memory is located inside the computing device, and another part of the memory is located outside the computing device.
本申请中,处理器和存储器还可能集成于一个器件中,即处理器和存储器还可以被集成在一起。In this application, the processor and the memory may also be integrated into one device, that is, the processor and the memory may also be integrated together.
第七方面,本申请实施例提供一种代码重构系统,所述代码重构系统包含用户设备和服务器,所述用户设备包含第四方面任一项所述代码重构装置;所述服务器包含第五方面任一项所述的代码重构装置。In the seventh aspect, the embodiment of the present application provides a code reconstruction system, the code reconstruction system includes a user equipment and a server, the user equipment includes the code reconstruction device according to any one of the fourth aspect; the server includes The code reconstruction device according to any one of the fifth aspect.
第八方面,本申请实施例提供一种计算机可读存储介质,所述计算机可读存储介质中存储有指令,当所述指令在至少一个处理器上运行时,实现前述第一方面任一项或第二方面任一项所描述的方法。In the eighth aspect, the embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium stores instructions, and when the instructions are run on at least one processor, any one of the aforementioned first aspects is implemented. Or the method described in any one of the second aspect.
第九方面,本申请提供了一种计算机程序产品,计算机程序产品包括计算机指令,当所述指令在至少一个处理器上运行时,实现前述第一方面任一项或第二方面任一项所描述的方法。In a ninth aspect, the present application provides a computer program product, the computer program product includes computer instructions, and when the instructions are run on at least one processor, it can realize any one of the above-mentioned first aspect or any one of the second aspect. described method.
可选的,该计算机程序产品可以为一个软件安装包,在需要使用前述方法的情况下,可以下载该计算机程序产品并在计算设备上执行该计算机程序产品。Optionally, the computer program product may be a software installation package. If the aforementioned method needs to be used, the computer program product may be downloaded and executed on the computing device.
本申请第二至第九方面所提供的技术方法,其有益效果可以参考第一方面的技术方案的有益效果,此处不再赘述。For the beneficial effects of the technical methods provided in the second to ninth aspects of the present application, reference may be made to the beneficial effects of the technical solution in the first aspect, and details are not repeated here.
附图说明Description of drawings
下面将对实施例描述中所需要使用的附图作简单的介绍。The drawings that need to be used in the description of the embodiments will be briefly introduced below.
图1是本申请实施例提供的一种代码重构系统的架构示意图;FIG. 1 is a schematic diagram of the architecture of a code refactoring system provided by an embodiment of the present application;
图2是本申请实施例提供的一种代码重构方法的流程示意图;FIG. 2 is a schematic flowchart of a code reconstruction method provided by an embodiment of the present application;
图3A是本申请实施例提供的一种代码结构的层级的示意图;FIG. 3A is a schematic diagram of a code structure hierarchy provided by an embodiment of the present application;
图3B是本申请实施例提供的又一种代码结构的层级的示意图;FIG. 3B is a schematic diagram of another code structure hierarchy provided by the embodiment of the present application;
图3C是本申请实施例提供的再一种代码结构的层级的示意图;FIG. 3C is a schematic diagram of another code structure hierarchy provided by the embodiment of the present application;
图3D是本申请实施例提供的再一种代码结构的层级的示意图;FIG. 3D is a schematic diagram of another code structure hierarchy provided by the embodiment of the present application;
图4是本申请实施例提供的一种用户界面的示意图;Fig. 4 is a schematic diagram of a user interface provided by an embodiment of the present application;
图5是本申请实施例提供的又一种用户界面的示意图;Fig. 5 is a schematic diagram of another user interface provided by the embodiment of the present application;
图6是本申请实施例提供的再一种用户界面的示意图;Fig. 6 is a schematic diagram of another user interface provided by the embodiment of the present application;
图7是本申请实施例提供的一种操作的示意图;Fig. 7 is a schematic diagram of an operation provided by the embodiment of the present application;
图8是本申请实施例提供的又一种代码重构方法的流程示意图;Fig. 8 is a schematic flowchart of another code reconstruction method provided by the embodiment of the present application;
图9是本申请实施例提供的一种架构坏味道自动检测与重构方案推荐模块的工作流程图;Fig. 9 is a work flow chart of an architecture bad smell automatic detection and reconstruction scheme recommendation module provided by the embodiment of the present application;
图10是本申请实施例提供的一种代码重构装置的结构示意图;FIG. 10 is a schematic structural diagram of a code reconstruction device provided by an embodiment of the present application;
图11是本申请实施例提供的一种计算设备的结构示意图。FIG. 11 is a schematic structural diagram of a computing device provided by an embodiment of the present application.
具体实施方式Detailed ways
下面结合附图对本申请实施例进行详细介绍。Embodiments of the present application will be described in detail below in conjunction with the accompanying drawings.
为了便于理解,以下示例地给出了部分与本申请实施例相关概念的说明以供参考。如下所示:For ease of understanding, the following descriptions of some concepts related to the embodiments of the present application are provided by way of example for reference. As follows:
代码工程包含开发者按照一定的程序设计语言规范编写的代码文件。在本申请中,代码文件一般是指源代码文件。代码文件包括一系列人类可读的计算机语言指令,其可以通过编译器编译为计算机可以执行的二进制指令。当二进制指令被执行时,可以实现与该二进制指令相应的功能。Code engineering includes code files written by developers according to certain programming language specifications. In this application, code files generally refer to source code files. A code file includes a series of human-readable computer language instructions, which can be compiled into computer-executable binary instructions by a compiler. When the binary instruction is executed, the function corresponding to the binary instruction can be realized.
当然,代码工程中还可以包含其他文件,例如与代码工程的开发环境相关的配置文件、资源文件、参考资料文件等。本申请对此不做限制。Of course, the code project may also contain other files, such as configuration files, resource files, reference files, etc. related to the development environment of the code project. This application does not limit this.
在项目开发的过程中,虽然开发者会遵循一些开发规划、规范来进行开发,但是当业务结构复杂、进度紧张,或者随着时间迁移、版本不断迭代这些原因,代码可能会出现一些不良设计,这些不良设计也称为“坏味道”。示例性的,代码坏味道可以包含以下种类:重复代码、长函数、参数列表过长、循环依赖、或非稳定依赖等中的一项或者多项。In the process of project development, although developers will follow some development plans and specifications for development, when the business structure is complex, the schedule is tight, or due to time migration and version iterations, some bad designs may appear in the code. These bad designs are also known as "bad taste". Exemplarily, code smells may include one or more of the following types: repeated code, long functions, too long parameter lists, circular dependencies, or unstable dependencies.
坏味道的出现会影响代码工程的质量,而通过代码重构可以改善代码的结构,修改代码工程中的坏味道,调整程序代码改善软件的质量、性能,使其程序的设计模式和架构更趋合理,提高软件的扩展性和维护性。The emergence of bad smells will affect the quality of code engineering, and code refactoring can improve the structure of the code, modify the bad smells in code engineering, adjust the program code to improve the quality and performance of the software, and make the design pattern and structure of the program more Reasonable, improve the scalability and maintainability of the software.
开发人员发现代码中的不良设计往往需要较高的层面来了解整个代码工程,但是,重构修复这个不良设计却只能从底层的代码层面着手,修改具体的代码。开发人员在重构时往往需要在不同的代码层面中进行切换,从而导致代码重构效率低。Developers often need to understand the entire code project at a higher level when they find bad design in the code. However, refactoring and repairing this bad design can only start from the underlying code level and modify the specific code. Developers often need to switch between different code levels when refactoring, resulting in low code refactoring efficiency.
有鉴于此,本申请实施例提供了代码重构方法及装置,能够将代码结构的视图展示和代码重构集成一体,使得开发人员无需在不同的代码层面中进行切换,从而大大提升代码重构效率。另外,可视化的操作更降低了使用门槛,提升了用户的代码重构体验。In view of this, the embodiment of the present application provides a code refactoring method and device, which can integrate the view display of the code structure and code refactoring, so that developers do not need to switch between different code levels, thereby greatly improving code refactoring efficiency. In addition, the visual operation lowers the threshold of use and improves the user's code refactoring experience.
下面对本申请实施例的系统架构进行示例性地描述。需要说明的是,本申请描述的系统架构是为了更加清楚的说明本申请的技术方案,并不构成对于本申请提供的技术方案的限定,本领域普通技术人员可知,随着系统架构的演变和新业务场景的出现,本申请提供的技术方案对于类似的技术问题,同样适用。The system architecture of the embodiment of the present application is exemplarily described below. It should be noted that the system architecture described in this application is to illustrate the technical solution of this application more clearly, and does not constitute a limitation to the technical solution provided by this application. Those of ordinary skill in the art know that with the evolution of system architecture and For the emergence of new business scenarios, the technical solution provided by this application is also applicable to similar technical problems.
请参见图1,图1是本申请实施例提供的一种可能的代码重构系统的架构示意图。该代码重构系统10包含用户设备101和服务器102。可选的,系统10还包含服务器103和/或服务器104。Please refer to FIG. 1 . FIG. 1 is a schematic structural diagram of a possible code refactoring system provided by an embodiment of the present application. The code reconstruction system 10 includes a user device 101 and a server 102 . Optionally, the system 10 further includes a server 103 and/or a server 104 .
其中,用户设备101是具有数据处理、数据收发能力的电子设备,能够呈现用户界面并接收用户输入的操作。用户设备101可以包括台式机、笔记本电脑、手持终端、可穿戴设备、车辆、或机器人等独立设备,也可以是包含在独立设备中的部件(例如芯片或集成电路等)。示例性地,当终端装置为手持终端时,可以是手机(mobile phone)、平板电脑(pad)、或掌上电脑等。Wherein, the user equipment 101 is an electronic equipment capable of data processing and data sending and receiving, capable of presenting a user interface and receiving user input operations. The user equipment 101 may include an independent device such as a desktop computer, a notebook computer, a handheld terminal, a wearable device, a vehicle, or a robot, or may be a component included in an independent device (such as a chip or an integrated circuit, etc.). Exemplarily, when the terminal device is a handheld terminal, it may be a mobile phone, a tablet computer (pad), or a palmtop computer.
服务器102是具有数据处理的装置,能够对代码工程进行重构。应理解,此处便于描述称为服务器,其具体形式可以为实体装置如服务器、或主机等,也可以是虚拟装置如虚拟机、或容器等。可选的,服务器102可以独立的部署在一个设备中,也可以分布式的部署在多个设备上。The server 102 is a device having data processing, and is capable of refactoring code engineering. It should be understood that it is referred to as a server for convenience of description here, and its specific form may be a physical device such as a server or a host, or a virtual device such as a virtual machine or a container. Optionally, the server 102 may be independently deployed on one device, or may be distributed and deployed on multiple devices.
服务器103是具有数据处理能力的装置,能够确定代码工程中的坏味道,和/或,能够生成关于代码工程重构推荐。The server 103 is a device with data processing capabilities, capable of determining bad smells in code engineering, and/or, capable of generating refactoring recommendations for code engineering.
服务器104是具有数据处理能力的装置,能够生成代码工程的代码结构。The server 104 is a device having data processing capability, capable of generating a code structure of a code project.
需要说明的是,前述的服务器,例如服务器102、服务器103、或服务器104等,可以是独立的设备,也可以被集成在其他设备中,或者部分是独立的设备,部分集成在其他设备中。It should be noted that the aforementioned servers, such as server 102, server 103, or server 104, etc., may be independent devices, or may be integrated in other devices, or partly independent devices, partly integrated in other devices.
作为一种可能方案,服务器102(或服务器、或服务器104等)可以是运行在计算设备中的一个进程或者线程,能够进行数据处理。As a possible solution, the server 102 (or the server, or the server 104, etc.) may be a process or a thread running on a computing device, capable of data processing.
作为又一种可选的方法,前述的服务器102、服务器103、或服务器104,还可以被集成在同一个设备中。As yet another optional method, the foregoing server 102, server 103, or server 104 may also be integrated into the same device.
在上述四者中任意两者之间建立通信连接时,通信连接的链路可以包括一种或者多种类型的连接介质,包括有线链路(例如光纤)、无线链路或者有线链路和无线链路的组合等。例如连接介质可以为无线链路,该无线链路采用近距离连接技术,例如802.11b/g技术、蓝牙(Blue Tooth)技术、紫蜂(Zigbee)技术、无线射频识别(Radio Frequency Identification,RFID)技术、超宽带(Ultra Wideband,UWB)技术、无线短距通信(例如车载无线短距通信)技术或车联网(vehicle to everything,V2X,车对外界的信息交换)技术等。再如,该无线链路采用远距离连接技术,例如全球移动通信系统(Global System for Mobile communications,GSM)、通用分组无线业务(General Packet Radio Service,GPRS)、通用移动通信系统(Universal Mobile Telecommunications System,UMTS),LTE,或5G等无线接入类型技术。When a communication connection is established between any two of the above four, the link of the communication connection may include one or more types of connection media, including wired links (such as optical fibers), wireless links, or wired links and wireless combination of links, etc. For example, the connection medium can be a wireless link, and the wireless link adopts a short-distance connection technology, such as 802.11b/g technology, Bluetooth (Blue Tooth) technology, Zigbee (Zigbee) technology, radio frequency identification (Radio Frequency Identification, RFID) technology, ultra-wideband (Ultra Wideband, UWB) technology, wireless short-range communication (such as vehicle-mounted wireless short-distance communication) technology or vehicle networking (vehicle to everything, V2X, information exchange between vehicles and the outside world) technology, etc. For another example, the wireless link adopts long-distance connection technology, such as Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Universal Mobile Telecommunications System (Universal Mobile Telecommunications System) , UMTS), LTE, or 5G and other wireless access technologies.
在一种可能的设计中,前述的服务器,例如服务器102、服务器103、或服务器104等可以部署在云平台中。其中,云平台包含云服务提供商提供的大量基础资源(包括但不限于计算资源、记录资源、或网络资源等),其中计算资源可以由一种或者多种计算模块提供(例如 机架式服务器、刀片式服务器、或虚拟机等)。In a possible design, the foregoing servers, such as the server 102, the server 103, or the server 104, may be deployed on a cloud platform. Among them, the cloud platform includes a large number of basic resources provided by cloud service providers (including but not limited to computing resources, recording resources, or network resources, etc.), where computing resources can be provided by one or more computing modules (such as rack server , blade server, or virtual machine, etc.).
在一种可能的实施场景中,上述代码重构系统中由服务器所完成的功能,能够由云服务提供商在云平台抽象成代码重构云服务提供给用户。例如,用户购买代码重构云服务之后,云平台响应于用户的请求操作,在云服务提供商提供的资源上对代码工程进行重构,然后向用户提供重构后的代码工程。相应的,用户所使用的用户设备可以呈现界面、使用代码重构云服务。In a possible implementation scenario, the functions performed by the server in the above code reconstruction system can be abstracted into code reconstruction cloud services by the cloud service provider on the cloud platform and provided to users. For example, after a user purchases a code refactoring cloud service, the cloud platform responds to the user's request, refactors the code project on the resources provided by the cloud service provider, and then provides the user with the refactored code project. Correspondingly, the user equipment used by the user can present the interface and use the code to reconstruct the cloud service.
需要说明的是,在本申请实施例中,云平台可以是中心云的云平台、边缘云的云平台或包括中心云和边缘云的云平台,本申请实施例对其不做具体限定。并且,当云平台为包括中心云和边缘云的云平台时,该代码重构系统可以部分部署在边缘云的云平台中,部分部署在中心云的云平台中。It should be noted that, in the embodiment of the present application, the cloud platform may be a cloud platform of the central cloud, a cloud platform of the edge cloud, or a cloud platform including the central cloud and the edge cloud, which is not specifically limited in the embodiment of the present application. Moreover, when the cloud platform includes a central cloud and an edge cloud, the code reconstruction system may be partially deployed on the edge cloud cloud platform and partially deployed on the central cloud cloud platform.
下面对本申请实施例的方法进行详细介绍。The method in the embodiment of the present application will be described in detail below.
【实施例一】[Example 1]
请参见图2,图2是本申请实施例提供的一种代码重构方法的流程示意图。可选的,该方法可以应用于图1所示的系统中。Please refer to FIG. 2 . FIG. 2 is a schematic flowchart of a code refactoring method provided by an embodiment of the present application. Optionally, the method can be applied to the system shown in FIG. 1 .
如图2所示的代码重构方法可以包括步骤S201至步骤S205。应理解,本申请为了方便描述,故通过S201至S205这一顺序进行描述,并不旨在限定一定通过上述顺序进行执行。本申请实施例对于上述一个或多个步骤的执行的先后顺序、执行的时间、执行的次数等不做限定。S201至步骤S205具体如下:The code reconstruction method shown in FIG. 2 may include steps S201 to S205. It should be understood that, for the convenience of description, the present application uses the sequence of S201 to S205 for description, and does not intend to limit the execution to be performed in the above sequence. The embodiment of the present application does not limit the execution sequence, execution time, and execution times of the above one or more steps. Step S201 to step S205 are as follows:
步骤S201:用户设备呈现第一用户界面。Step S201: the user equipment presents a first user interface.
第一用户界面用于指示代码工程的代码结构。代码工程的代码结构包含了第一代码工程中的一种或者多种元素。The first user interface is used to indicate the code structure of the code project. The code structure of the code project includes one or more elements in the first code project.
示例性地,代码结构包含包、类、类成员或底层代码中的一种或多种元素。进一步的,以包元素的形式展示代码工程的代码结构时,该代码工程的代码结构也可以称为代码工程的包结构。类似地,以类元素的形式展示代码工程的代码结构时,该代码工程的代码结构也可以称为代码工程的类结构。其余元素也可以如此类推,此处不再一一赘述。Exemplarily, the code structure includes one or more elements in packages, classes, class members, or underlying code. Further, when the code structure of the code project is displayed in the form of package elements, the code structure of the code project may also be called the package structure of the code project. Similarly, when the code structure of the code project is displayed in the form of class elements, the code structure of the code project may also be called the class structure of the code project. The rest of the elements can also be analogized in the same way, and will not be repeated here.
作为一种可能的方案,代码结构包含多个层级,每一个层级用于主要展示某一种元素。例如,主要展示包元素的代码结构层级称为包结构,主要展示累元素的代码机构层级称为类结构,其他层级以此类推。进一步的,不同层级之间可以进行切换,便于用户从各个层级了解代码工程的代码结构。As a possible solution, the code structure contains multiple levels, and each level is used to mainly display a certain kind of element. For example, the code structure level that mainly displays package elements is called package structure, the code structure level that mainly shows cumulative elements is called class structure, and so on for other levels. Further, different levels can be switched, which is convenient for users to understand the code structure of the code project from each level.
示例性的,请参见图3A、图3B、图3C和图3D,图3A、图3B、图3C和图3D是本申请实施例提供的几种可能的代码结构的层级的示意图。图3A用于示例性地展示代码工程的包结构,其中,包结构可以是全局的、也可以局部的,便于用户根据需求了解代码工程的包元素。作为一种可能的方案,用户设备接收用户输入的针对局部包结构的操作,可以展示局部包结构。示例性地,用户点击其中一个包,可以进入如图3B所示代码工程的类结构图,类结构图中可以展示类名称、参数、方法等中一项或者多项。示例性地,用户点击其中一个类,可以进入如图3C所示代码工程的类成员结构图。类成员结构图可以展示类中的方法、属性或其它类成员等中的一项或者多项。示例性的,用户点击其中一个类成员,可以展示该类成员相关的源代码,如图3D所示。For example, please refer to FIG. 3A , FIG. 3B , FIG. 3C and FIG. 3D . FIG. 3A , FIG. 3B , FIG. 3C and FIG. 3D are schematic diagrams of levels of several possible code structures provided by the embodiments of the present application. FIG. 3A is used to exemplarily show the package structure of the code project, wherein the package structure can be global or local, so that users can understand the package elements of the code project according to requirements. As a possible solution, the user equipment may display the partial packet structure after receiving an operation input by the user for the partial packet structure. Exemplarily, the user clicks one of the packages to enter the class structure diagram of the code project as shown in FIG. 3B . The class structure diagram can display one or more items of class names, parameters, methods, and the like. Exemplarily, the user clicks on one of the classes to enter the class member structure diagram of the code project as shown in FIG. 3C . A class member structure diagram can display one or more of the methods, attributes, or other class members in the class. Exemplarily, when the user clicks on one of the class members, the source code related to the class member may be displayed, as shown in FIG. 3D .
可选的,代码工程的数量可以是一个、也可以是多个,为了便于描述,以下第一代码工程为例进行说明。Optionally, there may be one code project or multiple code projects. For ease of description, the following first code project is taken as an example for illustration.
示例性地,请参见图4,图4是本申请实施例提供的一种可能的用户界面的示意图。用户界面401中包含多个界面组件,每个界面组件用于展示代码结构的一种或者多种元素。示例性的,如用户界面401中的界面组件402用于展示代码结构中的包,其中,如区域403所示的矩形框用于展示包的名称。为了便于理解,图4以“包1”“包2”等用于示例性的描述包的名称,并不表示对包的展示形式的限定,本申请对于元素的名称、元素的个数等不做限定。For example, please refer to FIG. 4 , which is a schematic diagram of a possible user interface provided by an embodiment of the present application. The user interface 401 includes multiple interface components, and each interface component is used to display one or more elements of the code structure. Exemplarily, the interface component 402 in the user interface 401 is used to display the package in the code structure, wherein the rectangular box shown in the area 403 is used to display the name of the package. For ease of understanding, Figure 4 uses "package 1", "package 2" and so on to describe the name of the package as an example, and does not represent a limitation on the display form of the package. Do limited.
可选的,用户界面还可以展示元素之间的联系。其中,元素之间的联系可以包含元素之间的调用关系、包含关系、引用关系、或依赖关系等。示例性的,图4所示的用户界面中,包4中可以包含包5和包6,而包1和包2之间可以存在依赖关系。Optionally, the user interface can also display connections between elements. Wherein, the relationship between the elements may include a call relationship, a containment relationship, a reference relationship, or a dependency relationship between the elements. Exemplarily, in the user interface shown in FIG. 4 , package 4 may include package 5 and package 6 , and there may be a dependency relationship between package 1 and package 2 .
可选的,第一代码工程的代码结构可以是通过如下两种方式获取的:Optionally, the code structure of the first code project can be obtained in the following two ways:
方式一,第一代码工程的代码结构可以是用户设备自己生成的。例如,第一代码工程存储在用户设备中,用户设备分析第一代码工程从而生成第一代码工程的代码结构。进一步的,用户设备通过第一用户界面展示第一代码工程的代码结构。Mode 1, the code structure of the first code project may be generated by the user equipment itself. For example, the first code project is stored in the user equipment, and the user equipment analyzes the first code project to generate a code structure of the first code project. Further, the user equipment displays the code structure of the first code project through the first user interface.
方式二,第一代码工程的代码结构可以是其他装置(例如服务器、或与用户装置相关的其他终端、或者用户设备对应的管理装置等)提供给用户设备的。例如,服务器(为了便于区别以下称为第三服务器)可以向用户设备提供第一代码工程的代码结构。Mode 2, the code structure of the first code project may be provided to the user equipment by other devices (such as a server, or other terminals related to the user equipment, or a management device corresponding to the user equipment, etc.). For example, the server (hereinafter referred to as the third server for ease of distinction) may provide the user equipment with the code structure of the first code project.
进一步的,用户设备可以向第三服务器发送请求消息,第三服务器响应用户设备的请求从而向用户设备反馈第一代码工程的代码结构。其中,请求消息可以包含第一代码工程的指示信息(便于区分称为第二指示信息),第二指示信息例如:第一代码工程本身、第一代码工程的标识(identify,ID)、第一代码工程的编号、第一代码工程所属的用户ID、第一代码工程所在的设备ID或第一代码工程的名称等。Further, the user equipment may send a request message to the third server, and the third server responds to the request of the user equipment to feed back the code structure of the first code project to the user equipment. Wherein, the request message may include indication information of the first code project (referred to as second indication information for convenience of distinction), and the second indication information is, for example: the first code project itself, the identification (identify, ID) of the first code project, the first The code project number, the user ID to which the first code project belongs, the device ID where the first code project is located, or the name of the first code project, etc.
示例性的,用户设备向第三服务器提供第一代码工程,第三服务器分析第一代码工程从而向用户设备反馈第一代码工程的代码结构。Exemplarily, the user equipment provides the first code project to the third server, and the third server analyzes the first code project to feed back the code structure of the first code project to the user equipment.
再如,代码工程存储在代码托管服务器中,并且使用ID进行区分。用户设备向第三服务器提供第一代码工程的ID,第三服务器基于第一代码工程的ID获取第一代码工程,分析第一代码工程从而向用户设备反馈第一代码工程的代码结构。For another example, the code engineering is stored in the code hosting server, and IDs are used for identification. The user equipment provides the ID of the first code project to the third server, and the third server acquires the first code project based on the ID of the first code project, analyzes the first code project, and feeds back the code structure of the first code project to the user equipment.
可选的,前述的第一服务器和第三服务器可能是同一个服务器,或者第一服务器和第三服务器可以包含于同一个服务器中。进一步的,第一服务器、第二服务器和第三服务器可能是同一个服务器,或者第一服务器、第二服务器和第三服务器可以包含于同一个服务器中。Optionally, the foregoing first server and the third server may be the same server, or the first server and the third server may be included in the same server. Further, the first server, the second server and the third server may be the same server, or the first server, the second server and the third server may be included in the same server.
在一种可能的设计中,第一用户界面还用于指示第一代码工程中存在的代码架构坏味道。其中,代码架构坏味道是指代码工程中的不良设计,例如重复代码、长函数、参数列表过长、循环依赖、或非稳定依赖等中的一项或者多项。应理解,代码架构坏味道的种类、判定规则等可以是由计算机程序管理机构、企业、法律法规、或者用户等定义或者配置的,本申请对于以不同方式设置的代码架构坏味道均适用。In a possible design, the first user interface is also used to indicate code architecture smells existing in the first code project. Among them, bad code architecture smell refers to bad design in code engineering, such as one or more of repeated code, long function, too long parameter list, circular dependency, or unstable dependency. It should be understood that the types of code architecture smells, judgment rules, etc. may be defined or configured by computer program management agencies, enterprises, laws and regulations, or users, and this application is applicable to code architecture smells set in different ways.
为了便于理解,本申请示例性的列举以下几种可能的方案:For ease of understanding, this application exemplifies the following possible solutions:
方案1:第一用户界面还用于指示第一代码工程中是否存在代码架构坏味道。Solution 1: the first user interface is also used to indicate whether there is a code architecture smell in the first code project.
进一步的,在第一代码工程中是否存在代码架构坏味道时,用户设备可以在第一用户界面上呈现提醒信息,该提醒信息可以提醒用户第一代码工程中存在代码架构坏味道。Further, when there is a bad code architecture smell in the first code project, the user equipment may present a reminder message on the first user interface, and the reminder message may remind the user that there is a code architecture smell in the first code project.
方案2:第一用户界面还用于指示第一代码工程中存在的代码架构坏味道的内容,代码坏味道的内容包含代码坏味道的编号、类型等。其中,第一代码工程中存在的代码架构坏味道的数量可以是一个,也可以是多个。示例性的,请参见图5,图5所示为本申请实施例提 供的又一种可能的用户界面的示意图。其中,区域502用于指示第一代码工程的代码结构,区域501用于展示第一代码工程中存在的代码架构坏味道的内容。示例性的,第一代码工程中存在以下代码架构坏味道:循环依赖、非稳定依赖等。Scheme 2: The first user interface is also used to indicate the content of the code architecture smell existing in the first code project, and the content of the code smell includes the number and type of the code smell. Wherein, the number of code architecture bad smells existing in the first code project may be one or more. For example, please refer to Fig. 5, which is a schematic diagram of another possible user interface provided by the embodiment of the present application. Among them, the area 502 is used to indicate the code structure of the first code project, and the area 501 is used to display the bad smell of the code structure existing in the first code project. Exemplarily, the following bad code architecture smells exist in the first code project: circular dependencies, unstable dependencies, and the like.
方案3:第一用户界面还用于指示第一代码工程中存在的代码架构坏味道的元素,或者,用于指示第一代码工程中存在的代码架构坏味道的位置。Solution 3: The first user interface is further used to indicate the elements of the code architecture smell existing in the first code project, or to indicate the location of the code architecture smell existing in the first code project.
其中,存在的代码架构坏味道的元素与不存在的代码架构坏味道的元素在显示上进行区分。示例性的,如图5所示,存在代码架构坏味道的元素以黑色矩形组件显示(如组件503所示),而不存在的代码架构坏味道的元素通过其他颜色的矩形组件显示。Among them, elements with bad code architecture smell that exist are distinguished from elements with bad code architecture smell that do not exist. Exemplarily, as shown in FIG. 5 , elements with bad code architecture smell are displayed by black rectangle components (as shown in component 503 ), and elements without code architecture smell are displayed by rectangle components of other colors.
方案4:第一用户界面还用于通过颜色区分所述元素中存在代码架构坏味道的程度。在这里的程度包含数量多少的程度、代码架构坏味道的严重程度或代码架构坏味道的紧急程度中的一项或者多项。Solution 4: The first user interface is also used to distinguish the degree of bad code architecture smell in the elements through colors. The degree here includes one or more of the degree of quantity, the severity of the code architecture smell, or the urgency of the code architecture smell.
例如,当元素中存在的代码架构坏味道的数量越多,则该元素在显示时具有更引人注目的显示效果。例如,当元素中存在的坏味道的数量落入[1,5]这一区间,则该元素使用第一颜色来显示;当元素中存在的坏味道的数量落入[6,10]这一区间,则该元素使用第二颜色来显示;当元素中存在的坏味道的数量大于10,则该元素使用第三颜色来显示。其中,第三颜色比第一颜色和第二颜色具有更高的亮度,第二颜色比第二颜色具有更高的亮度。For example, an element has a more compelling display when displayed when the greater the number of code architecture smells present in the element. For example, when the number of bad tastes in an element falls within the interval [1,5], the element is displayed with the first color; when the number of bad tastes in an element falls into the interval [6,10] range, the element is displayed with the second color; when the number of bad tastes in the element is greater than 10, the element is displayed with the third color. Wherein, the third color has higher brightness than the first color and the second color, and the second color has higher brightness than the second color.
再如,不同代码架构坏味道对代码工程带来的负面影响不同,使得不同种类的代码架构坏味道具有不同的紧急等级。当元素中存在的代码架构坏味道的紧急等级越高,则该元素在显示时具有更引人注目的显示效果。For another example, different code architecture smells have different negative impacts on code engineering, so different types of code architecture smells have different urgency levels. The higher the urgency level of a code architecture smell present in an element, the more compelling the element is when displayed.
一种可能的设计中,通过热力图可以区分元素中存在代码架构坏味道的程度,其中,热力图是一种以特殊显示(例如高亮、高饱和度、或绚丽的显示效果等)的形式显示用户更在意的页面区域的图示。In one possible design, the degree of bad code architecture in elements can be distinguished through heat maps, where heat maps are displayed in the form of special (such as highlighting, high saturation, or brilliant display effects, etc.) A diagram showing areas of the page that users care about more.
应理解,上述方案为示例性的方案,在具体设计中,还可以有更多方案用于提示用户第一代码工程中的代码架构坏味道。例如,通过声、光、电、震动等提示用户。上述方案还可以在不互斥的情况下结合,此处不在一一赘述。It should be understood that the above solution is an exemplary solution, and in a specific design, there may be more solutions for reminding the user of bad code architecture smells in the first code project. For example, the user is prompted by sound, light, electricity, vibration, etc. The above-mentioned solutions can also be combined under the condition that they are not mutually exclusive, and details will not be repeated here.
可选的,第一代码工程中存在的代码架构坏味道可以是用户设备确定的,也可以是通过其他装置(例如服务器、或与用户装置相关的其他终端、或者用户设备对应的管理装置等)确定的。为了便于理解,本申请示例性的列举以下几种可能的实现方式:Optionally, the bad code structure smell in the first code project may be determined by the user equipment, or through other devices (such as a server, or other terminals related to the user device, or a management device corresponding to the user device, etc.) definite. For ease of understanding, this application exemplifies the following possible implementations:
实现方式1,第一代码工程中存在的代码架构坏味道可以由用户设备确定。此时,用户设备可以分析第一代码工程,得到第一代码工程的代码架构坏味道。进一步的,在呈现用户界面时,将第一代码工程中的代码架构坏味道和第一代码工程的代码结构融合在一起呈现。Implementation mode 1, the code architecture smell existing in the first code project may be determined by the user equipment. At this time, the user equipment may analyze the first code project to obtain the bad smell of the code structure of the first code project. Further, when presenting the user interface, the bad smell of the code architecture in the first code project and the code structure of the first code project are fused together for presentation.
实现方式2,第一代码工程中存在的代码架构坏味道可以是其他装置提供给用户设备的。例如,服务器(为了便于区别以下称为第二服务器)可以向用户设备提供第一代码工程中存在的代码架构坏味道。Implementation mode 2, the bad smell of the code structure existing in the first code project may be provided to the user equipment by other devices. For example, the server (hereinafter referred to as the second server for ease of distinction) may provide the user equipment with the code architecture smell existing in the first code project.
进一步的,用户设备可以向第二服务器发送请求消息,第二服务器响应用户设备的请求,分析第一代码工程中的代码架构坏味道,向用户设备提供第一代码工程的第一指示信息,第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道。Further, the user equipment may send a request message to the second server, and the second server responds to the request of the user equipment, analyzes the bad smell of the code architecture in the first code project, and provides the user equipment with the first instruction information of the first code project. The indication information is used to indicate the bad smell of the code architecture existing in the first code project.
可选的,前述的第一服务器和第二服务器可能是同一个服务器,或者第一服务器和第二服务器可以包含于同一个服务器中。Optionally, the foregoing first server and the second server may be the same server, or the first server and the second server may be included in the same server.
在一种可能的设计中,第一用户界面还用于指示重构推荐。该重构推荐用于提示用户针对所述第一代码工程中存在的代码架构坏味道对所述第一代码工程进行修改。In a possible design, the first user interface is also used to indicate reconstruction recommendations. The refactoring recommendation is used to prompt the user to modify the first code project for the bad code architecture smell existing in the first code project.
示例性的,请参见图6,图6是本申请实施例提供的又一种可能的用户界面的示意图。其中,区域601用于指示第一代码工程的代码结构,区域602用于展示第一代码工程中存在的代码架构坏味道的内容。如区域603所示的组件用于展示第一代码工程中类的信息,类的信息包含类名称(如区域604所示)、类的参数(如区域605所示)、或类中的方法(如区域606所示)等中的一项或者多项。示例性地,类名称例如可以为“SpecialOrder”(即用于处理特殊订单业务的类,或称为特殊订单类)、“Customer(即用于处理顾客的类,或称为顾客类)”、“Order(即用于处理订单的类,或称为订单类)”、“NormalOrder(即用于处理常规订单的类,或称为常规订单类)”等。类的参数可选可以包含参数名以及参数的数据类型,例如,参数name的数据类型为字符串(图6表示为:String)、参数date的数据类型为日期格式(图6表示为:Date)。类中的方法通常以“方法名()”的形式展示,例如:“SendOrder()”、“ReceiveOrder()”、“GetOrderDate()”、“Confirm()”、“Close()”、“Dispatch()”、“Receive()”等。For example, please refer to FIG. 6 . FIG. 6 is a schematic diagram of another possible user interface provided by an embodiment of the present application. Among them, the area 601 is used to indicate the code structure of the first code project, and the area 602 is used to display the contents of the bad smell of the code structure existing in the first code project. The components shown in the area 603 are used to display the information of the class in the first code project, and the information of the class includes the class name (as shown in the area 604), the parameters of the class (as shown in the area 605), or the method in the class ( One or more of the above, as shown in area 606). Exemplarily, the class name can be, for example, "SpecialOrder" (that is, a class for processing special order business, or called a special order class), "Customer (that is, a class for processing customers, or called a customer class)", "Order (that is, the class used to process orders, or called the order class)", "NormalOrder (that is, the class used to process regular orders, or called the normal order class)" and so on. The parameters of the class can optionally include the parameter name and the data type of the parameter. For example, the data type of the parameter name is a string (represented as: String in Figure 6), and the data type of the parameter date is a date format (represented as: Date in Figure 6) . The methods in the class are usually displayed in the form of "method name ()", for example: "SendOrder()", "ReceiveOrder()", "GetOrderDate()", "Confirm()", "Close()", "Dispatch ()", "Receive()", etc.
在图6中,通过加粗和下划线所展示的内容,是第一代码工程中的“特性依恋”架构坏味道(即:类结构中的GetOrderDate()方法使得第一代码工程的类结构中存在架构坏味道)。如区域607所示,第一用户界面中还指示了消除此架构坏味道的重构推荐,用于提示用户:GetOrderDate()方法更适宜被移动到Order类中。In Figure 6, the content shown in bold and underlined is the bad smell of the "feature attachment" architecture in the first code project (that is, the GetOrderDate() method in the class structure makes the class structure of the first code project exist. architecture smells bad). As shown in area 607, the first user interface also indicates a refactoring recommendation to eliminate the bad smell of this architecture, which is used to prompt the user: the GetOrderDate() method is more suitable to be moved to the Order class.
可选的,重构推荐可以是用户设备确定的,也可以是通过其他装置(例如服务器、或与用户装置相关的其他终端、或者用户设备对应的管理装置等)确定的。为了便于理解,本申请示例性的列举以下几种可能情况:Optionally, the reconstruction recommendation may be determined by the user equipment, or determined by other devices (such as a server, or other terminals related to the user device, or a management device corresponding to the user device, etc.). For ease of understanding, this application exemplifies the following possible situations:
情况1,重构推荐可以由用户设备确定。此时,用户设备可以分析第一代码工程,确定针对第一代码工程的重构推荐。In case 1, the reconstruction recommendation may be determined by the user equipment. At this time, the user equipment may analyze the first code project to determine a refactoring recommendation for the first code project.
作为一种可选的方案,用户设备在呈现用户界面时,将重构推荐和第一代码工程的代码结构融合在一起呈现。As an optional solution, when the user equipment presents the user interface, the reconstruction recommendation and the code structure of the first code project are fused together for presentation.
可选的,在用户设备获取了第一代码工程的架构坏味道时,还可以将第一代码工程的架构坏味道、重构推荐和第一代码工程的代码结构融合在一起呈现。Optionally, when the user equipment acquires the architectural smell of the first code project, the architectural smell of the first code project, the refactoring recommendation, and the code structure of the first code project may also be presented together.
情况2,重构推荐可以是其他装置提供给用户设备的。例如,服务器(为了便于区别以下称为第二服务器)可以向用户设备提供第一代码工程中存在的代码架构坏味道。In case 2, the reconstruction recommendation may be provided to the user equipment by other devices. For example, the server (hereinafter referred to as the second server for ease of distinction) may provide the user equipment with the code architecture smell existing in the first code project.
进一步的,用户设备可以向第二服务器发送请求消息,第二服务器响应用户设备的请求,确定重构推荐,向用户设备提供重构推荐。Further, the user equipment may send a request message to the second server, and the second server responds to the request of the user equipment, determines the reconstruction recommendation, and provides the reconstruction recommendation to the user equipment.
作为一种可选的方案,第二服务器还可以向用户设备提供第一用户界面,第一用户界面融合了重构推荐和第一代码工程的代码结构。可选的,在第二服务器确定了第一代码工程的架构坏味道时,第一用户界面还可以融合了第一代码工程的架构坏味道、重构推荐和第一代码工程的代码结构。As an optional solution, the second server may also provide the user equipment with a first user interface, where the first user interface combines the code structure of the refactoring recommendation and the first code engineering. Optionally, when the second server determines the architectural smell of the first code project, the first user interface may also incorporate the architectural smell of the first code project, the refactoring recommendation, and the code structure of the first code project.
步骤S202:用户设备接收用户在第一用户界面上输入的第一操作。Step S202: the user equipment receives a first operation input by the user on the first user interface.
具体地,第一操作用于更新所述第一代码工程的代码结构。Specifically, the first operation is used to update the code structure of the first code project.
可选的,第一操作可以包含针对所述元素的移动、增加、删除、编辑、滑动、缩放、指向、点击、长按等中的一项或者多项。Optionally, the first operation may include one or more items of moving, adding, deleting, editing, sliding, zooming, pointing, clicking, long pressing, etc. for the element.
其中,移动操作可以更新代码结构中的元素的位置等。以移动类成员为例,用户可以将某一类成员从某一个类移动到另一个类。示例性地,用户设备可以呈现如图6所示的用户界面,用户在该用户界面中,可以将GetOrderDate()方法拖动到Order类中。相应的,用户设备则接收用户针对GetOrderDate()方法的移动操作。Wherein, the move operation may update the position of elements in the code structure and the like. Taking moving class members as an example, users can move a class member from one class to another. Exemplarily, the user equipment may present a user interface as shown in FIG. 6 , and the user may drag the GetOrderDate() method into the Order class in the user interface. Correspondingly, the user equipment receives the mobile operation of the user for the GetOrderDate() method.
增加操作可以增加元素,以增加类为例,用户可以创建新的类成员。以增加字段为例, 用户可以封装新的字段。以图4为例,用户可以创建一个新的包,例如称为“包7”。The adding operation can add elements. Taking adding a class as an example, the user can create a new class member. Taking adding fields as an example, users can encapsulate new fields. Taking Figure 4 as an example, the user can create a new package, for example called "package 7".
删除操作可以移除、销毁某一元素。例如,用户可以删除包、删除类、删除类成员、或删除依赖关系等。例如,在图6所示的用户界面中,用户可以删除顾客类中location字段。The delete operation can remove and destroy an element. For example, users can delete packages, delete classes, delete class members, or delete dependencies, etc. For example, in the user interface shown in Figure 6, the user can delete the location field in the customer class.
编辑操作可以对代码工程中元素进行更新。例如,用户可以变更字段的属性、修改类的名称、拆分类等等。以图4为例,用户可以在用户界面上重新命名包的名称,例如将“包4”重新命名为“包8”。Editing operations can update elements in the code project. For example, users can change the attributes of fields, modify the name of classes, split classes, and so on. Taking FIG. 4 as an example, the user can rename the name of the package on the user interface, for example, rename "package 4" to "package 8".
其中,滑动、缩放等操作可以用于调整显示区域、页面大小等。例如,在用户界面上进行滑动,可以将显示区域调整到某一区域。再如,如图7所示是本申请实施例提供的一种可能的操作的示意图,通过缩放操作,用户界面可以查看图7中的(a)部份所示的结构中的部分区域,即图7中的(b)部分所示的结构,从而可以更清晰的查看元素,便于对元素进行更新。Wherein, operations such as sliding and zooming may be used to adjust a display area, a page size, and the like. For example, sliding on the user interface can adjust the display area to a certain area. For another example, as shown in FIG. 7 is a schematic diagram of a possible operation provided by the embodiment of the present application. Through the zoom operation, the user interface can view a part of the structure shown in part (a) of FIG. 7, namely The structure shown in part (b) of FIG. 7 makes it possible to view the elements more clearly and facilitate updating of the elements.
其中,指向操作可以用于用户选择某一元素。点击操作可以用于用户选中元素、选择某一选项、或确认某一操作(如提交修改等)等。长按操作可以用于用户选中元素、移动元素、或删除元素等。Among them, the pointing operation can be used for the user to select an element. The click operation can be used for the user to select an element, select an option, or confirm an operation (such as submitting a modification, etc.). The long press operation can be used for the user to select an element, move an element, or delete an element, etc.
应理解,第一操作可以是一个操作,也可以多个操作。在第一操作为多个操作时,用户设备可以记录用户在第一用户界面上输入的多个操作。It should be understood that the first operation may be one operation or multiple operations. When the first operation is multiple operations, the user equipment may record multiple operations input by the user on the first user interface.
步骤S203:用户设备基于所述第一操作向第一服务器请求重构所述第一代码工程。Step S203: the user equipment requests reconstruction of the first code project from the first server based on the first operation.
具体地,第一操作用于更新所述第一代码工程的代码结构,因此用户设备基于用户输入的操作,可以向第一服务器请求重构所述第一代码工程。Specifically, the first operation is used to update the code structure of the first code project, so the user equipment may request the first server to reconstruct the first code project based on the operation input by the user.
例如,用户设备可以向第一服务器发送重构请求消息,重构请求消息中包含第一操作对应的指示信息。相应的,第一服务器可以接收该重构请求消息。For example, the user equipment may send a reconstruction request message to the first server, where the reconstruction request message includes indication information corresponding to the first operation. Correspondingly, the first server may receive the reconstruction request message.
在一种可能的设计中,第一操作对应的指示信息可以包含原子重构序列。具体地,用户设备根据输入的第一操作,可以生成原子重构序列,该原子重构序列用于记录更新第一代码工程的操作顺序。用户设备可以向第一服务器发送该原子重构序列,该原子重构序列用于服务器按照用户地操作顺序重构第一代码工程。In a possible design, the indication information corresponding to the first operation may include an atomic reconstruction sequence. Specifically, the user equipment may generate an atomic reconstruction sequence according to the input first operation, and the atomic reconstruction sequence is used to record an operation sequence for updating the first code project. The user equipment may send the atomic reconstruction sequence to the first server, and the atomic reconstruction sequence is used for the server to reconstruct the first code project according to the user's operation sequence.
作为一种可能的方案,原子重构序列包含多个原子重构操作,每个原子重构操作包含原子重构操作的标识和所述原子重构操作涉及的第一代码工程中的参数(便于描述以下称为控制参数)。为了便于理解,表1示例性地列举了一种可能的原子重构操作的标识与对应的控制参数。其中,重构操作的标识例如为“movemethod”、“movefield”等,对应了用户对方法移动操作和对字段的移动操作。而移动方法时,控制参数包含源(source)、目标(target)、方法名(method),分别用于记录该方法从哪里开始移动、移动的目的地以及该方法的名称。As a possible solution, the atomic reconstruction sequence includes multiple atomic reconstruction operations, and each atomic reconstruction operation includes an identifier of the atomic reconstruction operation and parameters in the first code project involved in the atomic reconstruction operation (for convenience described below as control parameters). For ease of understanding, Table 1 exemplarily lists a possible identifier of an atomic reconstruction operation and corresponding control parameters. Wherein, the identifiers of the refactoring operations are, for example, "movemethod", "movefield", etc., which correspond to the user's method move operation and field move operation. When moving a method, the control parameters include source (source), target (target), and method name (method), which are used to record where the method starts to move, the destination of the move, and the name of the method.
表1原子重构操作的标识与参数Table 1 Identification and parameters of atomic reconstruction operation
Figure PCTCN2022129822-appb-000001
Figure PCTCN2022129822-appb-000001
Figure PCTCN2022129822-appb-000002
Figure PCTCN2022129822-appb-000002
示例性地,用户移动方法时(如图6所示,用户可以移动GetOrderDate()方法),用户设备记录该操作的标识(即movemethod)和控制参数(即:“source:Customer”,“target:Order”,“method:GetOrderDate()”)。在具体实施过程中,原子重构操作可以使用以下公式来表示:Exemplarily, when the user moves the method (as shown in FIG. 6, the user can move the GetOrderDate() method), the user equipment records the identifier (namely movemethod) and control parameters (namely: "source: Customer", "target: Order", "method: GetOrderDate()"). In the specific implementation process, the atomic reconstruction operation can be expressed by the following formula:
ref(p1,p2,……)ref(p1,p2,...)
其中,ref表示原子重构的标识,p1,p2等表示原子重构操作的控制参数。进一步的,原子重构序列CR可以通过如下的表达式来表示:Wherein, ref represents the identifier of the atomic reconstruction, and p1, p2, etc. represent the control parameters of the atomic reconstruction operation. Furthermore, the atomic reconstruction sequence CR can be expressed by the following expression:
CR=[ref1(p1 1,pi1 2,……),ref2(p2 1,pi2 2,……),……] CR=[ref1(p1 1 , pi1 2 ,...), ref2(p2 1 , pi2 2 ,...),...]
其中,ref1(p1 1,pi1 2,……)为第1个原子重构操作,ref1表示第1个原子重构的标识,p1 1,pi1 2等表示第1个原子重构操作的控制参数,其余参数以此类推。 Among them, ref1(p1 1 , pi1 2 ,...) is the first atomic reconstruction operation, ref1 represents the identification of the first atomic reconstruction operation, p1 1 , pi1 2 , etc. represent the control parameters of the first atomic reconstruction operation , and so on for the rest of the parameters.
应理解,表1所示的原子重构操作的信息仅为示例,具体实施过程中,用户设备所生成的操作的指示信息还可以通过计算机程序管理机构、企业、法律法规、或者用户等定义或者配置。可选的,原子重构操作可以包含比表1更多或者更少的内容,其存储、传输、展示的形式也可以为对应关系集合、队列、堆、栈、或数据库表等,本申请对此不做限定。It should be understood that the information of the atomic reconstruction operation shown in Table 1 is only an example. During the specific implementation process, the instruction information of the operation generated by the user equipment may also be defined or configuration. Optionally, the atomic reconstruction operation may contain more or less content than Table 1, and its storage, transmission, and display forms may also be corresponding relationship sets, queues, heaps, stacks, or database tables. This is not limited.
步骤S204:第一服务器对第一代码工程进行重构。Step S204: the first server reconstructs the first code project.
用户设备基于用户输入的操作,可以向第一服务器请求重构所述第一代码工程。第一服务器响应用户设备的请求,对第一代码工程进行重构。Based on the operation input by the user, the user equipment may request the first server to reconstruct the first code project. The first server reconstructs the first code project in response to the request of the user equipment.
可选的,第一服务器可以接收来自用户设备的重构请求消息,重构请求消息中包含第一操作对应的指示信息。第一服务器根据第一操作对应的指示信息,对第一代码工程进行重构。Optionally, the first server may receive a reconfiguration request message from the user equipment, where the reconfiguration request message includes indication information corresponding to the first operation. The first server reconstructs the first code project according to the indication information corresponding to the first operation.
在一种可能的设计中,第一操作对应的指示信息可以包含原子重构序列,该原子重构序列用于记录更新第一代码工程的操作顺序。服务器可以根据原子重构序列,按照用户地操作顺序重构第一代码工程。In a possible design, the indication information corresponding to the first operation may include an atomic reconstruction sequence, and the atomic reconstruction sequence is used to record an operation sequence for updating the first code project. The server may reconstruct the first code project according to the user's operation sequence according to the atomic reconstruction sequence.
可选的,图2所示的代码重构方法可以包含步骤S205,这里的可选的可以理解为,具体 实施过程中可能会执行步骤S205,也可能不会执行步骤S205。步骤S205具体如下:Optionally, the code refactoring method shown in FIG. 2 may include step S205, which may be understood as optional here, step S205 may or may not be executed during the specific implementation process. Step S205 is specifically as follows:
步骤S205:第一服务器向用户设备反馈经过重构的第一代码工程。相应的,用户设备接收服务器提供的经过重构的第一代码工程。Step S205: the first server feeds back the reconstructed first code project to the user equipment. Correspondingly, the user equipment receives the reconstructed first code project provided by the server.
在一种可能的设计中,第一服务器可以将重构后的第一代码工程反馈给代码托管服务器,第一服务器向用户设备反馈重构完成消息。用户设备相应该重构完成消息,从代码托管服务器接收经过重构的第一代码工程。In a possible design, the first server may feed back the refactored first code project to the code hosting server, and the first server feeds back a refactoring completion message to the user equipment. In response to the reconstruction completion message, the user equipment receives the reconstructed first code project from the code hosting server.
在又一种可能的设计中,第一代码工程经过重构后,第一服务器可以向用户设备反馈经过重构的第一代码工程的代码结构,便于用户设备呈现经过重构的第一代码工程的代码结构。在用户设备请求第一代码工程时,第一服务器则向用户设备反馈第一代码工程。In yet another possible design, after the first code project is reconstructed, the first server may feed back the code structure of the reconstructed first code project to the user equipment, so that the user equipment can present the reconstructed first code project code structure. When the user equipment requests the first code project, the first server feeds back the first code project to the user equipment.
可选的,用户设备获取经过重构的第一代码工程(或经过重构的第一代码工程的代码结构)之后。用户设备可以接收用户输出的操作,以继续对第一代码工程进行重构。Optionally, after the user equipment acquires the reconstructed first code project (or the code structure of the reconstructed first code project). The user equipment may receive an operation output by the user to continue to reconstruct the first code project.
图2所示的实施例中,用户设备能够在用户界面上向用户呈现代码架构图,而用户通过界面操作就能够对代码结构进行修改,并获取到修改后的代码工程。如此,将代码结构的视图展示和代码重构集成一体,使得用户无需在不同的代码层面中进行切换,从而大大提升代码重构效率。另外,可视化的操作更降低了代码重构的使用门槛,提升了用户的代码重构体验。In the embodiment shown in FIG. 2 , the user equipment can present the code structure diagram to the user on the user interface, and the user can modify the code structure through interface operations and obtain the modified code project. In this way, the view display of the code structure and code refactoring are integrated, so that users do not need to switch between different code levels, thus greatly improving the efficiency of code refactoring. In addition, the visualized operation lowers the threshold for using code refactoring and improves the user's code refactoring experience.
【实施例二】[Example 2]
图2所示的实施例中包含了多种可能的方案,下面对其中的一些可选方案进行进一步说明。请参见图8,图8是本申请实施例提供的又一种可能的代码重构方法的流程图。图8所示的步骤可以包含步骤S801-步骤S810中的部分或者全部步骤。应理解,本申请为了方便描述,故通过S801至S810这一顺序进行描述,并不旨在限定一定通过上述顺序进行执行。对于上述一个或多个步骤的执行的先后顺序、执行的时间、执行的次数等不做限定。步骤S801-步骤S810具体如下:The embodiment shown in FIG. 2 includes various possible solutions, some of which are further described below. Please refer to FIG. 8 . FIG. 8 is a flowchart of another possible code refactoring method provided by the embodiment of the present application. The steps shown in FIG. 8 may include part or all of the steps in step S801-step S810. It should be understood that, for the convenience of description, the present application uses the sequence of S801 to S810 for description, and does not intend to limit the execution to be performed in the above sequence. There is no limitation on the execution sequence, execution time, and execution times of the above one or more steps. Step S801-step S810 are specifically as follows:
步骤S801:用户设备打开第一代码工程。Step S801: the user equipment opens the first code project.
其中,第一代码工程可以存储于本地。用户设备打开第一代码工程,该第一代码工程所有代码文件将被获取。可选的,用户可以在用户设备上输入操作,用户设备响应用户的输入的操作以打开第一代码工程。Wherein, the first code project may be stored locally. The user equipment opens the first code project, and all code files of the first code project will be acquired. Optionally, the user may input an operation on the user equipment, and the user equipment responds to the operation input by the user to open the first code project.
可选的,第一代码工程可以存储在其他装置中。用户设备可以向存储代码工程的装置发送请求,以呈现第一代码工程的相关内容。Alternatively, the first code project may be stored in other devices. The user equipment may send a request to the device storing the code project to present relevant content of the first code project.
步骤S802:服务器确定第一代码工程的代码结构。Step S802: the server determines the code structure of the first code project.
可选的,服务器可以使用静态程序分析技术分析源代码,并获取代码工程中的多个元素。Optionally, the server may use static program analysis techniques to analyze the source code, and obtain multiple elements in the code project.
可选的,服务器还可以确当代码工程中的元素之间的关系,例如确定代码工程中的调用关系、继承依赖关系、包含关系等代码关系元信息。Optionally, the server may also determine the relationship between elements in the code project, for example, determine code relationship meta-information such as call relationship, inheritance dependency relationship, inclusion relationship, etc. in the code project.
步骤S803:服务器生成代码结构图。Step S803: the server generates a code structure diagram.
具体的,服务器根据第一代码工程的元素和元素之间的关系(可选),生成代码结构图。Specifically, the server generates a code structure diagram according to the elements of the first code project and the relationships between elements (optional).
可选的,代码结构图可以包含多个层级,例如包结构图、类结构图、或类成员结构图等。Optionally, the code structure diagram may contain multiple levels, such as a package structure diagram, a class structure diagram, or a class member structure diagram.
作为一种可能的方案,服务器可以通过统一建模语言(Unified Modeling Language,UML)类图生成技术,生成代码结构图。As a possible solution, the server can generate a code structure diagram through a unified modeling language (Unified Modeling Language, UML) class diagram generation technology.
步骤S804:服务器进行代码坏味道检测。Step S804: The server performs code smell detection.
具体的,服务器对第一代码工程进行坏味道检测,以确定第一代码工程中存在的代码架 构坏味道。Specifically, the server performs bad smell detection on the first code project, so as to determine the bad smell of the code structure existing in the first code project.
在一种可能的设计中,步骤S804可以通过服务器中的架构坏味道自动检测模块来执行。该模块可以通过以下两种方式来确定第一代码工程中存在的代码架构坏味道:In a possible design, step S804 may be executed by an automatic architecture smell detection module in the server. This module can determine the bad smell of code architecture in the first code project through the following two methods:
方式1,通过架构坏味道检测模型,确定所述第一代码工程中的代码架构坏味道。其中,架构坏味道自动检测模块可以基于深度学习网络,根据训练好的神经网络模型分析出代码中的坏味道。Mode 1, using an architecture smell detection model to determine the code architecture smell in the first code project. Among them, the architecture bad smell automatic detection module can be based on the deep learning network, and analyze the bad smell in the code according to the trained neural network model.
方式2,对所述第一代码工程进行代码静态分析、文本相似度计算,得到所述第一代码工程中的代码架构坏味道。Mode 2: Static code analysis and text similarity calculation are performed on the first code project to obtain the bad smell of the code architecture in the first code project.
可选的,架构坏味道自动检测模块可以根据代码静态分析技术解析出代码中各类度量指标,结合代码中的文本相似度计算检测代码工程中的架构坏味道。Optionally, the architecture bad smell automatic detection module can analyze various metrics in the code based on the code static analysis technology, and combine the text similarity calculation in the code to detect the bad architecture smell in the code project.
应理解,上述两种方式还可以进行结合,通过结合两种方式,可以提升检测结果的正确性。It should be understood that the above two methods can also be combined, and the correctness of the detection result can be improved by combining the two methods.
可选的,图8所示的代码重构方法可以包含步骤S805,这里的可选的可以理解为,服务器可以执行步骤S805,也可以不执行步骤S805,具体实施过程中,若用户勾选了重构推荐服务则服务器可能会确定重构推荐,和/或,用户购买了重构推荐服务则服务器可能会确定重构推荐。步骤S805具体如下:Optionally, the code refactoring method shown in FIG. 8 may include step S805, which can be understood as optional here, the server may execute step S805, or may not execute step S805. During the specific implementation process, if the user checks the For the reconstruction recommendation service, the server may determine the reconstruction recommendation, and/or, if the user purchases the reconstruction recommendation service, the server may determine the reconstruction recommendation. Step S805 is specifically as follows:
步骤S805:服务器确定重构推荐。Step S805: the server determines the reconstruction recommendation.
具体的,服务器针对第一代码工程中存在代码架构坏味道,确定重构推荐,从而可以提示用户如何对第一代码工程进行更新。如此,可以提高用户代码重构的效率和准确性,提升用户代码重构的体验。Specifically, the server determines a refactoring recommendation for the bad code structure smell in the first code project, so as to prompt the user how to update the first code project. In this way, the efficiency and accuracy of user code refactoring can be improved, and the experience of user code refactoring can be improved.
在一种可能的设计中,步骤S804和步骤S805可以通过服务器中的架构坏味道自动检测与重构方案推荐模块来执行,该模块可以实现与上述架构坏味道自动检测模块的功能。相关描述可以参考对架构坏味道自动检测模块的描述,此处不再赘述。In a possible design, step S804 and step S805 can be executed by an automatic architecture smell detection and reconstruction scheme recommendation module in the server, and this module can realize the functions of the above-mentioned automatic architecture smell detection module. For related descriptions, please refer to the description of the automatic detection module for bad architecture smells, so I won't repeat them here.
请参见图9,图9是本申请提供的一种可能的架构坏味道自动检测与重构方案推荐模块的工作流程图。深度学习模型通过训练数据进行训练,该训练数据来自预先设置或者预先定义的正样本代码仓。该正样本代码仓还可以用于挖掘重构模式,得到重构模式,该重构模式用于生成重构代码推荐。深度学习模型可以用于分析出代码中的坏味道。架构坏味道检测模块可以通过代码静态分析、文本相似度计算,得到所述第一代码工程中的代码架构坏味道。应理解,深度学习模型和架构坏味道检测模块在具体实施过程中可以都存在,也可以保留其中一项。特征提取模块用于得到代码特征,该代码特征可以表示代码工程中的一个或者多个度量指标。可选的,该代码特征的种类、格式可以是预先定义或者预先配置的。Please refer to FIG. 9 . FIG. 9 is a work flow chart of a possible automatic detection of architecture bad smell and recommendation module for reconstruction scheme provided by the present application. The deep learning model is trained by training data from pre-set or pre-defined positive sample code bins. The positive sample code warehouse can also be used to mine refactoring patterns to obtain refactoring patterns, and the refactoring patterns are used to generate refactoring code recommendations. Deep learning models can be used to detect bad smells in code. The architecture smell detection module can obtain the code architecture smell in the first code project through code static analysis and text similarity calculation. It should be understood that both the deep learning model and the architecture bad smell detection module may exist in the specific implementation process, or one of them may be retained. The feature extraction module is used to obtain code features, which may represent one or more metrics in code engineering. Optionally, the type and format of the code feature may be pre-defined or pre-configured.
在工作时,待分析的代码工程被输入特征提取模块(可选),特征提取模块可以提取代码工程中的代码特征。该代码特征进一步被提供给深度学习模型和/或架构坏味道检测模块,得到代码工程中存在的架构坏味道。而重构代码推荐模块可以针对代码工程中存在的架构坏味道生成重构推荐。代码工程中存在的架构坏味道和重构推荐可以被输出,供服务器反馈给用户设备。During work, the code project to be analyzed is input into the feature extraction module (optional), and the feature extraction module can extract code features in the code project. The code features are further provided to the deep learning model and/or the architecture smell detection module to obtain the architecture smells existing in the code engineering. The refactoring code recommendation module can generate refactoring recommendations for bad architecture smells in code engineering. Architecture bad smells and refactoring recommendations in code engineering can be output for the server to feed back to user devices.
步骤S806:服务器将代码结构图和代码架构坏味道进行融合。Step S806: The server integrates the code structure diagram and the bad smell of the code structure.
如此,用户设备通过代码结构图即可同时查看第一代码工程的代码架构和第一代码工程的代码架构坏味道,无需在多个窗口中切换,减少操作、节约时间、提高代码重构的效率和准确性。In this way, the user device can view the code structure of the first code project and the bad taste of the code structure of the first code project at the same time through the code structure diagram, without switching between multiple windows, reducing operations, saving time, and improving the efficiency of code refactoring and accuracy.
可选的,在服务器确定重构推荐的情况下,服务器还可以将重构推荐、代码架构坏味道 与代码结构图进行融合。Optionally, when the server determines the refactoring recommendation, the server can also integrate the refactoring recommendation, the bad smell of the code architecture, and the code structure diagram.
服务器可以向用户设备提供融合后的代码结构图,相应的,用户设备接收融合后的代码结构图。The server may provide the fused code structure diagram to the user equipment, and correspondingly, the user equipment receives the fused code structure diagram.
步骤S807:用户设备呈现第一用户界面。Step S807: the user equipment presents a first user interface.
相关描述请参见步骤S201。For related description, refer to step S201.
步骤S808:用户设备接收用户输入的第一操作。Step S808: the user equipment receives a first operation input by the user.
相关描述请参见步骤S202。For related description, refer to step S202.
在一种可能的设计中,用户设备通过第一用户界面指示代码坏味道信息以及推荐的重构方案。用户可以在第一用户界面上通过界面操作(例如:元素拖拽、新增、删除等)更新第一代码工程。用户设备接收用户的重构确认操作后,向服务器请求重构第一代码工程。In a possible design, the user equipment indicates the code smell information and the recommended refactoring solution through the first user interface. The user can update the first code project through interface operations (for example: element dragging, adding, deleting, etc.) on the first user interface. After receiving the user's reconstruction confirmation operation, the user equipment requests the server to reconstruct the first code project.
在请求重构时,用户设备可以向服务器发送重构请求消息,相应的,服务器接收来自用户设备的重构请求消息。可选的,重构请求消息包含第一操作的指示信息。When requesting reconfiguration, the user equipment may send a reconfiguration request message to the server, and correspondingly, the server receives the reconfiguration request message from the user equipment. Optionally, the reconstruction request message includes indication information of the first operation.
步骤S809:服务器获取原子重构序列。Step S809: the server obtains the atomic reconstruction sequence.
可选的,重构请求消息中包含原子重构序列,从而服务器获取原子重构序列。Optionally, the reconstruction request message includes an atomic reconstruction sequence, so that the server obtains the atomic reconstruction sequence.
或者可选的,重构请求消息包含第一操作的指示信息,服务器根据第一操作的指示信息转化得到原子重构序列。Or optionally, the reconstruction request message includes the indication information of the first operation, and the server converts the atomic reconstruction sequence according to the indication information of the first operation.
步骤S810:服务器重构第一代码工程。Step S810: The server reconstructs the first code project.
相关描述请参见步骤S204。For related description, refer to step S204.
在图8所示的实施例中,用户设备能够在用户界面上向用户呈现高层代码架构图并接收用户对于代码结构的修改,而用户通过界面操作就能够对代码结构进行修改,并获取到修改后的代码工程。如此,将代码结构的视图展示和代码重构集成一体,使得用户无需在不同的代码层面中进行切换,从而大大提升代码重构效率。另外,可视化的操作更降低了使用门槛,提升了用户的代码重构体验。In the embodiment shown in Figure 8, the user equipment can present the high-level code architecture diagram to the user on the user interface and receive the user's modification of the code structure, and the user can modify the code structure through interface operations and obtain the modified code structure. The code behind works. In this way, the view display of the code structure and code refactoring are integrated, so that users do not need to switch between different code levels, thus greatly improving the efficiency of code refactoring. In addition, the visual operation lowers the threshold of use and improves the user's code refactoring experience.
【实施例三】[Embodiment 3]
一种可能的设计中,图8所示的服务器所完成的功能,可以分别由第一服务器、第二服务器和第三服务器来完成。其中,第一服务器用于实现重构代码工程相关的功能,第二服务器用于实现确定代码工程中的代码架构坏味道、确定重构推荐相关的功能,第三服务器用于实现代码工程的代码结构相关的功能。In a possible design, the functions performed by the server shown in FIG. 8 may be performed by the first server, the second server, and the third server respectively. Among them, the first server is used to implement functions related to refactoring code engineering, the second server is used to implement functions related to determining bad code architecture in code engineering and determining refactoring recommendations, and the third server is used to implement code engineering related functions. Structure related functions.
其中,第一服务器、第二服务器、第三服务器可以是独立的设备,也可以是集成在同一个设备中,或者部分是独立设备、部分集成在一个独立设备中。作为一种可能的方案,第一服务器、第二服务器、第三服务器还可以是软件服务、计算模块或云平台上的进程或线程。Wherein, the first server, the second server, and the third server may be independent devices, or may be integrated in the same device, or partly be independent devices, and partly be integrated into an independent device. As a possible solution, the first server, the second server, and the third server may also be software services, computing modules, or processes or threads on the cloud platform.
上述详细阐述了本申请实施例的方法,下面提供本申请实施例的装置。The method of the embodiment of the present application has been described in detail above, and the device of the embodiment of the present application is provided below.
请参见图10,图10是本申请实施例提供的一种代码重构装置100的结构示意图。该代码重构装置100可以包括处理单元1001和通信单元1002。该代码重构装置100用于实现前述的代码重构方法,例如图2或图8所示实施例中的代码重构方法。Please refer to FIG. 10 , which is a schematic structural diagram of a code reconstruction apparatus 100 provided in an embodiment of the present application. The code reconstruction apparatus 100 may include a processing unit 1001 and a communication unit 1002 . The code reconstruction apparatus 100 is used to implement the aforementioned code reconstruction method, for example, the code reconstruction method in the embodiment shown in FIG. 2 or FIG. 8 .
这里需要说明的是,上述多个单元的划分仅是一种根据功能进行的逻辑划分,不作为对代码重构装置100具体的结构的限定。在具体实现中,其中部分功能模块可能被细分为更多细小的功能模块,部分功能模块也可能组合成一个功能模块,但无论这些功能模块是进行了细。It should be noted here that the division of the above multiple units is only a logical division based on functions, and is not intended to limit the specific structure of the code reconstruction apparatus 100 . In a specific implementation, some of the functional modules may be subdivided into more smaller functional modules, and some of the functional modules may also be combined into one functional module, but no matter whether these functional modules are subdivided.
在一种可能的设计中,所述代码重构装置100用于实现图2或图8所示实施例中用户设备一侧的方法。In a possible design, the code reconstruction apparatus 100 is configured to implement the method on the user equipment side in the embodiment shown in FIG. 2 or FIG. 8 .
在一种可能的实施方式中,所述处理单元1001,用于呈现第一用户界面,所述第一用户界面用于指示第一代码工程的代码结构,所述代码结构包含包、类、类成员或底层代码中的一种或多种元素;In a possible implementation manner, the processing unit 1001 is configured to present a first user interface, the first user interface is used to indicate the code structure of the first code project, and the code structure includes a package, a class, a class one or more elements in a member or underlying code;
所述通信单元1002,用于接收用户在所述第一用户界面上输入的第一操作,所述第一操作用于更新所述第一代码工程的代码结构;The communication unit 1002 is configured to receive a first operation input by a user on the first user interface, where the first operation is used to update the code structure of the first code project;
所述处理单元1001和通信单元1002,还用于基于所述第一操作向第一服务器请求重构所述第一代码工程;The processing unit 1001 and the communication unit 1002 are further configured to request the first server to reconstruct the first code project based on the first operation;
所述处理单元1001和通信单元1002,还用于获取经过重构的所述第一代码工程。The processing unit 1001 and the communication unit 1002 are further configured to obtain the reconstructed first code project.
在又一种可能的实施方式中,所述第一操作包含针对所述元素的移动、增加、删除、编辑等中的一项或者多项。In yet another possible implementation manner, the first operation includes one or more of moving, adding, deleting, editing, and the like for the element.
其中,移动操作可以更新代码结构中的元素的位置等。以移动类成员为例,用户可以将某一类成员从某一个类移动到另一个类。Wherein, the move operation may update the position of elements in the code structure and the like. Taking moving class members as an example, users can move a class member from one class to another.
增加操作可以增加元素,以增加类为例,用户可以创建新的类成员。以增加字段为例,用户可以封装新的字段。The adding operation can add elements. Taking adding a class as an example, the user can create a new class member. Taking adding fields as an example, users can encapsulate new fields.
删除操作可以移除、销毁某一元素。例如,用户可以删除包、删除类、删除类成员等。The delete operation can remove and destroy an element. For example, a user can delete a package, delete a class, delete a class member, etc.
编辑操作可以对元素进行更新。例如,用户可以变更字段的属性、修改类的名称、拆分类等等。Editing operations can update elements. For example, users can change the attributes of fields, modify the name of classes, split classes, and so on.
可选的,第一操作还包括滑动、缩放、指向、点击、长按等。其中,滑动、缩放等操作可以用于调整显示区域、页面大小等。其中,指向操作可以用于用户选择某一元素。点击操作可以用于用户选中元素、选择某一选项、或确认某一操作(如提交修改等)等。长按操作可以用于用户选中元素、移动元素、或删除元素等。Optionally, the first operation also includes sliding, zooming, pointing, clicking, long pressing, and the like. Wherein, operations such as sliding and zooming may be used to adjust a display area, a page size, and the like. Among them, the pointing operation can be used for the user to select an element. The click operation can be used for the user to select an element, select an option, or confirm an operation (such as submitting a modification, etc.). The long press operation can be used for the user to select an element, move an element, or delete an element, etc.
在又一种可能的实施方式中,所述第一用户界面还用于指示所述第一代码工程中存在的代码架构坏味道。In yet another possible implementation manner, the first user interface is further used to indicate a code architecture smell existing in the first code project.
在又一种可能的实施方式中,所述第一代码工程中存在的代码架构坏味道对应于所述元素;In yet another possible implementation manner, the code architecture smell existing in the first code project corresponds to the element;
所述第一用户界面还用于通过颜色区分所述元素中存在代码架构坏味道的程度。The first user interface is also used to distinguish the degree of bad code structure smell in the elements by color.
在又一种可能的实施方式中,所述通信单元1002,还用于:In yet another possible implementation manner, the communication unit 1002 is further configured to:
接收第二服务器提供的所述第一代码工程的第一指示信息,所述第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道。Receive first indication information of the first code project provided by the second server, where the first indication information is used to indicate a code architecture smell existing in the first code project.
在又一种可能的实施方式中,所述第一用户界面还用于指示重构推荐,所述重构推荐用于提示用户针对所述第一代码工程中存在的代码架构坏味道对所述第一代码工程进行修改。In yet another possible implementation manner, the first user interface is further used to indicate a refactoring recommendation, and the refactoring recommendation is used to prompt the user to correct the code architecture smell existing in the first code project. The first code works to be modified.
在又一种可能的实施方式中,所述通信单元1002,还用于:In yet another possible implementation manner, the communication unit 1002 is further configured to:
接收第二服务器发送的所述重构推荐。The reconstruction recommendation sent by the second server is received.
可选的,第一服务器和第二服务器可能是同一个服务器,或者第一服务器和第二服务器可以包含于同一个服务器中。Optionally, the first server and the second server may be the same server, or the first server and the second server may be included in the same server.
在又一种可能的实施方式中,所述处理单元1001,还用于根据所述第一操作,得到原子重构序列,所述原子重构序列用于记录修改更新第一代码工程的操作顺序;In yet another possible implementation manner, the processing unit 1001 is further configured to obtain an atomic reconstruction sequence according to the first operation, and the atomic reconstruction sequence is used to record, modify and update the operation sequence of the first code project ;
所述通信单元1002,还用于向所述第一服务器发送重构请求消息,所述重构请求消息包 含所述原子重构序列。The communication unit 1002 is further configured to send a reconstruction request message to the first server, where the reconstruction request message includes the atomic reconstruction sequence.
在又一种可能的实施方式中,所述原子重构序列包含多个原子重构操作,每个原子重构操作包含原子重构操作的标识和所述原子重构操作涉及的第一代码工程中的参数。In yet another possible implementation manner, the atomic reconstruction sequence includes multiple atomic reconstruction operations, and each atomic reconstruction operation includes an identifier of the atomic reconstruction operation and the first code project involved in the atomic reconstruction operation parameters in .
在又一种可能的实施方式中,所述通信单元1002,还用于:In yet another possible implementation manner, the communication unit 1002 is further configured to:
向第三服务器发送所述第一代码工程的指示信息;sending indication information of the first code project to a third server;
接收所述第三服务器提供的所述第一代码工程的代码结构。Receive the code structure of the first code project provided by the third server.
相关描述还可以参考图2或图8所示实施例中的描述,此处不再赘述。For related descriptions, reference may also be made to the descriptions in the embodiment shown in FIG. 2 or FIG. 8 , and details are not repeated here.
在又一种可能的设计中,所述代码重构装置100用于实现图2或图8所示实施例中服务器一侧的方法。In yet another possible design, the code reconstruction apparatus 100 is used to implement the method on the server side in the embodiment shown in FIG. 2 or FIG. 8 .
在一种可能的实施方式中,所述通信单元1002,用于接收来自用户设备的重构请求消息,所述重构请求消息是根据在所述第一用户界面上输入的第一操作得到的,所述第一用户界面用于指示第一代码工程的代码结构,所述代码结构包含包、类、类成员或底层代码中的一种或多种元素,所述第一操作用于更新第一代码工程的代码结构;In a possible implementation manner, the communication unit 1002 is configured to receive a reconstruction request message from a user equipment, where the reconstruction request message is obtained according to a first operation input on the first user interface , the first user interface is used to indicate the code structure of the first code project, the code structure includes one or more elements in packages, classes, class members, or underlying codes, and the first operation is used to update the first A code structure of a code project;
所述处理单元1001,用于根据所述重构请求消息,对所述第一代码工程进行重构;The processing unit 1001 is configured to refactor the first code project according to the refactoring request message;
所述通信单元1002,还用于向所述用户设备反馈经过重构的所述第一代码工程。The communication unit 1002 is further configured to feed back the reconstructed first code project to the user equipment.
在又一种可能的实施方式中,所述第一操作包含针对所述元素的移动、增加、删除、编辑等中的一项或者多项。In yet another possible implementation manner, the first operation includes one or more of moving, adding, deleting, editing, and the like for the element.
其中,移动操作可以更新代码结构中的元素的位置等。以移动类成员为例,用户可以将某一类成员从某一个类移动到另一个类。Wherein, the move operation may update the position of elements in the code structure and the like. Taking moving class members as an example, users can move a class member from one class to another.
增加操作可以增加元素,以增加类为例,用户可以创建新的类成员。以增加字段为例,用户可以封装新的字段。The adding operation can add elements. Taking adding a class as an example, the user can create a new class member. Taking adding fields as an example, users can encapsulate new fields.
删除操作可以移除、销毁某一元素。例如,用户可以删除包、删除类、删除类成员等。The delete operation can remove and destroy an element. For example, a user can delete a package, delete a class, delete a class member, etc.
编辑操作可以对元素进行更新。例如,用户可以变更字段的属性、修改类的名称、拆分类等等。Editing operations can update elements. For example, users can change the attributes of fields, modify the name of classes, split classes, and so on.
可选的,第一操作还包括滑动、缩放、指向、点击、长按等。其中,滑动、缩放等操作可以用于调整显示区域、页面大小等。其中,指向操作可以用于用户选择某一元素。点击操作可以用于用户选中元素、选择某一选项、或确认某一操作(如提交修改等)等。长按操作可以用于用户选中元素、移动元素、或删除元素等。Optionally, the first operation also includes sliding, zooming, pointing, clicking, long pressing, and the like. Wherein, operations such as sliding and zooming may be used to adjust a display area, a page size, and the like. Among them, the pointing operation can be used for the user to select an element. The click operation can be used for the user to select an element, select an option, or confirm an operation (such as submitting a modification, etc.). The long press operation can be used for the user to select an element, move an element, or delete an element, etc.
在又一种可能的实施方式中,所述处理单元1001,还用于确定所述第一代码工程中存在的代码架构坏味道;In yet another possible implementation manner, the processing unit 1001 is further configured to determine a code architecture smell existing in the first code project;
所述通信单元1002,还用于向所述用户设备发送第一指示信息,所述第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道。The communication unit 1002 is further configured to send first indication information to the user equipment, where the first indication information is used to indicate a code architecture smell existing in the first code project.
在又一种可能的实施方式中,所述第一代码工程中存在的代码架构坏味道对应于所述元素;In yet another possible implementation manner, the code architecture smell existing in the first code project corresponds to the element;
所述第一用户界面还用于通过颜色区分所述元素中存在代码架构坏味道的程度。The first user interface is also used to distinguish the degree of bad code structure smell in the elements by color.
在又一种可能的实施方式中,所述处理单元1001,还用于通过架构坏味道检测模型,确定所述第一代码工程中的代码架构坏味道。In yet another possible implementation manner, the processing unit 1001 is further configured to determine a code architecture smell in the first code project by using an architecture smell detection model.
在又一种可能的实施方式中,所述处理单元1001,还用于对所述第一代码工程进行代码静态分析、文本相似度计算,得到所述第一代码工程中的代码架构坏味道。In yet another possible implementation manner, the processing unit 1001 is further configured to perform code static analysis and text similarity calculation on the first code project to obtain code architecture smells in the first code project.
在又一种可能的实施方式中,所述重构请求消息包含所述原子重构序列,所述原子重构 序列用于记录修改更新第一代码工程的操作顺序;In yet another possible implementation manner, the reconstruction request message includes the atomic reconstruction sequence, and the atomic reconstruction sequence is used to record the operation sequence of modifying and updating the first code project;
所述处理单元1001,还用于根据所述重构请求消息中的原子重构序列,对所述第一代码工程进行重构。The processing unit 1001 is further configured to reconstruct the first code project according to the atomic reconstruction sequence in the reconstruction request message.
在又一种可能的实施方式中,所述原子重构序列包含多个原子重构操作,每个原子重构操作包含原子重构操作的标识和所述原子重构操作涉及的第一代码工程中的元素。In yet another possible implementation manner, the atomic reconstruction sequence includes multiple atomic reconstruction operations, and each atomic reconstruction operation includes an identifier of the atomic reconstruction operation and the first code project involved in the atomic reconstruction operation elements in .
在又一种可能的实施方式中,所述通信单元1002,还用于接收来自所述用户设备的第一代码工程的指示信息;In yet another possible implementation manner, the communication unit 1002 is further configured to receive indication information of the first code project from the user equipment;
所述处理单元1001,还用于确定所述第一代码工程的代码结构;The processing unit 1001 is further configured to determine a code structure of the first code project;
所述通信单元1002,还用于向用户设备提供所述第一代码工程的代码结构。The communication unit 1002 is further configured to provide the user equipment with the code structure of the first code project.
相关描述还可以参考图2或图8所示实施例中的描述,此处不再赘述。For related descriptions, reference may also be made to the descriptions in the embodiment shown in FIG. 2 or FIG. 8 , and details are not repeated here.
请参见图11,图11是本申请实施例提供的一种计算设备110的结构示意图,该计算设备110可以为独立设备(例如服务器、或用户设备等等中的一个或者多个),也可以为独立设备内部的部件(例如芯片、软件模块或者硬件模块等)。该计算设备110可以包括至少一个处理器1101。可选的还可以包括至少一个存储器1103。进一步可选的,计算设备110还可以包括通信接口1102。更进一步可选的,还可以包含总线1104,其中,处理器1101、通信接口1102和存储器1103通过总线1104相连。Please refer to FIG. 11. FIG. 11 is a schematic structural diagram of a computing device 110 provided by an embodiment of the present application. The computing device 110 may be an independent device (such as one or more of a server, or a user device, etc.), or may be It is an internal component of an independent device (such as a chip, a software module or a hardware module, etc.). The computing device 110 may include at least one processor 1101 . Optionally, at least one memory 1103 may also be included. Further optionally, the computing device 110 may further include a communication interface 1102 . Further optionally, a bus 1104 may also be included, wherein the processor 1101 , the communication interface 1102 and the memory 1103 are connected through the bus 1104 .
其中,处理器1101是进行算术运算和/或逻辑运算的模块,具体可以是中央处理器(central processing unit,CPU)、图片处理器(graphics processing unit,GPU)、微处理器(microprocessor unit,MPU)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程逻辑门阵列(Field Programmable Gate Array,FPGA)、复杂可编程逻辑器件(Complex programmable logic device,CPLD)、协处理器(协助中央处理器完成相应处理和应用)、微控制单元(Microcontroller Unit,MCU)等处理模块中的一种或者多种的组合。Wherein, the processor 1101 is a module for performing arithmetic operations and/or logic operations, specifically, a central processing unit (central processing unit, CPU), a picture processing unit (graphics processing unit, GPU), a microprocessor (microprocessor unit, MPU) ), Application Specific Integrated Circuit (ASIC), Field Programmable Logic Gate Array (Field Programmable Gate Array, FPGA), Complex Programmable Logic Device (Complex programmable logic device, CPLD), coprocessor (assisting central processing One or more combinations of processing modules such as processors to complete corresponding processing and applications), Microcontroller Units (MCUs) and other processing modules.
通信接口1102可以用于为所述至少一个处理器提供信息输入或者输出。和/或,所述通信接口1102可以用于接收外部发送的数据和/或向外部发送数据,可以为包括诸如以太网电缆等的有线链路接口,也可以是无线链路(Wi-Fi、蓝牙、通用无线传输、车载短距通信技术以及其他短距无线通信技术等)接口。可选的,通信接口1102还可以包括与接口耦合的发射器(如射频发射器、天线等),或者接收器等。 Communication interface 1102 may be used to provide information input or output to the at least one processor. And/or, the communication interface 1102 can be used to receive data sent from the outside and/or send data to the outside, and can be a wired link interface such as an Ethernet cable, or a wireless link (Wi-Fi, Bluetooth, general wireless transmission, vehicle short-range communication technology and other short-range wireless communication technologies, etc.) interface. Optionally, the communication interface 1102 may further include a transmitter (such as a radio frequency transmitter, an antenna, etc.) or a receiver coupled with the interface.
存储器1103用于提供存储空间,存储空间中可以存储操作系统和计算机程序等数据。存储器1103可以是随机存储记忆体(random access memory,RAM)、只读存储器(read-only memory,ROM)、可擦除可编程只读存储器(erasable programmable read only memory,EPROM)、或便携式只读存储器(compact disc read-only memory,CD-ROM)等等中的一种或者多种的组合。The memory 1103 is used to provide a storage space, in which data such as operating systems and computer programs can be stored. Memory 1103 can be random access memory (random access memory, RAM), read-only memory (read-only memory, ROM), erasable programmable read-only memory (erasable programmable read only memory, EPROM), or portable read-only memory One or more combinations of memory (compact disc read-only memory, CD-ROM), etc.
该计算设备110中的至少一个处理器1101用于执行前述的代码重构方法,例如图2或图8所示实施例所描述的代码重构方法。At least one processor 1101 in the computing device 110 is configured to execute the aforementioned code reconstruction method, for example, the code reconstruction method described in the embodiment shown in FIG. 2 or FIG. 8 .
可选的,处理器1101,可以是专门用于执行这些方法的处理器(便于区别称为专用处理器),也可以是通过调用计算机程序来执行这些方法的处理器,例如通用处理器。可选的,至少一个处理器还可以既包括专用处理器也包括通用处理器。可选的,在计算设备包括至少一个存储器1103的情况下,上述计算机程序可以存在存储器1103中。Optionally, the processor 1101 may be a processor dedicated to executing these methods (referred to as a dedicated processor for convenience), or a processor that executes these methods by invoking computer programs, such as a general-purpose processor. Optionally, at least one processor may also include both a special-purpose processor and a general-purpose processor. Optionally, in the case that the computing device includes at least one memory 1103 , the above computer programs may be stored in the memory 1103 .
本申请还提供了一种算机可读存储介质,所述计算机可读存储介质中存储有指令,当所述指令在至少一个处理器上运行时,实现前述的代码重构方法,例如图2或图8所示的代码 重构方法。The present application also provides a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions are run on at least one processor, the aforementioned code reconstruction method is implemented, as shown in Figure 2 Or the code refactoring method shown in Figure 8.
本申请还提供了一种计算机程序产品,该计算机程序产品包括计算机指令,在被计算设备执行时,实现前述的代码重构方法,例如图2或图8所示的代码重构方法。The present application also provides a computer program product, the computer program product includes computer instructions, and when executed by a computing device, implements the aforementioned code refactoring method, such as the code refactoring method shown in FIG. 2 or FIG. 8 .
本申请实施例中,“示例性的”或者“例如”等词用于表示作例子、例证或说明。本申请中被描述为“示例性的”或者“例如”的任何实施例或设计方案不应被解释为比其他实施例或设计方案更优选或更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概念。In the embodiments of the present application, words such as "exemplary" or "for example" are used as examples, illustrations or descriptions. Any embodiment or design described herein as "exemplary" or "for example" is not to be construed as preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "such as" is intended to present related concepts in a concrete manner.
本申请中实施例提到的“至少一个”是指一个或者多个,“多个”是指两个或两个以上。“以下至少一项(个)”或其类似表达,是指的这些项中的任意组合,包括单项(个)或复数项(个)的任意组合。例如,a、b、或c中的至少一项(个),可以表示:a、b、c、(a和b)、(a和c)、(b和c)、或(a和b和c),其中a、b、c可以是单个,也可以是多个。“和/或”,描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A、同时存在A和B、单独存在B这三种情况,其中A、B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。The "at least one" mentioned in the embodiments of the present application refers to one or more, and the "multiple" refers to two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one item (piece) of a, b, or c may represent: a, b, c, (a and b), (a and c), (b and c), or (a and b and c), where a, b, c can be single or multiple. "And/or" describes the association relationship of associated objects, indicating that there may be three types of relationships, for example, A and/or B, which may indicate: A exists alone, A and B exist simultaneously, and B exists alone, among which A and B may be singular or plural. The character "/" generally indicates that the contextual objects are an "or" relationship.
以及,除非有相反的说明,本申请实施例使用“第一”、“第二”等序数词是用于对多个对象进行区分,不用于限定多个对象的顺序、时序、优先级或者重要程度。例如,第一事务和第二事务,只是为了便于描述,而并不是表示这第一事务和第二事务的事务结构、重要程度等的不同,在某些实施例中,第一事务和第二事务还可以是同样的事务。And, unless otherwise stated, the embodiments of the present application use ordinal numerals such as "first" and "second" to distinguish multiple objects, and are not used to limit the order, timing, priority or importance of multiple objects degree. For example, the first transaction and the second transaction are only for the convenience of description, and do not represent the difference in transaction structure, importance, etc. of the first transaction and the second transaction. In some embodiments, the first transaction and the second transaction A transaction can also be the same transaction.
上述实施例中所用,根据上下文,术语“当……时”可以被解释为意思是“如果……”或“在……后”或“响应于确定……”或“响应于检测到……”。以上所述仅为本申请的可选实施例,并不用以限制本申请,凡在本申请的构思和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。As used in the above embodiments, depending on the context, the term "when" may be interpreted to mean "if..." or "after" or "in response to determining..." or "in response to detecting... ". The above are only optional embodiments of the application, and are not intended to limit the application. Any modifications, equivalent replacements, improvements, etc. made within the concept and principles of the application shall be included in the protection of the application. within range.
本领域普通技术人员可以理解实现上述实施例的全部或部分步骤可以通过硬件来完成,也可以通过程序来指令相关的硬件完成,所述的程序可以存储于一种计算机可读存储介质中,上述提到的存储介质可以是只读存储器,磁盘或光盘等。Those of ordinary skill in the art can understand that all or part of the steps for implementing the above embodiments can be completed by hardware, and can also be completed by instructing related hardware through a program. The program can be stored in a computer-readable storage medium. The above-mentioned The storage medium mentioned may be a read-only memory, a magnetic disk or an optical disk, and the like.

Claims (34)

  1. 一种代码重构方法,其特征在于,包括:A code refactoring method, characterized in that it comprises:
    呈现第一用户界面,所述第一用户界面用于指示第一代码工程的代码结构,所述代码结构包含包、类、类成员或底层代码中的一种或多种元素;Presenting a first user interface, the first user interface is used to indicate the code structure of the first code project, the code structure includes one or more elements in packages, classes, class members or underlying code;
    接收用户在所述第一用户界面上输入的第一操作,所述第一操作用于更新所述第一代码工程的代码结构;receiving a first operation input by a user on the first user interface, where the first operation is used to update the code structure of the first code project;
    基于所述第一操作向第一服务器请求重构所述第一代码工程。Refactoring of the first code project is requested from a first server based on the first operation.
  2. 根据权利要求1所述的方法,其特征在于,所述方法还包括:method according to claim 1, is characterized in that, described method also comprises:
    获取经过重构的所述第一代码工程。Acquire the refactored first code project.
  3. 根据权利要求2所述的方法,其特征在于,所述第一操作包含针对所述元素的移动、增加、删除、编辑等中的一项或者多项。The method according to claim 2, wherein the first operation includes one or more of moving, adding, deleting, editing, etc. for the element.
  4. 根据权利要求1-3任一项所述的方法,其特征在于,所述第一用户界面还用于指示所述第一代码工程中存在的代码架构坏味道。The method according to any one of claims 1-3, wherein the first user interface is further used to indicate bad code architecture smells existing in the first code project.
  5. 根据权利要求4所述的方法,其特征在于,所述第一代码工程中存在的代码架构坏味道对应于所述元素;The method according to claim 4, wherein the code architecture bad smell existing in the first code project corresponds to the element;
    所述第一用户界面还用于通过颜色区分所述元素中存在代码架构坏味道的程度。The first user interface is also used to distinguish the degree of bad code structure smell in the elements by color.
  6. 根据权利要求3或4所述的方法,其特征在于,在所述呈现第一用户界面之前,所述方法还包括:The method according to claim 3 or 4, wherein, before presenting the first user interface, the method further comprises:
    接收第二服务器提供的所述第一代码工程的第一指示信息,所述第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道。Receive first indication information of the first code project provided by the second server, where the first indication information is used to indicate a code architecture smell existing in the first code project.
  7. 根据权利要求1-6任一项所述的方法,其特征在于,所述第一用户界面还用于指示重构推荐,所述重构推荐用于提示用户针对所述第一代码工程中存在的代码架构坏味道对所述第一代码工程进行修改。The method according to any one of claims 1-6, wherein the first user interface is further used to indicate a refactoring recommendation, and the refactoring recommendation is used to prompt the user for The code architecture bad smell makes modifications to the first code project.
  8. 根据权利要求7所述的方法,其特征在于,在所述呈现第一用户界面之前,所述方法还包括:The method according to claim 7, wherein, before presenting the first user interface, the method further comprises:
    接收第二服务器发送的所述重构推荐。The reconstruction recommendation sent by the second server is received.
  9. 根据权利要求1-8任一项所述的方法,其特征在于,所述基于所述第一操作向服务器请求重构所述第一代码工程,包括:The method according to any one of claims 1-8, wherein the requesting the server to reconstruct the first code project based on the first operation comprises:
    根据所述第一操作,得到原子重构序列,所述原子重构序列用于记录更新第一代码工程的操作顺序;According to the first operation, an atomic reconstruction sequence is obtained, and the atomic reconstruction sequence is used to record an operation sequence for updating the first code project;
    向所述第一服务器发送重构请求消息,所述重构请求消息包含所述原子重构序列。sending a reconstruction request message to the first server, where the reconstruction request message includes the atomic reconstruction sequence.
  10. 根据权利要求1-9任一项所述的方法,其特征在于,所述原子重构序列包含多个原子 重构操作,每个原子重构操作包含原子重构操作的标识和所述原子重构操作涉及的第一代码工程中的参数。The method according to any one of claims 1-9, wherein the atomic reconstruction sequence includes multiple atomic reconstruction operations, and each atomic reconstruction operation includes an identifier of the atomic reconstruction operation and the atomic reconstruction operation parameters in the first code project involved in the construction operation.
  11. 根据权利要求1-10任一项所述的方法,其特征在于,所述呈现第一用户界面之前,所述方法还包括:The method according to any one of claims 1-10, wherein before presenting the first user interface, the method further comprises:
    向第三服务器发送所述第一代码工程的第二指示信息;sending second indication information of the first code project to a third server;
    接收所述第三服务器提供的所述第一代码工程的代码结构。Receive the code structure of the first code project provided by the third server.
  12. 一种代码重构方法,其特征在于,包括:A code refactoring method, characterized in that it comprises:
    接收来自用户设备的重构请求消息,所述重构请求消息是根据在所述第一用户界面上输入的第一操作得到的,所述第一用户界面用于指示第一代码工程的代码结构,所述代码结构包含包、类、类成员或底层代码中的一种或多种元素,所述第一操作用于更新第一代码工程的代码结构;receiving a reconstruction request message from the user equipment, the reconstruction request message is obtained according to a first operation input on the first user interface, and the first user interface is used to indicate the code structure of the first code project , the code structure includes one or more elements in package, class, class member or underlying code, and the first operation is used to update the code structure of the first code project;
    根据所述重构请求消息,对所述第一代码工程进行重构。Refactor the first code project according to the refactoring request message.
  13. 根据权利要求12所示的方法,其特征在于,所述方法还包括;The method according to claim 12, characterized in that the method further comprises;
    向所述用户设备反馈经过重构的所述第一代码工程。Feedback the reconstructed first code project to the user equipment.
  14. 根据权利要求13所述的方法,其特征在于,所述第一操作包含针对所述元素的移动、增加、删除、编辑中的一项或者多项。The method according to claim 13, wherein the first operation includes one or more of moving, adding, deleting, and editing the element.
  15. 根据权利要求12-14任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 12-14, wherein the method further comprises:
    确定所述第一代码工程中存在的代码架构坏味道;Determining the code architecture bad smell that exists in the first code project;
    向所述用户设备发送第一指示信息,所述第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道。Sending first indication information to the user equipment, where the first indication information is used to indicate a code architecture smell existing in the first code project.
  16. 根据权利要求15所述的方法,其特征在于,所述第一代码工程中存在的代码架构坏味道对应于所述元素;The method according to claim 15, wherein the code architecture bad smell existing in the first code project corresponds to the element;
    所述第一用户界面还用于通过颜色区分指示所述元素中存在代码架构坏味道的程度。The first user interface is further used to indicate the degree of bad code structure smell in the element through color distinction.
  17. 根据权利要求15或16所述的方法,其特征在于,所述确定所述第一代码工程中存在的代码架构坏味道,包含:The method according to claim 15 or 16, wherein the determining the bad smell of the code architecture in the first code project comprises:
    通过架构坏味道检测模型,确定所述第一代码工程中的代码架构坏味道。The code architecture smell in the first code project is determined by using the architecture smell detection model.
  18. 根据权利要求13-15任一项所述的方法,其特征在于,所述确定所述第一代码工程中存在的代码架构坏味道,包含:The method according to any one of claims 13-15, wherein the determining the bad smell of the code architecture existing in the first code project comprises:
    对所述第一代码工程进行代码静态分析、文本相似度计算,得到所述第一代码工程中的代码架构坏味道。Static code analysis and text similarity calculation are performed on the first code project to obtain the bad smell of the code structure in the first code project.
  19. 根据权利要求12-18任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 12-18, wherein the method further comprises:
    确定重构推荐,所述重构推荐用于提示用户针对所述第一代码工程中存在的代码架构坏 味道对所述第一代码工程进行修改;Determining a refactoring recommendation, where the refactoring recommendation is used to prompt the user to modify the first code project for the bad smell of the code architecture existing in the first code project;
    向所述用户设备发送所述重构推荐。Sending the reconstruction recommendation to the user equipment.
  20. 根据权利要求12-19任一项所述的方法,其特征在于,所述重构请求消息包含所述原子重构序列,所述原子重构序列用于记录修改更新第一代码工程的操作顺序;The method according to any one of claims 12-19, wherein the reconstruction request message includes the atomic reconstruction sequence, and the atomic reconstruction sequence is used to record the operation sequence of modifying and updating the first code project ;
    所述根据所述重构请求消息,对所述第一代码工程进行重构,包括:The refactoring of the first code project according to the refactoring request message includes:
    根据所述重构请求消息中的原子重构序列,对所述第一代码工程进行重构。The first code project is reconstructed according to the atomic reconstruction sequence in the reconstruction request message.
  21. 根据权利要求12-20任一项所述的方法,其特征在于,所述原子重构序列包含多个原子重构操作,每个原子重构操作包含原子重构操作的标识和所述原子重构操作涉及的第一代码工程中的元素。The method according to any one of claims 12-20, wherein the atomic reconstruction sequence contains multiple atomic reconstruction operations, and each atomic reconstruction operation contains the identifier of the atomic reconstruction operation and the atomic reconstruction operation Elements in the first code project involved in the construct operation.
  22. 根据权利要求12-21任一项所述的方法,其特征在于,所述接收来自用户设备的重构请求消息之前,所述方法还包括:The method according to any one of claims 12-21, wherein before receiving the reconfiguration request message from the user equipment, the method further comprises:
    接收来自所述用户设备的第一代码工程的指示信息;receiving indication information of a first code project from the user equipment;
    确定所述第一代码工程的代码结构;determining the code structure of the first code project;
    向用户设备提供所述第一代码工程的代码结构。The code structure of the first code project is provided to the user equipment.
  23. 一种代码重构系统,其特征在于,所述代码重构系统包括用户设备和服务器,其中;A code reconstruction system, characterized in that the code reconstruction system includes a user device and a server, wherein;
    所述用户设备,用于呈现第一用户界面,所述第一用户界面用于指示第一代码工程的代码结构,所述代码结构包含包、类、类成员或底层代码中的一种或多种元素;The user equipment is configured to present a first user interface, the first user interface is used to indicate a code structure of a first code project, and the code structure includes one or more of a package, a class, a class member, or an underlying code kind of element;
    所述用户设备,还用于接收用户在所述第一用户界面上输入的第一操作,所述第一操作用于更新所述第一代码工程的代码结构;The user equipment is further configured to receive a first operation input by a user on the first user interface, where the first operation is used to update the code structure of the first code project;
    所述用户设备,还用于向所述服务器发送重构推荐消息,所述重构请求消息是根据在所述第一用户界面上输入的第一操作得到的;The user equipment is further configured to send a reconstruction recommendation message to the server, where the reconstruction request message is obtained according to a first operation input on the first user interface;
    所述服务器,用于接收来自所述用户设备的重构请求消息;The server is configured to receive a reconfiguration request message from the user equipment;
    所述服务器,还用于根据所述重构请求消息,对所述第一代码工程进行重构。The server is further configured to refactor the first code project according to the refactoring request message.
  24. 根据权利要求23所述的系统,其特征在于,所述服务器还用于向所述用户设备反馈经过重构的所述第一代码工程;The system according to claim 23, wherein the server is further configured to feed back the reconstructed first code project to the user equipment;
    所述用户设备还用于接收所述服务器提供的经过重构的所述第一代码工程。The user equipment is further configured to receive the reconstructed first code project provided by the server.
  25. 根据权利要求23或24所述的系统,其特征在于,所述第一操作包含针对所述元素的移动、增加、删除、编辑中的一项或者多项。The system according to claim 23 or 24, wherein the first operation includes one or more of moving, adding, deleting and editing of the element.
  26. 根据权利要求23-25任一项所述的系统,其特征在于,所述服务器还用于:The system according to any one of claims 23-25, wherein the server is also used for:
    确定所述第一代码工程中存在的代码架构坏味道;Determining the code architecture bad smell that exists in the first code project;
    向所述用户设备发送第一指示信息,所述第一指示信息用于指示所述第一代码工程中存在的代码架构坏味道;Sending first indication information to the user equipment, where the first indication information is used to indicate a code architecture smell existing in the first code project;
    所述用户设备还用于:The user equipment is also used for:
    接收来自所述服务器的第一指示信息;receiving first indication information from the server;
    通过所述第一用户界面指示所述第一代码工程中存在的代码架构坏味道。A bad code architecture smell existing in the first code project is indicated through the first user interface.
  27. 根据权利要求26所述的系统,其特征在于,所述服务器,还用于通过架构坏味道检测模型,确定所述第一代码工程中的代码架构坏味道。The system according to claim 26, wherein the server is further configured to determine a code architecture smell in the first code project by using an architecture smell detection model.
  28. 根据权利要求26或27所述的系统,其特征在于,所述服务器,还用于对所述第一代码工程进行代码静态分析、文本相似度计算,得到所述第一代码工程中的代码架构坏味道。The system according to claim 26 or 27, wherein the server is further configured to perform code static analysis and text similarity calculation on the first code project to obtain the code structure in the first code project bad taste.
  29. 根据权利要求23-28任一项所述的系统,其特征在于,所述服务器,还用于:The system according to any one of claims 23-28, wherein the server is also used for:
    确定重构推荐,所述重构推荐用于提示用户针对所述第一代码工程中存在的代码架构坏味道对所述第一代码工程进行修改;Determining a refactoring recommendation, where the refactoring recommendation is used to prompt the user to modify the first code project for the bad smell of the code architecture existing in the first code project;
    向所述用户设备发送所述重构推荐;sending the reconstruction recommendation to the user equipment;
    所述用户设备,还用于:The user equipment is also used for:
    接收所述服务器提供的所述重构推荐;receiving the reconstruction recommendation provided by the server;
    通过所述第一用户界面指示所述重构推荐。The refactoring recommendation is indicated through the first user interface.
  30. 根据权利要求23-29任一项所述的系统,其特征在于,所述用户设备还用于向所述服务器发送所述第一代码工程的第二指示信息;The system according to any one of claims 23-29, wherein the user equipment is further configured to send second indication information of the first code project to the server;
    所述服务器,还用于确定所述第一代码工程的代码结构;The server is further configured to determine the code structure of the first code project;
    所述服务器,还用于向所述用户设备发送所述第一代码工程的代码结构;The server is further configured to send the code structure of the first code project to the user equipment;
    所述用户设备,还用于接收所述服务器提供的所述第一代码工程的代码结构;The user equipment is further configured to receive the code structure of the first code project provided by the server;
    所述用户设备,还用于通过所述第一用户界面指示所述第一代码工程的代码结构。The user equipment is further configured to indicate the code structure of the first code project through the first user interface.
  31. 一种代码重构装置,其特征在于,所述代码重构装置包含处理单元和通信单元,所述代码重构装置用于实现权利要求1-11中任一项所述的方法。A code reconstruction device, characterized in that the code reconstruction device comprises a processing unit and a communication unit, and the code reconstruction device is used to implement the method according to any one of claims 1-11.
  32. 一种代码重构装置,其特征在于,所述代码重构装置包含处理单元和通信单元,所述代码重构装置用于实现权利要求12-22中任一项所述的方法。A code reconstruction device, characterized in that the code reconstruction device includes a processing unit and a communication unit, and the code reconstruction device is used to implement the method described in any one of claims 12-22.
  33. 一种计算设备,其特征在于,所述计算设备包括处理器和存储器;A computing device, characterized in that the computing device includes a processor and a memory;
    所述存储器中存储有计算机程序;所述处理器执行所述计算机程序时,所述计算设备实现权利要求1-11中任一项所述的方法,或者实现权利要求12至22中任一项所述的方法。A computer program is stored in the memory; when the processor executes the computer program, the computing device realizes the method according to any one of claims 1-11, or realizes any one of claims 12-22 the method described.
  34. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有指令,当所述指令在至少一个处理器上运行时,实现权利要求1至22中任一项所述的方法。A computer-readable storage medium, characterized in that instructions are stored in the computer-readable storage medium, and when the instructions are run on at least one processor, the method described in any one of claims 1 to 22 is implemented. method.
PCT/CN2022/129822 2022-02-18 2022-11-04 Code refactoring method and device WO2023155487A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210152592.3 2022-02-18
CN202210152592.3A CN116661851A (en) 2022-02-18 2022-02-18 Code reconstruction method and device

Publications (1)

Publication Number Publication Date
WO2023155487A1 true WO2023155487A1 (en) 2023-08-24

Family

ID=87577457

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/129822 WO2023155487A1 (en) 2022-02-18 2022-11-04 Code refactoring method and device

Country Status (2)

Country Link
CN (1) CN116661851A (en)
WO (1) WO2023155487A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110162335A (en) * 2019-04-26 2019-08-23 深圳壹账通智能科技有限公司 Code refactoring method, apparatus, computer equipment and medium
US10534604B1 (en) * 2018-03-20 2020-01-14 Architecture Technology Corporation Software refactoring systems and methods
CN111722873A (en) * 2020-07-23 2020-09-29 腾讯科技(深圳)有限公司 Code reconstruction method, device, equipment and medium
CN112764758A (en) * 2021-01-21 2021-05-07 中国工商银行股份有限公司 Code bad taste detection method and device
US11042369B1 (en) * 2020-02-03 2021-06-22 Architecture Technology Corporation Systems and methods for modernizing and optimizing legacy source code

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10534604B1 (en) * 2018-03-20 2020-01-14 Architecture Technology Corporation Software refactoring systems and methods
CN110162335A (en) * 2019-04-26 2019-08-23 深圳壹账通智能科技有限公司 Code refactoring method, apparatus, computer equipment and medium
US11042369B1 (en) * 2020-02-03 2021-06-22 Architecture Technology Corporation Systems and methods for modernizing and optimizing legacy source code
CN111722873A (en) * 2020-07-23 2020-09-29 腾讯科技(深圳)有限公司 Code reconstruction method, device, equipment and medium
CN112764758A (en) * 2021-01-21 2021-05-07 中国工商银行股份有限公司 Code bad taste detection method and device

Also Published As

Publication number Publication date
CN116661851A (en) 2023-08-29

Similar Documents

Publication Publication Date Title
US11789715B2 (en) Systems and methods for transformation of reporting schema
US10579344B2 (en) Converting visual diagrams into code
US10481884B2 (en) Systems and methods for dynamically replacing code objects for code pushdown
US11620117B2 (en) Systems and methods for code clustering analysis and transformation
US10592562B2 (en) Cloud deployment of a data fabric service system
US8706771B2 (en) Systems and methods for analyzing and transforming an application from a source installation to a target installation
US8145651B2 (en) On-demand database service system and method for determining whether a developed application will operate properly with at least one other application
US8671222B2 (en) Systems and methods for dynamically deploying an application transformation tool over a network
US11429365B2 (en) Systems and methods for automated retrofitting of customized code objects
CN104679500B (en) Method and device for realizing automatic generation of entity class
WO2023051125A1 (en) Structured data version management method, apparatus, and related device
WO2023155487A1 (en) Code refactoring method and device
EP3430518B1 (en) Analysis of recurring processes
CN115469860A (en) Method and system for automatically generating demand-to-software field model based on instruction set
Flake Towards the Completion of the Formal Semantics of OCL 2.0
CN109343871A (en) Method, apparatus, equipment and the storage medium that application program is packaged
CN110297651A (en) The update method and device of the common variable of protocol interface
WO2024040930A1 (en) Software deployment architecture management method and related device
WO2024086806A1 (en) Scanning application code to detect and classify sdk data into data categories
AU2015200369B2 (en) Widget framework, real-time service orchestration, and real-time resource aggregation
CN113760267A (en) Conditional rule multiplexing method based on interactive rule engine
CN114020965A (en) Data conversion method, device and storage medium
CN115495061A (en) Operation template script for industrial simulation software and implementation method
CN117035939A (en) Service order processing method, device, computing equipment and computer storage medium
CN117573758A (en) Data stream arrangement method based on BI platform

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22926791

Country of ref document: EP

Kind code of ref document: A1