A code generation method and apparatus

CN122593843APending Publication Date: 2026-08-18HAIYI INFORMATION TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510153013.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-11
Publication Date
2026-08-18

AI Technical Summary

Technical Problem

[0003]然而,使用单项目开发方式是将所有用户的定制需求都整合到一个单一的代码库中,随着不同用户需求的累积,代码库会变得十分庞大,导致应用程序的安装包体积增加,从而影响应用程序性能,并增加了设备存储压力

Benefits of technology

[0032] The effects of the aforementioned code generation device, electronic device, and storage medium are described in the explanation of the code generation method above, and will not be repeated here.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122593843A_ABST
    Figure CN122593843A_ABST
Patent Text Reader

Abstract

The method comprises the following steps: determining a target source code file and a resource file corresponding to a target user; determining code statements and methods belonging to the target user from the target source code file according to identification information of the target user and first annotation information of the target source code file; and generating an application code package of the target user based on the resource file and the code statements and methods belonging to the target user. The embodiment can save development resources, improve code generation efficiency, improve application program performance, and reduce device storage pressure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer technology, and more specifically, relates to a code generation method and apparatus. Background Technology

[0002] In multi-user customized development for clients, the needs of different users may differ. To address the needs of different users, single-project compatible development or multi-project development is generally used.

[0003] However, using a single-project development approach integrates all users' customized requirements into a single codebase. As different user needs accumulate, the codebase becomes extremely large, increasing the application's installation package size, thus impacting application performance and increasing device storage pressure. In a multi-project development approach, each user has an independent project and codebase. Since there is a large amount of common code across different applications, redeveloping each user's application would waste significant development resources and reduce code generation efficiency. Summary of the Invention

[0004] In view of this, the present disclosure provides at least one code generation method, apparatus, electronic device, and storage medium, which can improve code generation efficiency, enhance application performance, and reduce device storage pressure while saving development resources.

[0005] In a first aspect, embodiments of this disclosure provide a code generation method, including:

[0006] Identify the target source code files and resource files corresponding to the target user;

[0007] Based on the target user's identification information and the first annotation information of the target source code file, determine the code statements and methods belonging to the target user from the target source code file;

[0008] Based on the resource files and the code statements and methods belonging to the target user, generate the application code package for the target user.

[0009] Optionally, the target source code file corresponding to the target user is determined, including:

[0010] Scan the raw source code files in the library folder and identify the raw source code files marked with the second annotation information; the raw source code files in the library folder include source code files belonging to different users;

[0011] Create a source code file identical to the original source code file marked with the second annotation information as the target source code file corresponding to the target user.

[0012] Optionally, based on the target user's identification information and the first annotation information of the target source code file, the code statements and methods belonging to the target user are determined from the target source code file, including:

[0013] Remove the code statements and methods from the target source code file that are marked by the first annotation information and whose type array does not include the target user's identification information;

[0014] Modify the variable names of code statements and methods that include the target user's identification information in the type array to preset names to obtain code statements and methods belonging to the target user.

[0015] Optionally, based on resource files and code statements and methods belonging to the target user, an application code package for the target user is generated, including:

[0016] Based on the predefined configuration file, determine the code statements and methods belonging to the target user that need to be adjusted, and then adjust the code statements and methods belonging to the target user that need to be adjusted.

[0017] Based on the resource files and the adjusted code statements and methods belonging to the target user, generate the application code package for the target user.

[0018] Optionally, the method further includes:

[0019] In response to changes in code statements and methods belonging to the target user, update the first and second annotation information;

[0020] Based on the updated first and second annotation information, determine the new code statements and methods belonging to the target user.

[0021] Secondly, embodiments of this disclosure provide a code generation apparatus, including:

[0022] The first determination module is used to determine the target source code file and resource file corresponding to the target user;

[0023] The second determination module is used to determine the code statements and methods belonging to the target user from the target source code file based on the target user's identification information and the first annotation information of the target source code file.

[0024] The generation module is used to generate the target user's application code package based on resource files and code statements and methods belonging to the target user.

[0025] Optionally, the generation module is also used for:

[0026] Based on the predefined configuration file, determine the code statements and methods belonging to the target user that need to be adjusted, and then adjust the code statements and methods belonging to the target user that need to be adjusted.

[0027] Based on the resource files and the adjusted code statements and methods belonging to the target user, the application code package for the target user is generated.

