Code conversion method and device

CN119013984APending Publication Date: 2024-11-22HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202280094404.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2022-04-28
Filing Date
2022-12-06
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

When the code base is upgraded or changed, existing technology is difficult to achieve highly automated API call adaptation, resulting in compilation problems and adaptation limitations.

Method used

Through manual modification and accumulation of adaptation patterns, the code blocks input by the user are obtained, the target adaptation pattern is determined, and stored in the adaptation pattern library, which is used to generate adapted code blocks and improve the degree of automatic adaptation of the code.

Benefits of technology

It achieves highly automated adaptation when replacing code libraries, reduces manual modifications, improves adaptation accuracy and automation, and is suitable for API difference adaptation between different versions of code libraries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119013984A_ABST
    Figure CN119013984A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code conversion method which comprises the steps that when a first code library on which a code depends is replaced with a second code library, a second code block input by a user is obtained, and the second code block is used for enabling a first code block in the code to be matched with the second code library; determining a target adaptation mode of the second code block and the first code block; the target adaptation mode is stored in an adaptation mode library, the adaptation mode library is used for generating a fourth code block for a third code block suitable for the target adaptation mode, and the fourth code block is used for adapting the third code block to the second code library. According to the technical scheme, the automatic adaptation degree of the code can be improved by means of manual modification and accumulation of the adaptation mode.
Need to check novelty before this filing date? Find Prior Art

Description

Code conversion method and device

[0001] This application claims priority to Russian patent application No. 2022111733, filed with the Russian Federal Intellectual Property Office on April 28, 2022, entitled “Code conversion method and device”, the entire contents of which are incorporated herein by reference. Technical Field

[0002] The embodiments of the present application relate to the field of computer technology, and more particularly to a code conversion method and device. Background Art

[0003] During software development, it's often necessary to upgrade a dependent codebase to a newer version or change the codebase to another one. However, different versions of codebases inevitably have differences in application programming interfaces (APIs). Directly modifying the version number of a dependent codebase often leads to incompatible API calls in the upper-level code that relies on that codebase, which can introduce compilation issues. With codebase changes, the API differences for implementing the same or similar functions will be even greater. Therefore, after upgrading or modifying the dependent codebase, the upper-level codebase needs to be adapted.

[0004] Existing technologies use domain-specific languages ​​(DSLs) to describe adaptation rules to guide the discovery and application of adaptation patterns. However, it is difficult to describe the adaptation of some API call codes in code base upgrades or changes using rules, and customized adaptation rules cannot cover all code adaptation scenarios.

[0005] Therefore, how to build a flexible and highly automated code conversion method is a technical problem that needs to be solved urgently.

[0006] Summary of the Invention

[0007] The embodiments of the present application provide a code conversion method and apparatus, which can accumulate adaptation patterns with the help of manual modification and improve the degree of automatic adaptation of the code.

[0008] In a first aspect, a code conversion method is provided, the method comprising: when a first code library that a code depends on is replaced with a second code library, obtaining a second code block input by a user, the second code block being used to adapt a first code block in the code to the second code library; determining a target adaptation mode for the second code block and the first code block; storing the target adaptation mode in an adaptation mode library, the adaptation mode library being used to generate a fourth code block for a third code block that applies the target adaptation mode, the fourth code block being used to adapt the third code block to the second code library.

[0009] Optionally, the replacement of the first code base with the second code base may be an upgrade or modification of the code base. For example, it may be an upgrade of code base A version 1.0 to code base A version 2.0, or a modification of code base A to code base B.

[0010] It should be understood that the first code block is a code block that is not compatible with the second code library. For example, the first code block can be a code method method 1 that relies on an API in the first code library. When the first code library is replaced with the second code library, the API called by method 1 no longer exists due to the modification of the code's dependent library. Through the manually input second code block, method 1 can be modified to method 2 with the same functional replacement, or multiple sub-function methods that can replace the functionality of method 1. That is, the second code block is the first code block that is modified to adapt to the second code library.

[0011] It should be understood that determining the target adaptation mode of the second code block and the first code block can be to update the existing adaptation mode in the adaptation mode library, or to determine an adaptation mode that is not in the adaptation mode library. The target adaptation mode of the second code block and the first code block can convert the code block having the same characteristics as the first code block into a code block that is adapted to the second code library. That is to say, the first code block and the code block having the same characteristics as the first code block correspond to the target adaptation mode. Exemplarily, if the third code block is not adapted to the second code library, and the third code block is applicable to the target adaptation mode, that is, it has the same characteristics as the first code block and corresponds to the target adaptation mode, the target adaptation mode can modify the third code block to be adapted to the fourth code block of the second code library.

[0012] Optionally, the adaptation pattern library can be a local adaptation pattern database or a remote adaptation pattern database. Optionally, the adaptation pattern library can be used for multiple computer devices to share the target adaptation pattern, helping more users in the same scenario to achieve automatic code adaptation.

[0013] The embodiment of the present application provides a code conversion method, which can accumulate adaptation patterns with the help of manual modification when replacing the code library that the code depends on, thereby improving the degree of automatic adaptation of the code.

[0014] In combination with the first aspect, in some implementations of the first aspect, the third code block belongs to the code.

[0015] It should be understood that the third code block and the first code block can be located in the same code. For example, at the first moment, the target adaptation pattern corresponding to the first code block does not exist in the adaptation pattern library, that is, the first code block cannot be automatically adapted through the target adaptation pattern. After the user inputs the second code block and determines the target adaptation pattern, the target adaptation pattern is stored in the adaptation pattern library. At the second moment, the third code block with the same characteristics as the first code block can find the corresponding target adaptation pattern in the adaptation pattern library, and then complete the automatic adaptation of the code, so that the third code block is converted into a code block that adapts to the second code library.

[0016] The embodiment of the present application provides a code conversion method, which can accumulate adaptation patterns with the help of manual modification when replacing the code library that the code depends on, thereby improving the degree of automatic adaptation of the code.

[0017] In combination with the first aspect, in some implementations of the first aspect, the first code library and the second code library both belong to a first-party dependency library; or, the first code library and the second code library both belong to a second-party dependency library; or, the first code library and the second code library both belong to a third-party dependency library.

[0018] It should be understood that first-party, second-party, and third-party libraries can also be referred to as first-party libraries, second-party libraries, and third-party libraries, or as first-party packages, second-party packages, and third-party packages. Generally, first-party libraries refer to classes, methods, and interfaces within a project or program. Second-party libraries refer to internal company libraries, typically code packages released for internal projects. Third-party libraries refer to open source libraries outside the company.

[0019] The embodiment of the present application provides a code conversion method, which can use manual modification to accumulate adaptation patterns and improve the automatic adaptation degree and adaptation accuracy of the code when replacing the code library of the same category that the code depends on.

[0020] In combination with the first aspect, in some implementations of the first aspect, obtaining the second code block input by the user includes: when the target adaptation mode corresponding to the first code block is not present in the adaptation mode library, obtaining the second code block input by the user.

[0021] It should be understood that when the code library on which the code depends is replaced, the method provided in the embodiment of the present application first searches for the target adaptation pattern corresponding to the first code block in the adaptation pattern library. If there is no target adaptation pattern corresponding to the first code block in the adaptation pattern library, the second code block input by the user is obtained.

