CN110333851B - Code decoupling method and related equipment - Google Patents

Code decoupling method and related equipment Download PDF

Info

Publication number
CN110333851B
CN110333851B CN201910505108.9A CN201910505108A CN110333851B CN 110333851 B CN110333851 B CN 110333851B CN 201910505108 A CN201910505108 A CN 201910505108A CN 110333851 B CN110333851 B CN 110333851B
Authority
CN
China
Prior art keywords
code
codes
sub
calling
objects
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
CN201910505108.9A
Other languages
Chinese (zh)
Other versions
CN110333851A (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.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen 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 Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN201910505108.9A priority Critical patent/CN110333851B/en
Publication of CN110333851A publication Critical patent/CN110333851A/en
Application granted granted Critical
Publication of CN110333851B publication Critical patent/CN110333851B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

The present invention relates to classification models in intelligent decision, and in particular, to a code decoupling method and related devices, applied to electronic devices, the method comprising: acquiring a source code of a target application; analyzing the source code to obtain a plurality of use objects of the target application; the method comprises the steps of decoupling source codes into common calling codes and object calling codes based on a plurality of using objects, wherein the common calling codes comprise a plurality of first codes, each first code is allowed to be called by at least two using objects in the plurality of using objects, the object calling codes comprise a plurality of sub-object calling codes, each sub-object calling code comprises a plurality of second codes, the plurality of second codes included in the sub-object calling code i only allow the using objects associated by the sub-object calling code i to be called, and the sub-object calling code i is one of the plurality of sub-object calling codes. By adopting the embodiment of the application, the source code can be simplified and the maintainability of the source code can be improved.

Description

Code decoupling method and related equipment
Technical Field
The present disclosure relates to the field of electronic technologies, and in particular, to a code decoupling method and related devices.
Background
Multiple usage objects (e.g., express class applications may have managers, senders, acceptors, recipients, etc.) may exist for the same application, and multiple usage objects may have overlapping partial functions. The current code writing is very irregular, and the code writing mode of the application with a plurality of using objects is to develop each using object respectively, so that common codes which can be called by the plurality of using objects are repeatedly written, thereby causing redundancy and bulkiness of source codes and having low maintainability.
Disclosure of Invention
The embodiment of the application provides a code decoupling method and related equipment, which are used for simplifying source codes and improving maintainability of the source codes.
In a first aspect, an embodiment of the present application provides a code decoupling method, where the method includes:
acquiring a source code of a target application;
analyzing the source code to obtain a plurality of use objects of the target application;
the source code is decoupled into a common calling code and an object calling code based on the plurality of using objects, the common calling code comprises a plurality of first codes, each first code is allowed to be called by at least two using objects in the plurality of using objects, the object calling code comprises a plurality of sub-object calling codes, each sub-object calling code comprises a plurality of second codes, the plurality of second codes included in the sub-object calling code i only allow the using objects associated by the sub-object calling code i to be called, and the sub-object calling code i is one of the plurality of sub-object calling codes.
In a second aspect, an embodiment of the present application provides a code decoupling apparatus, applied to an electronic device, where the apparatus includes:
the acquisition unit is used for acquiring source codes of target applications;
The analyzing unit is used for analyzing the source codes to obtain a plurality of using objects of the target application;
and the decoupling unit is used for decoupling the source code into a common calling code and an object calling code based on the plurality of using objects, the common calling code comprises a plurality of first codes, each first code is allowed to be called by at least two using objects in the plurality of using objects, the object calling code comprises a plurality of sub-object calling codes, each sub-object calling code comprises a plurality of second codes, the plurality of second codes included in the sub-object calling code i only allow the using objects associated by the sub-object calling code i to be called, and the sub-object calling code i is one of the plurality of sub-object calling codes.
In a third aspect, embodiments of the present application provide an electronic device comprising a processor, a memory, a communication interface, and one or more programs stored in the memory and configured to be executed by the processor, the programs comprising instructions for performing the steps in the method of the first aspect of embodiments of the present application.
In a fourth aspect, embodiments of the present application provide a computer readable storage medium, where the computer readable storage medium is used to store a computer program, where the computer program is executed by a processor to implement some or all of the steps described in the method according to the first aspect of the embodiments of the present application.
In a fifth aspect, embodiments of the present application provide a computer program product, wherein the computer program product comprises a non-transitory computer readable storage medium storing a computer program, the computer program being operable to cause a computer to perform some or all of the steps described in the method according to the first aspect of the embodiments of the present application. The computer program product may be a software installation package.
It can be seen that, in the embodiment of the present application, an electronic device obtains a source code of a target application, and parses the source code to obtain a plurality of usage objects of the target application; the source code is then decoupled into common calling code and object calling code based on the plurality of usage objects. Compared with the source code before decoupling, the source code obtained by decoupling only comprises the common calling code and the object calling code, and the common calling code repeatedly written in the source code before decoupling is removed, so that the source code after decoupling is simpler and has strong readability. In the later maintenance process, only the public calling code or the object calling code which needs to be maintained is required to be readjusted, the whole framework of the source code is not required to be changed greatly, the difficulty in the maintenance process is reduced, and therefore the maintainability of the source code is improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art 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 for a person skilled in the art.
Fig. 1 is a schematic flow chart of a code decoupling method according to an embodiment of the present application;
fig. 2 is a flow chart of another code decoupling method according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present application;
fig. 4 is a code decoupling device provided in an embodiment of the present application.
Detailed Description
In order to make the present application solution better understood by those skilled in the art, the following description will be made in detail and with reference to the accompanying drawings in the embodiments of the present application, it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, shall fall within the scope of the present application.
The following will describe in detail.
The terms "first," "second," "third," and "fourth" and the like in the description and in the claims of this application and in the drawings, are used for distinguishing between different objects and not for describing a particular sequential order. 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 limited to only those listed steps or elements but may include other steps or elements not listed or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the present application. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments.
The electronic device mentioned in the present application may include various handheld devices, in-vehicle devices, wearable devices, computing devices, service devices, or other processing devices connected to a wireless modem, as well as various forms of User Equipment (UE), mobile Station (MS), terminal devices (terminal devices), and so forth.
Referring to fig. 1, fig. 1 is a code decoupling method provided in an embodiment of the present application, applied to an electronic device, where the method includes:
step 101: source code of the target application is obtained.
Further, before obtaining the source code of the target application, the method further comprises: and receiving a code decoupling instruction, wherein the code decoupling instruction carries the identification of the source code of the target application.
The code decoupling instruction refers to an instruction for reducing the correlation between codes. In software engineering, there is a dependency relationship between codes, and the absolute zero coupling is theoretically impossible, but the coupling degree can be reduced to the minimum by some existing methods, so that the code decoupling does not mean that the coupling between codes is completely removed, but the coupling between codes is reduced.
The source code refers to an uncompiled text file of a target application written according to a certain programming language specification, and is a series of human-readable computer language instructions. In modern programming languages, the source code may be in the form of a book or tape, but the most common format is a text file, the purpose of which is to compile a computer program.
Step 102: and analyzing the source code to obtain a plurality of using objects of the target application.
Specifically, one specific way of parsing the source code to obtain the plurality of usage objects of the target application is: analyzing the source code to obtain a code text of the source code; determining whether a use object keyword is contained in the code text; and if the code text contains the use object keywords, determining a plurality of use objects of the target application based on the use object keywords.
For example, assuming that the target application is a PA cable, the source code parsed by the electronic device obtains a code text, and if the code text includes "salesman of PA", "rectifier", "salesman of third part", "admin of PA", a plurality of usage objects of the PA cable may be determined as: PA salesman, recommender, third party salesman, PA administrator, wherein salesman of PA is the representing character of PA salesman in code text, recommender is the representing character of recommender in code text, salesman of third part is the representing character of third party salesman in code text, admin of PA is the representing character of administrator in code text.
Step 103: the source code is decoupled into a common calling code and an object calling code based on the plurality of using objects, the common calling code comprises a plurality of first codes, each first code is allowed to be called by at least two using objects in the plurality of using objects, the object calling code comprises a plurality of sub-object calling codes, each sub-object calling code comprises a plurality of second codes, the plurality of second codes included in the sub-object calling code i only allow the using objects associated by the sub-object calling code i to be called, and the sub-object calling code i is one of the plurality of sub-object calling codes.
Specifically, the decoupling the source code based on the plurality of use objects into a common calling code and an object calling code, the common calling code including a plurality of first codes, each first code being allowed to be called by at least two use objects of the plurality of use objects, the object calling code including a plurality of sub-object calling codes, includes: dividing the source code into a plurality of sub-source codes according to functions; determining a usage object that each sub-source code allows to be called; if the number of the usable objects allowed to be called by the sub-source code j is greater than or equal to 2, determining the sub-source code j as a first code in the common calling code; and if the number of the permitted called using objects of the sub-source code is 1, determining the sub-source code j as a second code in the sub-object calling codes corresponding to the permitted called using objects.
By way of example, assume that the target application is a PA-package, whose usage objects include the following four: the same functions of each application object are, for example, a message sending function and a message receiving function, the function of the PA service person is a release task function, the function of the recommender is a recommendation task function, the function of the third party service person is a receiving task function, and the function of the PA manager is a management task function.
It can be seen that, in the embodiment of the present application, an electronic device obtains a source code of a target application, and parses the source code to obtain a plurality of usage objects of the target application; the source code is then decoupled into common calling code and object calling code based on the plurality of usage objects. Compared with the source code before decoupling, the source code obtained by decoupling only comprises the common calling code and the object calling code, and the common calling code repeatedly written in the source code before decoupling is removed, so that the source code after decoupling is simpler and has strong readability. In the later maintenance process, only the public calling code or the object calling code which needs to be maintained is required to be readjusted, the whole framework of the source code is not required to be changed greatly, the difficulty in the maintenance process is reduced, and therefore the maintainability of the source code is improved.
In one implementation of the present application, after decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the method further includes:
mutually matching all the second codes to obtain a matching result, wherein the matching result comprises M first matching successful records, each first matching successful record comprises identifiers of at least two second codes with the same use object, each first matching successful record corresponds to one sub-object calling code, and M is a positive integer;
and deleting a plurality of first target second codes in the corresponding sub-object calling codes based on each first matching success record, wherein the deleted sub-object calling codes do not have any situation that any two second codes are matched, and the identifiers of the at least two second codes included in each first matching success record comprise the identifiers of the corresponding plurality of first target second codes.
The object calling codes comprise a sub-object calling code 1, a sub-object calling code 2 and a sub-object calling code 3; the sub-object calling code 1 comprises a second code A11, a second code B11, a second code C11 and a second code A12; the sub-object calling code 2 comprises a second code C21, a second code D21 and a second code E21; the sub-object calling code 3 includes a second code B31, a second code F31, and a second code G31. Matching all the second codes to obtain a matching result, wherein the matching result comprises a first matching success record: a11 and a12, then delete the second code a11 or the second code a12 in the child object call code 1.
In an implementation manner of the present application, the matching result further includes N second matching success records, each second matching success record includes an identifier of at least two second codes different from each other by using an object, where N is a positive integer, and the method further includes:
and moving a second code corresponding to one of the identifiers of the at least two second codes included in each second matching success record to the common calling code, and deleting the second code corresponding to one of the identifiers except the identifier of the at least two second codes included in each second matching success record.
The object calling codes comprise a sub-object calling code 1, a sub-object calling code 2 and a sub-object calling code 3; the sub-object calling code 1 comprises a second code A11, a second code B11, a second code C11 and a second code A12; the sub-object calling code 2 comprises a second code C21, a second code D21 and a second code E21; the sub-object calling code 3 includes a second code B31, a second code F31, and a second code G31. Matching all the second codes to obtain a matching result, wherein the matching result comprises a second matching success record: b11 and B31, then delete the second code B11 or B31, then move the remaining second code B11 or B31 into the common calling code.
Further, after moving the second code corresponding to one of the at least two identifiers of the second code included in each second matching success record into the common calling code, the method further includes:
and associating the use object of the second codes corresponding to the identifier except the identifier in the identifiers of the at least two second codes included in each second matching success record to the second code corresponding to the identifier.
For example, after all the second codes are matched with each other, a matching result is obtained, and the matching result includes a second matching success record: b11 and B31, then delete the second code B11 or B31, then move the remaining second code B11 or B31 into the common calling code. If the deleted second code is B11, the usage object of the second code B11 is associated to the second code B31, so that the second code B31 may be called by the original usage object of the second code B31 or by the original usage object of the second code B11.
In one implementation of the present application, after decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the method further includes:
Receiving a code calling instruction, wherein the code calling instruction carries a code type requested to be called;
if the code type of the request call is a public call code type, a first response instruction is sent, wherein the first response instruction carries at least one public call code existing in the electronic equipment;
if the code type requested to be called is the object calling code type, determining that the code calling instruction requests to call a first target using object of the code; and sending a second response instruction, wherein the second response instruction carries a sub-object calling code corresponding to the first target usage object.
Specifically, a specific implementation manner of determining that the code call instruction requests to call the first target usage object of the code is: determining the sending end electronic equipment of the code calling instruction; and determining that the code calling instruction requests to call a first target using object of the code based on the sending end electronic equipment of the code calling instruction.
By way of example, assume that the target application is a PA-package, whose usage object includes at least one of: and if the electronic terminal sending equipment is electronic equipment at the PA service operator terminal, determining that the first target using object is the PA service operator, and determining that the first target using object is the recommender, the third party service operator and the PA manager in the same manner as the PA service operator. It should be noted that, the determination manner of the sender electronic device may be determined by identifying account information of the target application on the sender electronic device.
In one implementation of the present application, after decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the method further includes:
when receiving an instruction for adding a third code, determining a using object of the third code;
if the number of the using objects of the third code is greater than or equal to 2, moving the third code into the common calling code;
if the number of the using objects of the third code is 1 and the plurality of using objects of the target application comprise the using objects of the third code, moving the third code into a sub-object calling code corresponding to the using objects of the third code;
if the number of the usage objects of the third code is 1 and the plurality of usage objects of the target application do not include the usage objects of the third code, creating a sub-object calling code and moving the third code into the created sub-object calling code.
Note that the above embodiment corresponds to a case where the use object is added in the code development process. If a function needs to be added in the development process, determining a code for realizing the function, then determining a use object capable of calling the code, and if the number of the use objects is more than or equal to 2, directly determining the code as a public calling code; if the number of the used objects is 1, whether the plurality of the previous used objects comprise the used objects or not is needed, if yes, the code can be directly classified into the corresponding sub-object calling code, and if not, a sub-object calling code is needed to be newly built and moved into the newly built sub-object calling code.
In one implementation of the present application, after decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the method further includes:
receiving a disassociation instruction, wherein the disassociation instruction is used for disassociating a second target use object from a fourth code, the second target use object is one use object of the plurality of use objects, the fourth code is one first code of a plurality of first codes included in the common calling code, and the use object of the fourth code comprises the second target use object and a third target use object;
and moving the fourth code into the sub-object calling code of the third target using object.
It should be noted that, in the above embodiment, the number of usage objects is reduced in the code development process, and if the number of usage objects of the fourth code is greater than 2, after the association between one of the usage objects and the fourth code is released, the remaining associated usage objects of the fourth code are still greater than or equal to 2, so that the fourth code is still a common calling code and does not need to be processed as above.
In one implementation of the present application, after decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the method further includes:
Compiling the public calling code and the object calling code, wherein the compiled public calling code and object calling code are allowed to be operated by the target application.
Referring to fig. 2, another code decoupling method provided in an embodiment of the present application is applied to an electronic device, where the method includes:
step 201: source code of the target application is obtained.
Step 202: and analyzing the source code to obtain a plurality of using objects of the target application.
Step 203: the source code is decoupled into a common calling code and an object calling code based on the plurality of using objects, the common calling code comprises a plurality of first codes, each first code is allowed to be called by at least two using objects in the plurality of using objects, the object calling code comprises a plurality of sub-object calling codes, each sub-object calling code comprises a plurality of second codes, the plurality of second codes included in the sub-object calling code i only allow the using objects associated by the sub-object calling code i to be called, and the sub-object calling code i is one of the plurality of sub-object calling codes.
Step 204: and mutually matching all the second codes to obtain a matching result, wherein the matching result comprises M first matching successful records, each first matching successful record comprises identifiers of at least two second codes with the same use object, each first matching successful record corresponds to one sub-object calling code, and M is a positive integer.
Step 205: and deleting a plurality of first target second codes in the corresponding sub-object calling codes based on each first matching success record, wherein the deleted sub-object calling codes do not have any situation that any two second codes are matched, and the identifiers of the at least two second codes included in each first matching success record comprise the identifiers of the corresponding plurality of first target second codes.
Step 206: the matching result further comprises N second matching success records, each second matching success record comprises identifiers of at least two second codes with different objects, N is a positive integer, and the second code corresponding to one of the identifiers of the at least two second codes included in each second matching success record is moved to the common calling code.
Step 207: and deleting the second codes corresponding to the identifiers except one of the identifiers in the identifiers of the at least two second codes included in each second matching success record.
Step 208: and receiving a code calling instruction, wherein the code calling instruction carries a code type of the request call.
Step 209: and if the code type of the request call is the common call code type, sending a first response instruction, wherein the first response instruction carries at least one common call code existing in the electronic equipment.
Step 210: if the code type of the request call is the object call code type, determining a first target use object of the code call instruction request call code and sending a second response instruction, wherein the second response instruction carries a sub-object call code corresponding to the first target use object.
Step 211: and when receiving an instruction for adding the code carrying the third code, determining a use object of the third code.
Step 212: and if the number of the using objects of the third code is greater than or equal to 2, moving the third code into the common calling code.
Step 213: and if the number of the using objects of the third code is 1 and the plurality of using objects of the target application comprise the using objects of the third code, moving the third code into a sub-object calling code corresponding to the using objects of the third code.
Step 214: if the number of the usage objects of the third code is 1 and the plurality of usage objects of the target application do not include the usage objects of the third code, creating a sub-object calling code and moving the third code into the created sub-object calling code.
Step 215: and receiving a disassociation instruction, wherein the disassociation instruction is used for disassociating a second target use object from a fourth code, the second target use object is one use object in the plurality of use objects, the fourth code is one first code in the plurality of first codes included in the common calling code, and the use object of the fourth code comprises the second target use object and a third target use object.
Step 216: and moving the fourth code into the sub-object calling code of the third target using object.
Step 217: compiling the public calling code and the object calling code, wherein the compiled public calling code and object calling code are allowed to be operated by the target application.
It should be noted that, steps 208-210 may be performed before step 211 or after step 211; steps 211-214 may precede step 208 or follow step 216; the implementation of step 214 and step 215 may be performed before step 208 or after step 208, and reference may be made to the implementation of the method embodiment described above, which is not described herein.
Referring to fig. 3, in accordance with the embodiments shown in fig. 1 and 2, fig. 3 is a schematic structural diagram of an electronic device according to an embodiment of the present application, where the electronic device includes a processor, a memory, a communication interface, and one or more programs, where the one or more programs are stored in the memory and configured to be executed by the processor, and the programs include instructions for performing the following steps:
acquiring a source code of a target application;
analyzing the source code to obtain a plurality of use objects of the target application;
the source code is decoupled into a common calling code and an object calling code based on the plurality of using objects, the common calling code comprises a plurality of first codes, each first code is allowed to be called by at least two using objects in the plurality of using objects, the object calling code comprises a plurality of sub-object calling codes, each sub-object calling code comprises a plurality of second codes, the plurality of second codes included in the sub-object calling code i only allow the using objects associated by the sub-object calling code i to be called, and the sub-object calling code i is one of the plurality of sub-object calling codes.
It can be seen that, in the embodiment of the present application, an electronic device obtains a source code of a target application, and parses the source code to obtain a plurality of usage objects of the target application; the source code is then decoupled into common calling code and object calling code based on the plurality of usage objects. Compared with the source code before decoupling, the source code obtained by decoupling only comprises the common calling code and the object calling code, and the common calling code repeatedly written in the source code before decoupling is removed, so that the source code after decoupling is simpler and has strong readability. In the later maintenance process, only the public calling code or the object calling code which needs to be maintained is required to be readjusted, the whole framework of the source code is not required to be changed greatly, the difficulty in the maintenance process is reduced, and therefore the maintainability of the source code is improved.
In an implementation of the present application, in decoupling the source code into a common calling code and an object calling code based on the plurality of usage objects, the common calling code including a plurality of first codes, each first code being allowed to be called by at least two usage objects of the plurality of usage objects, the object calling code including a plurality of sub-object calling codes, the program includes instructions specifically for performing the steps of:
Dividing the source code into a plurality of sub-source codes according to functions;
determining a usage object that each sub-source code allows to be called;
if the number of the usable objects allowed to be called by the sub-source code j is greater than or equal to 2, determining the sub-source code j as a first code in the common calling code;
and if the number of the permitted called using objects of the sub-source code is 1, determining the sub-source code j as a second code in the sub-object calling codes corresponding to the permitted called using objects.
In one implementation of the present application, after decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the program includes instructions for performing the following steps:
mutually matching all the second codes to obtain a matching result, wherein the matching result comprises M first matching successful records, each first matching successful record comprises identifiers of at least two second codes with the same use object, each first matching successful record corresponds to one sub-object calling code, and M is a positive integer;
and deleting a plurality of first target second codes in the corresponding sub-object calling codes based on each first matching success record, wherein the deleted sub-object calling codes do not have any situation that any two second codes are matched, and the identifiers of the at least two second codes included in each first matching success record comprise the identifiers of the corresponding plurality of first target second codes.
In an implementation manner of the present application, the matching result further includes N second matching success records, each second matching success record includes an identifier of at least two second codes different from each other by using an object, where N is a positive integer, and the program includes instructions further configured to perform the following steps:
and moving the second code corresponding to one of the identifiers of the at least two second codes included in each second matching success record to the common calling code, and deleting the second code corresponding to one of the identifiers divided among the identifiers of the at least two second codes included in each second matching success record.
In one implementation of the present application, after decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the program includes instructions for performing the following steps:
receiving a code calling instruction, wherein the code calling instruction carries a code type requested to be called;
if the code type of the request call is a public call code type, a first response instruction is sent, wherein the first response instruction carries at least one public call code existing in the electronic equipment;
If the code type requested to be called is the object calling code type, determining that the code calling instruction requests to call a first target using object of the code; and sending a second response instruction, wherein the second response instruction carries a sub-object calling code corresponding to the first target usage object.
In one implementation of the present application, after decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the program includes instructions for performing the following steps:
when receiving an instruction for adding a third code, determining a using object of the third code;
if the number of the using objects of the third code is greater than or equal to 2, moving the third code into the common calling code;
if the number of the using objects of the third code is 1 and the plurality of using objects of the target application comprise the using objects of the third code, moving the third code into a sub-object calling code corresponding to the using objects of the third code;
if the number of the usage objects of the third code is 1 and the plurality of usage objects of the target application do not include the usage objects of the third code, creating a sub-object calling code and moving the third code into the created sub-object calling code.
In one implementation of the present application, after decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the program includes instructions for performing the following steps:
receiving a disassociation instruction, wherein the disassociation instruction is used for disassociating a second target use object from a fourth code, the second target use object is one use object of the plurality of use objects, the fourth code is one first code of a plurality of first codes included in the common calling code, and the use object of the fourth code comprises the second target use object and a third target use object;
and moving the fourth code into the sub-object calling code of the third target using object.
In one implementation of the present application, after decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the program includes instructions for performing the following steps:
compiling the public calling code and the object calling code, wherein the compiled public calling code and object calling code are allowed to be operated by the target application.
It should be noted that, the specific implementation process of this embodiment may refer to the specific implementation process described in the foregoing method embodiment, which is not described herein.
The foregoing embodiments mainly describe the solutions of the embodiments of the present application from the point of view of the method-side execution procedure. It will be appreciated that the electronic device, in order to achieve the above-described functions, includes corresponding hardware structures and/or software modules that perform the respective functions. Those of skill in the art will readily appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be implemented as hardware or combinations of hardware and computer software. Whether a function is implemented as hardware or computer software driven hardware depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
According to the embodiment of the application, the electronic device may be divided into the functional units according to the method example, for example, each functional unit may be divided corresponding to each function, or two or more functions may be integrated into one processing unit. The integrated units may be implemented in hardware or in software functional units. It should be noted that, in the embodiment of the present application, the division of the units is schematic, which is merely a logic function division, and other division manners may be implemented in actual practice.
The following is an embodiment of the apparatus, which is configured to execute a method implemented by an embodiment of the method of the present application. Referring to fig. 4, a code decoupling device provided in an embodiment of the present application is applied to an electronic device, and the device includes:
an obtaining unit 401, configured to obtain a source code of a target application;
a parsing unit 402, configured to parse the source code to obtain a plurality of usage objects of the target application;
a decoupling unit 403, configured to decouple the source code into a common calling code and an object calling code based on the plurality of usage objects, where the common calling code includes a plurality of first codes, each first code is allowed to be called by at least two usage objects of the plurality of usage objects, the object calling code includes a plurality of sub-object calling codes, each sub-object calling code includes a plurality of second codes, and the plurality of second codes included in the sub-object calling code i only allow the usage objects associated by the sub-object calling code i, where the sub-object calling code i is one of the plurality of sub-object calling codes.
It can be seen that, in the embodiment of the present application, an electronic device obtains a source code of a target application, and parses the source code to obtain a plurality of usage objects of the target application; the source code is then decoupled into common calling code and object calling code based on the plurality of usage objects. Compared with the source code before decoupling, the source code obtained by decoupling only comprises the common calling code and the object calling code, and the common calling code repeatedly written in the source code before decoupling is removed, so that the source code after decoupling is simpler and has strong readability. In the later maintenance process, only the public calling code or the object calling code which needs to be maintained is required to be readjusted, the whole framework of the source code is not required to be changed greatly, the difficulty in the maintenance process is reduced, and therefore the maintainability of the source code is improved.
In an implementation manner of the present application, in decoupling the source code into a common calling code and an object calling code based on the plurality of usage objects, the common calling code includes a plurality of first codes, each first code is allowed to be called by at least two usage objects in the plurality of usage objects, the object calling code includes a plurality of sub-object calling codes, and the decoupling unit 403 is specifically configured to:
dividing the source code into a plurality of sub-source codes according to functions;
determining a usage object that each sub-source code allows to be called;
if the number of the usable objects allowed to be called by the sub-source code j is greater than or equal to 2, determining the sub-source code j as a first code in the common calling code;
and if the number of the permitted called using objects of the sub-source code is 1, determining the sub-source code j as a second code in the sub-object calling codes corresponding to the permitted called using objects.
In an implementation manner of the present application, after decoupling the source code into the common calling code and the object calling code based on the plurality of usage objects, the apparatus further includes a matching unit 404 and a deleting unit 405, where:
The matching unit 404 is configured to match all the second codes with each other to obtain a matching result, where the matching result includes M first matching success records, each first matching success record includes identifiers of at least two second codes that use the same object, each first matching success record corresponds to a sub-object calling code, and M is a positive integer;
the deleting unit 405 is configured to delete, based on each first matching success record, a plurality of first target second codes in the corresponding sub-object calling codes, where no two second codes match with each other in each deleted sub-object calling code, and the identifiers of the at least two second codes included in each first matching success record include the identifiers of the corresponding plurality of first target second codes.
In an implementation manner of the present application, the matching result further includes N second matching success records, where each second matching success record includes identifiers of at least two second codes that use a different object, where N is a positive integer, and the apparatus further includes a moving unit 406, configured to move, to the common calling code, a second code corresponding to one of the identifiers of the at least two second codes included in each second matching success record;
The deleting unit 405 is further configured to delete a second code corresponding to one of the identifiers of the at least two second codes included in each second matching success record, by dividing the second code by the one identifier.
In an implementation of the present application, after decoupling the source code into the common calling code and the object calling code based on the plurality of usage objects, the apparatus further comprises a communication unit 407 and a determination unit 408, wherein:
the communication unit 407 is configured to receive a code call instruction, where the code call instruction carries a code type requested to be called; if the code type of the request call is a public call code type, a first response instruction is sent, wherein the first response instruction carries at least one public call code existing in the electronic equipment;
the determining unit 408 is configured to determine that the code call instruction requests to call a first target object of use of the code if the code type requested to be called is an object call code type;
the communication unit 407 is further configured to send a second response instruction, where the second response instruction carries a sub-object calling code corresponding to the first target usage object.
In an implementation manner of the present application, after the source code is decoupled into the common calling code and the object calling code based on the plurality of usage objects, the determining unit 408 is further configured to determine, when receiving an add code instruction carrying a third code, a second usage object of the third code;
the mobile unit 406 is further configured to move the third code to the common calling code if the number of objects of use of the third code is greater than or equal to 2; if the number of the using objects of the third code is 1 and the plurality of using objects of the target application comprise the using objects of the third code, moving the third code into a sub-object calling code corresponding to the using objects of the third code;
the apparatus further includes a creating unit 409 configured to create a sub-object calling code if the number of the usage objects of the third code is 1 and the plurality of usage objects of the target application do not include the usage objects of the third code; the mobile unit 406 is further configured to move the third code into the newly created child object invocation code.
In an implementation manner of the present application, after the source code is decoupled into the common calling code and the object calling code based on the plurality of usage objects, the communication unit 407 is further configured to receive a disassociation instruction, where the disassociation instruction is used to disassociate a second target usage object with a fourth code, where the second target usage object is one usage object of the plurality of usage objects, and the fourth code is one first code of a plurality of first codes included in the common calling code, and the usage object of the fourth code includes the second target usage object and a third target usage object;
The moving unit 406 is further configured to move the fourth code into a sub-object calling code of the second usage object.
In an implementation manner of the present application, after decoupling the source code into a common calling code and an object calling code based on the plurality of usage objects, the apparatus further includes a compiling unit 410 configured to compile the common calling code and the object calling code, where the compiled common calling code and object calling code are allowed to be executed by the target application.
It should be noted that the obtaining unit 401, the parsing unit 402, the decoupling unit 403, the matching unit 404, the deleting unit 405, the moving unit 406, the determining unit 408, the creating unit 409, and the compiling unit 410 may be implemented by a processor, and the communication unit 407 may be implemented by a communication interface.
The present application also provides a computer storage medium storing a computer program for executing part or all of the steps of any one of the methods described in the above method embodiments by a processor.
Embodiments of the present application also provide a computer program product comprising a non-transitory computer-readable storage medium storing a computer program operable to cause a computer to perform some or all of the steps of any one of the methods described in the method embodiments above. The computer program product may be a software installation package.
It should be noted that, for simplicity of description, the foregoing method embodiments are all expressed as a series of action combinations, but it should be understood by those skilled in the art that the present application is not limited by the order of actions described, as some steps may be performed in other order or simultaneously in accordance with the present application. Further, those skilled in the art will also appreciate that the embodiments described in the specification are all preferred embodiments, and that the acts and modules referred to are not necessarily required in the present application.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and for parts of one embodiment that are not described in detail, reference may be made to related descriptions of other embodiments.
In the several embodiments provided in this application, it should be understood that the disclosed apparatus may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, such as the above-described division of units, merely a division of logic functions, and there may be additional manners of dividing in actual implementation, such as multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, or may be in electrical or other forms.
The units described above as separate components may or may not be physically separate, and components shown as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units described above, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable memory. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution in the form of a software product stored in a memory, including several instructions for causing a computer device (which may be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the above-mentioned method of the various embodiments of the present application. And the aforementioned memory includes: a U-disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Those of ordinary skill in the art will appreciate that all or a portion of the steps in the various methods of the above embodiments may be implemented by a program that instructs associated hardware, and the program may be stored in a computer readable memory, which may include: flash disk, read-Only Memory (ROM), random access Memory (Random Access Memory, RAM), magnetic disk or optical disk.
The foregoing has outlined rather broadly the more detailed description of embodiments of the present application, wherein specific examples are provided herein to illustrate the principles and embodiments of the present application, the above examples being provided solely to assist in the understanding of the methods of the present application and the core ideas thereof; meanwhile, as those skilled in the art will have modifications in the specific embodiments and application scope in accordance with the ideas of the present application, the present description should not be construed as limiting the present application in view of the above.

Claims (7)

1. A method of code decoupling, for application to an electronic device, the method comprising:
acquiring a source code of a target application;
analyzing the source code to obtain a plurality of use objects of the target application;
Decoupling the source code into a common calling code and an object calling code based on the plurality of use objects, the common calling code comprising a plurality of first codes, each first code allowing for calling by at least two of the plurality of use objects, the object calling code comprising a plurality of sub-object calling codes, each sub-object calling code comprising a plurality of second codes, a plurality of second codes comprised by a sub-object calling code i allowing for calling only a use object associated by the sub-object calling code i, the sub-object calling code i being one of the plurality of sub-object calling codes; comprising the following steps: dividing the source code into a plurality of sub-source codes according to functions; determining a usage object that each sub-source code allows to be called; if the number of the usable objects allowed to be called by the sub-source code j is greater than or equal to 2, determining the sub-source code j as a first code in the common calling code; if the number of the permitted called using objects of the sub-source code is 1, determining the sub-source code j as a second code in the sub-object calling codes corresponding to the permitted called using objects; mutually matching all the second codes to obtain a matching result, wherein the matching result comprises M first matching successful records, each first matching successful record comprises identifiers of at least two second codes with the same use object, each first matching successful record corresponds to one sub-object calling code, and M is a positive integer; deleting a plurality of first target second codes in the corresponding sub-object calling codes based on each first matching success record, wherein the deleted sub-object calling codes do not have any two second codes matched, and the identifiers of the at least two second codes included in each first matching success record comprise the identifiers of the corresponding plurality of first target second codes;
The matching result also comprises N second matching successful records, each second matching successful record comprises identifiers of at least two second codes with different use objects, and N is a positive integer; and moving the second code corresponding to one of the identifiers of the at least two second codes included in each second matching success record to the common calling code, and deleting the second code corresponding to one of the identifiers divided among the identifiers of the at least two second codes included in each second matching success record.
2. The method of claim 1, wherein after said decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the method further comprises:
receiving a code calling instruction, wherein the code calling instruction carries a code type requested to be called;
if the code type of the request call is a public call code type, a first response instruction is sent, wherein the first response instruction carries at least one public call code existing in the electronic equipment;
if the code type requested to be called is the object calling code type, determining that the code calling instruction requests to call a first target using object of the code; and sending a second response instruction, wherein the second response instruction carries a sub-object calling code corresponding to the first target usage object.
3. The method of claim 1 or 2, wherein after said decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the method further comprises:
when receiving an instruction for adding a third code, determining a using object of the third code;
if the number of the using objects of the third code is greater than or equal to 2, moving the third code into the common calling code;
if the number of the using objects of the third code is 1 and the plurality of using objects of the target application comprise the using objects of the third code, moving the third code into a sub-object calling code corresponding to the using objects of the third code;
if the number of the usage objects of the third code is 1 and the plurality of usage objects of the target application do not include the usage objects of the third code, creating a sub-object calling code and moving the third code into the created sub-object calling code.
4. The method of claim 1, wherein after said decoupling the source code into common calling code and object calling code based on the plurality of usage objects, the method further comprises:
Receiving a disassociation instruction, wherein the disassociation instruction is used for disassociating a second target use object from a fourth code, the second target use object is one use object of the plurality of use objects, the fourth code is one first code of a plurality of first codes included in the common calling code, and the use object of the fourth code comprises the second target use object and a third target use object;
and moving the fourth code into the sub-object calling code of the third target using object.
5. A code decoupling apparatus for use with an electronic device, the apparatus comprising:
the acquisition unit is used for acquiring source codes of target applications;
the analyzing unit is used for analyzing the source codes to obtain a plurality of using objects of the target application;
a decoupling unit, configured to decouple the source code into a common calling code and an object calling code based on the plurality of use objects, where the common calling code includes a plurality of first codes, each first code is allowed to be called by at least two use objects in the plurality of use objects, the object calling code includes a plurality of sub-object calling codes, each sub-object calling code includes a plurality of second codes, and a plurality of second codes included in a sub-object calling code i only allow a use object associated with the sub-object calling code i to be called, where the sub-object calling code i is one of the plurality of sub-object calling codes; comprising the following steps: dividing the source code into a plurality of sub-source codes according to functions; determining a usage object that each sub-source code allows to be called; if the number of the usable objects allowed to be called by the sub-source code j is greater than or equal to 2, determining the sub-source code j as a first code in the common calling code; if the number of the permitted called using objects of the sub-source code is 1, determining the sub-source code j as a second code in the sub-object calling codes corresponding to the permitted called using objects; mutually matching all the second codes to obtain a matching result, wherein the matching result comprises M first matching successful records, each first matching successful record comprises identifiers of at least two second codes with the same use object, each first matching successful record corresponds to one sub-object calling code, and M is a positive integer; deleting a plurality of first target second codes in the corresponding sub-object calling codes based on each first matching success record, wherein the deleted sub-object calling codes do not have any two second codes matched, and the identifiers of the at least two second codes included in each first matching success record comprise the identifiers of the corresponding plurality of first target second codes;
The matching result also comprises N second matching successful records, each second matching successful record comprises identifiers of at least two second codes with different use objects, and N is a positive integer; and moving the second code corresponding to one of the identifiers of the at least two second codes included in each second matching success record to the common calling code, and deleting the second code corresponding to one of the identifiers divided among the identifiers of the at least two second codes included in each second matching success record.
6. An electronic device comprising a processor, a memory, a communication interface, and one or more programs stored in the memory and configured to be executed by the processor, the programs comprising instructions for performing the steps in the method of any of claims 1-4.
7. A computer readable storage medium for storing a computer program for execution by a processor to implement the method of any one of claims 1-4.
CN201910505108.9A 2019-06-12 2019-06-12 Code decoupling method and related equipment Active CN110333851B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910505108.9A CN110333851B (en) 2019-06-12 2019-06-12 Code decoupling method and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910505108.9A CN110333851B (en) 2019-06-12 2019-06-12 Code decoupling method and related equipment

Publications (2)

Publication Number Publication Date
CN110333851A CN110333851A (en) 2019-10-15
CN110333851B true CN110333851B (en) 2023-06-16

Family

ID=68141098

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910505108.9A Active CN110333851B (en) 2019-06-12 2019-06-12 Code decoupling method and related equipment

Country Status (1)

Country Link
CN (1) CN110333851B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113220336A (en) * 2020-01-21 2021-08-06 腾讯科技(深圳)有限公司 Code processing method, device, medium and electronic equipment
CN112131025A (en) * 2020-09-28 2020-12-25 平安养老保险股份有限公司 Component transmission method and device, computer equipment and storage medium
CN117033287B (en) * 2023-10-08 2024-02-13 易方信息科技股份有限公司 Multi-bus communication method, system, equipment and storage medium based on SDK (software development kit) package

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6658425B1 (en) * 1998-03-16 2003-12-02 International Business Machines Corporation Generic data centric object structure and implementation
CN105892997A (en) * 2016-03-31 2016-08-24 北京奇虎科技有限公司 Code control method and device
CN108021360A (en) * 2016-11-04 2018-05-11 华为技术有限公司 Rules process method, code process method and relevant device
CN108491209A (en) * 2018-02-23 2018-09-04 厦门集微科技有限公司 The extracting method and device of common code in a kind of html pages

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB2552474A (en) * 2016-07-21 2018-01-31 Sony Interactive Entertainment Inc Program compiler, linker and method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6658425B1 (en) * 1998-03-16 2003-12-02 International Business Machines Corporation Generic data centric object structure and implementation
CN105892997A (en) * 2016-03-31 2016-08-24 北京奇虎科技有限公司 Code control method and device
CN108021360A (en) * 2016-11-04 2018-05-11 华为技术有限公司 Rules process method, code process method and relevant device
CN108491209A (en) * 2018-02-23 2018-09-04 厦门集微科技有限公司 The extracting method and device of common code in a kind of html pages

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于静态代码分析的自动化对象行为协议提取工具;黄洲 等;计算机科学(08);第175-179页 *

Also Published As

Publication number Publication date
CN110333851A (en) 2019-10-15

Similar Documents

Publication Publication Date Title
CN110333851B (en) Code decoupling method and related equipment
CN109617646B (en) Message conversion method and device, computer equipment and computer readable storage medium
CN102087615A (en) Automated merger of logically associated messages in a message queue
CN105224421B (en) Data backup method and device and electronic equipment
CN106790206A (en) The protocol analysis method and device of operation system
CN109992284A (en) Method and device for providing hot update program and electronic equipment
CN111563015A (en) Data monitoring method and device, computer readable medium and terminal equipment
CN113779422B (en) Method and device for realizing relationship chain label, electronic equipment and storage medium
CN109525629A (en) Information-pushing method, device and storage medium
CN107666431B (en) Bookmark communication message acquisition method and device
CN110505289B (en) File downloading method and device, computer readable medium and wireless communication equipment
CN117389655A (en) Task execution method, device, equipment and storage medium in cloud native environment
CN109683942B (en) Script management method, script management device, script management medium and electronic equipment
CN105430623A (en) Monitoring method, device and system for RCS junk message
CN104951715A (en) Information processing method and electronic equipment
CN107205229B (en) Method and device for issuing information at wireless routing equipment end
CN115454674A (en) Method and device for acquiring external data source data, electronic equipment and storage medium
CN113760993A (en) Service data query method and device and electronic equipment
CN108848021B (en) Message forwarding method and device
CN112637046A (en) Message pushing method and routing device
US8681949B1 (en) System, method, and computer program for automated non-sound operations by interactive voice response commands
CN113779945A (en) Method and device for generating file
CN111078215A (en) Software product application method and device, storage medium and electronic equipment
CN118071310B (en) Business processing method and system based on flow engine
CN115310065B (en) File generation method and device, storage medium and electronic equipment

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