[0028] Thirdly, embodiments of this disclosure also provide an electronic device, including: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the computer device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, the steps of the first aspect or any optional implementation of the first aspect are performed.

[0029] Fourthly, embodiments of this disclosure also provide a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the first aspect or any optional implementation thereof.

[0030] Fifthly, embodiments of this disclosure also provide a computer program product, including a computer program that, when executed by a processor, implements the methods of any of the above embodiments.

[0031] Any of the above-described aspects or any implementation thereof can first determine the target source code file and resource file belonging to the target user from the source code files and resource files of each user. This ensures that only the source code and resources related to the target user are retained, reducing the storage pressure on the device. Furthermore, since the target source code file corresponding to the target user may also include code statements and methods belonging to other users, the code statements and methods belonging to the target user can be further determined from the target source code file based on the target user's identification information and the annotation information in the target source code file. This further reduces the device storage pressure and improves application performance. Finally, the application code package for the target user can be generated using the determined resource files, code statements, and methods belonging to the target user. Thus, the code statements, methods, and resource files belonging to the target user can be determined solely through the target user's identification information and the annotation information in the source code file. This solves both the problem of increased application package size due to the accumulation of different user needs and the problem of wasting a large amount of development resources by redeveloping applications for each user. It saves development resources, improves code generation efficiency, enhances application performance, and reduces device storage pressure.

[0032] The effects of the aforementioned code generation device, electronic device, and storage medium are described in the explanation of the code generation method above, and will not be repeated here. Attached Figure Description

[0033] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. These drawings are incorporated in and constitute a part of this specification. They illustrate embodiments conforming to this disclosure and, together with the specification, serve to explain the technical solutions of this disclosure. It should be understood that the following drawings only show some embodiments of this disclosure and should not be considered as limiting the scope. Those skilled in the art can obtain other related drawings based on these drawings without creative effort.

[0034] Figure 1 A flowchart of a code generation method provided by an embodiment of this disclosure is shown;

[0035] Figure 2 A comparative diagram of the project before and after compilation provided in the embodiments of this disclosure is shown;

[0036] Figure 3 A schematic diagram of a code generation apparatus provided in an embodiment of this disclosure is shown;

[0037] Figure 4 An exemplary system architecture in which embodiments of this disclosure can be applied is shown;

[0038] Figure 5 A schematic diagram of the structure of a computer system used to implement the embodiments of the present disclosure is shown. Detailed Implementation

[0039] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.

[0040] It should be noted that the collection, use, storage, sharing and transfer of user personal information involved in the technical solution of the present invention all comply with the provisions of relevant laws and regulations, and require notification to users and obtaining their consent or authorization. When applicable, user personal information is subjected to de-identification and / or anonymization and / or encryption technical processing.

[0041] The above problems and solutions are the result of the inventor's practice and careful research. The discovery process of the above problems and the solutions proposed for the above problems should be considered as the inventor's contribution to this disclosure.

[0042] The technical solutions of this disclosure will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely to illustrate selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.

[0043] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0044] To facilitate understanding of this embodiment, a code generation method disclosed in this disclosure will first be described in detail. The execution subject of the code generation method provided in this disclosure is generally a computer device with certain computing capabilities. This computer device may include, for example, a terminal device, a server, or other processing devices. The terminal device may be a user equipment (UE), mobile device, user terminal, terminal, cellular phone, cordless phone, personal digital assistant (PDA), handheld device, computing device, in-vehicle device, wearable device, etc. In some possible implementations, this code generation method can be implemented by a processor calling computer-readable instructions stored in memory.

[0045] See Figure 1 The diagram shows a flowchart of a code generation method provided in an embodiment of this disclosure. The method includes steps S101 to S103, wherein:

[0046] S101: Determine the target source code file and resource file corresponding to the target user.

[0047] In this embodiment, a single-project can be established first to build the application. The framework for this single-project can be selected based on actual needs and circumstances. For example, Flutter (a framework for building cross-platform applications, allowing developers to build various types of applications such as iOS, Android, and Web using a single codebase), Xamarin (a cross-platform development framework supporting iOS, Android, and Windows platforms), and React Native (a framework for building mobile applications using JavaScript and React, supporting iOS and Android platforms) can be selected. The following description uses Flutter as an example of using the single-project framework and does not constitute an improper limitation of the invention. In practical applications, any step in the following description can be adapted according to the selected framework. This embodiment does not impose specific limitations in this regard, and the functionality should be achieved as the standard.

