CN111625275B - Code reconstruction planning method and device, storage medium and electronic equipment - Google Patents

Code reconstruction planning method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN111625275B
CN111625275B CN202010355273.3A CN202010355273A CN111625275B CN 111625275 B CN111625275 B CN 111625275B CN 202010355273 A CN202010355273 A CN 202010355273A CN 111625275 B CN111625275 B CN 111625275B
Authority
CN
China
Prior art keywords
function
call
target
information
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010355273.3A
Other languages
Chinese (zh)
Other versions
CN111625275A (en
Inventor
刘金玲
于全江
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beike Technology Co Ltd
Original Assignee
Beike Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beike Technology Co Ltd filed Critical Beike Technology Co Ltd
Priority to CN202010355273.3A priority Critical patent/CN111625275B/en
Publication of CN111625275A publication Critical patent/CN111625275A/en
Application granted granted Critical
Publication of CN111625275B publication Critical patent/CN111625275B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application discloses a code reconstruction planning method, a device, a storage medium and electronic equipment, and relates to a code reconstruction technology. The specific scheme comprises the following steps: acquiring a code to be reconstructed; determining function name information of an objective function to be reconstructed, class name information of a class to which the objective function belongs and calling relation information of the objective function according to the code to be reconstructed; the call relation information comprises at least one of the following: transaction call information, event call information and function call information; and determining the reconstruction type of the target function according to the function name information of the target function, the class name information of the class to which the target function belongs and the calling relation information of the target function. The application can determine the reconstruction type of the objective function in advance, so that a developer performing code reconstruction can perform code reconstruction operation according to the reconstruction type of the objective function, and the efficiency of code reconstruction is improved.

Description

Code reconstruction planning method and device, storage medium and electronic equipment
Technical Field
The present application relates to code reconstruction techniques, and in particular, to a code reconstruction planning method, apparatus, storage medium, and electronic device.
Background
Along with the development of internet technology, online systems used in the internet field are becoming larger, more developers participate in online system development, and code structures for implementing the online systems are becoming more complex. The complex code often has the problems of unclear structure division, disordered calling relationship, cyclic calling and the like, and the problems of cyclic calling and the like are easy to occur, and the complex code structure needs to be reconstructed to improve the problems in the code structure and prevent the code debugging and modification from producing excessive influence on the code of the whole system.
Existing methods of reconstructing code structures are typically performed by modifying code logic, etc., and each reconstruction needs to be performed separately for a specific function. However, the code logic is not required to be modified every time the code structure is reconstructed, the specific condition of the objective function to be reconstructed is not distinguished, and the code is directly reconstructed by adopting a method for modifying the code logic, so that the efficiency is lower.
Disclosure of Invention
Therefore, a main object of the present application is to provide a code reconstruction planning method, which can determine a reconstruction type of an objective function in advance, so that a developer performing code reconstruction can perform a code reconstruction operation according to the reconstruction type of the objective function, and improve efficiency of code reconstruction.
In order to achieve the above purpose, the technical scheme provided by the application is as follows:
in a first aspect, an embodiment of the present application provides a code reconstruction planning method, including the following steps:
acquiring a code to be reconstructed;
determining function name information of an objective function to be reconstructed, class name information of a class to which the objective function belongs and calling relation information of the objective function according to the code to be reconstructed; the call relation information comprises at least one of the following: transaction call information, event call information and function call information;
and determining the reconstruction type of the target function according to the function name information of the target function, the class name information of the class to which the target function belongs and the calling relation information of the target function.
In a possible implementation manner, the step of determining class name information of the class to which the objective function belongs according to the code to be reconstructed includes:
and determining class name information of the class to which the objective function belongs by using a reflection mechanism.
In a possible implementation manner, the step of determining function name information of the objective function according to the code to be reconstructed includes:
and determining function name information of the objective function according to the statement keywords of the objective function.
In a possible implementation manner, when the call relationship information includes transaction call information, the step of determining the call relationship information of the objective function according to the code to be reconstructed includes:
judging whether the target function comprises a calling statement of the transaction according to the calling keyword of the transaction;
when the target function comprises a call statement of the transaction, identifying transaction call information of the target function as containing transaction call;
the step of determining the reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class to which the objective function belongs and the call relation information of the objective function comprises the following steps:
judging whether the target function contains transaction call or not according to the transaction call information of the target function;
when the target function includes a transaction call, a reconstruction type of the target function is determined as a code transformation type.
In a possible implementation manner, when the call relationship information includes event call information, the step of determining the call relationship information of the objective function according to the code to be reconstructed includes:
judging whether the target function comprises a calling statement of the event according to the calling keyword of the event;
When the target function comprises a calling statement of the event, determining the name of the called event according to the calling statement of the event;
and determining the name of the called event as event calling information of the target function.
The step of determining the reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class to which the objective function belongs and the call relation information of the objective function comprises the following steps:
judging whether the objective function contains the event calling information or not;
and when the target function contains the event calling information, determining the reconstruction type of the target function as a code transformation type.
In a possible implementation manner, when the call relationship information includes function call information, the step of determining the call relationship information of the target function according to the code to be reconstructed includes:
judging whether the target function contains a call statement of the function according to the call keyword of the function;
when the target function contains a call statement of a function, determining function name information of the called function according to the call statement of the function, and determining class name information of a class to which the called function belongs by utilizing a reflection mechanism.
In a possible implementation manner, the step of determining the reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class to which the objective function belongs, and the call relationship information of the objective function is:
judging whether the target function is called according to the function calling information;
judging whether the target function is an entry function or not when the target function is not called, and determining the reconstruction type of the target function as a function deletion type when the target function is not an entry function;
when the target function is called, judging whether a cyclic calling condition exists in a calling relation chain of the target function;
when a loop call condition exists, determining the reconstruction type of the target function as a code transformation type;
when the cyclic calling condition does not exist, judging whether the function calling the target function belongs to the same class;
when the functions calling the target functions do not belong to the same class, judging whether function calling exists in the target functions;
when a function call exists in the objective function, determining the reconstruction type of the objective function as a code transformation type; when no function call exists in the objective function, determining the reconstruction type of the objective function as a code migration type;
When the functions calling the target functions belong to the same class, judging whether function calling exists in the target functions;
when a function call exists in the target function, judging whether the called function of the target function and the target function belong to the same class;
when the called function of the target function and the target function belong to the same class, determining the reconstruction type of the target function as a code migration type; when the called function of the target function and the target function do not belong to the same class, determining the reconstruction type of the target function as a code transformation type;
when no function call exists in the objective function, judging whether a database module is called in the objective function;
and when the database module is called in the objective function, determining the reconstruction type of the objective function as a code migration type.
In a possible implementation manner, after the step of determining the reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class to which the objective function belongs, and the call relationship information of the objective function, the method further includes:
And determining reconstruction cost data of code reconstruction according to the reconstruction type of at least one objective function in the code to be reconstructed.
In a possible implementation manner, the step of determining reconstruction cost data of code reconstruction according to the reconstruction type of at least one objective function in the code to be reconstructed includes:
determining the total number of functions included in the reconstruction type for each reconstruction type respectively;
and determining the reconstruction cost data of the code reconstruction according to the total number of functions respectively included by each reconstruction type and the respective sub-cost data of each reconstruction type.
In a possible implementation manner, after the step of determining the reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class to which the objective function belongs, and the call relationship information of the objective function, the method further includes:
and testing the objective function according to the reconstruction type of the objective function.
In a possible implementation manner, when the reconstruction type of the objective function is a code transformation type, the call relation information of the objective function includes the function call information;
The step of testing the objective function includes:
determining a calling relation chain of the target function according to the function calling information of the target function;
according to the calling relation chain, determining an entry function with a calling relation with the target function as a target entry function;
and testing the target function by testing whether the function of the target entry function is correct.
In a possible implementation, when the reconstruction type of the objective function is a code migration type,
the step of testing the objective function includes:
and testing the target function by comparing whether the code content of the target function after migration is the same as the code content of the target function before migration.
In a second aspect, an embodiment of the present application further provides a code reconstruction planning apparatus, including:
the acquisition module is used for acquiring the code to be reconstructed;
the class name determining module is used for determining class name information of a class to which the objective function to be reconstructed belongs according to the code to be reconstructed;
the function name determining module is used for determining function name information of the objective function to be reconstructed according to the code to be reconstructed;
The calling relation determining module is used for determining calling relation information of the target function according to the code to be reconstructed; the call relation information comprises at least one of the following: transaction call information, event call information and function call information;
and the reconstruction type determining module is used for determining the reconstruction type of the target function according to the function name information of the target function, the class name information of the class to which the target function belongs and the call relation information of the target function.
In a possible implementation manner, the class name determining module is configured to determine class name information of a class to which the objective function belongs by using a reflection mechanism.
In a possible implementation manner, the function name determining module is configured to determine function name information of the objective function according to the declaration keyword of the objective function.
In a possible implementation manner, when the call relation information includes transaction call information, the call relation determining module includes:
the transaction call information determining unit is used for judging whether the target function comprises a call statement of the transaction according to the call keyword of the transaction; when the target function comprises a call statement of the transaction, identifying transaction call information of the target function as containing transaction call;
The reconstruction type determining module is used for:
judging whether the target function contains transaction call or not according to the transaction call information of the target function; when the target function includes a transaction call, a reconstruction type of the target function is determined as a code transformation type.
In a possible implementation manner, when the call relation information includes event call information, the call relation determining module includes:
the event calling information determining unit is used for judging whether the target function comprises a calling statement of an event according to the calling keyword of the event; when the target function comprises a calling statement of the event, determining the name of the called event according to the calling statement of the event; and determining the name of the called event as event calling information of the target function.
The reconstruction type determining module is used for:
judging whether the objective function contains the event calling information or not; and when the target function contains the event calling information, determining the reconstruction type of the target function as a code transformation type.
In a possible implementation manner, when the call relation information includes function call information, the call relation determining module includes:
The function information determining unit is used for judging whether the target function contains a call statement of the function according to the call keyword of the function; when the target function contains a call statement of a function, determining function name information of the called function according to the call statement of the function, and determining class name information of a class to which the called function belongs by utilizing a reflection mechanism.
In a possible implementation manner, the reconstruction type determining module includes:
the first judging subunit is used for judging whether the target function is called according to the function calling information;
a type determining unit, configured to determine whether the objective function is an entry function when the objective function is not called, and determine a reconstruction type of the objective function as a function deletion type when the objective function is not an entry function;
the second judging subunit is used for judging whether a cyclic calling condition exists in a calling relation chain of the target function when the target function is called;
the type determining unit is used for determining the reconstruction type of the target function as a code transformation type when a cyclic calling condition exists;
a third judging subunit, configured to judge whether a function calling the objective function belongs to the same class when there is no cyclic calling condition;
A fourth judging subunit, configured to judge whether there is a function call in the objective function when the functions that call the objective function do not belong to the same class;
a type determining unit, configured to determine a reconstruction type of the objective function as a code transformation type when there is a function call in the objective function; when no function call exists in the objective function, determining the reconstruction type of the objective function as a code migration type;
a fifth judging subunit, configured to judge whether there is a function call in the objective function when the functions that call the objective function belong to the same class;
a sixth judging subunit, configured to judge, when there is a function call in the objective function, whether a called function of the objective function and the objective function belong to the same class;
a type determining unit, configured to determine a reconstruction type of the objective function as a code migration type when a called function of the objective function and the objective function belong to the same class; when the called function of the target function and the target function do not belong to the same class, determining the reconstruction type of the target function as a code transformation type;
A seventh judging subunit, configured to judge whether a database module is called in the objective function when there is no function call in the objective function;
and the type determining unit is used for determining the reconstruction type of the target function as a code migration type when the database module is called in the target function.
In a possible embodiment, the apparatus further comprises:
and the cost data determining module is used for determining reconstruction cost data of code reconstruction according to the reconstruction type of at least one objective function in the code to be reconstructed.
In a possible implementation manner, the cost data determining module includes:
a function statistics unit, configured to determine, for each of the reconstruction types, a total number of functions included in the reconstruction type;
and the cost determining unit is used for determining the reconstruction cost data of the code reconstruction according to the total number of functions respectively included by each reconstruction type and the respective sub-cost data of each reconstruction type.
In a possible embodiment, the apparatus further comprises:
and the test module is used for testing the objective function according to the reconstruction type of the objective function.
In a possible implementation manner, when the reconstruction type of the objective function is a code transformation type, the call relation information of the objective function includes the function call information;
the test module is used for:
determining a calling relation chain of the target function according to the function calling information of the target function;
according to the calling relation chain, determining an entry function with a calling relation with the target function as a target entry function;
and testing the target function by testing whether the function of the target entry function is correct.
In a possible implementation, when the reconstruction type of the objective function is a code migration type,
the test module is used for:
and testing the target function by comparing whether the code content of the target function after migration is the same as the code content of the target function before migration.
In a third aspect, embodiments of the present application also provide a computer-readable storage medium. The specific scheme is as follows:
a computer readable storage medium storing computer instructions which when executed by a processor perform the steps of any one of the possible implementations of the first aspect and the first aspect.
In a fourth aspect, the embodiment of the application further provides electronic equipment. The specific scheme is as follows:
an electronic device, the electronic device comprising:
a processor; a memory for storing the processor-executable instructions;
the processor is configured to read the executable instructions from the memory and execute the instructions to implement the steps of any one of the foregoing first aspect and any possible implementation manner of the first aspect.
In summary, the application provides a code reconstruction planning method, a device, a storage medium and an electronic device. According to the code to be reconstructed, function name information, class name information and calling relation information of the target function to be reconstructed are determined, and the reconstruction type of the target function is determined according to the function name information, the class name information and the calling relation information of the target function. Before a developer starts to reconstruct codes, determining a reconstruction scheme of the codes to be reconstructed, ensuring that each developer participating in the reconstruction can reconstruct the codes according to the determined reconstruction scheme, and improving the efficiency of the code reconstruction.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort to a person skilled in the art.
FIG. 1 is a schematic diagram of a code structure before reconstruction according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a reconstructed code structure according to an embodiment of the present application;
fig. 3 is a flow chart of a code reconstruction planning method according to an embodiment of the present application;
fig. 4 is a schematic flow chart of determining a reconstruction type of an objective function according to call relationship information in the code reconstruction planning method according to the embodiment of the present application;
fig. 5 is a schematic structural diagram of a code reconstruction planning apparatus according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of another code reconstruction planning apparatus according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a reconstruction type determining module in the code reconstruction planning apparatus according to the embodiment of the present application;
fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
The terms "first," "second," "third," "fourth" and the like in the description and in the claims and in the above drawings, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the application described herein may be implemented, for example, in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprise" and "have," as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those elements but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Along with the increasing size of online systems used in the internet field, more and more developers participate in online system development, and the code structure for realizing the online system is more and more complex. Complicated codes often have the problems of unclear structural division, disordered calling relationship, circular calling and the like. As shown in fig. 1, the code structures ServiceA, serviceB and ServiceC belong to three classes of a service layer, modelA, modelB and ModelC belong to three classes of a data layer, controllerA, controllerB belongs to two classes of an access layer, and due to the mutual call of functions between the same layers (for example, between the service layers shown in fig. 1), problems such as loop call are easy to occur, and abnormal conditions such as dead loop are easy to occur during code running. At this time, a complex code structure needs to be reconstructed to improve the problems existing in the code structure, and prevent debugging and modification of the code from having an excessive influence on the code of the whole system.
The goal of reconstructing the code is to reestablish a reasonable code hierarchy structure, so that the code structure is clear and the calling relationship is clear, for example, the code shown in fig. 1 is reconstructed into a tree-shaped code structure shown in fig. 2, serviceA, serviceB and ServiceC are three classes belonging to a service layer, coreServiceA, coreServiceB and CoreServiceC are three classes belonging to a service core layer, modelA, modelB and ModelC are three classes belonging to a data layer, controllerA, controllerB are two classes belonging to an access layer, and the problems of unclear structure division, messy calling relationship, cyclic calling and the like are solved by adding the service core layer and modifying functions in each layer and each class. The existing reconstruction method of the code structure is usually directly performed by modifying code logic and the like, and each reconstruction needs to be performed separately for specific functions. However, the code logic is not required to be modified every time the code structure is reconstructed, the specific condition of the objective function to be reconstructed is not distinguished, and the code is directly reconstructed by adopting a method for modifying the code logic, so that the efficiency is lower.
In view of this, the core points of the present application are: according to the code to be reconstructed, determining function name information of the objective function to be reconstructed, class name information of the class and calling relation information, and determining the reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class and the calling relation information. Before a developer starts to reconstruct codes, determining a reconstruction scheme of the codes to be reconstructed, ensuring that each developer participating in the reconstruction can reconstruct the codes according to the determined reconstruction scheme, and improving the efficiency of the code reconstruction.
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail with specific examples. The following embodiments may be combined with each other, and some embodiments may not be repeated for the same or similar concepts or processes.
Fig. 3 is a flow chart of a code reconstruction planning method according to an embodiment of the present application, as shown in fig. 3, where the embodiment mainly includes:
s301: and obtaining the code to be reconstructed.
Code is a source file written by a developer using a programming language supported by a software development tool. The code to be reconstructed is the target code for which the code reconstruction is required. In the computer field, a function is a block of code in which a particular function is implemented. The code to be reconstructed comprises at least one function.
S302: determining function name information of an objective function to be reconstructed, class name information of a class to which the objective function belongs and calling relation information of the objective function according to the code to be reconstructed; the call relation information comprises at least one of the following: transaction call information, event call information, and function call information.
Here, a transaction is a database transaction, which is a sequence of database operations that access and possibly manipulate data items in a database. A transaction consists of all database operations performed between the beginning of the transaction and the end of the transaction. An event is a special function that performs a particular operation.
The function of the code to be reconstructed, which is to be reconstructed, is the objective function. Before the code reconstruction, the embodiment of the application firstly determines the information related to the target function reconstruction according to the code to be reconstructed. Illustratively, function name information of the objective function, class name information of a class to which the objective function belongs, and call relationship information of the objective function are determined. Specifically, the function name information is name information of the objective function. The code to be reconstructed in the embodiment of the application is the code of object-oriented programming, so that the objective function is realized in the class, and the class name information of the class to which the objective function belongs is the name information of the class for realizing the objective function.
Here, the call relation information of the objective function includes information that the objective function is called by other functions and information that the objective function calls other functions, transactions, or events. Specifically, the call relation information may include at least one of transaction call information, event call information, and function call information according to a difference of the object function call objects. The transaction calling information is information which is called by the target function with the transaction as an object; the event calling information is information which is called by the target function by taking the event as an object; the function call information is information that the target function calls the function or information that the target function is called by the function.
S303: and determining the reconstruction type of the target function according to the function name information of the target function, the class name information of the class to which the target function belongs and the calling relation information of the target function.
According to the embodiment of the application, the reconstruction type of the target function is determined according to the function name information of the target function, the class name information of the class to which the target function belongs and the call relation information of the target function. Before the actual code reconstruction, the embodiment of the application takes each function in the code to be reconstructed as an objective function, determines the reconstruction type of the objective function, and reconstructs the code to be reconstructed according to the reconstruction type of the objective function.
Before a developer starts to reconstruct codes, a reconstruction scheme of the codes to be reconstructed is determined, so that each developer participating in the reconstruction can be guaranteed to reconstruct the codes according to the determined reconstruction scheme aiming at the calling relation characteristics of each function in the codes to be reconstructed, and the efficiency of the code reconstruction is improved.
In the implementation, after the code to be reconstructed is obtained, each function contained in the code to be reconstructed is used as an objective function, and the reconstruction type of the objective function is determined.
The class name information of the class to which the objective function belongs can be determined by utilizing a reflection mechanism according to the code to be reconstructed.
And then, determining the function name information of the objective function according to the declaration keywords of the objective function. Regardless of the programming language, the code to be reconstructed adopts declaration statements to define functions. Further, since declaration statements of functions are defined in a specific declaration keyword and a fixed grammar format, function name information of an objective function can be determined from the declaration keyword of the function. Illustratively, in JavaScript programming language, function is used as a declaration key, an objective function named test, which defines a statement as function test (). Therefore, a regular matching method can be adopted to match the declaration keywords of the functions in the code to be reconstructed, and further the function name information of the objective function is determined. Specifically, in the example, a regular matching method may be adopted to match out the declaration keyword function of the objective function, so as to determine the function name information test of the function.
The embodiment of the application also needs to determine the calling relation information of the target function. For transaction call information, it may be determined from the call key of the transaction. Specifically, judging whether the target function comprises a calling statement of the transaction according to the calling keyword of the transaction; and when the target function comprises a call statement of the transaction, identifying the transaction call information of the target function as containing transaction call. In the code to be reconstructed, the start of the transaction is also characterized using a specific call key, a fixed grammar format. Illustratively, in JavaScript programming language, the call key DB of the transaction is employed: : the begin transaction characterizes the transaction start. Therefore, the method of regular matching can be utilized to match the call keywords of the transaction in the code to be reconstructed, so as to determine whether the target function comprises the call statement of the transaction. In the embodiment of the application, whether the transaction is called only needs to be clear, so that the embodiment of the application only adopts the identification of whether the transaction call is included as the transaction call information of the target function. Specifically, when the target function includes a call statement of a transaction, transaction call information of the target function is identified as including a transaction call, for example, the transaction call information of the target function is identified as yes; when the target function does not include a transactional call statement, the transactional call information of the target function is identified as not containing a transactional call, e.g., the transactional call information of the target function is identified as no.
For event invocation information, it may be determined from the invocation key of the event. Specifically, judging whether the target function comprises a calling statement of an event according to a calling keyword of the event; when the target function comprises a calling statement of the event, determining the name of the called event according to the calling statement of the event; and determining the name of the called event as event calling information of the target function. In the code to be reconstructed, the event is invoked using a specific call key, a fixed grammar format. For example, in JavaScript programming language, an event may be invoked by invoking an event function. Therefore, the calling keywords of the event in the code to be reconstructed can be matched by using a regular matching method, so that whether the calling statement of the event is included in the objective function is determined. Specifically, for example, the call keyword of the event function may be used as the call keyword of the event, and it is determined whether the call statement of the event is included in the target function. When the call statement of the event is included, the name of the called event can be determined according to the call statement of the event, and the name of the called event is determined as event call information of the target function.
For function call information, it may be determined according to a call key of a function. Specifically, judging whether the target function contains a call statement of the function according to the call keyword of the function; when the target function contains a call statement of a function, determining function name information of the called function according to the call statement of the function, and determining class name information of a class to which the called function belongs by utilizing a reflection mechanism. The method can adopt a regular matching method to determine the call key words of the functions, further judge whether the target functions contain call sentences of the functions, and determine the function name information of the called functions according to the call sentences of the functions. Here, the called function is a function declared in the objective function, which is called by the objective function.
And respectively taking each function in the code to be reconstructed as a target function, and determining transaction call information, event call information and function call information of the target function to obtain the transaction call information, event call information and function call information of each function in the code to be reconstructed.
In actual implementation, call relation information of each function in the code to be reconstructed can be stored, so that the reconstruction type of the target function can be determined according to the call relation information.
Specifically, taking the call relationship of the target function as an example, assuming that the call relationship information of the target function includes transaction call information, event call information and function call information, the call relationship information of each function in the code to be reconstructed may be stored in the following structure:
class name information of the class: the information about the presence of XXX,
function name information: the information about the presence of XXX,
transaction call information: whether or not it is possible to determine,
event call information: {
Event 1, event 2.
},
Function call information of called functions of the target function: {
Function 1, function 2.
},
Function call information with the target function as a called function: {
Function 1, function 2.
}
After the calling relation information of each function in the code to be reconstructed is determined and stored, each function in the code to be reconstructed is taken as an objective function, and the reconstruction type of the objective function is determined according to the calling relation information.
Specifically, when the call relation information includes transaction call information, determining a reconstruction type of the target function according to the transaction call information. In order to prevent the situation of transaction nesting, judging whether the target function contains transaction calling according to the transaction calling information of the target function; when the objective function includes a transaction call, a reconstruction type of the objective function is determined as a code transformation type. In particular, when the class to which the objective function belongs is not located in the code layer directly called by the access layer, in order to prevent the transaction nesting, the transaction should be strictly forbidden in the objective function. Thus, when a transaction call is included in the objective function, the reconstruction type of the objective function should be determined as the code modification type. Since the transaction call information of the objective function is an identification of whether the transaction call is included, when the transaction call information of the objective function is identified as including the transaction call, for example, when the identification of the transaction call information of the objective function is yes, the transaction call is included in the objective function.
Here, according to the code reconstruction planning method provided by the embodiment of the application, the reconstruction type of the objective function is determined, so that a developer performing code reconstruction reconstructs the objective function according to the reconstruction type. In the embodiment of the present application, the reconstruction types of the objective function may include: code transformation type, code migration type and function deletion type. The code reconstruction type is a reconstruction type which needs to be reconstructed for code content of an objective function. The code migration type is a reconstruction type which needs to migrate the whole objective function to the objective hierarchy. The function deletion type is a reconstruction type requiring deletion of the objective function.
Because transaction nesting can cause great hidden trouble to system operation, and the problem of transaction nesting can be avoided only by analyzing and modifying the code content of the objective function, when the transaction call information of the objective function is identified as containing transaction call, the reconstruction type of the objective function is determined as the code modification type.
When the call relation information includes event call information, similar to the case of containing transaction call information, in order to prevent nested call of events, the target function is modified when the event call is contained in the target function, that is, the code content of the target function is modified. Specifically, judging whether the objective function contains the event calling information or not; and when the target function contains the event calling information, determining the reconstruction type of the target function as a code transformation type.
When the call relation information comprises function call information, the called function condition and the called condition of the target function in the function call chain are judged according to the specific function call information, and the reconstruction type of the target function is determined according to the called function condition and the called condition.
Specifically, the function call information includes the called function condition and the called condition of the target function in the function call chain, and when the call information of the target function is determined, the function name information of the called function is determined, and the class name information of the class to which the called function belongs is determined by utilizing the reflection mechanism. Thus, the function call information of the objective function can be recorded as:
function call information of called functions of the target function: {
Called functions of own class: {
Function 1, function 2.
},
Called functions of other classes: {
{ class name: XXX, function name: XXX } { class name: XXX, function name: XXX }.
},
},
Function call information with the target function as a called function: {
A set of functions called by its class: {
Function 1, function 2.
},
Function sets called by other classes: {
{ class name: XXX, function name: XXX } { class name: XXX, function name: XXX }.
},
}
Here, the own class refers to a class to which the objective function belongs, and the other classes in the code to be reconstructed refer to classes other than the class to which the objective function belongs.
Furthermore, a calling relation chain can be obtained according to the calling relation information containing the called function information and the called information, and whether the cyclic calling condition exists in the calling relation chain of the target function is determined according to the calling relation chain. The loop call condition of the call relation chain and the target function is also stored as a part of the call relation information.
When the reconstruction is carried out, in order to enable the reconstructed code structure to be clear and the calling relation to be clear after the reconstruction, hidden danger is avoided. Some code reconstruction criteria need to be complied with, for example:
1) Tightly forbidding function call between the same layers;
2) When an objective function is used by multiple classes of functions, it is necessary to sink the objective function to the next layer in order to maximize code multiplexing that implements the objective function;
3) When the objective function involves the invocation of multiple database models, the objective function needs to be placed on the upper layer of a plurality of layers so as to ensure that each database model corresponds to one data table;
4) The target function of the code layer which is not directly called with the access layer strictly forbids the use of the transaction so as to avoid the occurrence of the nesting condition of the transaction.
Therefore, according to the call relation information, the reconstruction type of the target function can be determined, and in particular, according to the function call information in the call relation information, the reconstruction type of the target function is determined.
The process of determining the reconstruction type of the objective function according to the function call information mainly comprises the steps of determining the reconstruction type of the objective function according to the called function of the objective function, the function taking the objective function as the called function, the class to which the called function of the objective function belongs and the class to which the function taking the objective function as the called function belongs. The specific flow is shown in fig. 4:
s401: and judging whether the target function is called according to the function calling information.
Specifically, according to the function call information taking the target function as the called function in the function call information, whether the target function is called or not is judged.
In the code to be reconstructed, a calling relation exists between functions and called functions, in the calling relation, functions in the calling positions of other functions are called calling functions, and functions in the calling relation in the calling positions of other functions are called functions.
Further, the called function of the objective function is a function called by the objective function.
The function taking the target function as the called function is the function calling the target function.
S402: when the objective function is not called, judging whether the objective function is an entry function or not.
The class to which the entry function belongs is located in the access layer, for example, in the code structure shown in fig. 1, the functions of the ControllerA class and the ControllerB class are entry functions, and the entry functions usually take the role of communicating with the outside, so that the entry functions are not called by the functions in the code to be reconstructed, and only the functions in the code to be reconstructed are called. Therefore, when the objective function is an entry function, no code reconstruction is required.
S403: and when the objective function is not an entry function, determining a reconstruction type of the objective function as a function deletion type.
When the objective function is not an entry function and is not called by any other function, the objective function is not used, and the objective function which is not called by any other function is not necessary, and the reconstruction type of the objective function is determined as a function deletion type. And deleting the objective function when the developer performs code reconstruction.
S404: when the target function is called, judging whether a loop calling condition exists in a calling relation chain of the target function.
When the target function is called, firstly judging whether a loop calling condition exists in a calling relation chain of the target function, and if the loop calling condition exists, the hidden danger of dead loop exists when the code to be reconstructed runs. Therefore, it is first determined whether a loop call condition exists in the call relation chain of the objective function.
For example, in the code structure shown in fig. 1, the ServiceA class, the ServiceB class and the ServiceC class have a mutual call condition, and at this time, there is a hidden danger of loop call, and if the objective function of the ServiceA class calls a function in the ServiceB class as a called function, there is a possibility that a function calls an objective function of the ServiceA class as a called function in a downstream of a call relation chain of the called function in the ServiceB class.
In a possible implementation manner, the call relation information may include not only function call information, but also transaction call information or event call information, and when the function call information, the transaction call information and the event call information are combined, the reconstruction type of the target function is judged. At this time, before judging whether the loop calling condition exists in the calling relation chain of the target function, judging whether the target function contains transaction calling information or event calling information, and determining the reconstruction type of the target function as the code transformation type when the target function contains the transaction calling information or the event calling information.
S405: and when a loop call condition exists, determining the reconstruction type of the target function as a code transformation type.
When the loop call condition exists in the call relation chain of the target function, the code content of the target function needs to be studied deeply to reconstruct the target function, and therefore, the reconstruction type of the target function is determined as the code reconstruction type.
S406: and when the cyclic calling condition does not exist, judging whether the function calling the target function belongs to the same class.
When the functions calling the objective functions do not belong to the same class, step S407 is executed; when the functions that call the objective function belong to the same class, step S410 is performed.
S407: and when the functions calling the target functions do not belong to the same class, judging whether function calling exists in the target functions.
When the function calling the objective function does not belong to the same class, similarly to the case of the ServiceB class in fig. 1, the objective function in the ServiceB class may be called by the functions belonging to the ServiceA class, the ServiceC class, and the ControllerB class, and at this time, the called functions of the objective function in the ServiceB class are two or more functions, and the functions calling the objective function in the ServiceB class do not belong to the same class. At this time, it is determined whether there is a function call in the objective function.
S408: when there is a function call in the objective function, determining the reconstruction type of the objective function as a code transformation type.
When the functions calling the objective function do not belong to the same class and there is a function call in the objective function, for example, the objective function in the ServiceB class is called by the functions of the ServiceA class, the ServiceC class and the ControllerB class respectively, and when the objective function in the ServiceB class calls the functions of the ServiceC class, there are situations of same-layer call, cross call and the like in the objective function, at this time, the code content of the objective function needs to be studied deeply to reconstruct the objective function, so that the reconstruction type of the objective function is determined as the code reconstruction type.
S409: and when no function call exists in the objective function, determining the reconstruction type of the objective function as a code migration type.
When the target function is not called by the functions of the same layer or the upper layer, and the functions of the next layer or the same layer are not called, the code content of the target function is only required to be migrated to the target level as a whole, and normally, the code content of the target function is required to be migrated downwards by at least one level. Specifically, for example, an objective function in the ServiceB class is migrated to the coreerviceb class. Thus, the reconstruction type of the objective function is determined as the code migration type in order to maximize the code multiplexing that implements the objective function.
S410: and when the functions calling the target functions belong to the same class, judging whether function calling exists in the target functions.
When the functions that call the objective function belong to the same class, the functions in the ServiceC class are called only by the ServiceB class, similar to the case of the ServiceC class in fig. 1. When there is a function call in the objective function, step S411 is executed; when there is no function call in the objective function, step S414 is performed.
S411: when the function call exists in the target function, judging whether the called function of the target function and the target function belong to the same class.
When the called function of the objective function and the objective function belong to the same class, it is indicated that the objective function calls a function belonging to the same class as itself, for example, the called function called by the objective function in the ServiceC class is also a function belonging to the ServiceC class, and step S412 is executed; when the called function of the objective function and the objective function do not belong to the same class, it is indicated that the objective function calls a function not belonging to the same class as itself, for example, the called function called by the objective function in the ServiceC class is a function belonging to the ServiceB class, and step S413 is performed.
S412: and when the called function of the target function and the target function belong to the same class, determining the reconstruction type of the target function as a code migration type.
When the objective function calls the function belonging to the same class as the objective function, the whole code content of the objective function is only required to be migrated to the objective level, and in general, the code content of the objective function is migrated to other classes of the same level, or the code content of the objective function is migrated to the class of the next level. For example, the objective function in the ServiceC class may be migrated into the ServiceB class, or the objective function in the ServiceC class may be migrated into the CoreServiceC class. Thus, the reconstruction type of the objective function is determined as the code migration type in order to maximize the code multiplexing that implements the objective function.
S413: and when the called function of the target function and the target function do not belong to the same class, determining the reconstruction type of the target function as a code transformation type.
When the target function calls a function which does not belong to the same class as the target function, the code content of the target function needs to be studied deeply to reconstruct the target function, and therefore the reconstruction type of the target function is determined as a code reconstruction type.
S414: and when no function call exists in the objective function, judging whether a database module is called in the objective function.
Assuming that the objective function in the ServiceA class does not call a function located at the service layer, at this time, it is determined whether the objective function in the ServiceA class calls a database module of the data layer, for example, it is determined that the objective function in the ServiceA class calls a database module (repositive) in the Model a class.
S415: and when the database module is called in the objective function, determining the reconstruction type of the objective function as a code migration type.
Assuming that the objective function in the ServiceA class calls a database module (repository) in the Model a class, the objective function in the ServiceA class is determined as a code migration type.
Furthermore, the code content of the objective function can be migrated to different levels according to the number of the calling database modules in the objective function. Specifically, for example, when the number of the calling database modules in the objective function is one, the code content of the objective function is migrated to the data layer; when the number of the called database modules in the objective function is more than two, the code content of the objective function is migrated to the upper layer of the data layer, so that each database model can correspond to one data table.
According to the code reconstruction planning method provided by the embodiment of the application, a static code analysis technology is used, the reconstruction type of each function in the code to be reconstructed is determined according to the function name information, the class name information and the calling relation information of the target function by taking each function in the code to be reconstructed as the target function, and the code reconstruction scheme is planned, so that the reconstruction scheme of the code to be reconstructed is determined before a developer starts to reconstruct the code. The embodiment of the application can provide a method for determining the reconstruction type of each function in the code to be reconstructed in batches by statically analyzing the code to be reconstructed. So that a developer can implement code reconstruction according to the reconstruction type, the code reconstruction can be performed according to the same reconstruction concept, the phenomenon that hundreds of people take place in the code reconstruction implementation process is avoided, and the efficiency and the accuracy of code reconstruction are improved.
Further, after determining the reconstruction type of the objective function by taking each function in the code to be reconstructed as an objective function, the embodiment of the application can determine reconstruction cost data of code reconstruction according to the reconstruction type of at least one objective function in the code to be reconstructed. Therefore, before the code reconstruction is executed, reconstruction cost data are estimated, how many developers or how much reconstruction time are needed are determined in advance, and the labor cost or the time cost required for the code reconstruction is planned.
Specifically, determining the total number of functions included in the reconstruction types for each reconstruction type respectively; and determining the reconstruction cost data of the code reconstruction according to the total number of functions respectively included by each reconstruction type and the respective sub-cost data of each reconstruction type. For example, the total number of functions included in the reconstruction type may be determined by summing, and thus the reconstruction cost data for the code reconstruction.
The sub-cost data of each reconstruction type is different, and for the function deletion type, only the objective function needs to be deleted, so that the cost is lowest; for the code migration type, migrating the code content of the objective function from the class to which the objective function belongs to the class of the objective hierarchy, so that the cost is low; for the code transformation type, the transformation needs to be carried out for specific code content of the objective function, and the cost is high.
According to each function in the code to be reconstructed, according to the reconstruction type of the function, the total number of the functions contained in each reconstruction type can be determined, and further, according to the total number of the functions respectively contained in each reconstruction type and the respective sub-cost data of each reconstruction type, reconstruction cost data of the code reconstruction is determined.
Here, the sub-cost data and the modification cost data may be any data commonly used for estimating the modification cost of the code, and may be, for example, human cost data or time cost data.
Further, in order to ensure the correctness of the reconstructed code to be reconstructed, prevent major fault hidden danger caused by reconstruction, further improve the reconstruction efficiency of the code, after the code to be reconstructed is reconstructed according to the reconstruction type, each function in the code to be reconstructed is used as an objective function, and the objective function is tested according to the reconstruction type of the objective function.
How to test the objective function is determined according to the reconstruction type of the objective function.
For the function deletion type, the objective function has been deleted, and no test is naturally required.
For the code modification type, the test needs to be performed depending on function call information in call relation information of the objective function. Specifically, according to the function call information of the target function, determining a call relation chain of the target function; according to the calling relation chain, determining an entry function with a calling relation with the target function as a target entry function; and testing the target function by testing whether the function of the target entry function is correct. For the code transformation type, since the code content of the objective function is changed, it is necessary to test whether the function of the modified objective function is correct. In the embodiment of the application, the target entry function with the calling relation with the target function is determined according to the calling relation chain, and whether the function of the target function is correct is deduced by testing whether the function of the target entry function is correct. Here, the entry function is a function located in a class of the access stratum, and the entry function generally plays a role of communication with the outside. The entry function is not called, but functions that act as interfaces call other functions. Thus, for each function in the code to be reconstructed, the uppermost layer in its call relationship chain is the entry function. The method is characterized in that the method comprises the steps of testing an entry function, namely, in practice, briefly testing the whole calling relation chain, wherein the function of the entry function is correct, and the fact that the whole calling relation chain can complete a normal function is explained; if the function of the entry function is wrong, the links with errors in the calling relation chain are proved. In practical implementation, each function in the reconstructed code to be reconstructed can be taken as an objective function, at least one objective entry function of the objective function is marked according to a calling relation chain of the objective function, and the at least one objective entry function is marked in a mode of unique identification information. And, by way of example, a regression testing method may be employed, in which each of the at least one target entry function is subjected to a regression test with the target entry function as a routing entry for the regression test. The test entry function is used for testing the objective function, so that the function of the objective function is tested, whether the calling relation chain of the objective function is smooth or not is also tested, the functional correctness of the objective function after the code is reconstructed can be automatically evaluated, directional reference is provided for further refined manual test, and the code reconstruction efficiency is further improved.
In the case of the code migration type, the code content of the whole objective function is migrated from the class to which the objective function source belongs to the class in the objective layer as it is when the objective function is code reconstructed due to the reconstruction type of the code migration type. Thus, the objective function can be tested by comparing whether the code content of the objective function after migration is the same as the code content of the objective function before migration. For example, an MD5 algorithm may be used to calculate the MD5 code of the objective function before migration and the MD5 code of the objective function after migration, respectively, and if the MD5 code of the objective function before migration and the MD5 code of the objective function after migration are the same, the code content of the objective function after migration is the same as the code content of the objective function before migration; if the MD5 code of the objective function before migration and the MD5 code of the objective function after migration are different, the code content of the objective function after migration is different from the code content of the objective function before migration. If the code content of the objective function is unchanged during the code migration, its function will not normally change. Therefore, after the code is reconstructed, the functional correctness of the objective function after the code is migrated can be automatically and roughly evaluated, a directional reference is provided for further refined manual testing, and the code reconstruction efficiency is further improved.
Furthermore, each function in the code to be reconstructed can be used as an objective function, and the test cost data of the code reconstruction can be determined according to the reconstruction type of at least one objective function in the code to be reconstructed. And determining test cost data of code reconstruction according to the total number of functions respectively included in each reconstruction type and the respective sub-test cost data of each reconstruction type.
Based on the same design concept, the embodiment of the application also provides a code reconstruction planning device, a storage medium and electronic equipment.
As shown in fig. 5, a code reconstruction planning apparatus 500 provided in an embodiment of the present application includes:
an obtaining module 501, configured to obtain a code to be reconstructed;
a class name determining module 502, configured to determine class name information of a class to which the objective function to be reconstructed belongs according to the code to be reconstructed;
a function name determining module 503, configured to determine function name information of an objective function to be reconstructed according to the code to be reconstructed;
a calling relation determining module 504, configured to determine calling relation information of the objective function according to the code to be reconstructed; the call relation information comprises at least one of the following: transaction call information, event call information and function call information;
The reconstruction type determining module 505 is configured to determine a reconstruction type of the objective function according to function name information of the objective function, class name information of a class to which the objective function belongs, and call relationship information of the objective function.
The obtaining module 501 is respectively connected with the class name determining module 502, the function name determining module 503 and the calling relation determining module 504, and sends the obtained code to be reconstructed to the class name determining module 502, the function name determining module 503 and the calling relation determining module 504. The class name determining module 502, the function name determining module 503 and the calling relation determining module 504 determine class name information of a class to which the objective function to be reconstructed belongs, function name information of the objective function and calling relation information of the objective function according to the code to be reconstructed, respectively. The class name determining module 502, the function name determining module 503 and the calling relation determining module 504 are connected with the reconstruction type determining module 505, and the class name information of the class to which the determined objective function belongs, the function name information of the objective function and the calling relation information of the objective function are sent to the reconstruction type determining module 505, and the reconstruction type determining module 505 determines the reconstruction type of the objective function.
In a possible implementation manner, the class name determining module 502 is configured to determine class name information of a class to which the objective function belongs by using a reflection mechanism.
In a possible implementation manner, the function name determining module 503 is configured to determine function name information of the objective function according to the declaration keyword of the objective function.
In a possible implementation manner, as shown in fig. 6, when the call relationship information includes transaction call information, the call relationship determining module 504 includes:
the transaction call information determining unit 641 is configured to determine whether the target function includes a call statement of a transaction according to a call keyword of the transaction; when the target function comprises a call statement of the transaction, identifying transaction call information of the target function as containing transaction call;
the reconstruction type determining module 505 is configured to:
judging whether the target function contains transaction call or not according to the transaction call information of the target function; when the target function includes a transaction call, a reconstruction type of the target function is determined as a code transformation type.
The transaction call information determining unit 641 is connected to the acquiring module 501 and the reconstruction type determining module 505, and determines transaction call information according to a call keyword of a transaction in the code to be reconstructed. And transmits the transaction call information to the reconstruction type determination module 505 so that the reconstruction type determination module 505 determines the reconstruction type of the objective function according to the transaction call information.
In a possible implementation manner, when the call relationship information includes event call information, the call relationship determining module 504 includes:
an event calling information determining unit 642, configured to determine whether the target function includes a calling statement of an event according to a calling keyword of the event; when the target function comprises a calling statement of the event, determining the name of the called event according to the calling statement of the event; and determining the name of the called event as event calling information of the target function.
The reconstruction type determining module 505 is configured to:
judging whether the objective function contains the event calling information or not; and when the target function contains the event calling information, determining the reconstruction type of the target function as a code transformation type.
The event call information determining unit 642 is connected to the acquiring module 501 and the reconstruction type determining module 505, and determines event call information according to a call keyword of an event in the code to be reconstructed. And transmits the event call information to the reconstruction type determination module 505 so that the reconstruction type determination module 505 determines the reconstruction type of the objective function according to the event call information.
In a possible implementation manner, when the call relationship information includes function call information, the call relationship determining module 504 includes:
a function call information determining unit 643, configured to determine, according to a call keyword of a function, whether the target function includes a call statement of the function; when the target function contains a call statement of a function, determining function name information of the called function according to the call statement of the function, and determining class name information of a class to which the called function belongs by utilizing a reflection mechanism.
The function call information determining unit 643 is connected to the acquiring module 501 and the reconstruction type determining module 505, and determines function call information according to a call keyword of a function in a code to be reconstructed. And transmits the function call information to the reconstruction type determination module 505 so that the reconstruction type determination module 505 determines the reconstruction type of the objective function according to the function call information.
In a possible implementation manner, as shown in fig. 7, the reconstruction type determining module 505 includes:
a first judging subunit 701, configured to judge whether the target function is called according to the function call information;
a type determining unit 702, configured to determine whether the objective function is an entry function when the objective function is not called, and determine a reconstruction type of the objective function as a function deletion type when the objective function is not an entry function;
A second judging subunit 703, configured to judge, when the target function is called, whether a loop call condition exists in a call relation chain of the target function;
a type determining unit 702, configured to determine, when a loop call condition exists, a reconstruction type of the objective function as a code transformation type;
a third judging subunit 704, configured to judge whether the functions calling the objective function belong to the same class when there is no loop calling condition;
a fourth judging subunit 705, configured to judge whether there is a function call in the objective function when the functions that call the objective function do not belong to the same class;
a type determining unit 702, configured to determine a reconstruction type of the objective function as a code modification type when there is a function call in the objective function; when no function call exists in the objective function, determining the reconstruction type of the objective function as a code migration type;
a fifth judging subunit 706, configured to judge whether there is a function call in the objective function when the functions that call the objective function belong to the same class;
a sixth judging subunit 707, configured to judge whether a called function of the objective function and the objective function belong to the same class when there is a function call in the objective function;
A type determining unit 702, configured to determine, when a called function of the objective function and the objective function belong to the same class, a reconstruction type of the objective function as a code migration type; when the called function of the target function and the target function do not belong to the same class, determining the reconstruction type of the target function as a code transformation type;
a seventh judging subunit 708, configured to judge whether a database module is called in the objective function when there is no function call in the objective function;
a type determining unit 702, configured to determine, when the database module is called in the objective function, a reconstruction type of the objective function as a code migration type.
The first determination subunit 701 is connected to the call relation determining module 504, acquires a function call relation and determines whether the target function is called, and the first determination subunit 701 is connected to the type determining unit 702 and sends the determination result to the type determining unit 702. The type determining unit 702 determines the reconstruction type of the objective function according to the determination result of the first determining subunit 701. The second judging subunit 703 is connected to the call relation determining module 504 and the type determining unit 702, and determines whether to operate the second judging subunit 703 according to the determination result of the type determining unit 702, where the second judging subunit 703 obtains the function call relation from the call relation determining module 504 and judges whether there is a loop call condition in the call relation chain of the target function, and sends the judgment result to the type determining unit 702. The type determining unit 702 determines the reconstruction type of the objective function according to the judgment result of the second judging subunit 703. The third judging subunit 704 is connected to the type determining unit 702, and determines whether to operate the third judging subunit 704 according to the determination result of the type determining unit 702, where the third judging subunit 704 is further connected to the calling relation determining module 504, the fourth judging subunit 705, and the fifth judging subunit 706, and the third judging subunit 704 determines whether to operate the fourth judging subunit 705 or the fifth judging subunit 706 according to the function calling relation. The fourth judging subunit 705 and the fifth judging subunit 706 are respectively connected to the call relation determining module 504, and respectively obtain the function call relation and judge. The fourth judging subunit 705 is further connected to the type determining unit 702, and sends the judging result to the type determining unit 702. The type determining unit 702 determines the reconstruction type of the objective function according to the judgment result of the fourth judging subunit 705. The fifth judgment subunit 706 is connected to the sixth judgment subunit 707 and the seventh judgment subunit 708, respectively, and the fifth judgment subunit 706 judges whether to operate the sixth judgment subunit 707 or the seventh judgment subunit 708 according to the function call relationship. The sixth determination subunit 707 and the seventh determination subunit 708 are respectively connected to the call relationship determining module 504, and respectively obtain the function call relationship and determine. The sixth determination subunit 707 and the seventh determination subunit 708 are respectively connected to the type determination unit 702, and send the determination result to the type determination unit 702. The type determining unit 702 determines the reconstruction type of the objective function according to the determination results of the sixth determining subunit 707 and the seventh determining subunit 708.
In one possible embodiment, as shown in fig. 6, the apparatus 500 further includes:
and the cost data determining module 506 is configured to determine reconstruction cost data of the code reconstruction according to the reconstruction type of at least one objective function in the code to be reconstructed.
The cost data determining module 506 is connected to the reconstruction type determining module 505, and determines reconstruction cost data of the code reconstruction according to the reconstruction type determined by the reconstruction type determining module 505.
In a possible implementation manner, as shown in fig. 6, the cost data determining module 506 includes:
a function statistics unit 661, configured to determine, for each of the reconstruction types, a total number of functions included in the reconstruction type;
a cost determining unit 662, configured to determine the reconstruction cost data of the code reconstruction according to the total number of functions included in each reconstruction type and the respective sub-cost data of each reconstruction type.
The function statistics unit 661 is connected to the reconstruction type determination module 505, and determines the total number of functions included in each reconstruction type, respectively. The function statistics unit 661 is connected to the cost determination unit 662, and transmits the total number of functions included in each of the determined reconstruction types to the cost determination unit 662, and the cost determination unit 662 determines reconstruction cost data of the code reconstruction.
In one possible embodiment, as shown in fig. 6, the apparatus 500 further includes:
and the testing module 507 is used for testing the objective function according to the reconstruction type of the objective function.
The test module 507 is connected with the reconstruction type determination module 505, and tests the objective function according to the reconstruction type determined by the reconstruction type determination module 505.
In a possible implementation manner, when the reconstruction type of the objective function is a code transformation type, the call relation information of the objective function includes the function call information;
the test module 507 is configured to:
determining a calling relation chain of the target function according to the function calling information of the target function;
according to the calling relation chain, determining an entry function with a calling relation with the target function as a target entry function;
and testing the target function by testing whether the function of the target entry function is correct.
In a possible implementation, when the reconstruction type of the objective function is a code migration type,
the test module 507 is configured to:
and testing the target function by comparing whether the code content of the target function after migration is the same as the code content of the target function before migration.
In a possible implementation manner, the code reconstruction planning device provided by the embodiment of the application further may include a central control module and a storage module, wherein each module in the code reconstruction planning device is connected with the central control module, the storage module is also connected with the central control module, the central control module performs scheduling of executing sequence and data interaction between each module, each intermediate data is stored in an internal storage or memory, and the intermediate data is read from the internal storage or memory or written into the internal storage or memory through the central control module.
According to the code reconstruction planning device provided by the embodiment of the application, the reconstruction type of each function in the code to be reconstructed is determined according to the function name information, the class name information and the calling relation information of the target function by taking each function in the code to be reconstructed as the target function, and the code reconstruction scheme is planned, so that before a developer starts to reconstruct the code, the reconstruction scheme of the code to be reconstructed is determined, and each developer participating in the reconstruction can reconstruct the code according to the determined reconstruction scheme, and the efficiency of the code reconstruction is improved.
Furthermore, the code reconstruction planning device provided by the embodiment of the application can also determine reconstruction cost data of the code reconstruction according to the reconstruction type of at least one objective function in the code to be reconstructed. Therefore, before the code reconstruction is executed, reconstruction cost data are estimated, how many developers or how much reconstruction time are needed are determined in advance, and the labor cost or the time cost required for the code reconstruction is planned.
Furthermore, the code reconstruction planning device provided by the embodiment of the application can also automatically evaluate the functional correctness of the objective function after the code reconstruction, provide directional references for further fine test and further improve the code reconstruction efficiency.
Embodiments of the present application also provide a computer readable storage medium storing instructions that, when executed by a processor, cause the processor to perform the steps of any of the code reconstruction planning methods provided by the embodiments of the present application. In practice, the computer readable medium may be contained in the apparatus/device/system described in the above embodiments or may exist alone without being assembled into the apparatus/device/system. The computer readable storage medium carries one or more programs, which when executed, implement the steps of any one of the code reconstruction planning methods provided by the embodiments of the present application according to any one of the code reconstruction planning apparatuses provided by the embodiments of the present application.
According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example, but is not limited to: portable computer diskette, hard disk, random Access Memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the foregoing, but are not intended to limit the scope of the application. In the disclosed embodiments, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The method steps of the present application may be implemented by hardware, such as logic gates, switches, application Specific Integrated Circuits (ASIC), programmable logic controllers, embedded microcontrollers, etc., in addition to data processing programs. Such hardware capable of carrying out the methods of the application may therefore also constitute the application.
The embodiment of the application also provides electronic equipment which can be a computer or a server, wherein any code reconstruction planning device provided by the embodiment of the application can be integrated. As shown in fig. 8, an electronic device 800 provided by an embodiment of the present application is shown.
The electronic device may comprise one or more processors 801 of a processing core, one or more memories 802 for storing instructions executable by the processors 801. The electronic device may further comprise a power supply 803, an input output unit 804. Those skilled in the art will appreciate that fig. 8 is not intended to be limiting of the electronic device and may include more or fewer components than shown, or may combine certain components, or may be arranged in different components.
Wherein:
the processor 801 is a control part of the electronic device, and uses various interfaces and lines to connect the various parts, reads the executable instructions from the memory 802, and executes or executes the instructions stored in the memory 802 to implement the steps of any code reconstruction planning method provided by the embodiments of the present application.
The memory 802 may be used to store a software program, i.e., a program involved in any of the code reconstruction planning methods provided by embodiments of the present application.
The processor 801 executes various functional applications and data processing by executing software programs stored in the memory 802. The memory 802 may include a storage program area that may store an operating system, application programs required for at least one function, and the like, and a storage data area; the storage data area may store data or the like that is used according to the needs of the electronic device. In addition, memory 802 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 802 may also include a memory controller to provide the processor 801 with access to the memory 802.
The electronic device further comprises a power supply 803 for powering the various components, preferably the power supply 803 can be logically coupled to the processor 801 via a power management system such that functions such as managing charging, discharging, and power consumption are performed by the power management system. The power supply 803 may also include one or more of any components, such as a direct current or alternating current power supply, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and the like.
The server may also include an input output unit 804 such as may be used to receive input numeric or character information and to generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control; such as various graphical user interfaces that may be used to display information entered by or provided to a user and a server, which may be composed of graphics, text, icons, video, and any combination thereof.
Any code reconstruction planning method, device, storage medium and electronic equipment provided by the embodiment of the application are based on the same design conception, and the technical means in any embodiment of the application can be freely combined, and the combined technical means are still within the protection scope of the application.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that the features recited in the various embodiments of the application and/or in the claims may be combined in various combinations and/or combinations even if such combinations or combinations are not explicitly recited in the application. In particular, the features recited in the various embodiments of the application and/or in the claims may be combined in various combinations and/or combinations without departing from the spirit and teachings of the application, all of which are within the scope of the disclosure.
The principles and embodiments of the present application have been described in detail in the present application, the above examples are provided to facilitate understanding of the method of the present application and the core ideas thereof, and are not intended to limit the present application. It will be apparent to those skilled in the art that variations can be made in the present embodiments and applications within the spirit and principles of the application, and any modifications, equivalents, improvements, etc. are intended to be included within the scope of the present application.