[0022] The embodiment of the present application provides a code conversion method, which can accumulate adaptation patterns with the help of manual modification when replacing the code library that the code depends on, thereby improving the degree of automatic adaptation of the code.

[0023] In combination with the first aspect, in certain implementations of the first aspect, the method further includes: if the target adaptation pattern corresponding to the first code block exists in the adaptation pattern library, generating the second code block or the fifth code block based on the target adaptation pattern, and the second code block or the fifth code block is used to adapt the first code block in the code to the second code library.

[0024] It should be understood that when replacing a code-dependent code base, if the code includes multiple identical first code blocks that are not compatible with the second code base, a target adaptation mode is determined based on the second code block input by the user and the first first code block. For the second first code block, if a target adaptation mode corresponding to the first code block already exists in the adaptation mode library, the second first code block can be directly converted into a code block compatible with the second code base using this target adaptation mode. This code block can be the second code block or a fifth code block similar to the second code block that is compatible with the second code base.

[0025] The embodiment of the present application provides a code conversion method, which can accumulate adaptation patterns with the help of manual modification when replacing the code library that the code depends on, thereby improving the degree of automatic adaptation of the code.

[0026] In combination with the first aspect, in certain implementations of the first aspect, before obtaining the second code block input by the user, the method further includes: learning K adaptation modes based on the adaptation operations of N code blocks, the adaptation operation of the nth code block in the adaptation operations of the N code blocks includes the operation of adapting the nth code block in the N code blocks to the second code library, the kth adaptation mode in the K adaptation modes is used to adapt the code block to which the kth adaptation mode is applicable to the second code library, N is a positive integer greater than or equal to 2, n=1,…,N, K is greater than or equal to 2 and less than or equal to N, k=1,…,K; and storing the K adaptation modes in the adaptation mode library.

[0027] It should be understood that the adaptation pattern library can be enriched before obtaining the second code block input by the user. Alternatively, offline mining of historical modification data of code repositories in some open source communities can be performed to obtain some adaptation patterns, which can then be used as the basis for code adaptation. Alternatively, the adaptation pattern database can be continuously enriched through historical records of user code modifications.

[0028] Exemplarily, a first code block set and a second code block set may be obtained, where the first code block set includes N code blocks that are not compatible with the second code base, and the second code block set includes M code blocks that are compatible with the second code base. The N code blocks correspond one-to-one with the M code blocks, and each code block in the second code block set is obtained by modifying a corresponding code block in the first code block set, where M = N. Based on the first code block set and the second code block set, an adaptation operation for the N code blocks may be determined.

[0029] Among the K adaptation modes, the nth code block among the N code blocks corresponds to one of the K adaptation modes. The adaptation mode corresponding to the nth code block can convert a code block having the same characteristics as the nth code block into a code block adapted to the second code library, that is, the kth adaptation mode among the K adaptation modes is used to adapt the code block to which the kth adaptation mode is applicable to the second code library.

[0030] An embodiment of the present application provides a code conversion method, which can first obtain the adaptation operations of some code blocks to enrich the adaptation pattern library. When the code library that the code depends on is replaced, the code blocks that are not compatible with the replaced code library can be automatically converted according to the adaptation pattern in the adaptation pattern library, thereby reducing manual modification and improving the degree of automatic adaptation of the code.

[0031] In combination with the first aspect, in certain implementations of the first aspect, the learning of K adaptation modes based on the adaptation operations of the N code blocks includes: constructing N operation trees based on the adaptation operations of the N code blocks, where the nth operation tree among the N operation trees includes an operation for adapting the nth code block to the second code library; determining K operation tree groups based on the N operation trees, where each of the K operation tree groups includes multiple operation trees having the same characteristics; and determining the K adaptation modes based on the K operation tree groups.

[0032] Exemplarily, if an operation tree is constructed based on the first code block set and the second code block set, the codes in the first code block set and the second code block set can be first parsed into an abstract syntax tree (AST), and then N operation trees are constructed based on the ASTs before and after the modification, where the nth operation tree among the N operation trees includes an operation of modifying the nth code block to a corresponding code block among the M code blocks.

[0033] Optionally, the N operation trees may be clustered, or K operation tree groups may be determined based on a statistical method.

[0034] It should be understood that each of the K operation tree groups may include one or more operation trees, multiple operation trees belonging to the same operation tree group have the same characteristics, and operation trees belonging to different operation tree groups have different characteristics.

[0035] Optionally, the method for determining the K adaptation modes includes an anti-unity algorithm, a machine learning method, or a statistics-based method.

[0036] It should be understood that if the operation tree group includes only one operation tree, then the operation tree is the adaptation mode corresponding to the operation tree group.

[0037] An embodiment of the present application provides a code conversion method that can construct an operation tree based on the adaptation operations of a code block and extract the corresponding adaptation pattern based on the operation tree group. When replacing the code library that the code depends on, manual modification can be used to support the accumulation and evolution of the adaptation pattern, thereby improving the degree of automatic adaptation and adaptation accuracy of the code.

[0038] In combination with the first aspect, in certain implementations of the first aspect, determining K operation tree groups based on the N operation trees includes: determining P operation subtrees based on the N operation trees, the P operation subtrees being used to adapt sub-code blocks of the N code blocks to the second code library, where P is an integer greater than or equal to N; and determining the K operation tree groups based on the P operation subtrees.

[0039] In the embodiment of the present application, P operation trees can be split into operation subtrees that describe complete independent changes, each of which includes an operation node and a useful node. For example, P can be determined by the nth operation tree in N operation trees. n Operation subtree, where the P n The operation subtree and the nth code block include P n There is a one-to-one correspondence between the sub-code blocks, P n is a positive integer greater than or equal to 1. nThe mth operation subtree in the operation subtrees includes an operation node and a useful node. The operation node included in the mth operation subtree is used to convert the P n The mth sub-code block in the sub-code blocks is converted into a sub-code block adapted to the second code library, and the useful nodes included in the mth operation subtree are nodes that affect the conversion operation of the mth sub-code block, m=1, ..., P n .

[0040] An embodiment of the present application provides a code conversion method that can construct an operation tree based on the adaptation operations of a code block, split the operation tree, and then extract the corresponding adaptation pattern based on the operation subtree group. When replacing the code library that the code depends on, manual modification can be used to support the accumulation and evolution of the adaptation pattern, thereby improving the degree of automatic adaptation and adaptation accuracy of the code.

[0041] In combination with the first aspect, in certain implementations of the first aspect, determining the K operation tree groups based on the P operation subtrees includes: deleting useless nodes in the P operation subtrees, where the useless nodes include nodes that do not affect the adaptation of corresponding sub-code blocks in the N code blocks to the second code library; and clustering the P operation subtrees after deleting the useless nodes to obtain the K operation tree groups.

[0042] Exemplarily, a node in the operation subtree that is not a useful node is a useless node. Useful nodes include a first type of useful node and a second type of useful node, where the first type of useful node is a node to which a modification operation is applied, and the second type of node is the parent node of the first type of useful node. Optionally, useful nodes may also include at least one type of useful node from a third type of useful node, a fourth type of useful node, and a fifth type of useful node, where the third type of useful node includes an intermediate node for connecting two useful nodes, the fourth type of useful node includes a child node whose parent node is a useful node and must be connected to the parent node to meet the code syntax requirements, and the fifth type of useful node is a node with the same identifier as the first type of useful node or the second type of useful node.