[0048] Flutter projects typically have a standard directory structure to ensure clear and easy-to-manage organization of resources. This mainly includes a library folder (lib folder) for storing Dart code (an object-oriented programming language, which can be referred to as source code files in this embodiment), including application business logic, UI (User Interface) components, and data models; a resources folder (assets folder) for storing static resource files such as images, fonts, and icons; test folders; and configuration folders, etc.

[0049] In this embodiment of the disclosure, each folder stores content corresponding to different users. For example, the directory structure of a resource folder might look like this:

[0050] assets customerA background_customer_a.jpg customerB background_customer_b.jpg

[0051] Here, assets represents the project's resource folder; within the resource folder, resource files belonging to user A and user B are stored respectively. background_customer_a.jpg represents the resource belonging to user A, and background_customer_b.jpg represents the resource belonging to user B.

[0052] In practical implementation, a utility project called `target_code_builder` can be created in the root directory specifically for code generation. This utility project can depend on Flutter's `build_runner` and `source_gen` libraries. `build_runner` is responsible for executing build tasks and provides a general mechanism for managing code generation tasks. Specifically, `build_runner` can automatically generate Dart code files, such as entity classes, serializers, and services, based on predefined rules or templates. It can also define a series of steps through the builder to automate tasks such as code generation, file conversion, and resource compilation. During development, it monitors file changes and automatically triggers corresponding build tasks, keeping the project's code and generated code synchronized. The `source_gen` library is a Dart library for code generation that works with `build_runner` to generate additional code based on source code. Specifically, `source_gen` can generate new Dart code files by scanning and parsing Dart source code files. By using annotations in the code, it can mark certain classes, fields, or methods, thereby generating related code for those parts. Furthermore, `source_gen` supports developers creating custom code generators to generate specific code files to meet project needs.

[0053] In practice, the created utility project `target_code_builder` can be used to perform code generation tasks. Furthermore, developers can create annotation classes to represent specific parts of the source code files. For example, the `TargetDector` class in the `target_detector.dart` file can be used to mark classes that need to be processed; the `Target` class annotation in the `target.dart` file can be used to mark code statements that need to be processed, which can include operations such as adding, deleting, and modifying code; the `builder.dart` file can serve as the entry point for the utility project; and the classes declared in the `generator.dart` file can represent the logic used to generate code.

[0054] Specifically, if a piece of code is:

[0055] @TargetDetector() @Target(type:['CustomerA'], name:'kycUpgrade')

[0056] Here, @TargetDetector() indicates that this class needs to be processed; @Target(type:['CustomerA'], name:'kycUpgrade') indicates that the method in the following line will apply to CustomerA, and the method name will be renamed to kycUpgrade.

[0057] It should be noted that the above annotation class is only used as an example of a feasible setting method in the embodiments of this disclosure, and does not constitute an improper limitation of the present invention. In actual applications, it can be set according to actual needs and circumstances. The embodiments of this disclosure do not make specific limitations in this regard, and the function shall be achieved as the standard.

[0058] Then you can develop a kyc_upgrade_page.dart class, which can contain logic for displaying different page elements based on different users. For example, different users can use different background images or different task processing flows.

[0059] In this embodiment of the disclosure, after completing the above development steps, the target source code file and resource file corresponding to the target user can be determined.

[0060] In practical implementation, the entry class `builder.dart` of the aforementioned code generation tool project can be launched, and the target user's identification information can be added to the startup command parameters to indicate that the current compilation is an application customized for the target user. For example, "CustomerB" can be added to the startup command parameters to indicate that the current compilation is an application customized for user B. It should be noted that the above-mentioned target user identification information is only used as an example of one possible implementation in this disclosure and does not constitute an improper limitation of the present invention. In practical applications, any format of identification information can be set to represent the target user according to the actual situation. For example, other combinations of letters or numbers can be used to represent the target user's identification information. This disclosure does not specifically limit this, as long as its function can be achieved.