Claims (8)

1. A code reconstruction planning method, comprising:
acquiring a code to be reconstructed;
determining function name information of an objective function to be reconstructed, class name information of a class to which the objective function belongs and calling relation information of the objective function according to the code to be reconstructed; the call relation information comprises at least one of the following: transaction call information, event call information and function call information;
determining a reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class to which the objective function belongs and the calling relation information of the objective function;
when the call relation information comprises function call information, the step of determining the call relation information of the target function comprises the following steps: judging whether the target function contains a call statement of the function according to the call keyword of the function; when the target function contains a call statement of a function, determining function name information of the called function according to the call statement of the function, and determining class name information of a class to which the called function belongs by utilizing a reflection mechanism;
The step of determining the reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class to which the objective function belongs and the call relation information of the objective function comprises the following steps:
judging whether the target function is called according to the function calling information;
judging whether the target function is an entry function or not when the target function is not called, and determining the reconstruction type of the target function as a function deletion type when the target function is not an entry function;
when the target function is called, judging whether a cyclic calling condition exists in a calling relation chain of the target function; when a loop call condition exists, determining the reconstruction type of the target function as a code transformation type;
when the cyclic calling condition does not exist, judging whether the function calling the target function belongs to the same class;
when the functions calling the target functions do not belong to the same class, judging whether function calling exists in the target functions;
when a function call exists in the objective function, determining the reconstruction type of the objective function as a code transformation type; when no function call exists in the objective function, determining the reconstruction type of the objective function as a code migration type;
When the functions calling the target functions belong to the same class, judging whether function calling exists in the target functions;
when a function call exists in the target function, judging whether the called function of the target function and the target function belong to the same class;
when the called function of the target function and the target function belong to the same class, determining the reconstruction type of the target function as a code migration type; when the called function of the target function and the target function do not belong to the same class, determining the reconstruction type of the target function as a code transformation type;
when no function call exists in the objective function, judging whether a database module is called in the objective function;
and when the database module is called in the objective function, determining the reconstruction type of the objective function as a code migration type.
2. The method according to claim 1, wherein the step of determining class name information of the class to which the objective function belongs from the code to be reconstructed comprises:
and determining class name information of the class to which the objective function belongs by using a reflection mechanism.
3. The method according to claim 1, wherein the step of determining function name information of the objective function from the code to be reconstructed comprises:
And determining function name information of the objective function according to the statement keywords of the objective function.
4. The method of claim 1, wherein when the call relationship information includes transaction call information, the step of determining call relationship information of the objective function according to the code to be reconstructed includes:
judging whether the target function comprises a calling statement of the transaction according to the calling keyword of the transaction;
when the target function comprises a call statement of the transaction, identifying transaction call information of the target function as containing transaction call;
the step of determining the reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class to which the objective function belongs and the call relation information of the objective function comprises the following steps:
judging whether the target function contains transaction call or not according to the transaction call information of the target function;
when the target function includes a transaction call, a reconstruction type of the target function is determined as a code transformation type.
5. The method of claim 1, wherein when the call relationship information includes event call information, the step of determining call relationship information of the objective function according to the code to be reconstructed includes:
Judging whether the target function comprises a calling statement of the event according to the calling keyword of the event;
when the target function comprises a calling statement of the event, determining the name of the called event according to the calling statement of the event;
determining the name of the called event as event calling information of the target function;
the step of determining the reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class to which the objective function belongs and the call relation information of the objective function comprises the following steps:
judging whether the objective function contains the event calling information or not;
and when the target function contains the event calling information, determining the reconstruction type of the target function as a code transformation type.
6. A code reconstruction planning apparatus, comprising:
the acquisition module is used for acquiring the code to be reconstructed;
the class name determining module is used for determining class name information of a class to which the objective function to be reconstructed belongs according to the code to be reconstructed;
the function name determining module is used for determining function name information of the objective function to be reconstructed according to the code to be reconstructed;
the calling relation determining module is used for determining calling relation information of the target function according to the code to be reconstructed; the call relation information comprises at least one of the following: transaction call information, event call information and function call information; when the call relation information comprises function call information, the step of determining the call relation information of the target function comprises the following steps: judging whether the target function contains a call statement of the function according to the call keyword of the function; when the target function contains a call statement of a function, determining function name information of the called function according to the call statement of the function, and determining class name information of a class to which the called function belongs by utilizing a reflection mechanism;
The reconstruction type determining module is used for determining the reconstruction type of the target function according to the function name information of the target function, the class name information of the class to which the target function belongs and the calling relation information of the target function; the step of determining the reconstruction type of the objective function according to the function name information of the objective function, the class name information of the class to which the objective function belongs and the call relation information of the objective function comprises the following steps: judging whether the target function is called according to the function calling information; judging whether the target function is an entry function or not when the target function is not called, and determining the reconstruction type of the target function as a function deletion type when the target function is not an entry function; when the target function is called, judging whether a cyclic calling condition exists in a calling relation chain of the target function; when a loop call condition exists, determining the reconstruction type of the target function as a code transformation type; when the cyclic calling condition does not exist, judging whether the function calling the target function belongs to the same class; when the functions calling the target functions do not belong to the same class, judging whether function calling exists in the target functions; when a function call exists in the objective function, determining the reconstruction type of the objective function as a code transformation type; when no function call exists in the objective function, determining the reconstruction type of the objective function as a code migration type; when the functions calling the target functions belong to the same class, judging whether function calling exists in the target functions; when a function call exists in the target function, judging whether the called function of the target function and the target function belong to the same class; when the called function of the target function and the target function belong to the same class, determining the reconstruction type of the target function as a code migration type; when the called function of the target function and the target function do not belong to the same class, determining the reconstruction type of the target function as a code transformation type; when no function call exists in the objective function, judging whether a database module is called in the objective function; and when the database module is called in the objective function, determining the reconstruction type of the objective function as a code migration type.
7. A computer readable storage medium storing computer instructions which, when executed by a processor, implement the steps of the method of any one of claims 1 to 5.
8. An electronic device, comprising:
a processor;
a memory for storing the processor-executable instructions;
the processor is configured to read the executable instructions from the memory and execute the instructions to implement the method of any one of claims 1-5.
CN202010355273.3A 2020-04-29 2020-04-29 Code reconstruction planning method and device, storage medium and electronic equipment Active CN111625275B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010355273.3A CN111625275B (en) 2020-04-29 2020-04-29 Code reconstruction planning method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010355273.3A CN111625275B (en) 2020-04-29 2020-04-29 Code reconstruction planning method and device, storage medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN111625275A CN111625275A (en) 2020-09-04
CN111625275B true CN111625275B (en) 2023-10-20