[0043] An embodiment of the present application provides a code conversion method that can construct an operation tree based on the adaptation operations of a code block, split and simplify the operation tree, and then extract the corresponding adaptation pattern based on the operation subtree group. When replacing the code library that the code depends on, manual modification can be used to support the accumulation and evolution of the adaptation pattern, thereby improving the degree of automatic adaptation and adaptation accuracy of the code.

[0044] In combination with the first aspect, in certain implementations of the first aspect, determining the K adaptation modes based on the K operation tree groups includes: determining a code template and a code conversion operation corresponding to each of the K operation tree groups, the code template including replaceable features and identical features of an operation tree in a corresponding operation array, and the code conversion operation being used to convert a code block having identical features to the code template of the corresponding operation tree group into a code block adapted to the second code library; and determining the K adaptation modes based on the code template and the code conversion operation corresponding to each of the K operation tree groups.

[0045] Exemplarily, the i-th code template corresponding to the i-th operation tree group among the K operation tree groups includes replaceable features and identical features of the operation trees in the i-th operation tree group, and the i-th code conversion operation corresponding to the i-th operation tree group is capable of converting a code block having the same features as the i-th code template into a code block adapted to the second code library, i=1,…,K.

[0046] An embodiment of the present application provides a code conversion method that can construct an operation tree based on the adaptation operations of a code block and extract the corresponding adaptation pattern based on the operation tree group. When replacing the code library that the code depends on, manual modification can be used to support the accumulation and evolution of the adaptation pattern, thereby improving the degree of automatic adaptation and adaptation accuracy of the code.

[0047] In a second aspect, an embodiment of the present application provides a computer device, which includes a unit for implementing the first aspect or any possible implementation manner of the first aspect.

[0048] In a third aspect, an embodiment of the present application provides a computer device, which includes a processor, wherein the processor is used to couple with a memory, read and execute instructions and / or program codes in the memory to execute the first aspect or any possible implementation of the first aspect.

[0049] In a fourth aspect, an embodiment of the present application provides a chip system, which includes a logic circuit, which is used to couple with an input / output interface and transmit data through the input / output interface to execute the first aspect or any possible implementation method of the first aspect.

[0050] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores program code. When the computer storage medium runs on a computer, it enables the computer to execute the first aspect or any possible implementation of the first aspect.

[0051] In a sixth aspect, an embodiment of the present application provides a computer program product, which includes: a computer program code, which, when running on a computer, enables the computer to execute the first aspect or any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] FIG1 is a schematic diagram of an application scenario of a code conversion device provided in an embodiment of the present application.

[0053] FIG2 is a schematic diagram of a project file directory tree provided in an embodiment of the present application.

[0054] FIG3 is a schematic diagram of a code conversion device provided in an embodiment of the present application.

[0055] FIG4 is a schematic diagram of an application scenario of another code conversion device provided in an embodiment of the present application.

[0056] FIG5 is a schematic structural diagram of a code conversion device provided in an embodiment of the present application.

[0057] FIG6 is a schematic diagram of an adaptation pattern mining principle provided in an embodiment of the present application.

[0058] FIG7 is a schematic diagram of an adaptation mode browsing provided in an embodiment of the present application.

[0059] FIG8 is an exemplary flowchart of adaptation pattern mining provided in an embodiment of the present application.

[0060] FIG9 is a schematic diagram of constructing an operation tree provided in an embodiment of the present application.

[0061] FIG10 is a schematic diagram of another method for constructing an operation tree provided in an embodiment of the present application.

[0062] FIG11 is a schematic diagram of another method for constructing an operation tree provided in an embodiment of the present application.

[0063] FIG12 is a schematic diagram of an adaptation mode provided in an embodiment of the present application.

[0064] FIG13 is a schematic diagram of an application scenario of another code conversion device provided in an embodiment of the present application.

[0065] FIG14 is a diagram showing an example of the structure of a computer device provided in an embodiment of the present application.

[0066] FIG15 is a structural example diagram of another computer device provided in an embodiment of the present application.

[0067] FIG16 is an example diagram of a computer program product provided in an embodiment of the present application. DETAILED DESCRIPTION

[0068] During software development, developers typically include code libraries in their code files to improve efficiency and ensure quality. It should be understood that a code library can be a first-party, second-party, or third-party dependency library. These libraries can also be referred to as first-party libraries, second-party libraries, or third-party libraries, or as first-party packages, second-party packages, or third-party packages. First-party libraries refer to classes, methods, interfaces, and so on within a project or program. Second-party libraries refer to internal company dependency libraries, generally code packages released for internal company projects. Third-party libraries refer to open-source libraries outside the company.

[0069] However, the code base introduced by the code may have various risks. For example, some open source third-party library versions contain high-risk vulnerabilities, and some open source third-party library licenses have restrictions on commercial use. These risks may lead to serious security issues.

[0070] For risk issues existing in the code base, developers usually adopt two methods to solve them: upgrading the code base to a newer version or changing it to another code base with the same or similar functions. However, different versions of code bases inevitably have API differences. Directly modifying the version number of the dependent code base will often lead to incompatible API calls in the upper-level code that depends on the code base, thereby introducing compilation problems. With changes to the code base, the API differences for implementing the same or similar functions will be greater. Therefore, after the code base is upgraded or changed, the upper-level code needs to be adapted. However, the existing technology for adapting API calls has a low degree of automation and has great limitations. The present application can identify the adaptation scenarios of API calls, accumulate modification patterns with the help of manual modifications, and improve the automation of API adaptation in code base upgrade and change scenarios.

[0071] The technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making any creative efforts should fall within the scope of protection of this application.

[0072] FIG1 is a schematic diagram of an application scenario of a code conversion device provided by an embodiment of the present application, which mainly includes operations on the user side and the server side.

[0073] 110, the user selects a project.

[0074] FIG2 is a schematic diagram of a project file directory tree provided in an embodiment of the present application. A user can select to analyze a project file. For example, a user can click the box in front of the pluginTest project file to select to analyze the pluginTest file project.

[0075] 120,Analyze dependent code base.

[0076] Optionally, a designated risk identification and repair device can be used to analyze the code bases that the project file depends on, or the functionality of the risk identification and repair device can be built into the code conversion device 100 of the present application, and the code conversion device 100 can be used to analyze the code bases that the project file depends on. This application is not limited to this. By analyzing the code bases that the project file depends on, the type and version of the code bases that the project file depends on can be determined. It should be understood that a project file can depend on one or more code bases.

[0077] It should be understood that the code conversion device 100 can be a software / functional module in a computer that performs operations such as conversion of code blocks. For the sake of convenience of description, the software / functional module used to implement the code conversion operation is referred to as a "code conversion device" in the embodiment of the present application. This name should not be understood as a limitation to the present application.

[0078] 130, query vulnerabilities and repair suggestions.

[0079] Exemplarily, the code conversion device 100 can obtain a repair plan for the project file based on the repair suggestions in the repair suggestion database 101. Optionally, the repair plan can include upgrading the code base or changing the code base. For example, code base A version 1.0 can be upgraded to code base A version 2.0, or code base A can be changed to code base B.

[0080] 140, select a repair solution.

[0081] Optionally, the user can manually select a repair solution for the code base, or the server can automatically select a default repair solution, which is not limited in this application.

[0082] 150, code adaptation.

[0083] For example, the repair solution is to change code base A to code base B. The code conversion device 100 uses the adaptation pattern database 190 to match the adaptation pattern of the code block with the execution error in the project file. It should be understood that the execution error of the code block means that the code block is not compatible with code base B. Optionally, the adaptation pattern in the adaptation pattern database 190 can be matched based on the code block, or the code block can be matched based on the adaptation pattern in the adaptation pattern database 190.

[0084] The code conversion device 100 performs a conversion operation on the code block according to the matched adaptation mode, so that the code block is adapted to the code library B.

[0085] 160, manual adaptation code.

[0086] It should be understood that if the transcoding apparatus 100 does not match the adaptation pattern corresponding to an erroneous code block, the user can manually modify the code block. The transcoding apparatus 100 can then update the adaptation pattern in the adaptation pattern database 190 based on the code block and the last modified code block in the adaptation code library B. It should be understood that the transcoding apparatus 100 can record each time a user runs an erroneous code block and each time a successful code block runs. For example, if a code block B1 is successfully compiled after five modifications by the user, the transcoding apparatus 100 can record the four code blocks corresponding to code block B1 that failed to compile and the fifth code block that successfully compiled. The adaptation pattern database 190 can then be updated based on these five code blocks.

[0087] FIG3 is a schematic diagram of a code conversion device provided in an embodiment of the present application.

[0088] If the code block B1 compiles incorrectly after the code base that the project file depends on is changed from A to B, and the code conversion device 100 cannot automatically convert the code block B1 into code adapted to code base B, the user can manually modify the code block B1.

[0089] 210, automatically triggered.

[0090] When the user manually converts the code block B1 into the code block B2 adapted to the code library B, the code conversion apparatus 100 may automatically record the code block B1 and the code block B2 and perform adaptation pattern mining in step 230 .

[0091] 220, manual trigger.

[0092] Optionally, the user may manually select whether to perform adaptation pattern mining on the code block B1 and the code block B2.

[0093] 230, Adaptation pattern mining.

[0094] The transcoding device 100 can mine adaptation patterns based on the code blocks before and after the modification. For example, the transcoding device 100 can mine adaptation patterns for when code base A is upgraded from version 1.0 to version 2.0, or it can mine adaptation patterns for when code base A is changed to code base B. It should be understood that because the mining process is performed on the server side, the user is unaware of the entire mining process. The transcoding device 100 can store successfully mined adaptation patterns in different adaptation pattern databases. For example, for adaptation patterns mined for a code base upgrade scenario, the transcoding device 100 can store the mined adaptation patterns in the code base upgrade adaptation pattern database 215. For adaptation patterns mined for a code base change scenario, the transcoding device 100 can store the mined adaptation patterns in the code base change adaptation pattern database 225. Optionally, the transcoding device 100 can also store successfully mined adaptation patterns in a single adaptation pattern database. Exemplarily, the code base upgrade adaptation mode database 215 and the code base change adaptation mode database 225 may be placed in one database, which is not limited in this application.

[0095] If the user encounters the same scenario in subsequent project file modifications, such as upgrading version 1.0 of code base A to version 2.0, the updated adaptation pattern database can be used to adapt the code to achieve the same purpose as manual modification.

[0096] 240, offline mining of open source code repositories.

[0097] Optionally, you can first conduct offline mining of historical modification data of code repositories in some open source communities to obtain some adaptation patterns, and then use these adaptation patterns as the basis for code adaptation. You can also continuously enrich the adaptation pattern database directly through the historical records of users manually modifying the code. It should be understood that the adaptation pattern database mentioned in the embodiment of the present application can be a code base upgrade adaptation pattern database 215, or a code base change adaptation pattern database 225, or a combination of the two.

[0098] FIG4 is a schematic diagram of an application scenario of another code conversion device provided in an embodiment of the present application.

[0099] 310. Computer device A modifies the code library on which the code depends.

[0100] Computer device A modifies the code library that the code depends on, automatically or manually. For example, computer device A modifies information such as the project organization identifier (Group ID), project name (Artifact ID), or project version number (Version) of the code library that the code depends on, such as the project object model (Pom) in the project file or the Gradle dependency file. For example, computer device A upgrades version 1.0 of code library A to version 2.0.

[0101] At this point, if the project file compiles without errors, it means that the API has not changed before and after the code base upgrade or modification. This is a compatible scenario, and there is no need to adapt the API in the project file. If the project compiles with errors, it means that incompatible changes have occurred before and after the code base upgrade or modification, and the API in the project file needs to be adapted.

[0102] 320. Computer device A performs code adaptation.

[0103] The transcoding device 100 uses the local adaptation pattern database 301 to adapt the code blocks in the project file that have compilation errors, converting the code blocks that have compilation errors into code blocks in the adapted replacement code library. Optionally, the transcoding device 100 may also use the remote adaptation pattern database 305 to adapt the code blocks in the project file that have compilation errors, or may use both the local adaptation pattern database 301 and the remote adaptation pattern database 305 to adapt the code blocks in the project file that have compilation errors, although this application does not limit this.

[0104] 330, determine whether the compilation reports an error.

[0105] If the project file is compiled without errors after code adaptation, it means that the adaptation mode local database 301 is sufficient to support the project file to perform code conversion to adapt to the replaced code base, and the adapted code 303 can be obtained at this time.

[0106] If the project file compiles with an error after code adaptation, it means that the error code block in the project file has not found a corresponding adaptation mode in the adaptation mode local database 301 for code conversion, and manual modification of the project file is required to eliminate the compilation error.

[0107] 340, manual adaptation code.

[0108] Users can manually modify the code blocks with compilation errors to eliminate compilation errors.

[0109] 350, Adaptation Pattern Mining.

[0110] The code conversion device 100 in the computer device A can mine the adaptation pattern based on the code block with compilation errors and the code block that was finally compiled successfully, including updating the corresponding adaptation pattern in the adaptation pattern database or determining a new adaptation pattern.

[0111] Optionally, the code conversion device 100 can automatically update the adaptation mode local database 301 and / or the adaptation mode remote database 305 according to the code blocks before and after the modification, or manually select whether to update the adaptation mode local database 301 and / or the adaptation mode remote database 305.

[0112] If computer device A chooses to store the successfully mined adaptation patterns in the local adaptation pattern database 301, if a subsequent project encounters the same scenario, such as upgrading version 1.0 of the code library A that the project file depends on to version 2.0, the project file can be directly adapted using the local adaptation pattern database 301. Computer device A can also choose to upload the successfully mined adaptation patterns to the remote adaptation pattern database 305. This allows other computer devices to pull the required adaptation patterns into the local adaptation pattern database and directly adapt the project file code when encountering the corresponding scenario, achieving the same purpose as manual modification.

[0113] 360, computer device B modifies the code library that the code depends on.

[0114] For example, computer device B modifies the code library that the code depends on automatically or manually, for example, by upgrading version 1.0 of code library A to version 2.0.