[0061] In practical implementation, the builder class can determine the resource file corresponding to the target user's identifier from the resource folder. This determined resource file is the resource file belonging to the target user. After determining the resource file corresponding to the target user, resource files belonging to other users can be deleted from the resource folder, ensuring that only the target user's resource file is retained. Furthermore, the resource file paths for each user can be managed through a database or pre-configured files. When the application starts, the corresponding resource file is loaded according to the target user's configuration, thus ensuring that only the resource file corresponding to the target user is loaded. Besides determining the resource file corresponding to the target user from the resource folder based on the target user's identifier, various types of resources can also be stored in the resource folder according to their type, allowing users to select their preferred resource types to determine the resource file corresponding to the target user based on their settings.

[0062] It should be noted that the method for determining the resource file corresponding to the target user in this disclosure is not specifically limited. The two methods described above are only examples of possible implementation methods provided by this disclosure and do not constitute an improper limitation of the present invention. In practical applications, the methods can be set according to the actual situation to achieve their functions.

[0063] In this embodiment of the disclosure, determining the target source code file corresponding to the target user includes: scanning the original source code files under the library folder and identifying the original source code files marked by the second annotation information; the original source code files under the library folder include source code files belonging to different users; and creating a source code file identical to the original source code file marked by the second annotation information as the target source code file corresponding to the target user.

[0064] In practical implementation, the library folder may include source code files corresponding to different users. These source code files may include specific functional code corresponding to each user, used to implement business logic, UI components, page and interaction logic related to the target user; they may also include data models and structures related to different users. When it is necessary to compile an application customized for the target user, the source code files corresponding to the target user can be selected from the library folder, such as the kyc_upgrade_page.dart class. Specifically, the original source code files in the library folder can be scanned to identify the source code files marked with the second annotation information. This second annotation information can be the @TargetDetector() annotation mentioned earlier, or any other annotation class. This embodiment does not specifically limit the setting of the annotation class, as long as it can achieve its function. Then, for these files identified by the second annotation information, a corresponding .g.dart file can be created as the target source code file corresponding to the target user. The initial content of the created target source code file can be the same as the corresponding original source code file. The purpose of creating a source code file that is the same as the original source code file as the target user's target source code file is to avoid directly modifying the code in the original source code file, improve code maintainability, and ensure that the code generated later does not interfere with the code in the original source code file. In addition, having the same initial content as the original source code file also helps to keep the structure of the generated code consistent with the original source code file, avoiding mismatch problems between the generated code and the original code.

[0065] In another possible implementation, in addition to determining the target source code file corresponding to the target user based on the annotation information, the source code files can also be classified and stored in the library folder according to the user or functional module, thereby also being able to determine the target source code file corresponding to the target user from the original source code file.

[0066] In this embodiment, the purpose of creating a source code file identical to the original code file marked with the second annotation information as the target source code file corresponding to the target user is to protect the original source code file. Therefore, in addition to creating the same source code file to achieve the above purpose, the consistency and correctness of the subsequently generated code and the original code can be verified by performing test steps to avoid mutual interference or mismatch between the subsequently generated code and the original code; alternatively, management tools can be used to manage the versions of code generation tools and libraries to ensure compatibility between the subsequently generated code and the original code. This embodiment does not specifically limit the specific methods for ensuring that the subsequently generated code does not interfere with the code in the original source code file and to avoid mismatch between the generated code and the original code. In practical applications, the methods can be set according to the actual situation to achieve the desired functionality.

[0067] S102: Based on the target user's identification information and the first annotation information of the target source code file, determine the code statements and methods belonging to the target user from the target source code file.

[0068] In this step, since the source code file may contain general functions and code that can serve multiple users, or it may contain specific code statements or methods corresponding to different users, after identifying the target source code file corresponding to the target user, the code statements and methods belonging to the target user can be determined from it.

[0069] In one possible implementation, based on the target user's identification information and the first annotation information of the target source code file, the code statements and methods belonging to the target user are determined from the target source code file, including: deleting code statements and methods marked by the first annotation information that do not include the target user's identification information in the type array from the target source code file; and modifying the variable names of code statements and methods that include the target user's identification information in the type array to preset names to obtain the code statements and methods belonging to the target user.

[0070] In practice, the target source code file includes the following: @Target(type:['CustomerA'], name:'bgPath') String bgPath='image / background_customer_a.png'; @Target(type:['CustomerB'], name:'bgPath') String bgCustomerBPath='image / background_customer_b.png';

[0071] Taking user B as the target user as an example, as shown in the code snippet above, the target source code file includes not only code statements belonging to user B but also code statements belonging to user A. The `@Target` annotation class (i.e., the first annotation information) is used to identify the code statements that need to be processed, and `CustomerA` in the type array indicates that the following method is valid for user A. In this case, the code statements in the target source code file marked with the first annotation information and whose type array does not contain the target user's identifier information can be deleted, and the corresponding variable names can be changed to the value of `name`. After these steps, the code snippet is adjusted as follows:

[0072] @Target(type:['CustomerB'], name:'bgPath') String bgPath='image / background_customer_b.png';

[0073] This ensures that only the code statements belonging to the target user are retained in the target source code file. Furthermore, similar processing can be applied to methods with the first annotation information: delete those methods in the target source code file whose type arrays do not contain the target user's identifier information, and modify their variable names. The specific method is similar to the method described above for deleting code statements unrelated to the target user, and will not be elaborated here.

[0074] For example, suppose the code before deleting methods irrelevant to the target user is as follows:

[0075] @Target(type:['CustomerA'], name:'kycUpgrade') kycUpgrade() { / / 1. Mobile Number Verification / / 2. ID card verification / / 3. Face recognition } @Target(type:['CustomerB'], name:'kycUpgrade') kycUpgradeCustomerB () { / / 1. Mobile Number Verification / / 2. ID card verification } The code generated using the above method can then be: @Target(type:['CustomerB'], name:'kycUpgrade') kycUpgrade() { / / 1. Mobile Number Verification / / 2. ID card verification }

[0076] This results in only the code statements and methods belonging to the target user being retained in the target source code file.

[0077] Another possible implementation involves recording the target user's identification information and corresponding code snippets in a pre-configured file. Upon application startup or runtime, the code or methods related to the target user are dynamically loaded and enabled based on the file's contents. Alternatively, metadata can be used in the code to mark and organize code or methods related to the target user, thereby enabling the identification of code statements and methods belonging to the target user from the target source code file.

[0078] In this embodiment of the disclosure, when the needs of the target user change, the first annotation information and the second annotation information can be adjusted to adapt to such changes. Specifically, the method further includes: updating the first annotation information and the second annotation information in response to changes in the code statements and methods belonging to the target user; and determining new code statements and methods belonging to the target user based on the updated first annotation information and the second annotation information.

[0079] In practice, when the target user's needs change, the first and second annotation information can be adjusted. For example, annotation information no longer relevant to the target user can be deleted, new annotation information related to the target user's new needs can be added, and existing annotation information can be modified. Based on the updated annotation information, the original source code files in the library folder can be rescanned to identify new target source code files corresponding to the target user. Furthermore, based on the updated annotation information, new code statements and methods belonging to the target user can be further identified from the newly identified target source code files to effectively respond to changes in user needs.

[0080] Another possible implementation is to control whether a corresponding function is available to the target user by designing a function switch. As the target user's needs change, the state of the function switch can be adjusted to dynamically determine which code statements and methods are executed. Alternatively, a strategy pattern can be used to respond to changes in user needs. Specifically, functions related to user needs can be encapsulated in different strategy classes, and an appropriate strategy can be selected as the code statements and methods belonging to the target user based on their needs. This disclosure does not impose specific limitations on this embodiment; the implementation of its functionality is the standard.

[0081] S103: Generate the target user's application code package based on resource files and code statements and methods belonging to the target user.

[0082] In this step, after identifying the resource files, code statements, and methods belonging to the target user, a customized application installation package for the target user can be generated.

[0083] In this embodiment of the disclosure, in addition to the processing steps described above, customized processing can also be performed on the code statements and methods belonging to the target user. Specifically, generating the target user's application code package based on resource files and the code statements and methods belonging to the target user includes: determining the code statements and methods belonging to the target user that need to be adjusted according to a predefined configuration file, and adjusting the code statements and methods belonging to the target user that need to be adjusted; generating the target user's application code package based on resource files and the adjusted code statements and methods belonging to the target user.

