Code package reference method and device
By parsing the code package name and method attribute information in the script code, finding the target version of the code package, solving the problem of abnormal script code running caused by reference to the wrong version, ensuring that the script code can run normally.
Patent Information
- Application Number
- CN202010284657.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-13
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2040-04-13
AI Technical Summary
During the software development process, developers reference the wrong version of the code package, causing the script code to not run normally.
By parsing the code package name and method attribute information in the script code, find the target version of the code package, and make sure that the code package contains the required methods, thereby avoiding referencing the wrong version of the code package.
This implements the method of redirecting script code to the code package normally, so that the script code can run normally, solving the problem of not being able to determine the target version of the code package.
Smart Images

Figure CN113535178B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and device for citing a code package. Background Art
[0002] In the software development process, in order to reduce duplication of work and improve code development efficiency, developers will encapsulate the common functions they implement into code packages and make them public for other developers to call. Other developers only need to understand the input and output interfaces of the code packages to directly reference them, thereby quickly realizing business development.
[0003] However, each code package is independently developed by different developers according to their own needs. Developers will add new versions of code packages according to their needs and change the script code in the new version of the code package (for example, add a method to the code package or delete a method). Therefore, during the development process, the script code will not be able to jump to the method normally because it references the wrong version of the code package (the wrong version of the code package does not contain the method called by the script code), causing the script code to run abnormally. Summary of the invention
[0004] The present application provides a method and device for citing a code package, which are used to solve the problem of how to avoid citing a wrong version of a code package, which causes the script code to fail to run normally.
[0005] In order to achieve the above objectives, this application adopts the following technical solutions:
[0006] In a first aspect, the present application provides a method for citing a code package, the method comprising:
[0007] The computer device parses the script code to determine the name of the first code package and the attribute information of the first method referenced by the script code; according to the name of the first code package, M versions of the first code package are found, where M is a positive integer; according to the attribute information of the first method, the first code package of the target version is determined from the M versions of the first code packages, and the first code package of the target version includes the first method; and the script code is instructed to reference the first code package of the target version.
[0008] Based on the above technical solution, the computer device can determine the first code package of the target version (the first code package of the target version includes the first method) from the first code packages of M versions, which solves the problem that the computer device cannot determine which version of the first code package has the first method, and thus cannot determine the first code package of the target version. In addition, since the first code package of the target version includes the first method, the script code references the first code package of the target version, which can realize the normal jump of the script code to the first method in the first code package, so that the script code can run normally.
[0009] In one possible design, it is checked whether the first code package of the i-th version contains a method whose attribute information is the same as the attribute information of the first method, where the i-th version is any version among M versions, and i is a positive integer less than or equal to M; if the first code package of the i-th version contains a method whose attribute information is the same as the attribute information of the first method, then the first code package of the i-th version is determined to be the first code package of the target version.
[0010] In one possible design, the attribute information of the first method includes the name of the first method; if the first code packages of M versions do not include a method whose attribute information is the same as the attribute information of the first method, then the name similarity between each of the N methods and the first method is calculated, and the name similarity is used to indicate the degree of similarity between the two methods in name, and the N methods are all the methods included in the first code packages of M versions; from the N methods, determine the method with the highest name similarity; and use the first code package containing the method with the highest name similarity as the first code package of the target version.
[0011] In one possible design, the reference method of the code package also includes: determining the name of the second code package called by the first method and the attribute information of the second method; determining P versions of the second code package according to the name of the second code package, where P is a positive integer; determining a referenced version of the second code package from the P versions of the second code packages according to the attribute information of the second method; the referenced version of the second code package includes the second method; and indicating that the script code references the referenced version of the second code package.
[0012] In a second aspect, the present application provides a device for citing a code package, the device comprising:
[0013] A parsing unit is used to parse the script code to determine the name of the first code package and the attribute information of the first method referenced by the script code; a processing unit is used to find M versions of the first code package according to the name of the first code package, where M is a positive integer; and according to the attribute information of the first method, determine the first code package of the target version from the M versions of the first code packages, where the first code package of the target version includes the first method; and a referencing unit is used to instruct the script code to reference the first code package of the target version.
[0014] In one possible design, the processing unit is also used to check whether the first code package of the i-th version contains a method whose attribute information is the same as the attribute information of the first method, the i-th version is any version among M versions, and i is a positive integer less than or equal to M; if the first code package of the i-th version contains a method whose attribute information is the same as the attribute information of the first method, then the first code package of the i-th version is determined to be the first code package of the target version.
[0015] In one possible design, the processing unit is further used to calculate the name similarity between each of the N methods and the first method if the first code packages of the M versions do not include a method whose attribute information is the same as the attribute information of the first method, the name similarity being used to indicate the degree of similarity between the two methods in name, and the N methods being all the methods included in the first code packages of the M versions; determining the method with the highest name similarity from among the N methods; and using the first code package containing the method with the highest name similarity as the first code package of the target version.
[0016] In a possible design, the parsing unit is further used to determine the name of the second code package called by the first method and the attribute information of the second method; the processing unit is further used to determine P versions of the second code package according to the name of the second code package, where P is a positive integer; and according to the attribute information of the second method, determine the referenced version of the second code package from the P versions of the second code package; the referenced version of the second code package includes the second method. The referencing unit is further used to instruct the script code to reference the referenced version of the second code package.
[0017] In a third aspect, the present application provides a computer device comprising: a processor and a communication interface; the communication interface and the processor are coupled, and the processor is used to run a computer program or instructions to implement a code package reference method as described in the first aspect and any possible implementation of the first aspect.
[0018] In a fourth aspect, the present application provides a computer-readable storage medium, which stores instructions. When the instructions are executed on a computer, the computer executes the method for referencing a code package described in the above-mentioned first aspect and any possible implementation of the first aspect.
[0019] In a fifth aspect, the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the method for referencing a code package described in the first aspect and any possible implementation of the first aspect.
[0020] In a sixth aspect, the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run a computer program or instructions to implement a method for referencing a code package as described in the first aspect and any possible implementation of the first aspect.
[0021] In the above scheme, the technical problems that can be solved by the reference device, computer device, computer storage medium, computer program product or chip of the code package and the technical effects achieved can be referred to the technical problems and technical effects solved by the above-mentioned first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 A flowchart of a method for referencing a code package provided in an embodiment of the present application;
[0023] Figure 2 A flowchart of another method for referencing a code package provided in an embodiment of the present application;
[0024] Figure 3 A flowchart of another method for referencing a code package provided in an embodiment of the present application;
[0025] Figure 4 A flowchart of another method for referencing a code package provided in an embodiment of the present application;
[0026] Figure 5 A schematic diagram of the structure of a code package reference device provided in an embodiment of the present application;
[0027] Figure 6 A schematic diagram of the structure of another computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only 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 creative work are within the scope of protection of this application.
[0029] In this article, the character " / " generally indicates that the objects before and after are in an "or" relationship. For example, A / B can be understood as A or B.
[0030] The terms “first” and “second” in the description and claims of the present application are used to distinguish different objects rather than to describe a specific order of the objects.
[0031] In addition, the terms "including" and "having" and any variations thereof mentioned in the description of this application are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or modules is not limited to the listed steps or modules, but may optionally include other steps or modules that are not listed, or may optionally include other steps or modules that are inherent to these processes, methods, products or devices.
[0032] In addition, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present concepts in a specific way.
[0033] The technical solution provided in the embodiment of the present application can be executed by a computer device. The computer device is a device equipped with a programming tool, which supports the use of a programming language with a code package sharing platform, a programming language that makes a reference statement to the code package, and a programming language (such as Java language, Python language) that has a reference method for programming, for example, the programming tool can be IntelliJ IDEA, eclipse. The computer device can store script codes written by developers, or automatically generate script codes generated by script software. Wherein, the computer device can be a tablet computer, a laptop computer, a desktop computer, a portable computer, etc., and the embodiment of the present application does not limit this.
[0034] like Figure 1 As shown, a method for referencing a code package provided in an embodiment of the present application includes the following steps:
[0035] S101. A computer device parses a script code to determine a name of a first code package and attribute information of a first method referenced by the script code.
[0036] The script code may be a script code written by a developer, or a script code generated by automatic script generation software, which is not limited in the embodiments of the present application.
[0037] The script code includes a reference declaration and attribute information of the first method. The reference declaration includes a reference word (such as import) and the name of the code package referenced by the script code. For example, the reference declaration may be: importPackageA, the reference word is import, and the name of the code package referenced by the script code is PackageA. The attribute information of the first method includes: the name of the first method, the parameter type of the first method, the number of parameters of the first method, and the return value type of the first method.
[0038] In a possible implementation, the computer device parses the script code to determine the reference declaration and the property information of the first method. Then, the computer device determines the name of the first code package referenced by the script code according to the reference declaration.
[0039] S102: The computer device searches for M versions of the first code package according to the name of the first code package.
[0040] Wherein, M is a positive integer.
[0041] In a possible implementation, the computer device reads an environment variable and searches for M versions of the first code package according to the name of the first code package. The environment variable includes the M versions of the first code package.
[0042] It should be noted that since the methods in the code package may change with the update of technology or the change of requirements, the computer device will save different versions of the code package to achieve the purpose that different versions of a code package can meet different requirements.
[0043] S103: The computer device determines a first code package of a target version from the first code packages of M versions according to the attribute information of the first method.
[0044] The first code package of the target version includes a first method.
[0045] S104. The computer device instructs the script code to reference the first code package of the target version.
[0046] It can be understood that, since the first code package of the target version includes the first method, the computer device instructs the script code to reference the first code package of the target version, so that the script code can jump normally to the first method in the first code package.
[0047] based on Figure 1 In the technical solution shown, the computer device can determine the first code package of the target version (the first code package of the target version includes the first method) from the first code packages of M versions, which solves the problem that the computer device cannot determine which version of the first code package contains the first method, and thus cannot determine the first code package of the target version. In addition, since the first code package of the target version includes the first method, the script code references the first code package of the target version, and the script code can jump normally to the first method in the first code package, so that the script code can run normally.
[0048] like Figure 2 As shown, step S103 can be specifically implemented as the following steps:
[0049] S201: A computer device checks whether a first code package of an i-th version includes attribute information that is the same as attribute information of a first method.
[0050] The i-th version is any one of the M versions, and i is a positive integer less than or equal to M.
[0051] It should be noted that the attribute information of the method is the same as the attribute information of the first method, which means that the name, parameter type, number of parameters, and return value type of the method are the same as the attribute information of the first method.
[0052] Exemplarily, the attribute information of the first method is: inta=new Le().Function1(3,5). Then the name of the first method is Function1, the parameters of the first method are 3 and 5 of integer type (int), and the return value type of the first method is int.
[0053] The computer device parses the first code package of version 1.0 to obtain the attribute information of the method in the code package of this version. The method of the first code package of version 1.0 is as follows:
[0054]
[0055] The method in the first code package of version 1.0 is named Function1, the parameter types of the method are all integer types, the number of parameters of the method is 2, and the return value type is int. Therefore, the first code package of version 1.0 contains a method whose attribute information is the same as that of the first method.
[0056] S202: If the first code package of the i-th version includes a method whose attribute information is the same as the attribute information of the first method, the computer device determines that the first code package of the i-th version is the first code package of the target version.
[0057] based on Figure 2 In the technical solution shown, the computer device can select different methods to determine the first code package of the target version by judging whether the first code package of the i-th version contains the same attribute information as the attribute information of the first method, thereby solving the problem that the computer device cannot determine which version of the first code package contains the method called by the script code, and thus cannot determine the first code package of the target version. In addition, since the first code package of the target version contains the method called by the script code, the script code references the first code package of the target version, which can realize the normal jump of the script code to the method in the first code package, so that the script code can run normally.
[0058] If the first code packages of the M versions do not contain a method whose attribute information is the same as the attribute information of the first method, then Figure 3 As shown, step S103 can also be specifically implemented as follows:
[0059] S301. A computer device calculates the similarity between the name of each of the N methods and the first method.
[0060] The name similarity is used to indicate the similarity between two methods in name, and the N methods are all methods included in the first code packages of the M versions.
[0061] In a possible implementation, the computer device parses N methods from the M versions of the first code package, and calculates the name similarity between each of the N methods and the first method.
[0062] It should be noted that factors such as whether the name components of the two methods are the same, whether the name components of the two methods are arranged in the same order, and the capitalization of letters will affect the name similarity. The following three examples are used to illustrate this.
[0063] Example 1, the name of the first method is Function1, the name of method 2 is Function2, and the computer device calculates that the name similarity between method 2 and method 1 is 8 / 9.
[0064] Example 2: The name of method 1 is Function1, the name of method 2 is Function, and the computer device calculates the name similarity between method 2 and method 1 as 1 / 9.
[0065] Example 3, the name of method 1 is Function1, the name of method 2 is Function2, and the computer device calculates that the name similarity between method 2 and method 1 is 7 / 9.
[0066] It is understandable that the name similarity needs to consider multiple factors such as whether the name components of the two methods are the same, so that the computer device can obtain a method with a higher name similarity to the first method.
[0067] S302: The computer device determines the method with the highest name similarity from the N methods.
[0068] In a possible implementation, a computer device compares N name similarities and determines a method with the highest name similarity.
[0069] For example, Table 1 shows that the first code package (eg, Package A) has 2 versions, and the 2 versions of the first code package contain 4 methods. A row in Table 1 is a piece of data, which is used to represent the methods contained in each version of Package A. The name of the first method is Function1.
[0070] Table 1
[0071]
[0072] Among them, the name similarity between Function method and Function1 method is 8 / 9, the name similarity between Funi1 method and Function1 method is 3 / 9, the name similarity between Funct method and Function1 method is 5 / 9, and the name similarity between Funaaaaa1 method and Function1 method is 4 / 9. 8 / 9>5 / 9>4 / 9>3 / 9. In other words, Function method and Function1 method have the highest name similarity.
[0073] S303: The computer device uses the first code package containing the method with the highest name similarity as the first code package of the target version.
[0074] It can be understood that when the attribute information of the first method is incorrect and the computer device cannot obtain a method with the same attribute information as the first method from the first code packages of M versions, the computer device lowers the search conditions and determines the method most similar to the first method based on the name similarity, which enables the computer device to determine the first code package of the target version.
[0075] based on Figure 3 According to the technical solution shown, when the first code packages of M versions do not include methods whose attribute information is the same as that of the first method, the computer device lowers the search conditions, searches for methods similar to the first method, and determines the method with the highest name similarity (that is, the method with the highest similarity to the first method), thereby avoiding the problem of being unable to determine the first code package of the target version when the attribute information of the first method is incorrect.
[0076] After the computer device determines the target version of the first code package, the script code in the first code package will also reference the second code package containing the reference version of the second method. The second code package has multiple versions. If the reference version of the second code package cannot be determined, the computer device still has the risk of referencing the wrong version of the code package, resulting in the script code failing to jump normally and causing the script code to run abnormally.
[0077] In order to avoid the problem of citing the wrong version of the code package, which causes the script code to not jump normally, such as Figure 4 As shown, a method for referencing a code package provided in an embodiment of the present application includes the following steps:
[0078] S401. A computer device determines a name of a second code package called by a first method and attribute information of the second method.
[0079] In a possible implementation manner, the computer device parses the first code package of the target version to determine the name of the second code package called by the first method and the attribute information of the second method.
[0080] The first code package of the target version includes the name of the second code package and the attribute information of the second method. The attribute information of the second method includes: the name of the second method, the parameter type of the second method, the number of parameters of the second method, and the return value type of the second method.
[0081] S402: The computer device determines P versions of the second code package according to the name of the second code package.
[0082] Wherein, P is a positive integer.
[0083] In a possible implementation, the computer device reads an environment variable and searches for P versions of the second code package according to the name of the second code package. The environment variable includes the P versions of the second code package installed by the computer device.
[0084] S403: The computer device determines a second code package of a referenced version from the second code packages of P versions according to the attribute information of the second method.
[0085] The second code package of the referenced version includes a second method.
[0086] In a possible implementation, the computer device checks whether the second code package of the kth version includes a method whose attribute information is the same as the attribute information of the second method. When the second code package of the kth version includes a method whose attribute information is the same as the attribute information of the second method, the computer device determines that the second code package of the kth version is the second code package of the reference version. The kth version is one of the P versions.
[0087] Its specific implementation can refer to the description of steps S201-S202, which will not be repeated here.
[0088] Another possible implementation is that when none of the second code packages of the P versions contains a method whose attribute information is the same as the attribute information of the second method, the computer device calculates the name similarity between each of the Q methods and the second method. The computer device determines the method with the highest name similarity from the Q methods. The computer device uses the second code package containing the method with the highest name similarity as the second code package of the reference version. The Q methods are all the methods included in the second code packages of the P versions.
[0089] The specific implementation thereof may refer to the description of steps S301 to S303 , which will not be repeated here.
[0090] S404. The computer device instructs the script code to reference the second code package of the referenced version.
[0091] It can be understood that, since the second code package of the referenced version includes the second method, the computer device instructs the script code to reference the second code package of the referenced version, so that the script code can normally jump from the first method to the second method in the second code package of the referenced version.
[0092] based on Figure 4 In the technical solution shown, the computer device can determine the referenced version of the second code package (the referenced version of the second code package includes the second method) from the P versions of the second code package, which solves the problem that the computer device cannot determine which version of the second code package has the second method, and thus cannot determine the referenced version of the second code package. In addition, since the first code package of the target version includes the first method, the script code references the first code package of the target version, which can realize the normal jump of the script code to the first method in the first code package, so that the script code can run normally.
[0093] It should be noted that Figure 4 The embodiment shown is a specific description of the process of the first code package referencing the second code package (the referenced version of the second code package). However, the script code in the second code package may also reference the third method in the third code package, and the computer device cannot determine which version of the third code package contains the third method. In other words, when a code package references a code package, there is always a problem of being unable to determine the referenced version of the code package. Therefore, when a code package references a code package, it can refer to Figure 4 The embodiment shown.
[0094] The embodiment of the present application can divide the server into functional modules or functional units according to the above method example. For example, each functional module or functional unit can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules or functional units. Among them, the division of modules or units in the embodiment of the present application is schematic, which is only a logical function division. There may be other division methods in actual implementation.
[0095] like Figure 5 As shown, an embodiment of the present invention provides a device for quoting a code package, including:
[0096] The parsing unit 101 is used to parse the script code and determine the name of the first code package and the attribute information of the first method referenced by the script code;
[0097] The processing unit 102 is configured to find M versions of the first code package according to the name of the first code package, where M is a positive integer; and determine a first code package of a target version from the M versions of the first code packages according to the attribute information of the first method, where the first code package of the target version includes the first method;
[0098] The reference unit 103 is used to instruct the script code to reference the first code package of the target version.
[0099] Optionally, the processing unit 102 is further used to check whether the first code package of the i-th version contains a method whose attribute information is the same as the attribute information of the first method, the i-th version is any version among M versions, and i is a positive integer less than or equal to M; if the first code package of the i-th version contains a method whose attribute information is the same as the attribute information of the first method, then the first code package of the i-th version is determined to be the first code package of the target version.
[0100] Optionally, the processing unit 102 is further used to calculate the name similarity between each of the N methods and the first method if none of the first code packages of the M versions includes a method whose attribute information is the same as the attribute information of the first method, the name similarity being used to indicate the degree of similarity between two methods in name, the N methods being all the methods included in the first code packages of the M versions; determining the method with the highest name similarity from among the N methods; and using the first code package containing the method with the highest name similarity as the first code package of the target version.
[0101] Optionally, the parsing unit 101 is further configured to determine a name of a second code package called by the first method and attribute information of the second method;
[0102] The processing unit 102 is further configured to determine, according to the name of the second code package, P versions of the second code package, where P is a positive integer; and determine, according to the attribute information of the second method, a referenced version of the second code package from the P versions of the second code package; the referenced version of the second code package includes the second method;
[0103] The reference unit 103 is further used to instruct the script code to reference the second code package of the referenced version.
[0104] Figure 6 Another possible structure of the computer device involved in the above embodiment is shown. The computer device includes: a processor 201 and a communication interface 202. The processor 201 is used to control and manage the actions of the device, for example, to execute the various steps in the method flow shown in the above method embodiment, and / or to execute other processes of the technology described herein. The communication interface 202 is used to support the communication between the computer device and other network entities. The computer device may also include a memory 203 and a bus 204, and the memory 203 is used to store program codes and data of the device.
[0105] Among them, the above-mentioned processor 201 can implement or execute various exemplary logic blocks, units and circuits described in conjunction with the disclosure of the present invention. The processor can be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It can implement or execute various exemplary logic blocks, units and circuits described in conjunction with the disclosure of the present invention. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of DSP and microprocessors, etc.
[0106] The memory 203 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a read-only memory, a flash memory, a hard disk or a solid-state drive; the memory may also include a combination of the above types of memory.
[0107] The bus 204 may be an Extended Industry Standard Architecture (EISA) bus, etc. The bus 204 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0108] Through the description of the above implementation methods, technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0109] An embodiment of the present application provides a computer program product including instructions. When the computer program product is run on a computer, the computer is enabled to execute the method for referencing the code package in the above method embodiment.
[0110] An embodiment of the present application also provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a computer, the computer executes the method for referencing the code package in the method flow shown in the above method embodiment.
[0111] Among them, the computer readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a register, a hard disk, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above, or any other form of computer readable storage medium known in the art. An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application-specific integrated circuit (ASIC). In the embodiments of the present application, a computer-readable storage medium may be any tangible medium that contains or stores a program, which may be used by or in conjunction with an instruction execution system, apparatus, or device.
[0112] Since the computer device, computer-readable storage medium, and computer program product in the embodiments of the present invention can be applied to the above method, the technical effects that can be obtained can also refer to the above method embodiments, and the embodiments of the present invention will not be repeated here.
[0113] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for quoting a code package, characterized in that: The method comprises: Parsing the script code to determine the name of the first code package and the attribute information of the first method referenced by the script code; According to the name of the first code package, find M versions of the first code package, where M is a positive integer; Determining, according to the attribute information of the first method, from the first code packages of the M versions, a first code package of a target version, comprising: checking whether a first code package of an i-th version includes a method whose attribute information is the same as the attribute information of the first method, the i-th version being any one of the M versions, and i being a positive integer less than or equal to M; If the first code package of the i-th version includes a method whose attribute information is the same as the attribute information of the first method, determining that the first code package of the i-th version is the first code package of the target version, and the first code package of the target version includes the first method; The attribute information of the first method includes the name of the first method; If none of the M versions of the first code packages include a method having the same attribute information as the first method, then calculating the name similarity between each of the N methods and the first method, where the name similarity is used to indicate the degree of similarity between the two methods in name, and the N methods are all the methods included in the M versions of the first code packages; From the N methods, determine the method with the highest name similarity; Taking the first code package containing the method with the highest name similarity as the first code package of the target version; Instruct the script code to reference the first code package of the target version.
2. The method for quoting a code package according to claim 1, characterized in that: The method further comprises: Determine the name of a second code package called by the first method and attribute information of the second method; Determine P versions of the second code package according to the name of the second code package, where P is a positive integer; According to the attribute information of the second method, determining a second code package of a reference version from the P versions of the second code packages; the second code package of the reference version includes the second method; Instruct the script code to reference the second code package of the referenced version.
3. A code package quoting device, characterized in that: The device comprises: A parsing unit, used for parsing the script code to determine the name of the first code package and the attribute information of the first method referenced by the script code; a processing unit, configured to search, according to the name of the first code package, M versions of the first code package, where M is a positive integer; and determine, according to the attribute information of the first method, a first code package of a target version from the first code packages of the M versions, where the first code package of the target version includes the first method; A reference unit, used to instruct the script code to reference the first code package of the target version; The processing unit is further configured to check whether a first code package of an i-th version includes a method whose attribute information is the same as the attribute information of the first method, where the i-th version is any one of the M versions, and i is a positive integer less than or equal to M; if the first code package of the i-th version includes a method whose attribute information is the same as the attribute information of the first method, then determining that the first code package of the i-th version is the first code package of the target version; The processing unit is further used for calculating the name similarity between each of the N methods and the first method if none of the first code packages of the M versions includes a method having attribute information identical to that of the first method, the name similarity being used to indicate the degree of similarity between two methods in name, the N methods being all the methods included in the first code packages of the M versions; determining the method with the highest name similarity from among the N methods; and using the first code package containing the method with the highest name similarity as the first code package of the target version.
4. The code package quoting device according to claim 3, characterized in that: The parsing unit is further configured to determine the name of a second code package called by the first method and attribute information of the second method; The processing unit is further configured to determine P versions of the second code package according to the name of the second code package; determine a referenced version of the second code package from the P versions of the second code package according to the attribute information of the second method; the referenced version of the second code package includes the second method; The reference unit is further used to instruct the script code to reference the second code package of the referenced version.
5. A computer device, characterized in that: include: A processor, a memory and a communication interface; wherein the communication interface and the processor are coupled, and when the computer device is running, the processor executes the computer execution instructions stored in the memory to implement the code package reference method in any one of claims 1-2 above.
6. A computer-readable storage medium having instructions stored therein, characterized in that: When a computer executes the instruction, the computer executes the method for referencing the code package in any one of claims 1-2.