[0115] At this point, if the project file compiles without errors, it means that the API has not changed before and after the code base upgrade or modification. This is a compatible scenario, and there is no need to adapt the API in the project file. If the project compiles with errors, it means that incompatible changes have occurred before and after the code base upgrade or modification, and the API in the project file needs to be adapted.

[0116] 370. Computer device B performs code adaptation.

[0117] The code conversion device 100 in computer device B can use the local adaptation pattern database to adapt the code with compilation errors in the project file, and convert the code with compilation errors into adapted code 303. Optionally, the code conversion device 100 can also pull the required adaptation pattern from the remote adaptation pattern database 305 to the local adaptation pattern database of computer device B, and then use the updated local adaptation pattern database to adapt the code with compilation errors in the project file.

[0118] FIG5 is a schematic diagram of the structure of a code conversion device provided by an embodiment of the present application. The code conversion device can implement an adaptive pattern mining function, an adaptive pattern browsing function, and an adaptive pattern application function. The adaptive pattern mining function can be implemented by an adaptive pattern mining module 410 in the code conversion device, the adaptive pattern browsing function can be implemented by an adaptive pattern browsing module 420 in the code conversion device, and the adaptive pattern application function can be implemented by an adaptive pattern application module 430 in the code conversion device.

[0119] The adaptation pattern mining module 410 can automatically mine the adaptation pattern without the user's perception. When the user upgrades the code base that the project file depends on or changes the code base, the adaptation pattern mining module 410 can automatically monitor the mining timing, confirm the mining target, and then mine the adaptation pattern, and prompt the user to perform subsequent operations. Figure 6 is a schematic diagram of an adaptation pattern mining principle provided by an embodiment of the present application. The adaptation pattern mining module 410 can monitor the compilation status of the user's project file. If the code change of the project file causes the compilation to fail, the adaptation pattern mining module 410 will be triggered to track and record the code status. When the code compilation of the project file is successful, the adaptation pattern mining module 410 will automatically perform mining.

[0120] For example, as shown in FIG6 , the code base that a project file depends on is changed from A to B, and a compilation error occurs in the project file. The user manually modifies the code block that caused the compilation error. The adaptation pattern mining module 410 can track and record the code manually modified by the user, automatically mine adaptation patterns, and then store the mined adaptation patterns in the adaptation pattern database 400. It should be understood that the adaptation pattern database 400 can include one or more different types of databases. For example, it can include the code base upgrade adaptation pattern database 215 and the code base change adaptation pattern database 225.

[0121] The adaptation pattern browsing module 420 can be used to view the adaptation patterns saved in the adaptation pattern database 400. Figure 7 is a schematic diagram of an adaptation pattern browsing provided by an embodiment of the present application. The user can use the adaptation pattern browsing module 420 to preview the code before and after the transformation, and then select the corresponding adaptation pattern database to automatically convert the code. For example, the user can first preview the code before and after the transformation using the code library to upgrade the adaptation pattern database 215 and the code before and after the transformation using the code library to change the adaptation pattern database 225, and then select the code library to upgrade the adaptation pattern database 215 or the code library to change the adaptation pattern database 225 to automatically adapt the code.

[0122] Adaptation pattern application module 430 can perform code conversion on project files selected by the user. For example, as shown in FIG2 , the user can select which project files to convert. For example, the user can click the box in front of the GuavaTest.java file to select the GuavaTest.java file for code conversion. Adaptation pattern application module 430 will analyze the code in the project file to identify code blocks that can be applied to the adaptation pattern and then automatically complete the code conversion based on the adaptation pattern database 400.

[0123] FIG8 is an exemplary flowchart of adaptation pattern mining provided in an embodiment of the present application.

[0124] 510, construct an operation tree.

[0125] The code conversion device 100 can first parse the code before and after the user modification into an abstract syntax tree. Figure 9 is a schematic diagram of a construction operation tree provided by an embodiment of the present application. For example, Figure 9 (a) and Figure 9 (b) are schematic diagrams of an abstract syntax tree provided by an embodiment of the present application. Among them, Figure 9 (a) is the AST of the code before modification, and Figure 9 (b) is the AST of the code after modification. It should be understood that the letters or numbers in the nodes can represent a code statement, a code block, an identifier or a parameter, etc. Figure 9 (c) is a schematic diagram of an operation tree provided by an embodiment of the present application. The code conversion device 100 can construct an operation tree based on the two ASTs before and after the code modification by analyzing the differences between the two. As shown in the two ASTs in Figure 9 (a) and Figure 9 (b), the difference is that after the code modification, the child node C of A is replaced by branch 1-2-BG. The code conversion device 100 will store the child node C and branch 1-2-BG as a change pair to generate an operation node. As shown in the operation tree of (c) of Figure 9, the Ref of the operation node indicates the reference node in the change pair, that is, the node to which the code modification operation is applied. In the embodiment of the present application, the reference node of the operation tree is node C. The Rep of the operation node indicates the replacement branch node in the change pair, that is, the branch node that replaces the reference node after the code modification. In the embodiment of the present application, the replacement node of the operation tree is node 1-2-BG. It should be understood that the modification operation indicated by the operation node of (c) of Figure 9 is to replace the entire subtree with the node indicated by Rep as the root node with the entire tree with the node indicated by Ref as the root node. Exemplarily, if node C has multiple child nodes, node C and the multiple child nodes will be replaced with branch 1-2-BG.

[0126] Figure 10 is a schematic diagram of another operation tree provided by an embodiment of the present application. Figure 10 (a) and Figure 10 (b) are schematic diagrams of another abstract syntax tree provided by an embodiment of the present application. Among them, Figure 10 (a) is the AST of the code before modification, and Figure 10 (b) is the AST of the code after modification. It should be understood that the letters or numbers in the nodes can represent a code statement, a code block, an identifier or a parameter, etc. Figure 10 (c) is a schematic diagram of another operation tree provided by an embodiment of the present application. The code conversion device 100 can construct an operation tree based on the two ASTs before and after the code modification by analyzing the differences between the two. The two ASTs shown in Figure 10 (a) and Figure 10 (b) differ in that after the code is modified, branch 1-2-BG is added after the child node C of A. The code conversion device 100 will store the child node C and branch 1-2-BG as a change pair to generate an operation node. In the operation tree shown in Figure 10, the Ref of the operation node indicates the reference node in the change pair, that is, the node to which the code modification operation is applied. In the embodiment of the present application, the reference node of the operation tree is node C. The Acc of the operation node indicates the branch node added in the change pair, that is, the branch node added after the reference node C after the code is modified. In the embodiment of the present application, the added branch node of the operation tree is 1-2-BG, that is, the code statement represented by the branch node 1-2-BG is added after the code statement represented by the reference node C after the code is modified. It should be understood that the modification operation indicated by the operation node (c) of Figure 9 is to add the entire subtree with the node indicated by Acc as the root node to the entire subtree with the node indicated by Ref as the root node. Exemplarily, if the C node has multiple child nodes, the branch node 1-2-BG will be added to the C node and the multiple child nodes.