[0084] In practice, the target source code file can be parsed first, and code analysis tools can be used to obtain the syntax tree of the source code file. This syntax tree is a structured representation of the source code, containing information such as all classes, methods, properties, and import statements (a syntax used to import code from other modules, libraries, or files for use in the current file). Then, based on a predefined configuration file, the code statements and methods that need adjustment can be determined. For example, the node names indicated in the configuration file can be extracted from the syntax tree, and the values ​​of these name nodes can be modified to rename classes, etc. Furthermore, the import statements indicated in the configuration file can be found in the syntax tree, and adjusted according to the adjustment methods specified in the configuration file (e.g., adding, modifying, or deleting). After modification, the updated syntax tree can be converted back to source code format, and the target user's application code package can be generated based on the code statements and methods in the updated target source code file. Alternatively, after generating a new target source code file, the library folder can be scanned, and the new target source code file can replace the previous one. This completes the resource removal and method replacement of non-target user customized content before compiling and installing the package.

[0085] In another possible implementation, besides determining the code statements and methods belonging to the target user that need adjustment based on a predefined configuration file, the code statements and methods belonging to the target user that need adjustment can also be determined by identifying annotation information pre-added to classes, methods, or properties. This disclosure does not specifically limit the embodiments in this regard, but rather focuses on achieving the desired functionality.

[0086] Figure 2 A comparison chart of the project before and after compilation, such as... Figure 2 As shown, the above method ensures that applications customized for different users can adjust their resources and functions during compilation to meet the specific needs of different users. This solves the problems of existing single-project development methods impacting application performance and increasing device storage pressure; it also solves the problems of wasting significant development resources and reducing code generation efficiency when using multi-project development methods. Through this method, code generation efficiency can be improved while saving development resources, enhancing application performance, and reducing device storage pressure.

[0087] According to a second aspect of the embodiments of this disclosure, such as Figure 3 As shown, a code generation apparatus 300 is provided, comprising:

[0088] The first determining module 301 is used to determine the target source code file and resource file corresponding to the target user;

[0089] The second determining module 302 is used to determine the code statements and methods belonging to the target user from the target source code file based on the target user's identification information and the first annotation information of the target source code file.

[0090] The generation module 303 is used to generate the application code package of the target user based on the resource files and the code statements and methods belonging to the target user.

[0091] Optionally, the first determining module 301 is specifically used for:

[0092] Scan the raw source code files in the library folder and identify the raw source code files marked with the second annotation information; the raw source code files in the library folder include source code files belonging to different users;

[0093] Create a source code file identical to the original source code file marked with the second annotation information as the target source code file corresponding to the target user.

[0094] Optionally, the second determining module 302 is specifically used for:

[0095] Remove the code statements and methods from the target source code file that are marked by the first annotation information and whose type array does not include the target user's identification information;

[0096] Modify the variable names of code statements and methods that include the target user's identification information in the type array to preset names to obtain code statements and methods belonging to the target user.

[0097] Optionally, the generation module 303 is specifically used for:

[0098] Based on the predefined configuration file, determine the code statements and methods belonging to the target user that need to be adjusted, and then adjust the code statements and methods belonging to the target user that need to be adjusted.

[0099] Based on the resource files and the adjusted code statements and methods belonging to the target user, generate the application code package for the target user.

[0100] Optionally, the second determining module 302 is further configured to:

[0101] In response to changes in code statements and methods belonging to the target user, update the first and second annotation information;

[0102] Based on the updated first and second annotation information, determine the new code statements and methods belonging to the target user.

[0103] According to a third aspect of the present disclosure, an electronic device for code generation is provided, comprising: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the present invention.

[0104] According to a fourth aspect of the present disclosure, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method provided in the first aspect of the present invention.

[0105] According to a fifth aspect of the present invention, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method of any of the above embodiments.

[0106] Figure 4 An exemplary system architecture 400 is shown that can be applied to the code generation method or code generation apparatus implemented in this disclosure.

[0107] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, and 403, a network 404, and a server 405. Network 404 serves as the medium for providing communication links between terminal devices 401, 402, and 403 and server 405. Network 404 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0108] Users can use terminal devices 401, 402, and 403 to interact with server 405 via network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, and 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).

[0109] Terminal devices 401, 402, and 403 can be various electronic devices with displays that support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0110] Server 405 can be a server that provides various services, such as a backend management server that supports shopping websites browsed by users using terminal devices 401, 402, and 403 (for example only). The backend management server can process received code generation requests and return the processing results (for example only) to the terminal device.