Family

ID=72271636

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010355273.3A Active CN111625275B (en) 2020-04-29 2020-04-29 Code reconstruction planning method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN111625275B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH05324344A (en) * 1992-05-21 1993-12-07 Hitachi Ltd Argument processing optimization method at the time of calling function
CN106502907A (en) * 2016-10-28 2017-03-15 中国科学院软件研究所 A kind of distributed software abnormality diagnostic method that is followed the trail of based on perform track
CN106970820A (en) * 2017-04-26 2017-07-21 腾讯科技(深圳)有限公司 Code storage method and code storage
CN110147238A (en) * 2019-05-29 2019-08-20 中国人民解放军战略支援部队信息工程大学 A kind of program compiling method, apparatus and system
CN110162335A (en) * 2019-04-26 2019-08-23 深圳壹账通智能科技有限公司 Code refactoring method, apparatus, computer equipment and medium

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7228529B2 (en) * 2002-08-27 2007-06-05 International Business Machines Corporation Restructuring computer programs
US8621448B2 (en) * 2010-09-23 2013-12-31 Apple Inc. Systems and methods for compiler-based vectorization of non-leaf code
JP5506721B2 (en) * 2011-03-09 2014-05-28 インターナショナル・ビジネス・マシーンズ・コーポレーション Optimization device, optimization method, and optimization program for optimizing a program by reusing the execution result of the subclass test function
US20190317760A1 (en) * 2018-04-17 2019-10-17 The Regents Of The University Of Michigan Interactive And Dynamic Search Based Approach To Software Refactoring Recommendations

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH05324344A (en) * 1992-05-21 1993-12-07 Hitachi Ltd Argument processing optimization method at the time of calling function
CN106502907A (en) * 2016-10-28 2017-03-15 中国科学院软件研究所 A kind of distributed software abnormality diagnostic method that is followed the trail of based on perform track
CN106970820A (en) * 2017-04-26 2017-07-21 腾讯科技(深圳)有限公司 Code storage method and code storage
CN110162335A (en) * 2019-04-26 2019-08-23 深圳壹账通智能科技有限公司 Code refactoring method, apparatus, computer equipment and medium
CN110147238A (en) * 2019-05-29 2019-08-20 中国人民解放军战略支援部队信息工程大学 A kind of program compiling method, apparatus and system