[0127] Figure 11 is a schematic diagram of another operation tree provided by an embodiment of the present application. Figure 11 (a) and Figure 11 (b) are schematic diagrams of another abstract syntax tree provided by an embodiment of the present application. Among them, Figure 11 (a) is the AST of the code before modification, and Figure 11 (b) is the AST of the code after modification. It should be understood that the letters or numbers in the nodes can represent a code statement, a code block, an identifier or a parameter, etc. Figure 11 (c) is a schematic diagram of another operation tree provided by an embodiment of the present application. The code conversion device 100 can construct an operation tree based on the two ASTs before and after the code modification by analyzing the difference between the two. The two ASTs shown in Figure 11 (a) and Figure 11 (b) are different in that the child node C of A is deleted after the code is modified. In the operation tree shown in Figure 11, the Ref of the operation node indicates the reference node in the change pair, that is, the node to which the code modification operation is applied. In the embodiment of the present application, the reference node of the operation tree is node C. The Del operation node indicates the branch node to be deleted, that is, the branch node to be deleted after the code is modified. In the embodiment of the present application, the deletion node of the operation tree is node C, that is, the code statement represented by the reference node C is deleted after the code is modified. It should be understood that the modification operation indicated by the operation node (c) in Figure 11 is to delete the entire subtree with the node indicated by Del as the root node. Exemplarily, if node C has multiple child nodes, node C and the multiple child nodes will be deleted.

[0128] 520, Split and minimize the operation tree.

[0129] The code conversion device 100 can split the operation tree into operation subtrees that describe complete independent changes. Describing complete independent changes means that these operation subtrees must be as small as possible but functionally complete. This ensures that each node in the subtree has a context. The context of a node refers to the parent node or sibling node of the node, which is reflected in the actual code as the method where the code statement represented by the node is located, the code statements before and after, etc.

[0130] The code conversion device 100 can use a traversal method to extract an operation subtree, and the traversal method includes pre-order traversal, in-order traversal, post-order traversal, level-order traversal, etc. Each operation subtree in the operation subtree includes an operation node and a useful node. The operation nodes shown in Figures 9, 10 and 11 are used to indicate the conversion operations before and after the code modification. The useful nodes include a first type of useful node and a second type of useful node. The first type of useful node is a node to which the modification operation is applied, and the second node is the parent node of the first type of useful node. As shown in Figure 9, node C and node A, node C is a reference node to which the modification operation is applied, and node A is the parent node of reference node C. Optionally, the useful nodes may also include at least one type of useful node from the third type of useful node, the fourth type of useful node and the fifth type of useful node. The third type of useful node includes an intermediate node for connecting two useful nodes. For example, if node A and node G in Figure 9 are both useful nodes, then node B is also a useful node. The fourth type of useful node is a mandatory child node. A mandatory child node refers to a child node that is meaningful only when connected to its useful parent node. For example, some function parameters are mandatory child nodes. The parameters will lose their meaning without the corresponding method. For example, if node A in Figure 9 represents a function and node Y is a parameter of the function, then node Y is a mandatory child node. The fifth type of useful node is a node with the same identifier as the first type of useful node or the second type of useful node. It should be understood that an identifier is a name used by the user when programming. It is used to name variables, constants, functions, statement blocks, etc. to establish a relationship between the name and the use. The identifier is usually composed of letters, numbers and other characters.

[0131] It should be understood that if a node does not belong to any of the five categories of useful nodes mentioned above, then the node is a useless node.

[0132] It should be understood that if the operation subtrees extracted by the code conversion apparatus 100 have duplicates, the redundant and duplicate operation subtrees may be filtered out.

[0133] Minimizing the operation subtree by the transcoding apparatus 100 includes clearing nodes in the operation subtree that are not related to the change, i.e., deleting unused nodes in the operation subtree. For example, if nodes E and F in FIG. 9 are unused nodes, the transcoding apparatus 100 may delete them. It should be understood that the node pointing to the operation node is the root node of the minimized operation subtree, such as node A in FIG. 10 . Node A may also be said to own the operation node.

[0134] 530, minimize the operation subtree grouping.

[0135] The transcoding apparatus 100 may use a clustering method to place the minimized operation subtrees into the same or similar operation subtree group. The clustering method may include a partition-based method, a hierarchy-based method, a density-based method, a grid-based method, and a model-based method.

[0136] 540, determine the adaptation mode of the minimization operation subtree group.

[0137] Figure 12 is a schematic diagram of an adaptation mode provided by an embodiment of the present application. The adaptation mode includes a general code template and a code conversion operation. For example, in the adaptation mode 1 shown in (b) of Figure 12, AXY-#-C is the code template of the adaptation mode 1, and converting the node C indicated by Ref into the Rep branch 1-2-# is the code conversion operation of the adaptation mode 1. The code conversion device 100 can generalize the minimized operation subtree in each minimized operation subtree group to obtain the adaptation mode corresponding to each minimized operation subtree group. Optionally, the generalization method includes using an anti-unification algorithm, a machine learning method, or a statistically based method.

[0138] Taking the anti-unified algorithm as an example, the anti-unified algorithm can be used to determine an adaptation mode for two minimized operation subtrees. Assuming that there are N minimized operation subtrees in a minimized operation subtree group, the code conversion device 100 can apply the anti-unified algorithm to the first minimized operation subtree and the second minimized operation subtree to obtain the first adaptation mode corresponding to these two minimized operation subtrees. Then, the anti-unified algorithm can be applied to the first adaptation mode and the third minimized operation subtree to obtain the second adaptation mode. And so on. Finally, the anti-unified algorithm is applied to the (N-2)th adaptation mode and the (N)th minimized operation subtree to finally obtain the adaptation mode corresponding to this minimized operation subtree group.

[0139] For example, Figure 12 (a) is a minimization operation subtree in the first minimization operation subtree group, Figure 12 (b) is the adaptation mode 1 corresponding to the first minimization operation subtree group, Figure 12 (c) is a minimization operation subtree in the second minimization operation subtree group, and Figure 12 (d) is the adaptation mode 2 corresponding to the second minimization operation subtree group. A unique node refers to a node used to distinguish different adaptation modes. For example, nodes X and Y correspond to adaptation mode 1, and nodes W and 3 correspond to adaptation mode 2. That is, an adaptation mode that includes nodes X and Y is considered to be adaptation mode 1, and an adaptation mode that includes nodes W and 3 is considered to be adaptation mode 2. A common node refers to a node in the common structure of all minimization operation subtrees in the same minimization operation subtree group. It should be understood that a unique node is also a common node. A replaceable node refers to a different node on the same branch of a minimization operation subtree in the same minimization operation subtree group.

[0140] 550, analyzing the context information of the node.

[0141] The process of minimizing the subtree operation contains the context of the node, and these contexts can be continuously reused in multiple nodes. However, in some cases, this context cannot express valid information. For example, the context of the first method D is C, and the actual call of this method D in the code is ABCD. The context of the second method D is also C, but the actual call of this method D in the code is EFCD. Therefore, the pattern originally applicable to a specific scenario will be arranged in a more generalized scenario, which will result in a large amount of invalid analysis. The embodiment of the present application can use static analysis tools to infer the complete information of the node context and the complete type of the variable, so as to match a specific scenario with a specific adaptation pattern.

[0142] FIG13 is a schematic diagram of an application scenario of another code conversion device provided in an embodiment of the present application.