[0111] It should be noted that the code generation method provided in the embodiments of the present invention is generally executed by server 405, and correspondingly, the code generation device is generally located in server 405. The code generation method provided in the embodiments of the present invention can also be executed by terminal devices 401, 402, and 403, and correspondingly, the code generation device can be located in terminal devices 401, 402, and 403.

[0112] It should be understood that Figure 4 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0113] The following is for reference. Figure 5 It shows a schematic diagram of the structure of a computer system 500 suitable for implementing a terminal device of the present invention. Figure 5 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.

[0114] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 502 or programs loaded from storage section 508 into random access memory (RAM) 503. The RAM 503 also stores various programs and data required for the operation of the system 500. The CPU 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0115] The following components are connected to I / O interface 505: an input section 506 including a keyboard, mouse, etc.; an output section 507 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to I / O interface 505 as needed. A removable medium 511, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 510 as needed so that computer programs read from it can be installed into storage section 508 as needed.

[0116] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 509, and / or installed from removable medium 511. When the computer program is executed by central processing unit (CPU) 501, it performs the functions defined above in the system of this invention.

[0117] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0118] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0119] The modules described in the embodiments of the present invention can be implemented in software or in hardware. The described modules can also be housed in a processor. For example, a processor may include a first determining module, a second determining module, and a generating module. The names of these modules do not necessarily limit the module itself; for example, the first module may be described as "a module for determining the target source code file and resource file corresponding to the target user."

[0120] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the device, the device implements the following method: determining a target source code file and resource files corresponding to a target user; determining code statements and methods belonging to the target user from the target source code file based on the target user's identification information and the first annotation information of the target source code file; and generating an application code package for the target user based on the resource file and the code statements and methods belonging to the target user.

[0121] Finally, it should be noted that the above embodiments are merely specific implementations of this disclosure, used to illustrate the technical solutions of this disclosure, and not to limit it. The protection scope of this disclosure is not limited thereto. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this disclosure. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure, and should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be determined by the protection scope of the claims.

Claims

1. A code generation method, characterized in that, include: Identify the target source code files and resource files corresponding to the target user; Based on the target user's identification information and the first annotation information of the target source code file, determine the code statements and methods belonging to the target user from the target source code file; Based on the resource files and the code statements and methods belonging to the target user, the application code package for the target user is generated.

2. The method according to claim 1, characterized in that, Identify the target source code file corresponding to the target user, including: Scan the original source code files in the library folder and identify the original source code files marked with the second annotation information; the original source code files in the library folder include source code files belonging to different users; Create a source code file identical to the original source code file marked with the second annotation information as the target source code file corresponding to the target user.

3. The method according to claim 1, characterized in that, Based on the target user's identification information and the first annotation information of the target source code file, determine the code statements and methods belonging to the target user from the target source code file, including: From the target source code file, delete the code statements and methods that are marked by the first annotation information and whose type array does not include the target user's identification information; Modify the variable names of the code statements and methods that include the target user's identification information in the type array to preset names to obtain the code statements and methods belonging to the target user.

4. The method according to claim 1, characterized in that, Based on the resource files and the code statements and methods belonging to the target user, an application code package for the target user is generated, including: Based on the predefined configuration file, determine the code statements and methods belonging to the target user that need to be adjusted, and then adjust the code statements and methods belonging to the target user that need to be adjusted. Based on the resource files and the adjusted code statements and methods belonging to the target user, the application code package for the target user is generated.

5. The method according to claim 1, characterized in that, The method further includes: In response to changes in the code statements and methods belonging to the target user, the first annotation information and the second annotation information are updated; Based on the updated first and second annotation information, new code statements and methods belonging to the target user are determined.

6. A code generation device, characterized in that, include: The first determination module is used to determine the target source code file and resource file corresponding to the target user; The second determining module is used to determine the code statements and methods belonging to the target user from the target source code file based on the target user's identification information and the first annotation information of the target source code file. The generation module is used to generate the application code package of the target user based on the resource file and the code statements and methods belonging to the target user.

7. The apparatus according to claim 6, characterized in that, The generation module is also used for: Based on the predefined configuration file, determine the code statements and methods belonging to the target user that need to be adjusted, and then adjust the code statements and methods belonging to the target user that need to be adjusted. Based on the resource files and the adjusted code statements and methods belonging to the target user, the application code package for the target user is generated.

8. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-5.

9. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-5.

10. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-5.