Also Published As

Publication number Publication date
CN111625275A (en) 2020-09-04

Similar Documents

Publication Publication Date Title
Weyuker et al. Using developer information as a factor for fault prediction
CN107506300B (en) User interface testing method, device, server and storage medium
CN106325970A (en) Compiling method and compiling system
US9904524B2 (en) Method and device for visually implementing software code
CN111782539B (en) Test diagnosis integrated development platform based on domestic operating system
CN105302714B (en) The monitoring method and device of memory overflow in a kind of test process
CN103577308B (en) Method for obtaining log files of mobile device
CN109240666B (en) Function calling code generation method and system based on call stack and dependent path
CN108874649B (en) Method and device for generating automatic test script and computer equipment thereof
US9495265B2 (en) Test executive system with processing of results data in chunks
Fontana et al. An experience report on detecting and repairing software architecture erosion
Ell Identifying failure inducing developer pairs within developer networks
CN112765031A (en) Decomposition method of crowd-sourcing vulnerability mining task
CN113590454A (en) Test method, test device, computer equipment and storage medium
CN112948275A (en) Test data generation method, device, equipment and storage medium
CN109542444A (en) Monitoring method, device, server and the storage medium of JAVA application
CN114201328A (en) Fault processing method and device based on artificial intelligence, electronic equipment and medium
CN111625275B (en) Code reconstruction planning method and device, storage medium and electronic equipment
Anand et al. Testing resource allocation for software with multiple versions
Long et al. Mutation-based exploration of a method for verifying concurrent Java components
King et al. The value of verification: Positive experience of industrial proof
CN112395199B (en) Distributed software instance testing method based on cloud computing and software development platform
Püschel et al. Testing self-adaptive software: requirement analysis and solution scheme
CN104145249A (en) Debugging method and computer program product
JP4997144B2 (en) Multitask processing apparatus and method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant