CN113900643A - Method and device for generating code - Google Patents

Method and device for generating code Download PDF

Info

Publication number
CN113900643A
CN113900643A CN202111191097.5A CN202111191097A CN113900643A CN 113900643 A CN113900643 A CN 113900643A CN 202111191097 A CN202111191097 A CN 202111191097A CN 113900643 A CN113900643 A CN 113900643A
Authority
CN
China
Prior art keywords
code
feature model
replaced
codes
layout
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.)
Pending
Application number
CN202111191097.5A
Other languages
Chinese (zh)
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information 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 Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202111191097.5A priority Critical patent/CN113900643A/en
Publication of CN113900643A publication Critical patent/CN113900643A/en
Pending legal-status Critical Current

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/35Creation or generation of source code model driven

Abstract

The application discloses a method and a device for generating codes. One embodiment of the method comprises: acquiring a code of a first application in a first operating system; determining replacement code in the second operating system corresponding to at least part of the code of the first application based on the code correspondence between the first operating system and the second operating system; code for a second application in a second operating system corresponding to the first application is generated in accordance with the replacement code. The application provides a method for generating codes of a second application in a second operating system corresponding to a first application based on the codes of the first application of the first operating system, and the code development efficiency is improved.

Description

Method and device for generating code
Technical Field
The embodiment of the application relates to the technical field of computers, in particular to a method and a device for generating codes.
Background
The main programming languages of the android application code and the hong meng application code are java, the development tools are community versions of open source IntelliJ IDEA (integration environment for java programming language development), and the engineering structures of the android platform and the hong meng platform are similar. At present, although the hongmeng system is used as a new operating system, although the system is the same as the development language of the Application in the android system, and the API (Application Programming Interface) is similar to that of the Application in the android system, when a hongmeng Application code is newly developed, because the functions provided by the API and the support library of the hongmeng system are lack of understanding, a developer needs to spend much effort in the process of developing the hongmeng Application corresponding to the android Application, and the development efficiency is low.
Disclosure of Invention
The embodiment of the application provides a method and a device for generating codes.
In a first aspect, an embodiment of the present application provides a method for generating a code, including: acquiring a code of a first application in a first operating system; determining replacement code in the second operating system corresponding to at least part of the code of the first application based on the code correspondence between the first operating system and the second operating system; code for a second application in a second operating system corresponding to the first application is generated in accordance with the replacement code.
In some embodiments, the determining replacement code in the second operating system corresponding to at least part of the code of the first application based on the code correspondence between the first operating system and the second operating system includes: determining whether codes of the first application comprise codes to be replaced or not according to a pre-established first code feature model library of the first operating system; in response to determining that the code includes, for each portion of code to be replaced included in the code for the first application, determining replacement code for the portion of code to be replaced from a second code feature model library of the second operating system.
In some embodiments, for each part of the code to be replaced included in the code of the first application, determining, from the second code feature model library of the second operating system, a replacement code of the part of the code to be replaced includes: for each part of codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of codes to be replaced and the feature model tree of the code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacing codes of the part of codes to be replaced from the second code feature model library according to the matching degree.
In some embodiments, the code to be replaced includes a function code to be replaced that characterizes function information of the first application and a layout code to be replaced that characterizes layout information of the first application; and for each part of codes to be replaced included in the codes of the first application, determining the matching degree between the feature model tree of the part of codes to be replaced and the feature model tree of the code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement codes of the part of codes to be replaced from the second code feature model library according to the matching degree, wherein the method comprises the following steps: for each part of function codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement function codes of the part of function codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library; for each part of layout codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement layout codes of the part of layout codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
In some embodiments, the determining, for each part of the layout code to be replaced included in the code of the first application, a matching degree between the feature model tree of the part of the layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement layout code of the part of the layout code to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of the layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library includes: and determining the matching degree between the feature model tree of the part of layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm for the layout code to be replaced corresponding to each view node from the root view node in the first application, and determining the replacement layout code of the part of layout code to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
In some embodiments, the above method further comprises: aiming at a first operating system, establishing a first code feature model library; and establishing a second code characteristic model library aiming at the second operating system.
In some embodiments, the first operating system is an android system and the second operating system is a Hongmon system.
In a second aspect, an embodiment of the present application provides an apparatus for generating a code, including: an acquisition unit configured to acquire code of a first application in a first operating system; a determination unit configured to determine, based on a code correspondence relationship between the first operating system and the second operating system, replacement code in the second operating system corresponding to at least part of code of the first application; a generating unit configured to generate a code of a second application in the second operating system corresponding to the first application, according to the replacement code.
In some embodiments, the determining unit is further configured to: determining whether codes of the first application comprise codes to be replaced or not according to a pre-established first code feature model library of the first operating system; in response to determining that the code includes, for each portion of code to be replaced included in the code for the first application, determining replacement code for the portion of code to be replaced from a second code feature model library of the second operating system.
In some embodiments, the determining unit is further configured to: for each part of codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of codes to be replaced and the feature model tree of the code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacing codes of the part of codes to be replaced from the second code feature model library according to the matching degree.
In some embodiments, the code to be replaced includes a function code to be replaced that characterizes function information of the first application and a layout code to be replaced that characterizes layout information of the first application; and a determination unit further configured to: for each part of function codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement function codes of the part of function codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library; for each part of layout codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement layout codes of the part of layout codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
In some embodiments, the determining unit is further configured to: and determining the matching degree between the feature model tree of the part of layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm for the layout code to be replaced corresponding to each view node from the root view node in the first application, and determining the replacement layout code of the part of layout code to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
In some embodiments, the above apparatus further comprises: a first establishing unit configured to establish a first code feature model library for a first operating system; and the second establishing unit is configured to establish a second code feature model library aiming at a second operating system.
In some embodiments, the first operating system is an android system and the second operating system is a Hongmon system.
In a third aspect, the present application provides a computer-readable medium, on which a computer program is stored, where the program, when executed by a processor, implements the method as described in any implementation manner of the first aspect.
In a fourth aspect, an embodiment of the present application provides an electronic device, including: one or more processors; a storage device having one or more programs stored thereon, which when executed by one or more processors, cause the one or more processors to implement a method as described in any implementation of the first aspect.
According to the method and the device for generating the code, the code of the first application in the first operating system is obtained; determining replacement code in the second operating system corresponding to at least part of the code of the first application based on the code correspondence between the first operating system and the second operating system; according to the replacement code, the code of the second application in the second operating system corresponding to the first application is generated, so that a method for generating the code of the second application in the second operating system corresponding to the first application based on the code of the first application of the first operating system is provided, and the code development efficiency is improved.
Drawings
Other features, objects and advantages of the present application will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
FIG. 1 is an exemplary system architecture diagram in which one embodiment of the present application may be applied;
FIG. 2 is a flow diagram of one embodiment of a method for generating code in accordance with the present application;
FIG. 3 is a schematic diagram of an application scenario of the method for generating code according to the present embodiment;
FIG. 4 is a flow diagram of yet another embodiment of a method for generating code in accordance with the present application;
FIG. 5 is a block diagram of one embodiment of an apparatus for generating code according to the present application;
FIG. 6 is a block diagram of a computer system suitable for use in implementing embodiments of the present application.
Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
FIG. 1 illustrates an exemplary architecture 100 to which the methods and apparatus for generating code of the present application may be applied.
As shown in fig. 1, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The communication connections between the terminal devices 101, 102, 103 form a topological network, and the network 104 serves to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The terminal devices 101, 102, 103 may be hardware devices or software that support network connections for data interaction and data processing. When the terminal devices 101, 102, 103 are hardware, they may be various electronic devices supporting network connection, information acquisition, interaction, display, processing, and the like, including but not limited to smart phones, tablet computers, e-book readers, laptop portable computers, desktop computers, and the like. When the terminal apparatuses 101, 102, 103 are software, they can be installed in the electronic apparatuses listed above. It may be implemented, for example, as multiple software or software modules to provide distributed services, or as a single software or software module. And is not particularly limited herein.
The server 105 may be a server that provides various services, for example, a background processing server that obtains a code development request sent by a user through the terminal devices 101, 102, and 103, and generates code of a second application in a second operating system corresponding to a first application based on code of the first application in the first operating system. As an example, the server 105 may be a cloud server.
The server may be hardware or software. When the server is hardware, it may be implemented as a distributed server cluster formed by multiple servers, or may be implemented as a single server. When the server is software, it may be implemented as multiple pieces of software or software modules (e.g., software or software modules used to provide distributed services), or as a single piece of software or software module. And is not particularly limited herein.
It should be further noted that the method for generating the code provided by the embodiment of the present application may be executed by the server, the terminal device, or by the server and the terminal device in cooperation with each other. Accordingly, each part (for example, each unit) included in the apparatus for generating a code may be entirely provided in the server, may be entirely provided in the terminal device, and may be provided in the server and the terminal device, respectively.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation. The system architecture may only include the electronic device (e.g., server or terminal device) on which the method for generating code is run, when the electronic device on which the method for generating code is run does not require data transfer with other electronic devices.
With continued reference to FIG. 2, a flow 200 of one embodiment of a method for generating code is shown, comprising the steps of:
step 201, acquiring a code of a first application in a first operating system.
In this embodiment, an execution subject (for example, a server in fig. 1) of the method for generating the code may obtain the code of the first application in the first operating system from a remote location or a local location through a wired network connection or a wireless network connection.
The first operating system may be any operating system, including but not limited to an android operating system, a saiban operating system, an apple phone operating system, a Windows phone operating system, and a firefox operating system. The first application may be an application in the first operating system that provides various services, including but not limited to social applications, lifestyle applications, office applications, shopping applications, financial applications, entertainment applications, and camera applications.
The code is a source file written by a programmer in a language supported by the development tool, and comprises functional code for realizing the functions of the controls in the application and layout code for realizing the layout of the controls in the application.
Step 202, based on the code correspondence between the first operating system and the second operating system, determining a replacement code in the second operating system, which corresponds to at least part of the code of the first application.
In this embodiment, the execution subject may determine, based on the code correspondence between the first operating system and the second operating system, a replacement code in the second operating system, which corresponds to at least a part of the code of the first application.
The second operating system may be any operating system different from the first operating system. As an example, when the first operating system is an iphone operating system, the second operating system may be an android operating system.
The code corresponding relation represents the corresponding relation between codes which realize the same or similar functions in the first operating system and the second operating system and complete the same or similar operations. The function may be any function of the first operating system and the second operating system, and the operation may be any operation of the first operating system and the second operating system.
As an example, the execution subject described above may determine the code correspondence between the first operating system and the second operating system according to the received correspondence determination operation for determining the code correspondence.
As another example, for a code provided by the first operating system, the execution main body divides the code into partial codes corresponding to the functional units by taking the functional units as units; for the code provided by the second operating system, the execution main body is divided into partial codes corresponding to the functional units by taking the functional units as units. The functional unit is a minimum function obtained by subdividing functions provided by an operating system. And for the partial codes corresponding to the functional units of the first operating system and the partial codes corresponding to the functional units of the second operating system, the execution main body determines the matching degree between every two partial codes, and further determines the code corresponding relation between the first operating system and the second operating system based on the matching degree. Specifically, when the matching degree between the partial code corresponding to the first operating system functional unit and the partial code corresponding to the second operating system functional unit is greater than a preset matching degree threshold, the correspondence between the two may be determined. The preset matching degree threshold may be specifically set according to an actual situation, and is not limited herein.
In some optional implementation manners of this embodiment, the execution subject may establish a first code feature model library for the first operating system; and establishing a second code characteristic model library aiming at the second operating system.
As an example, for a support library of the first operating system, the execution subject may generate an implementation sample supporting a common function in the library, and establish the first code feature model library by using the implementation sample as a code feature model. Similarly, for the support library of the second operating system, the execution subject may generate an implementation example supporting a common function in the library, and establish the second code feature model library by using the implementation example as a code feature model.
In some optional implementations of this embodiment, the executing main body may execute the step 202 by:
firstly, whether codes to be replaced are included in codes of a first application is determined according to a pre-established first code feature model library of a first operating system.
As an example, the execution subject scans the code of the first application, locates each method in each file in the application, and determines that the code to be replaced is included if the method name is consistent with the method name of a certain code feature model in the first code feature model library.
Second, in response to determining that includes, for each portion of code included in the code of the first application to be replaced, determining replacement code for the portion of code to be replaced from a second code feature model library of the second operating system.
As an example, the execution subject may determine a matching degree of each part of the code to be replaced included in the code of the first application with each code feature model in the second code feature model library, and determine a code characterized by a code feature model matching with the part of the code to be replaced as a replacement code of the part of the code to be replaced.
In some optional implementations of this embodiment, the executing body may execute the second step by:
for each part of codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of codes to be replaced and the feature model tree of the code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacing codes of the part of codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of codes to be replaced and the feature model tree of the code feature model in the second code feature model library.
In this implementation, the degree of match between the codes corresponding to the two feature model trees is determined based on the degree of match between the two feature model trees. As an example, a simple tree matching algorithm is used to calculate the maximum matching node number between two feature model trees, so as to obtain the similarity between codes, that is, the matching degree between the feature model tree of the part of code to be replaced and the feature model tree of the code feature model in the second code feature model library. Specifically, the executing agent may determine, as the replacement code of the part of the code to be replaced, the code feature model with the highest matching degree between the feature model tree in the second code feature model library and the feature model tree of the part of the code to be replaced.
In some optional implementations of the embodiment, the code to be replaced includes a function code to be replaced that characterizes function information of the first application and a layout code to be replaced that characterizes layout information of the first application. The execution main body may determine, for each part of the to-be-replaced function codes included in the code of the first application, a matching degree between a feature model tree of the part of the to-be-replaced function codes and a feature model tree of a code feature model in the second code feature model library based on a tree matching algorithm, and determine, according to the matching degree between the feature model tree of the part of the to-be-replaced function codes and a feature model tree of a function code feature model in the second code feature model library, replacement function codes of the part of the to-be-replaced function codes from the second code feature model library; for each part of layout codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement layout codes of the part of layout codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
In this implementation manner, when the first code feature model library and the second code feature model library are established, the function codes and the layout codes may be divided, and a function code feature model sub-library and a layout code feature model sub-library in the first code feature model library, and a function code feature model sub-library and a layout code feature model sub-library in the second code feature model library are established.
For each method included in the code of the first application, when the method name is consistent with the method name of a certain code feature model in a function code feature model sub-library in a first code feature model library, determining to-be-replaced function codes, and further determining the replaced function codes of the part of to-be-replaced function codes from a function code feature model sub-library in a second code feature model library according to the matching degree between the feature model tree of the part of to-be-replaced function codes and the feature model tree of the function code feature model in the function code feature model sub-library in the second code feature model library. Similarly, when the method name is consistent with the method name of a certain code feature model in the layout code feature model sub-library in the first code feature model library, the method name is determined to include the layout code to be replaced, and then the replacement layout code of the part of the function code to be replaced is determined from the layout code feature model sub-library in the second code feature model library according to the matching degree between the feature model tree of the part of the layout code to be replaced and the feature model tree of the layout code feature model in the layout code feature model sub-library in the second code feature model library.
In some optional implementations of this embodiment, for the layout code to be replaced, the executing entity may employ a depth-first search algorithm, starting from a root view node in the first application, for the layout code to be replaced corresponding to each view node, determine, based on a tree matching algorithm, a matching degree between a feature model tree of the part of the layout code to be replaced and a feature model tree of a layout code feature model in the second code feature model library, and determine, according to the matching degree between the feature model tree of the part of the layout code to be replaced and a feature model tree of a layout code feature model in the second code feature model library, the replacement layout code of the part of the layout code to be replaced from the second code feature model library.
Specifically, in the layout resource file of the layout of the first application, each control node is traversed, a depth-first search algorithm is adopted, starting from a root view node, and each child node of the starting point is traversed sequentially by taking the root view node as the starting point. When traversing the child node, similarly taking the child node as a starting point, traversing each leaf node of the starting point until all control nodes are traversed. And aiming at the attribute method (such as the layout method for representing the attributes of the size, the position and the like of the control) of each control node, determining a replacement layout code of the layout code to be replaced for representing the attribute method of the control node from the second code characteristic model library.
And step 203, generating codes of a second application in a second operating system corresponding to the first application according to the replacing codes.
In this embodiment, the execution subject may generate, in the second operating system, a code of the second application corresponding to the first application according to the replacement code.
As an example, when replacement code for all code in the first application is found in the second code feature model library of the second operating system, the execution agent may integrate all the replacement code to generate code for the second application corresponding to the first application.
As another example, when the replacement code of the partial code in the first application is found in the second code feature model library of the second operating system, the execution subject may integrate the replacement code for the partial code in the first application, and generate the code of the second application corresponding to the first application in combination with the development code of the developer for the partial code in the first application for which the code to be replaced is not determined.
For the case that the replacement function code and the replacement layout code of the code in the first application are determined, the execution subject may generate the code of the second application corresponding to the first application in combination with the replacement function code and the replacement layout code.
In some optional implementations of this embodiment, the first operating system is an android system, and the second operating system is a hong meng system.
In practice, a plug-in for implementing the method shown in the above step 201-.
Specifically, the plug-in development process needs to be assisted by IntelliJ IDEA. Opening IntelliJ IDEA, sequentially selecting File- > New- > Project in the interface, then selecting plugin Project, creating menu, and performing function description on the plug-in to be generated as step 201 and 203 to generate the plug-in. After the development of the plug-in is completed, the following plug-in deployment operations are carried out: selecting Build- > Prepare plug in Module in sequence in an interface of IntelliJ IDEA based on plug in.xml file generated in the plug-in generating process, and generating jar package in the project root directory; opening devEco studio, sequentially selecting File- > Setting- > plugs- > instrumentation from disk in the interface, and then selecting the jar package just generated to be installed in the devEco studio. And restarting after successful installation to complete the deployment of the plug-in.
With continued reference to fig. 3, fig. 3 is a schematic diagram 300 of an application scenario of the method for generating a code according to the present embodiment. In the application scenario of fig. 3, a user 301 issues a code development request to a server 303 through a terminal device 302. The code development request characterizes code of a first application based on a first operating system, and code of a second application in a second operating system corresponding to the first application is generated. After receiving the code development request, the server first obtains the code of the first application in the first operating system. Then, based on the code correspondence between the first operating system and the second operating system, replacement code in the second operating system corresponding to at least part of the code of the first application is determined. The code corresponding relation represents the corresponding relation between codes which realize the same or similar functions in the first operating system and the second operating system and complete the same or similar operations. Finally, code for a second application in a second operating system corresponding to the first application is generated based on the replacement code.
In the method provided by the above embodiment of the present application, a code of a first application in a first operating system is obtained; determining replacement code in the second operating system corresponding to at least part of the code of the first application based on the code correspondence between the first operating system and the second operating system; in the second operating system, codes of the second application corresponding to the first application are generated according to the replacement codes, so that a method for generating the codes of the second application in the second operating system corresponding to the first application based on the codes of the first application of the first operating system is provided, and the code development efficiency is improved.
With continuing reference to FIG. 4, an illustrative flow 400 of one embodiment of a method for generating code in accordance with the present application is shown comprising the steps of:
step 401, establishing a first code feature model library for a first operating system.
Step 402, establishing a second code feature model library for the second operating system.
At step 403, code of a first application in a first operating system is obtained.
Step 404, determining whether the code of the first application includes a code to be replaced according to a pre-established first code feature model library of the first operating system.
The code to be replaced includes a function code to be replaced representing function information of the first application and a layout code to be replaced representing layout information of the first application.
Step 405, in response to the determination, determining a matching degree between the feature model tree of the part of the function code to be replaced and the feature model tree of the function code feature model in the second code feature model library based on a tree matching algorithm for each part of the function code to be replaced included in the code of the first application, and determining a replaced function code of the part of the function code to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of the function code to be replaced and the feature model tree of the function code feature model in the second code feature model library.
Step 406, for each part of to-be-replaced layout codes included in the codes of the first application, determining a matching degree between the feature model tree of the part of to-be-replaced layout codes and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement layout codes of the part of to-be-replaced layout codes from the second code feature model library according to the matching degree between the feature model tree of the part of to-be-replaced layout codes and the feature model tree of the layout code feature model in the second code feature model library.
Step 407, generating a code of a second application in the second operating system corresponding to the first application according to the replacement function code and the replacement layout code.
As can be seen from this embodiment, compared with the embodiment corresponding to fig. 2, the flow 400 of the method for generating a code in this embodiment specifically illustrates the determination processes of the first code feature model library and the second code feature model library, and the accuracy and efficiency of the code development process are improved for the determination process of the replacement function code of the function code to be replaced and the determination process of the replacement layout code of the layout code to be replaced.
With continuing reference to fig. 5, as an implementation of the method shown in the above figures, the present application provides an embodiment of an apparatus for generating a code, which corresponds to the embodiment of the method shown in fig. 2, and which can be applied in various electronic devices.
As shown in fig. 5, the apparatus for generating a code includes: an acquisition unit configured to acquire code of a first application in a first operating system; a determination unit configured to determine, based on a code correspondence relationship between the first operating system and the second operating system, replacement code in the second operating system corresponding to at least part of code of the first application; a generating unit configured to generate a code of a second application in the second operating system corresponding to the first application, according to the replacement code.
In some embodiments, the determining unit is further configured to: determining whether codes of the first application comprise codes to be replaced or not according to a pre-established first code feature model library of the first operating system; in response to determining that the code includes, for each portion of code to be replaced included in the code for the first application, determining replacement code for the portion of code to be replaced from a second code feature model library of the second operating system.
In some embodiments, the determining unit is further configured to: for each part of codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of codes to be replaced and the feature model tree of the code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacing codes of the part of codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of codes to be replaced and the feature model tree of the code feature model in the second code feature model library.
In some embodiments, the code to be replaced includes a function code to be replaced that characterizes function information of the first application and a layout code to be replaced that characterizes layout information of the first application; and a determination unit further configured to: for each part of function codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement function codes of the part of function codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library; for each part of layout codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement layout codes of the part of layout codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
In some embodiments, the determining unit is further configured to: and determining the matching degree between the feature model tree of the part of layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm for the layout code to be replaced corresponding to each view node from the root view node in the first application, and determining the replacement layout code of the part of layout code to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
In some embodiments, the above apparatus further comprises: a first establishing unit configured to establish a first code feature model library for a first operating system; and the second establishing unit is configured to establish a second code feature model library aiming at a second operating system.
In some embodiments, the first operating system is an android system and the second operating system is a Hongmon system.
In this embodiment, an obtaining unit in the apparatus for generating a code obtains a code of a first application in a first operating system; a determination unit determines, based on a code correspondence relationship between the first operating system and the second operating system, replacement code in the second operating system that corresponds to at least part of code of the first application; the generation unit generates the code of the second application in the second operating system corresponding to the first application according to the replacement code, so that a device for generating the code of the second application in the second operating system corresponding to the first application based on the code of the first application in the first operating system is provided, and the code development efficiency is improved.
Referring now to FIG. 6, shown is a block diagram of a computer system 600 suitable for use in implementing devices of embodiments of the present application (e.g., devices 101, 102, 103, 105 shown in FIG. 1). The apparatus shown in fig. 6 is only an example, and should not bring any limitation to the function and use range of the embodiments of the present application.
As shown in fig. 6, the computer system 600 includes a processor (e.g., CPU, central processing unit) 601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM603, various programs and data necessary for the operation of the system 600 are also stored. The processor 601, the ROM602, and the RAM603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to embodiments of the application, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program, when executed by the processor 601, performs the above-described functions defined in the method of the present application.
It should be noted that the computer readable medium of the present application can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, 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. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present application may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the client computer, partly on the client computer, as a stand-alone software package, partly on the client computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the client computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. 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 and/or flowchart illustration, and combinations of blocks in the block diagrams and/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.
The units described in the embodiments of the present application may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes an acquisition unit, a determination unit, and a generation unit. Where the names of the units do not in some cases constitute a limitation on the units themselves, for example, the determination unit may also be described as a "unit that determines replacement code in the second operating system corresponding to at least part of the code of the first application based on the code correspondence between the first operating system and the second operating system".
As another aspect, the present application also provides a computer-readable medium, which may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by the apparatus, cause the computer device to: acquiring a code of a first application in a first operating system; determining replacement code in the second operating system corresponding to at least part of the code of the first application based on the code correspondence between the first operating system and the second operating system; code for a second application in a second operating system corresponding to the first application is generated in accordance with the replacement code.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention herein disclosed is not limited to the particular combination of features described above, but also encompasses other arrangements formed by any combination of the above features or their equivalents without departing from the spirit of the invention. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.

Claims (16)

1. A method for generating code, comprising:
acquiring a code of a first application in a first operating system;
determining replacement code in the second operating system corresponding to at least part of code of the first application based on a code correspondence between the first operating system and the second operating system;
code corresponding to a second application in the second operating system of the first application is generated according to the replacement code.
2. The method of claim 1, wherein the determining replacement code in the second operating system corresponding to at least part of code of the first application based on the code correspondence between the first operating system and the second operating system comprises:
determining whether codes of the first application comprise codes to be replaced or not according to a pre-established first code feature model library of the first operating system;
in response to determining that the code for the second application includes the replacement code for the portion of code to be replaced, determining, for each portion of code included in the code for the first application, replacement code for the portion of code to be replaced from a second code feature model library of the second operating system.
3. The method of claim 2, wherein the determining, for each portion of code to be replaced included in the code of the first application, replacement code for the portion of code to be replaced from a second code feature model library of the second operating system comprises:
and for each part of codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of codes to be replaced and the feature model tree of the code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacing codes of the part of codes to be replaced from the second code feature model library according to the matching degree.
4. The method according to claim 3, wherein the code to be replaced includes a function code to be replaced which characterizes function information of the first application and a layout code to be replaced which characterizes layout information of the first application; and
the determining, for each part of codes to be replaced included in the codes of the first application, a matching degree between a feature model tree of the part of codes to be replaced and a feature model tree of a code feature model in the second code feature model library based on a tree matching algorithm, and determining a replacement code of the part of codes to be replaced from the second code feature model library according to the matching degree, includes:
for each part of function codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement function codes of the part of function codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library;
for each part of layout codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement layout codes of the part of layout codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
5. The method according to claim 4, wherein the determining, for each part of the layout code to be replaced included in the code of the first application, a matching degree between the feature model tree of the part of the layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement layout code of the part of the layout code to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of the layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library, comprises:
and determining the matching degree between the feature model tree of the part of layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm for the layout code to be replaced corresponding to each view node from the root view node in the first application by adopting a depth-first search algorithm, and determining the replacement layout code of the part of layout code to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
6. The method of claim 2, further comprising:
establishing the first code feature model library aiming at the first operating system;
and establishing the second code feature model library aiming at the second operating system.
7. The method of any of claims 1-6, wherein the first operating system is an android system and the second operating system is a Hongmon system.
8. An apparatus for generating code, comprising:
an acquisition unit configured to acquire code of a first application in a first operating system;
a determination unit configured to determine, based on a code correspondence between the first operating system and a second operating system, replacement code in the second operating system corresponding to at least part of code of the first application;
a generating unit configured to generate code of a second application in the second operating system corresponding to the first application according to the replacement code.
9. The apparatus of claim 8, wherein the determining unit is further configured to:
determining whether codes of the first application comprise codes to be replaced or not according to a pre-established first code feature model library of the first operating system; in response to determining that the code for the second application includes the replacement code for the portion of code to be replaced, determining, for each portion of code included in the code for the first application, replacement code for the portion of code to be replaced from a second code feature model library of the second operating system.
10. The apparatus of claim 9, wherein the determining unit is further configured to:
and for each part of codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of codes to be replaced and the feature model tree of the code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacing codes of the part of codes to be replaced from the second code feature model library according to the matching degree.
11. The apparatus of claim 10, wherein the code to be replaced comprises a function code to be replaced characterizing function information of the first application and a layout code to be replaced characterizing layout information of the first application; and
the determining unit is further configured to:
for each part of function codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement function codes of the part of function codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of function codes to be replaced and the feature model tree of the function code feature model in the second code feature model library; for each part of layout codes to be replaced in the codes of the first application, determining the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm, and determining the replacement layout codes of the part of layout codes to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout codes to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
12. The apparatus of claim 11, wherein the determining unit is further configured to:
and determining the matching degree between the feature model tree of the part of layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library based on a tree matching algorithm for the layout code to be replaced corresponding to each view node from the root view node in the first application by adopting a depth-first search algorithm, and determining the replacement layout code of the part of layout code to be replaced from the second code feature model library according to the matching degree between the feature model tree of the part of layout code to be replaced and the feature model tree of the layout code feature model in the second code feature model library.
13. The apparatus of claim 9, further comprising:
a first establishing unit configured to establish the first code feature model library for the first operating system;
a second establishing unit configured to establish the second code feature model library for the second operating system.
14. The apparatus of any of claims 8-13, wherein the first operating system is an android system and the second operating system is a Hongmon system.
15. A computer-readable medium, on which a computer program is stored, wherein the program, when executed by a processor, implements the method of any one of claims 1-7.
16. An electronic device, comprising:
one or more processors;
a storage device having one or more programs stored thereon,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
CN202111191097.5A 2021-10-13 2021-10-13 Method and device for generating code Pending CN113900643A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111191097.5A CN113900643A (en) 2021-10-13 2021-10-13 Method and device for generating code

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111191097.5A CN113900643A (en) 2021-10-13 2021-10-13 Method and device for generating code