[0143] 610, API call point 1 matches adaptation mode 1.

[0144] When user A upgrades or changes the code base that a project file relies on, the transcoding device 100 attempts to extract a matching adaptation pattern from the adaptation pattern database 600 for each API call point that requires adaptation. If a matching adaptation pattern exists, for example, if API call point 1 matches adaptation pattern 1, transcoding is performed on API call point 1 according to adaptation pattern 1 to adapt it to the modified code base.

[0145] Alternatively, the historical modification data of code repositories in some open source communities can be mined offline to obtain some adaptation patterns, which can then be added to the adaptation pattern database 600 as the basis for code adaptation. The adaptation pattern database 600 can also be continuously enriched through the historical records of manual code modifications by users.

[0146] 620 , user A manually adapts API call point 2.

[0147] If the API call point 2 cannot find the corresponding adaptation pattern in the adaptation pattern database 600, the code conversion device 100 can obtain the code manually modified by user A on the call point 2, and then perform adaptation pattern mining based on the code before and after user A modifies the API call point 2, and store the mined adaptation pattern in the adaptation pattern database 600.

[0148] 630, API call point 3 matches adaptation mode 2.

[0149] After the adaptation pattern database 600 is updated, when user A encounters a call point identical to API call point 2 in his engineering project, such as API call point 3, the newly added adaptation pattern 2 can be directly matched from the adaptation pattern database 600 and applied to API call point 3.

[0150] 640, API call point 4 matches adaptation mode 2.

[0151] When user B encounters a call point that is the same or similar to that of user A in his engineering project, such as API call point 4 is similar to API call point 2, the code conversion device 100 will match adaptation pattern 2 from the adaptation pattern database 600 and apply it to API call point 4.

[0152] 650, user B manually adapts API call point 4.

[0153] If the API call point 4 cannot find the corresponding adaptation pattern in the adaptation pattern database 600, the code conversion device 100 can obtain the code manually modified by user B on the call point 4, and then perform adaptation pattern mining based on the code before and after user B's modification of the API call point 4, and store the mined adaptation pattern in the adaptation pattern database 600.

[0154] The above describes the code conversion method according to the embodiment of the present application. The following describes the device and apparatus according to the embodiment of the present application in conjunction with Figures 14 and 15 respectively.

[0155] An embodiment of the present application further provides a computer storage medium storing program instructions. When the program is executed, the program may include some or all steps of the code conversion method in the corresponding embodiments of Figures 1, 3, 4, 8-13.

[0156] FIG14 is a diagram illustrating a structure of a computer device 1000 according to an embodiment of the present application. The computer device 1000 includes an acquisition module 1010 and a processing module 1020 .

[0157] The acquisition module 1010 is configured to acquire the modified code input by the user and execute steps 160 of the method in FIG. 1 , 230 of the method in FIG. 3 , 350 of the method in FIG. 4 , and steps 620 and 650 of the method in FIG. 13 .

[0158] The processing module 1020 is used to obtain the probability of the vehicle being in each lane based on the vehicle's speed information and the vehicle's lane-changing behavior probability, and execute some or all of the steps in the method of Figure 4, the method of Figure 5, the method of Figure 6, the method of Figure 7, and the method of Figure 9.

[0159] FIG15 is a diagram illustrating the structure of another computer device 1300 according to an embodiment of the present application. The computer device 1300 includes a processor 1302, a communication interface 1303, and a memory 1304. An example of the computer device 1300 is a chip. Another example of the computer device 1300 is a computing device.

[0160] The methods disclosed in the above embodiments of the present application can be applied to or implemented by processor 1302. Processor 1302 can be a central processing unit (CPU), or other general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc. The general-purpose processor can be a microprocessor or any conventional processor. During implementation, each step of the above method can be performed by hardware integrated logic circuits or software instructions in processor 1302. The methods, steps, and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present application can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor.

[0161] The memory 1304 may be a volatile memory or a nonvolatile memory, or may include both volatile and nonvolatile memories. The nonvolatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM bus RAM (DR RAM). It should be noted that the memory of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0162] The processor 1302, the memory 1304 and the communication interface 1303 can communicate with each other via a bus. The memory 1304 stores executable code, and the processor 1302 reads the executable code in the memory 1304 to execute the corresponding method. The memory 1304 may also include an operating system and other software modules required for running processes. The operating system may be LINUX TM , UNIX TM , WINDOWS TM wait.

[0163] For example, the executable code in the memory 1304 is used to implement the methods shown in Figures 1, 3, 4, 8-13, and the processor 1302 reads the executable code in the memory 1304 to execute the methods shown in Figures 1, 3, 4, 8-13.

[0164] In some embodiments of the present application, the disclosed methods may be implemented as computer program instructions encoded in a machine-readable format on a computer-readable storage medium or encoded on other non-transitory media or articles. Figure 16 schematically illustrates a conceptual partial view of an example computer program product arranged according to at least some of the embodiments presented herein, the example computer program product comprising a computer program for executing a computer process on a computing device. In one embodiment, the example computer program product 1400 is provided using a signal-bearing medium 1401. The signal-bearing medium 1401 may include one or more program instructions 1402, which, when executed by one or more processors, may provide the functions or partial functions described above for the methods shown in Figures 1, 3, 4, 8-13. Thus, for example, with reference to the embodiments shown in Figures 1, 3, 4, 8-13, one or more features therein may be borne by one or more instructions associated with the signal-bearing medium 1401.

[0165] In some examples, signal-bearing medium 1401 may include computer-readable media 1403, such as, but not limited to, a hard drive, a compact disc (CD), a digital video disc (DVD), a digital tape, a memory, a read-only memory (ROM), or a random access memory (RAM), etc. In some embodiments, signal-bearing medium 1401 may include computer-recordable media 1404, such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, etc. In some embodiments, signal-bearing medium 1401 may include communication media 1405, such as, but not limited to, digital and / or analog communication media (e.g., fiber optic cables, waveguides, wired communication links, wireless communication links, etc.). Thus, for example, signal-bearing medium 1401 may be communicated via a wireless form of communication media 1405 (e.g., a wireless communication medium that complies with the IEEE 802.11 standard or other transmission protocols). One or more program instructions 1402 may be, for example, computer-executable instructions or logic-implemented instructions. In some examples, the aforementioned computing device can be configured to provide various operations, functions, or actions in response to one or more program instructions 1402 communicated to the computing device by computer-readable media 1403, computer-recordable media 1404, and / or communication media 1405. It should be understood that the arrangement described herein is merely for illustrative purposes. Thus, it will be understood by those skilled in the art that other arrangements and other elements (e.g., machines, interfaces, functions, sequences, and functional groups, etc.) can be used instead, and some elements can be omitted altogether according to the desired result. In addition, many of the described elements can be implemented as discrete or distributed components or in any appropriate combination and position to implement functional entities in conjunction with other components.

[0166] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0167] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0168] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0169] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0170] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0171] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0172] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

Claims

1. A code conversion method, characterized in that: The method comprises: When a first code library that the code depends on is replaced with a second code library, obtaining a second code block input by a user, where the second code block is used to adapt the first code block in the code to the second code library; determining a target adaptation mode of the second code block and the first code block; The target adaptation mode is stored in an adaptation mode library, the adaptation mode library is used to generate a fourth code block for the third code block applicable to the target adaptation mode, and the fourth code block is used to adapt the third code block to the second code library.

