Code extension method and device and related product
By obtaining the extension configuration file and using code dynamic compilation technology to expand the source code, the problems of heavy workload and low efficiency of code expansion in the existing technology are solved, and efficient code expansion and smooth upgrade of application modules are achieved.
Patent Information
- Application Number
- CN202510774215.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-10
- Publication Date
- 2025-09-19
AI Technical Summary
In the prior art, the code expansion process requires overall modification of the complete code, resulting in a large workload and low efficiency, and the application module cannot be smoothly upgraded after expansion.
By obtaining the extended configuration file, converting it into a code string, and using the code dynamic compilation technology to expand the source code, the overall modification of the complete code is avoided and the target code is generated.
It improves the efficiency of code expansion, ensures the smooth upgrade of application modules, and realizes lightweight incremental expansion while being compatible with the original logic.
Smart Images

Figure CN120669976A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of incremental expansion technology, and in particular to a code expansion method, device and related products. Background Art
[0002] Jar packages support the operation of application modules within an application. Related technologies utilize complete source code reuse to achieve application module expansion. This reuse approach involves directly copying the complete code from the corresponding Jar package for the application module, comprehensively modifying the copied code, and then packaging the modified code to expand the application module. This requires extensive code modifications, resulting in high workload and low efficiency.
[0003] Therefore, how to better implement code expansion is a key issue that those skilled in the art are concerned about. Summary of the Invention
[0004] Based on the above problems, the present application provides a code expansion method, device and related products to better implement code expansion.
[0005] The embodiments of this application disclose the following technical solutions:
[0006] In a first aspect, the present application provides a code expansion method. The code expansion method includes:
[0007] Obtaining source code and an extension configuration file corresponding to a target entity class in the source code, wherein the extension configuration file is used to describe entity class extension logic of the target entity class, the entity class extension logic including attributes to be extended of the target entity class and attribute representations of the attributes to be extended;
[0008] Converting the extension configuration file to obtain a code string containing the attribute to be extended and the attribute representation;
[0009] By using a code dynamic compilation technology, the source code is extended according to the code character string containing the attribute to be extended and the attribute representation to obtain a target code.
[0010] A second aspect of the present application provides a code expansion device. The code expansion device includes:
[0011] a code file acquisition unit, configured to acquire source code and an extension configuration file corresponding to a target entity class in the source code, wherein the extension configuration file is used to describe entity class extension logic of the target entity class, and the entity class extension logic includes attributes to be extended of the target entity class and attribute representations of the attributes to be extended;
[0012] a configuration file conversion unit, configured to convert the extended configuration file to obtain a code string containing the attribute to be extended and the attribute representation;
[0013] The target code obtaining unit is used to perform expansion processing on the source code according to the code string containing the attribute to be extended and the attribute representation by using the code dynamic compilation technology to obtain the target code.
[0014] A third aspect of the present application provides a computer device. The computer device includes:
[0015] a memory having a computer program stored thereon;
[0016] A processor is used to execute the computer program in the memory to implement the steps of the code expansion method provided in the first aspect.
[0017] A fourth aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the code expansion method provided in the first aspect.
[0018] Compared with the prior art, this application has the following beneficial effects:
[0019] In this application, the source code and an extension configuration file corresponding to the target entity class in the source code can first be obtained. The extension configuration file can then be converted to obtain a code string containing the attributes to be extended and the attribute representations. Finally, the source code can be extended using dynamic code compilation technology based on the code string containing the attributes to be extended and the attribute representations to obtain the target code. It should be noted that the extension configuration file is used to describe the entity class extension logic of the target entity class, and the entity class extension logic includes the attributes to be extended of the target entity class and the attribute representations of the attributes to be extended.
[0020] As can be seen, in this application, an extension configuration file can be obtained in advance. This extension configuration file can indicate how to extend the target entity class in the source code. That is, the extension configuration file contains the attributes to be extended and their attribute representations. At this time, the source code can be extended based on the code string containing the attributes to be extended and the attribute representations through code dynamic compilation technology. In this way, the problem of large modification workload caused by overall modification of the complete code is avoided in this application, thereby better implementing code extension and improving code extension efficiency to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0022] Figure 1 A flowchart of a code expansion method provided in an embodiment of the present application;
[0023] Figure 2 A flowchart for implementing an entity class extension method in a code extension method provided in an embodiment of the present application;
[0024] Figure 3 A flowchart of extending function information in a code extension method provided in an embodiment of the present application;
[0025] Figure 4 A flowchart for implementing extended function information in a code extension method provided in an embodiment of the present application;
[0026] Figure 5 A flowchart of accessing a configuration file in a code expansion method provided in an embodiment of the present application;
[0027] Figure 6 A schematic diagram of merging configuration files in a code expansion method provided in an embodiment of the present application;
[0028] Figure 7 A flowchart for implementing access to a configuration file in a code expansion method provided in an embodiment of the present application;
[0029] Figure 8 A full flow chart of code expansion in a code expansion method provided in an embodiment of the present application;
[0030] Figure 9 A schematic diagram of the structure of a code expansion device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] As described above, Jar packages support the operation of application modules within an application. Related technologies utilize complete source code reuse to achieve application module expansion. This reuse approach involves directly copying the complete code from the Jar package corresponding to the application module, making comprehensive modifications to the copied code, and then packaging the modified code to generate a new application module. This requires extensive code modifications, resulting in high workload and low efficiency.
[0032] Furthermore, when the system upgrades the original application module, the new application module is not automatically upgraded and must be manually copied and modified. This prevents smooth upgrades for the new application module. For example, if code A is added through full source code reuse, and code B is added to the original application module, the new application module will not be aware of code B and will need to be manually added to the new application module.
[0033] Furthermore, in related technologies, application module expansion can be achieved by overwriting individual source code. This method involves forcibly overwriting the code that needs to be modified within the complete code corresponding to the application module, with the same package name and type. However, when the system upgrades the original application module, the overwritten code is not automatically updated and must be manually modified, preventing a smooth upgrade of the expanded application module. Therefore, how to effectively implement code expansion is a key issue for those skilled in the art.
[0034] In view of the above problems, a solution is provided in the embodiments of the present application, and a code extension method, device and related products are proposed, aiming to better implement code extension. In the technical solution of the present application, the source code and the extension configuration file corresponding to the target entity class in the source code can be obtained first. Thereafter, the extension configuration file can be converted to obtain a code string containing the attributes to be extended and the attribute representation. Finally, the source code can be extended based on the code string containing the attributes to be extended and the attribute representation through the code dynamic compilation technology to obtain the target code. Among them, the extension configuration file is used to describe the entity class extension logic of the target entity class, and the entity class extension logic includes the attributes to be extended of the target entity class and the attribute representation of the attributes to be extended.
[0035] As can be seen, in this application, an extension configuration file can be obtained in advance. This extension configuration file can indicate how to extend the target entity class in the source code. That is, the extension configuration file contains the attributes to be extended and their attribute representations. At this time, the source code can be extended based on the code string containing the attributes to be extended and the attribute representations through code dynamic compilation technology. In this way, the problem of large modification workload caused by overall modification of the complete code is avoided in this application, thereby better implementing code extension and improving code extension efficiency to a certain extent.
[0036] In order to help those skilled in the art better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0037] Next, the technical terms that may appear in this application are explained.
[0038] Jar package: Java Archive package, a file format for packaging code.
[0039] See also Figure 1 , which is a flow chart of a code expansion method provided by an embodiment of the present application. Figure 1 The code extension methods shown include:
[0040] S101: Obtain source code and an extension configuration file corresponding to a target entity class in the source code.
[0041] In this step, the source code can be understood as the code under the application module in the application, and the source code can support the operation of the application module. For example, the application can be a social application, the application module can be a login module, and the source code can be the code that supports login of the login module.
[0042] The extension configuration file is used to describe the entity class extension logic for the target entity class. The entity class extension logic includes the target entity class's attributes to be extended and their attribute representations. It is understood that the extension configuration file can be used to describe which entity classes to add to the application, which attributes to add to those entity classes, and which attribute representations to add to those attributes.
[0043] Among them, the target entity class includes the entity class that needs to be extended in the source code, and the entity class includes but is not limited to: user, entity, dto and vo. The attributes to be extended include the attributes that need to be added for the target entity class. The attribute representation includes the attribute type, attribute name and attribute annotation of the attribute to be extended. The attribute representation is used to describe the specific implementation of the attribute to be extended.
[0044] It should be noted that in this application, the extension configuration file can be written in advance by the developer, or the extension configuration file can be automatically generated by the server, and no specific limitation is made here. In some examples, this application can use a domain-specific language (DSL) to determine the extension configuration file, that is, the entity class extension logic of the target entity class is described in a domain-specific language, so that the content that needs to be extended for the target entity class can be expressed concisely and efficiently.
[0045] It should also be noted that in this application, entity class preset rules, attribute preset rules and attribute representation preset rules can be constructed for specific domain languages, wherein the entity class preset rules include multiple entity classes to be expanded, and the entity class preset rules are used to describe the entity classes to be expanded, so that the entity classes to be expanded can be selected when the expansion is actually carried out; the attribute preset rules include multiple attributes to be expanded, and the attribute preset rules are used to describe the attributes to be expanded, so that the attributes to be expanded can be selected when the expansion is actually carried out; the attribute representation preset rules include multiple representations, and the attribute representation preset rules are used to express the attribute representation corresponding to the attributes to be expanded, so that the required representation can be selected when the expansion is actually carried out.
[0046] Furthermore, in the present application, before obtaining an extension configuration file corresponding to a target entity class in the source code, the target entity class can be selected from the entity class preset rules, the corresponding attribute to be extended from the attribute preset rules can be selected, and the attribute representation corresponding to the attribute to be extended from the attribute representation preset rules can be selected. In this way, based on the target entity class, the corresponding attribute to be extended from the target entity class, and the attribute representation corresponding to the attribute to be extended, an extension configuration file corresponding to the target entity class in the source code can be generated. It should be noted that in actual applications, multiple target entity classes can have their attributes to be extended extended at the same time, and each target entity class can have multiple attributes to be extended extended at the same time.
[0047] In an achievable implementation, the extended configuration file may be specifically embodied as follows (it should be noted that the extended configuration files shown below are only some examples):
[0048] YAML
[0049] #Describe the entity class User
[0050] -beanClass:com.neusoft.oscoe.osmium.rbac.bean.entity.User
[0051] #Describe the property set propMetas that needs to be extended in the User class:
[0052] #Describe the specific phone attributes
[0053] -propName:phone#The property name is phone
[0054] propType:java.lang.String#The property type is String type
[0055] #Describe the annotation collection associated with the phone attribute
[0056] annnMetas:
[0057] #phone attribute associated with @Size annotation
[0058] -annoClass:jakarta.validation.constraints.Size
[0059] #Describe the property set of @Size annotation
[0060] annoAttrs:
[0061] #Describe the specific properties of @Size
[0062] -attrName:min#@Size annotation attribute name is min
[0063] intValue:5#@Size annotation attribute min value is the number 5
[0064] -attrName:max#@Size annotation attribute name is mx
[0065] intValue:50#@Size annotation attribute max value is the number 50
[0066] It can be understood that in this application, a specific domain language is used to display the entity class extension logic of the target entity class in the form of an extended configuration file. The entity class User in the extended configuration file can be understood as the target entity class, and the characters before the symbol ":" in the extended configuration file can be understood as the attribute to be extended corresponding to the target entity class. The characters after the symbol ":" in the extended configuration file can be understood as the attribute type or attribute name in the attribute representation corresponding to the attribute to be extended, and the characters after the symbol "#" in the extended configuration file can be understood as the attribute annotation in the attribute representation corresponding to the attribute to be extended.
[0067] S102: Convert the extension configuration file to obtain a code string including the attribute to be extended and the attribute representation.
[0068] In this step, the extension configuration file can be converted to obtain a code string containing a description of the target entity class's corresponding attributes to be extended and the corresponding attribute representations. In other words, in this application, by converting the extension configuration file, the entity class extension logic of the target entity class can be converted into a unified format, so that the code string obtained after the conversion can be executable code logic.
[0069] S103: Using a code dynamic compilation technology, the source code is extended according to the code string containing the attribute to be extended and the attribute representation to obtain a target code.
[0070] In this step, the code dynamic compilation technology can be understood as runtime dynamic compilation technology, which includes at least ASM and Byte-Buddy. Specifically, in this application, the code string can first be compiled using the code dynamic compilation technology to obtain the entity class extension code corresponding to the target entity class. It can be understood that in this application, the code string can be compiled into loadable entity class extension code under the action of the code dynamic compilation technology, so that the entity class extension code can be expanded to the source code in the subsequent process.
[0071] Thereafter, the source code can be extended according to the entity class extension code to obtain the target code, wherein the target code includes the entity class extension code and the code in the source code except the code related to the entity class extension code that needs to be modified during the extension process. It can be understood that after obtaining the entity class extension code, the present application can use the code dynamic compilation technology to load the entity class extension code into the JVM compiler under the action of the preset interface or reflection operation, so that the JVM compiler can synchronously load the entity class extension code during the process of loading the source code. The preset interface includes a custom interface, and specific code (such as the entity class extension code) can be dynamically loaded based on the custom interface and the reflection operation.
[0072] Furthermore, by using a domain-specific language to define the extension configuration file in this application, it is possible to avoid directly referencing the relevant entity classes in the source code and having them loaded by the JVM compiler. This eliminates the need to overwrite or modify the underlying source code; the JVM compiler can directly load the entity class extension code at runtime, improving code extension efficiency, ensuring smooth upgrades of subsequent application modules, and ensuring perfect compatibility of code extensions.
[0073] In one feasible implementation, the target code is specifically embodied as follows (it should be noted that the target code shown below is only a partial example):
[0074] Java
[0075] package com.neusoft.oscoe.osmium.rbac.bean.entity.User;
[0076] import jakarta.validation.constraints.Size;
[0077] public class User{
[0078] / / Extend and add phone attribute
[0079] @Size(min=5,max=50)
[0080] private String phone;
[0081] / / Extend and add getPhone method
[0082] public String getPhone(){
[0083] return this.phone;
[0084] }
[0085] / / Extend and add setPhone method
[0086] public void setPhone(String phone){
[0087] this.phone = phone;}}
[0088] It can be understood that the extended code content shown in the above target code includes the to-be-extended attribute corresponding to the target entity class and the attribute representation corresponding to the to-be-extended attribute, as well as getter / setter functions.
[0089] like Figure 2 As shown, Figure 2 This is a flowchart for implementing the expansion of entity classes in a code expansion method provided in an embodiment of the present application. Figure 2 In this application, the developer's extension configuration file can first be obtained. This extension configuration file can then be converted to obtain a code string containing the attributes to be extended and their representations. Finally, the source code can be extended based on this code string through dynamic code compilation technology. In this way, the application does not need to overwrite or modify the underlying source code, which effectively implements the expansion of the target entity class, improves the expansion efficiency, ensures the smooth upgrade of subsequent application modules, and ensures perfect compatibility of code extensions.
[0090] Furthermore, in this application, function information related to the target entity class can also be expanded. Figure 3 As shown, Figure 3 This is a flowchart of extending function information in a code extension method provided in an embodiment of the present application. Figure 3 Steps S104 to S106 are shown, and steps S104 to S106 are specifically embodied as follows:
[0091] S104: Obtain entity class replacement function.
[0092] In this step, the entity class replacement function is used to replace the function information related to the target entity class in the source code. The entity class replacement function includes function tag information. In other words, in this application, the developer can mark the function information that needs to be replaced in the source code in advance to obtain the entity class replacement function, or the server can automatically mark the function information that needs to be replaced in the source code to obtain the entity class replacement function.
[0093] S105: parsing the entity class replacement function to obtain function information to be replaced related to the target entity class in the source code and target function replacement information corresponding to the function information to be replaced in the entity class replacement function.
[0094] In this application, the function information to be replaced can be understood as the function information that needs to be replaced, and the target function replacement information can be understood as the function information that replaces the function information to be replaced. The function information to be replaced includes function information under public class functions, function information under private class functions, function information under default class functions, and function information under immutable function classes. The function information to be replaced includes at least the first function information under the service function and the second function information under the dao function. The target function replacement information includes at least the third function information under the service function and the fourth function information under the dao function.
[0095] The first function information can be understood as supporting the service logic for the entity class attributes under the target entity class; the second function information can be understood as supporting the access / query logic for the entity class attributes under the target entity class; the third function information can be understood as supporting the service logic for the to-be-extended attributes corresponding to the target entity class; and the fourth function information can be understood as supporting the access / query logic for the to-be-extended attributes corresponding to the target entity class. For example, if the target entity class is user, the entity class attribute is the name attribute, and the to-be-extended attribute is the mobile phone number attribute, then the first function information can be the processing logic for the name, the second function information can be the access / query logic for the name, the third function information can be the processing logic for the mobile phone number, and the fourth function information can be the access / query logic for the mobile phone number.
[0096] Specifically, in the present application, the entity class replacement function can first be parsed to obtain the function tag information in the entity class replacement function. The function tag information in the entity class replacement function includes tag annotations and tag configuration files. It should be noted that the function tag information includes the function information to be replaced related to the target entity class in the source code, the target function replacement information corresponding to the function information to be replaced, and the function information replacement method for the function information to be replaced, wherein the function information replacement method includes whether to retain the function information to be replaced and whether to replace it before the target entity class is loaded.
[0097] After that, the function tag information can be parsed to obtain the function information to be replaced in the entity class replacement function that is related to the target entity class in the source code, and the function tag information can be parsed to obtain the target function replacement information corresponding to the function information to be replaced in the entity class replacement function. In a feasible implementation, the present application can also parse the function tag information to obtain the function information replacement method for the function information to be replaced in the entity class replacement function. In this way, the present application can know what function information to replace and what function replacement information should be replaced in the subsequent process through the means of marking, thereby improving the expansion efficiency of function information to a certain extent.
[0098] S106: Using the code dynamic compilation technology, the to-be-replaced function information related to the target entity class in the source code is replaced with the target function replacement information.
[0099] In this step, the function information to be replaced related to the target entity class in the source code can be intercepted, and through the code dynamic compilation technology, when the JVM compiler loads the source code, the target function replacement information is called and loaded, thereby realizing the replacement of the function information to be replaced. That is, during loading, only the function information and the target function replacement information except the function information to be replaced in the source code are loaded, and the function information to be replaced is not loaded, thereby avoiding direct modification of the source code. In this way, the partial replacement of function information is realized in the present application, and there is no need to modify the complete target entity class to which the function information belongs. It also solves the problem that the related technology cannot copy private class functions, default class functions and immutable class functions, greatly reducing the scope of influence of function reconstruction.
[0100] In a feasible implementation, if the function information replacement method is to retain the function information to be replaced, the function information to be replaced related to the target entity class in the source code will not be intercepted, and through code dynamic compilation technology, when the JVM compiler loads the source code, the target function replacement information is called and loaded, thereby realizing the extended loading of the function information to be replaced.
[0101] like Figure 4 As shown, Figure 4 This is a flowchart for implementing the extended function information in a code extension method provided in an embodiment of the present application. Figure 4 First, the entity class replacement function marked in advance by the developer can be obtained. Then, the entity class replacement function can be parsed to obtain the function information to be replaced related to the target entity class in the source code, and the target function replacement information corresponding to the function information to be replaced. Finally, the target function replacement information can be used to replace / expand the function information to be replaced based on the target function replacement information through code dynamic compilation technology. In this way, the local replacement of function information under the target entity class is achieved in this application, which greatly reduces the scope of the impact of function reconstruction.
[0102] Furthermore, when the target function replacement information includes access function information, the access profile related to the access function information can also be expanded in this application. The access function information can be understood as the above-mentioned dao function, and the access profile supports access / query of the access function information. Figure 5 As shown, Figure 5 A flowchart of accessing a configuration file in a code expansion method provided in an embodiment of the present application is provided. Figure 5 Steps S107 to S1010 are shown, and steps S107 to S1010 are specifically embodied as follows:
[0103] S107: Acquire a target access configuration file related to the access function information.
[0104] In this step, the target access profile includes the target dao xml configuration, which is used to indicate the elements that need to be changed in the original access profile, that is, the target access profile contains the elements that need to be modified in the original access profile. The target access profile also contains the profile name of the original access profile related to the access function information. The profile name includes the namespace, so that in the subsequent process, the accuracy of the identified original access profile can be ensured based on the profile name.
[0105] It should be noted that in this application, for each original access profile that needs to be changed, a target access profile can be created by the developer under the specified target, or the server can automatically create a target access profile under the specified target based on pipeline operations, so as to avoid directly modifying the original access profile in subsequent processes.
[0106] S108: intercepting an original access configuration file corresponding to the configuration file name among a plurality of access configuration files related to the access function information by using the code dynamic compilation technology.
[0107] It should be noted that before executing the code dynamic compilation technology to intercept the original access profile operations corresponding to the profile names in multiple access profiles related to the access function information, the present application can also obtain multiple access profiles related to the access function information. It is understandable that a dao function can correspond to multiple access profiles, and these multiple access profiles are present in the Jar package corresponding to the application module.
[0108] Specifically, in this application, the dynamic code compilation technology can first be used to parse multiple access configuration files to obtain the file names corresponding to the multiple access configuration files. Then, the dynamic code compilation technology can be used to filter the file names corresponding to the multiple access configuration files based on the configuration file names to obtain the target file names corresponding to the configuration file names among the file names corresponding to the multiple access configuration files. Finally, the dynamic code compilation technology can be used to intercept the original access configuration files corresponding to the target file names among the multiple access configuration files. In this way, the original access configuration files can be correctly intercepted under the influence of the configuration file names.
[0109] It should be noted that the information in the target access configuration file is different from the information in the original access configuration file. The original access configuration file includes the original dao xml configuration, which is located in the constructor of the xml configuration loader in the dao framework. The xml configuration loader includes at least Mybatis, Mybatis-plus, Hibernate, and JPA. Specifically, Mybatis can be further XMLMapperBuilder in Mybatis, and Mybatis-Plus can be further MybatisXMLMapperBuilder in Mybatis-Plus.
[0110] S109: Merge the target access profile and the original access profile to obtain a merged access profile.
[0111] Specifically, in this application, the target access profile and the original access profile can be first parsed to obtain the target element in the target access profile and the original element in the original access profile, where the number of target elements in the target access profile can be one or more, and the number of original elements in the original access profile can be one or more, and the number of elements is not specifically limited here.
[0112] After this, the application can determine whether the element name of the target element is the same as the element name of the original element. If the element name of the target element is the same as the element name of the original element, the original element in the original access configuration file can be replaced with the target element to obtain a merged access configuration file. If the element name of the target element is different from the element name of the original element, the target element can be added to the original access configuration file to obtain a merged access configuration file, where the merged access configuration file is used to support access to access function information. In this way, local changes / additions to the access configuration file can be implemented, reducing the scope of impact on subsequent access configuration file upgrades.
[0113] like Figure 6 As shown, Figure 6 A schematic diagram of merging configuration files in a code expansion method provided in an embodiment of the present application. Figure 6In the example, it is assumed that the target access profile includes element 1, element 2, ..., element n+1, and the original access profile includes element 1, element 2, ..., element n. At this time, when the element name of element 1 in the target access profile is the same as the element name of element 1 in the original access profile, element 1 in the original access profile is replaced with element 1 in the target access profile; when the element name of element 2 in the target access profile is the same as the element name of element 2 in the original access profile, element 2 in the original access profile is replaced with element 2 in the target access profile; when the element name of element n+1 in the target access profile is different from the element names of element 1 / element 2 / element n in the original access profile, element n+1 in the target access profile is added to the original access profile. In this way, the replacement and addition operations are completed to obtain a merged access profile, which includes the replaced element 1, the replaced element 2, ..., the original element n, and the added element n+1.
[0114] S1010: Using the code dynamic compilation technology, replace the original access configuration files in the multiple access configuration files with the merged access configuration file.
[0115] In this step, the code dynamic compilation technology can be used to call and load the merged access profile when the JVM compiler loads multiple access profiles, thereby realizing dynamic replacement of the original access profile. That is, during loading, only the access profiles and the merged access profile other than the original access profile are loaded in the multiple access profiles, without loading the original access profile, thereby avoiding direct modification of the entire access profile. In this way, in this application, only the target access profile is needed to implement partial modification / addition of the original access profile, without overwriting and modifying the complete original access profile, and based on the code compilation technology, the dynamic replacement of the original access profile in multiple access profiles can be realized, which not only solves the problem that the dao xml configuration cannot be modified in the related technology, but also reduces the scope of impact brought by the subsequent access profile upgrade.
[0116] like Figure 7 As shown, Figure 7 This is a flowchart of accessing a configuration file in a code expansion method provided in an embodiment of the present application. Figure 7First, the target access profile created by the developer can be obtained. The target access profile can then be used to intercept the original access profile and merge the target and original access profiles to obtain a merged access profile. Finally, dynamic code compilation technology can be used to dynamically replace the original access profiles in multiple access profiles. This approach enables dynamic, local replacement of access profiles corresponding to DAO functions and addresses the issue of DAO XML configurations being unable to be modified in related technologies.
[0117] like Figure 8 As shown, Figure 8 A full flow chart of code expansion in a code expansion method provided in an embodiment of the present application, Figure 8 The invention relates to a process of lightweight code expansion for the Jar package corresponding to the application module. Specifically, in the present application, a domain-specific language can be used to describe an extension configuration file first, so that under the action of code dynamic compilation technology, the attribute extension of the target entity class in the source code of the Jar package can be realized based on the extension configuration file; thereafter, under the action of code dynamic compilation technology, based on the entity class replacement function, the local dynamic replacement of the function information related to the target entity class in the source code of the Jar package can be realized; thereafter, under the action of code dynamic compilation technology, the original access configuration file and the target access configuration file in multiple access configuration files in the Jar package can be merged, and based on the merged access configuration file, the local dynamic replacement of the original access configuration file in multiple access configuration files in the Jar package can be realized. In this way, the code expansion is better realized in the present application, and while being as compatible as possible with the original implementation logic, only the functions required for lightweight incremental expansion are removed, thereby ensuring the subsequent smooth upgrade of the application module.
[0118] In summary, in this embodiment, an extension configuration file can be obtained in advance, and the extension configuration file can indicate how to extend the target entity class in the source code, that is, the extension configuration file contains the attributes to be extended and their attribute representations that need to be extended. At this time, the source code can be extended based on the code string containing the attributes to be extended and the attribute representations through code dynamic compilation technology. In this way, the problem of large modification workload caused by overall modification of the complete code is avoided in this application, thereby better achieving code extension and improving the efficiency of code extension to a certain extent. Moreover, the problem of the complete source code reuse method and individual source code overwriting method in the related art, which directly modify the underlying source code and cannot achieve smooth upgrades of the application module obtained after expansion, is avoided. In addition, in this application, function information related to the target entity class and access configuration files related to the extended access function information can also be extended. In this way, while being as compatible as possible with the original implementation logic, only the functions required for lightweight incremental expansion are removed, ensuring the subsequent smooth upgrade of the application module.
[0119] Based on the code expansion method provided in the aforementioned embodiment, the present application also provides a code expansion device accordingly. Figure 9 This is a schematic diagram of the structure of a code expansion device provided in an embodiment of the present application. Figure 9 As shown, the code expansion device includes:
[0120] A code file acquisition unit 901 is configured to acquire source code and an extension configuration file corresponding to a target entity class in the source code, wherein the extension configuration file is configured to describe entity class extension logic of the target entity class, the entity class extension logic including attributes to be extended of the target entity class and attribute representations of the attributes to be extended;
[0121] The configuration file conversion unit 902 is configured to convert the extended configuration file to obtain a code string including the attribute to be extended and the attribute representation;
[0122] The target code obtaining unit 903 is configured to perform expansion processing on the source code according to the code string containing the attribute to be extended and the attribute representation by using a code dynamic compilation technology to obtain a target code.
[0123] In an achievable implementation, the target code obtaining unit 903 is specifically configured to:
[0124] Compile the code string using a dynamic code compilation technique to obtain an entity class extension code corresponding to the target entity class;
[0125] The source code is extended according to the entity class extension code to obtain the target code.
[0126] In one possible implementation, the device further includes:
[0127] a replacement function acquiring unit, configured to acquire an entity class replacement function, wherein the entity class replacement function is used to replace function information related to the target entity class in the source code;
[0128] a replacement function parsing unit, configured to parse the entity class replacement function to obtain function information to be replaced in the entity class replacement function, which is related to the target entity class in the source code, and target function replacement information corresponding to the function information to be replaced;
[0129] The function information replacement unit is used to replace the to-be-replaced function information related to the target entity class in the source code with the target function replacement information through the code dynamic compilation technology.
[0130] In an achievable implementation, when the target function replacement information includes access function information, the apparatus further includes:
[0131] a target file acquiring unit, configured to acquire a target access configuration file related to the access function information, wherein the target access configuration file includes a configuration file name of an original access configuration file related to the access function information;
[0132] an original file interception unit, configured to intercept, by means of the code dynamic compilation technology, an original access configuration file corresponding to the configuration file name among a plurality of access configuration files related to the access function information, wherein information in the target access configuration file is different from information in the original access configuration file;
[0133] a merged file obtaining unit, configured to merge the target access configuration file and the original access configuration file to obtain a merged access configuration file, wherein the merged access configuration file is used to support access to the access function information;
[0134] The configuration file replacement unit is used to replace the original access configuration files in the multiple access configuration files with the merged access configuration file through the code dynamic compilation technology.
[0135] In one feasible implementation, the merged file obtaining unit is specifically configured to:
[0136] Parsing the target access configuration file and the original access configuration file to obtain a target element in the target access configuration file and an original element in the original access configuration file;
[0137] If the element name of the target element is the same as the element name of the original element, the original element in the original access configuration file is replaced with the target element to obtain a merged access configuration file;
[0138] Alternatively, if the element name of the target element is different from the element name of the original element, the target element is added to the original access configuration file to obtain a merged access configuration file.
[0139] In one possible implementation, the device further includes:
[0140] a plurality of file acquisition units, configured to acquire a plurality of access configuration files related to the access function information;
[0141] The original file interception unit is specifically used to:
[0142] Parsing the multiple access configuration files through the code dynamic compilation technology to obtain the file names corresponding to the multiple access configuration files;
[0143] By using the code dynamic compilation technology, a plurality of file names are screened according to the configuration file name to obtain a target file name corresponding to the configuration file name from the plurality of file names;
[0144] The original access configuration file corresponding to the target file name in the multiple access configuration files is intercepted by the code dynamic compilation technology.
[0145] In an achievable implementation, the replacement function parsing unit is specifically configured to:
[0146] Performing function parsing on the entity class replacement function to obtain function tag information in the entity class replacement function;
[0147] Parsing the function tag information to obtain information about a to-be-replaced function in the entity class replacement function that is related to the target entity class in the source code;
[0148] The function tag information is parsed to obtain target function replacement information corresponding to the to-be-replaced function information in the entity class replacement function.
[0149] The code expansion device provided in the embodiment of the present application has the same beneficial effects as the code expansion method provided in the above embodiment, and can improve the efficiency of code expansion, which will not be repeated here.
[0150] The present application also provides a computer device. The computer device includes:
[0151] A memory having a computer program stored thereon.
[0152] The processor is used to execute the computer program in the memory to implement some or all of the steps in the code expansion method introduced in the above embodiment.
[0153] The present application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements some or all of the steps of the code expansion method described in the above embodiments.
[0154] It should be noted that the "first" and "second" (if any) mentioned in the embodiments of this application are only used as name identifiers and do not represent the first or second in order.
[0155] It should also be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and equipment embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments. The device and equipment embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components indicated as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without expending creative work.
[0156] The above is merely one 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 the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. A code expansion method, characterized in that: include: Obtaining source code and an extension configuration file corresponding to a target entity class in the source code, wherein the extension configuration file is used to describe entity class extension logic of the target entity class, the entity class extension logic including attributes to be extended of the target entity class and attribute representations of the attributes to be extended; Converting the extension configuration file to obtain a code string containing the attribute to be extended and the attribute representation; By using a code dynamic compilation technology, the source code is extended according to the code character string containing the attribute to be extended and the attribute representation to obtain a target code.
2. The method according to claim 1, characterized in that The method of performing expansion processing on the source code according to the code string containing the attribute to be expanded and the attribute representation by using the code dynamic compilation technology to obtain the target code includes: Compile the code string using a dynamic code compilation technique to obtain an entity class extension code corresponding to the target entity class; The source code is extended according to the entity class extension code to obtain the target code.
3. The method according to claim 1, characterized in that After the source code is expanded according to the code string by the code dynamic compilation technology to obtain the target code, the method further includes: Obtaining an entity class replacement function, wherein the entity class replacement function is used to replace function information related to the target entity class in the source code; Parsing the entity class replacement function to obtain function information to be replaced related to the target entity class in the source code and target function replacement information corresponding to the function information to be replaced; By using the code dynamic compilation technology, the to-be-replaced function information related to the target entity class in the source code is replaced with the target function replacement information.
4. The method according to claim 3, characterized in that When the target function replacement information includes access function information, after replacing the to-be-replaced function information related to the target entity class in the source code with the target function replacement information by using the code dynamic compilation technology, the method further includes: Acquire a target access configuration file related to the access function information, wherein the target access configuration file includes a configuration file name of an original access configuration file related to the access function information; intercepting, by means of the code dynamic compilation technology, an original access configuration file corresponding to the configuration file name among a plurality of access configuration files related to the access function information, wherein information in the target access configuration file is different from information in the original access configuration file; Merging the target access configuration file and the original access configuration file to obtain a merged access configuration file, wherein the merged access configuration file is used to support access to the access function information; By using the code dynamic compilation technology, original access configuration files among the multiple access configuration files are replaced with the merged access configuration file.
5. The method according to claim 4, characterized in that The merging of the target access profile and the original access profile to obtain a merged access profile includes: Parsing the target access configuration file and the original access configuration file to obtain a target element in the target access configuration file and an original element in the original access configuration file; If the element name of the target element is the same as the element name of the original element, the original element in the original access configuration file is replaced with the target element to obtain a merged access configuration file; Alternatively, if the element name of the target element is different from the element name of the original element, the target element is added to the original access configuration file to obtain a merged access configuration file.
6. The method according to claim 4, characterized in that Before intercepting the original access configuration file corresponding to the configuration file name from among the multiple access configuration files related to the access function information by the code dynamic compilation technology, the method further includes: Acquire multiple access configuration files related to the access function information; The method of intercepting, by using the code dynamic compilation technology, an original access configuration file corresponding to the configuration file name among multiple access configuration files related to the access function information, includes: Parsing the multiple access configuration files through the code dynamic compilation technology to obtain the file names corresponding to the multiple access configuration files; By using the code dynamic compilation technology, a plurality of file names are screened according to the configuration file name to obtain a target file name corresponding to the configuration file name from the plurality of file names; The original access configuration file corresponding to the target file name in the multiple access configuration files is intercepted by the code dynamic compilation technology.
7. The method according to claim 3, characterized in that The parsing process of the entity class replacement function to obtain function information to be replaced related to the target entity class in the source code and target function replacement information corresponding to the function information to be replaced includes: Performing function parsing on the entity class replacement function to obtain function tag information in the entity class replacement function; Parsing the function tag information to obtain information about a to-be-replaced function in the entity class replacement function that is related to the target entity class in the source code; The function tag information is parsed to obtain target function replacement information corresponding to the to-be-replaced function information in the entity class replacement function.
8. A code expansion device, characterized in that: include: a code file acquisition unit, configured to acquire source code and an extension configuration file corresponding to a target entity class in the source code, wherein the extension configuration file is used to describe entity class extension logic of the target entity class, and the entity class extension logic includes attributes to be extended of the target entity class and attribute representations of the attributes to be extended; a configuration file conversion unit, configured to convert the extended configuration file to obtain a code string containing the attribute to be extended and the attribute representation; The target code obtaining unit is used to perform expansion processing on the source code according to the code string containing the attribute to be extended and the attribute representation by using the code dynamic compilation technology to obtain the target code.
9. A computer device, characterized in that: include: a memory having a computer program stored thereon; A processor is configured to execute the computer program in the memory to implement the steps of the code expansion method according to claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the code expansion method according to claims 1 to 7 are implemented.