Publications (1)

Publication Number Publication Date
CN113900643A true CN113900643A (en) 2022-01-07

Family

ID=79191666

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111191097.5A Pending CN113900643A (en) 2021-10-13 2021-10-13 Method and device for generating code

Country Status (1)

Country Link
CN (1) CN113900643A (en)

Similar Documents

Publication Publication Date Title
CN110019350B (en) Data query method and device based on configuration information
CN109766127B (en) Method for updating application version information
CN108846753B (en) Method and apparatus for processing data
CN110554876A (en) Method and device for compiling android project
CN110391938B (en) Method and apparatus for deploying services
CN110780874B (en) Method and device for generating information
CN109726217B (en) Database operation method, device, equipment and storage medium
CN110960855B (en) Communication protocol code updating method and device, electronic equipment and storage medium
CN110865889A (en) Method and apparatus for transferring events between components
CN110543297A (en) method and apparatus for generating source code
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN114461247A (en) Hot update method, device, electronic equipment and computer readable medium
CN111787041B (en) Method and device for processing data
CN113536748A (en) Method and device for generating chart data
CN111752644A (en) Interface simulation method, device, equipment and storage medium
CN111324470A (en) Method and device for generating information
CN109254778B (en) Method and apparatus for deploying an information flow system
CN111278085A (en) Method and device for acquiring target network
CN111124541A (en) Configuration file generation method, device, equipment and medium
CN108804442B (en) Serial number generation method and device
CN112947912A (en) Method and device for generating code, electronic equipment and storage medium
CN111125163A (en) Method and apparatus for processing data
CN113282489B (en) Interface testing method and device
CN113900643A (en) Method and device for generating code
CN111124523A (en) Method and apparatus for initializing applications

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