2. The method according to claim 1, characterized in that The third code block belongs to the code.

3. The method according to claim 1 or 2, characterized in that The first code library and the second code library both belong to a party's dependent library; or, The first code library and the second code library are both second-party dependency libraries; or, Both the first code library and the second code library are third-party dependency libraries.

4. The method according to any one of claims 1 to 3, characterized in that The second code block for obtaining user input includes: When the target adaptation mode corresponding to the first code block does not exist in the adaptation mode library, the second code block input by the user is obtained.

5. The method according to any one of claims 1 to 4, characterized in that The method further comprises: If the target adaptation pattern corresponding to the first code block exists in the adaptation pattern library, the second code block or the fifth code block is generated based on the target adaptation pattern, and the second code block or the fifth code block is used to adapt the first code block in the code to the second code library.

6. The method according to any one of claims 1 to 5, characterized in that Before the second code block of obtaining user input, the method further includes: K adaptation modes are learned based on adaptation operations of N code blocks, wherein the adaptation operation of an nth code block in the adaptation operations of the N code blocks includes an operation of adapting the nth code block in the N code blocks to the second code library, and the kth adaptation mode in the K adaptation modes is used to adapt the code block applicable to the kth adaptation mode to the second code library, where N is a positive integer greater than or equal to 2, n=1, ..., N, K is greater than or equal to 2 and less than or equal to N, and k=1, ..., K; The K adaptation patterns are stored in the adaptation pattern library.

7. The method according to claim 6, characterized in that According to the adaptation operation of N code blocks, K adaptation modes are learned, including: Constructing N operation trees according to the adaptation operations of the N code blocks, wherein an nth operation tree among the N operation trees includes an operation of adapting the nth code block to the second code library; Determine K operation tree groups based on the N operation trees, wherein multiple operation trees included in each of the K operation tree groups have the same characteristics; The K adaptation modes are determined according to the K operation tree groups.

8. The method according to claim 7, characterized in that Determining K operation tree groups according to the N operation trees includes: Determine P operation subtrees based on the N operation trees, where the P operation subtrees are used to adapt sub-code blocks of the N code blocks to the second code library, where P is an integer greater than or equal to N; The K operation tree groups are determined according to the P operation subtrees.

9. The method according to claim 8, characterized in that Determining the K operation tree groups according to the P operation subtrees includes: Deleting useless nodes in the P operation subtrees, wherein the useless nodes include deleting nodes that do not affect the adaptation of corresponding sub-code blocks in the N code blocks to the second code library; The P operation subtrees after deleting the useless nodes are clustered to obtain the K operation tree groups.

10. The method according to any one of claims 7 to 9, characterized in that Determining the K adaptation modes according to the K operation tree groups includes: Determining a code template and a code conversion operation corresponding to each of the K operation tree groups, wherein the code template includes replaceable features and identical features of the operation trees in the corresponding operation array, and the code conversion operation is used to convert a code block having identical features to the code template of the corresponding operation tree group into a code block adapted to the second code library; The K adaptation modes are determined according to the code template and the code conversion operation corresponding to each operation tree group in the K operation tree groups.

11. A computer device, characterized in that: include: an acquisition module, configured to acquire a second code block input by a user when a first code library that the code depends on is replaced with a second code library, wherein the second code block is used to adapt the first code block in the code to the second code library; a processing module, configured to determine a target adaptation mode between the second code block and the first code block; The processing module is further used to store the target adaptation mode in an adaptation mode library, the adaptation mode library is used to generate a fourth code block for the third code block applicable to the target adaptation mode, and the fourth code block is used to adapt the third code block to the second code library.

12. The device according to claim 11, characterized in that The third code block belongs to the code.

13. The device according to claim 11 or 12, characterized in that The first code library and the second code library both belong to a one-party dependency library; or, the first code library and the second code library both belong to a two-party dependency library; or, the first code library and the second code library both belong to a three-party dependency library.

14. The device according to any one of claims 11 to 13, characterized in that The acquisition module is further configured to acquire the second code block input by the user when the target adaptation mode corresponding to the first code block is not found in the adaptation mode library.

15. The device according to any one of claims 11 to 14, characterized in that The processing module is also used to generate the second code block or the fifth code block based on the target adaptation pattern if the target adaptation pattern corresponding to the first code block exists in the adaptation pattern library, and the second code block or the fifth code block is used to adapt the first code block in the code to the second code library.

16. The device according to any one of claims 11 to 15, characterized in that The processing module is specifically used to: K adaptation modes are learned based on adaptation operations of N code blocks, wherein the adaptation operation of an nth code block in the adaptation operations of the N code blocks includes an operation of adapting the nth code block in the N code blocks to the second code library, and the kth adaptation mode in the K adaptation modes is used to adapt the code block applicable to the kth adaptation mode to the second code library, where N is a positive integer greater than or equal to 2, n=1, ..., N, K is greater than or equal to 2 and less than or equal to N, and k=1, ..., K; The K adaptation patterns are stored in the adaptation pattern library.

17. The device according to claim 16, characterized in that The processing module is specifically used to: Constructing N operation trees according to the adaptation operations of the N code blocks, wherein an nth operation tree among the N operation trees includes an operation of adapting the nth code block to the second code library; Determine K operation tree groups based on the N operation trees, wherein multiple operation trees included in each of the K operation tree groups have the same characteristics; The K adaptation modes are determined according to the K operation tree groups.

18. The device according to claim 17, characterized in that The processing module is specifically used to: Determine P operation subtrees based on the N operation trees, where the P operation subtrees are used to adapt sub-code blocks of the N code blocks to the second code library, where P is an integer greater than or equal to N; The K operation tree groups are determined according to the P operation subtrees.

19. The device according to claim 18, characterized in that The processing module is specifically used to: Deleting useless nodes in the P operation subtrees, wherein the useless nodes include deleting nodes that do not affect the adaptation of corresponding sub-code blocks in the N code blocks to the second code library; The P operation subtrees after deleting the useless nodes are clustered to obtain the K operation tree groups.

20. The device according to any one of claims 17 to 19, characterized in that The processing module is specifically used to: Determining a code template and a code conversion operation corresponding to each of the K operation tree groups, wherein the code template includes replaceable features and identical features of the operation trees in the corresponding operation array, and the code conversion operation is used to convert a code block having identical features to the code template of the corresponding operation tree group into a code block adapted to the second code library; The K adaptation modes are determined according to the code template and the code conversion operation corresponding to each operation tree group in the K operation tree groups.

21. A computer device, characterized in that: include: A processor, wherein the processor is coupled to a memory, and is configured to read and execute instructions and / or program codes in the memory to perform the method according to any one of claims 1 to 10.

22. A chip system, characterized in that: include: A logic circuit, wherein the logic circuit is configured to be coupled to an input / output interface and transmit data through the input / output interface to execute the method according to any one of claims 1 to 10.

23. A computer-readable medium, characterized in that The computer-readable medium stores a program code, and when the computer program code is run on a computer, the computer is caused to perform the method according to any one of claims 1 to 10.