Code processing method and device, electronic equipment and storage medium
In the application development of the Hongmeng operating system, the automatic generation of object codes is solved by using abstract syntax tree analysis technology, and the problem of repeated writing of similar business codes is achieved, the code specifications and development cycles are shortened, and the maintenance costs are reduced.
Patent Information
- Application Number
- CN202510571699.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2025-08-29
AI Technical Summary
In the application development of Hongmeng operating system, developers need to repeatedly write similar business code, resulting in extended development cycles and confusing code structures, and increasing maintenance costs.
During the compilation and construction stage, abstract syntax tree parsing technology is used to identify custom components modified by predefined target decorators, generate metadata, and automatically generate target code through the template engine, including code for the registration management center and abstract adapter, combined with custom components in the run stage.
Reduces repeated code writing work, shortens development cycle, unifies code specifications, reduces the difficulty of troubleshooting errors, and reduces maintenance costs.
Smart Images

Figure CN120560641A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer application technology, and in particular to a code processing method, device, electronic device and storage medium. Background Art
[0002] In the application development of HarmonyOS, a declarative user interface (UI) development framework (ArkUI) is usually used. When developers use ArkUI to develop Harmony applications, most of their time is spent on repeatedly writing the same or similar business code. For example, in the sliding list scenario, every time an item is added to the list, the developer needs to write a custom UI component and connect the custom UI component to the sliding list through some kind of logical control method. The code for the logical control method corresponding to different custom UI components here is similar and always needs to be rewritten.
[0003] This repetitive coding work prolongs the development cycle, and the differences in coding styles among different developers easily lead to chaotic code structure, increasing the difficulty of troubleshooting and maintenance costs. Summary of the Invention
[0004] The embodiments of the present application provide a code processing method, device, electronic device, and storage medium to reduce repetitive code writing work, shorten the development cycle, reduce the difficulty of error detection, and reduce maintenance costs.
[0005] To solve the above technical problems, this application provides the following technical solutions:
[0006] In a first aspect, a code processing method is provided, comprising:
[0007] During the compilation and construction phase of HarmonyOS applications, identify target custom components modified by predefined target decorators;
[0008] Analyzing the parameter information of the target custom component using abstract syntax tree parsing technology to obtain metadata of the target code, wherein the target code includes the registration class code of the registration management center and the specific implementation class code of the abstract adapter;
[0009] Inputting the metadata into a template engine, generating the target code by using a predefined registration class generation template and an adapter implementation class generation template;
[0010] During the running phase of the HarmonyOS application, the target code is combined with the target custom component for running.
[0011] Optionally, the parameter information of the target custom component includes:
[0012] Identification information of the target custom component;
[0013] The data model entity information associated with the target custom component.
[0014] Optionally, the parameter information of the target custom component further includes at least one of the following:
[0015] Configuration information indicating whether to enable the automatic exposure tracking reporting function;
[0016] File information associated with the target custom component;
[0017] Module information associated with the target custom component;
[0018] The custom adapter information of the target custom component.
[0019] Optionally, inputting the metadata into a template engine, using a predefined registration class generation template and an adapter implementation class generation template to generate the target code includes:
[0020] Inputting the metadata into a template engine, using a predefined registration class to generate a template, and generating a registration class code for the registration management center based on the first information in the metadata;
[0021] Generate a specific implementation class code of the abstract adapter based on the second information in the metadata using a predefined adapter implementation class generation template;
[0022] Wherein, the first information includes the identification information of the target custom component; the second information includes the identification information of the target custom component and the data model entity information associated with the target custom component;
[0023] Alternatively, the first information includes identification information of the target custom component; the second information includes configuration information for indicating whether the automatic exposure point reporting function is enabled, file information associated with the target custom component, module information associated with the target custom component, at least one item of custom adapter information of the target custom component, as well as identification information of the target custom component and data model entity information associated with the target custom component.
[0024] Optionally, identifying a target custom component modified by a predefined target decorator includes:
[0025] Scan the code file within a predetermined scanning range to obtain a scanning result;
[0026] In the scanning results, target custom components modified by predefined target decorators are filtered out.
[0027] Optionally, running the target code in combination with the target custom component includes:
[0028] Run the registration class code of the registration management center to register the specific implementation class of the abstract adapter with the registration management center;
[0029] When there is a need for interface rendering of the target custom component, obtaining the abstract adapter through the registration management center;
[0030] Run the specific implementation class code of the abstract adapter and call the target custom component to complete the interface rendering.
[0031] Optionally, during the running phase of the Hongmeng application, the method further includes:
[0032] An environment context is injected into the target custom component, wherein the environment context has a built-in hash table for maintaining exposure tracking points.
[0033] In a second aspect, a code processing device is provided, comprising:
[0034] The identification unit is used to identify the target custom components modified by the predefined target decorator during the compilation and construction phase of the HarmonyOS application;
[0035] An obtaining unit, configured to analyze parameter information of the target custom component using an abstract syntax tree parsing technique to obtain metadata of a target code, wherein the target code includes a registration class code of a registration management center and a specific implementation class code of an abstract adapter;
[0036] A generating unit, configured to input the metadata into a template engine, generate the target code by using a predefined registration class generation template and an adapter implementation class generation template;
[0037] The running unit is used to combine the target code with the target custom component for operation during the running phase of the Harmony application.
[0038] In a third aspect, an electronic device is provided, comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the code processing method described in the first aspect are implemented.
[0039] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the code processing method described in the first aspect are implemented.
[0040] In a fifth aspect, a computer program product is provided, which includes computer instructions, which are stored in a computer-readable storage medium and are suitable for being read and executed by a processor, so that an electronic device having the processor performs the steps of the code processing method described in the first aspect.
[0041] By applying the technical solution provided by the embodiments of the present application, during the compilation and construction phase of the HarmonyOS application, the target custom component modified by the predefined target decorator is identified, and the parameter information of the target custom component is analyzed using abstract syntax tree parsing technology to obtain metadata of the target code. The target code includes the registration class code of the registration management center and the specific implementation class code of the abstract adapter. The metadata is input into the template engine, and the target code is generated using the predefined registration class generation template and the adapter implementation class generation template. During the runtime phase of the HarmonyOS application, the target code is combined with the target custom component for operation. For different custom components, there is no need to repeatedly write the target code, and the target code can be automatically generated, which helps reduce the repeated coding work and shorten the development cycle. In addition, using templates to generate the target code can unify code specifications, constrain code structure, reduce the difficulty of error detection, and reduce maintenance costs.
[0042] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 This is a flowchart of an implementation method of a code processing method in an embodiment of the present application;
[0044] Figure 2 Schematic diagram of the metadata generation process in an embodiment of the present application;
[0045] Figure 3 This is a schematic diagram of the overall process in the embodiment of this application;
[0046] Figure 4 This is a schematic diagram of the operating framework in an embodiment of the present application;
[0047] Figure 5 This is a schematic diagram of the structure of a code processing device in an embodiment of the present application;
[0048] Figure 6 This is a structural diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0050] The core of this application is to provide a code processing method that can be applied to the development scenarios of HarmonyOS applications.
[0051] In the related art, when developers use ArkUI to develop HarmonyOS applications, most of their time is spent on repeatedly writing the same or similar business code. For example, for a sliding list, every time an item is added to the list, the developer needs to complete the following operations:
[0052] 1. Write custom UI components;
[0053] 2. Write the data model entities required for custom UI components;
[0054] 3. Write a parser to convert the agreed protocol into data model entities;
[0055] 4. Write the exposure tracking reporting logic in the custom UI component;
[0056] 5. Write an adapter to provide a builder for custom UI components based on the data model;
[0057] 6. Associate the sliding list with the adapter and build the list items through the adapter instance.
[0058] The code for steps 3-6 (parser, exposure tracking reporting logic, adapter, and list association) written for each newly added custom UI component is similar and repetitive. For example, each new custom component requires reimplementing the adapter binding and exposure tracking reporting logic, which prolongs the development cycle. Differences in coding styles among developers lead to confusing code structure and increase the probability of errors. For example, different developers may implement exposure tracking reporting logic in inconsistent ways, making it more difficult to troubleshoot errors.
[0059] During the compilation and construction phase of a HarmonyOS application, an embodiment of the present application identifies a target custom component modified by a predefined target decorator, analyzes the parameter information of the target custom component using abstract syntax tree parsing technology, and obtains metadata for the target code. The target code includes the registration class code of the registration management center and the specific implementation class code of the abstract adapter. The metadata is input into a template engine, and the target code is generated using a predefined registration class generation template and an adapter implementation class generation template. During the runtime phase of the HarmonyOS application, the target code is combined with the target custom component for operation. This eliminates the need to rewrite the target code and allows for automatic target code generation, which helps reduce repetitive coding and shortens the development cycle. Furthermore, using templates to generate the target code unifies code specifications, constrains code structure, simplifies error detection, and reduces maintenance costs.
[0060] See also Figure 1 FIG. 1 is a flowchart of an implementation of a code processing method provided in an embodiment of the present application. The method may include the following steps:
[0061] S110: During the compilation and construction phase of the HarmonyOS application, identify the target custom component modified by the predefined target decorator.
[0062] In an embodiment of the present application, a developer can write a target custom component according to business needs, and predefine a target decorator, such as the @Cell decorator, and then use the predefined target decorator to modify the target custom component.
[0063] The target custom component can be understood as the target custom UI component. In ArkUI, all UI content is components. Those directly provided by the framework are called system components, and those defined by the developer are called custom components.
[0064] During the compilation and construction phase of the HarmonyOS application, the target custom components modified by the predefined target decorators can be identified. Optionally, the target custom components modified by the predefined target decorators can be identified through a custom Hvigor plug-in. Hvigor is an automated build tool based on the task management mechanism, mainly for the ArkTS development scenario of HarmonyOS applications. ArkTS is the application development language of the HarmonyOS ecosystem, based on TypeScript (a computer programming language) extension. Hvigor allows developers to implement their own plug-ins, developers can define their own build logic and extend the build process. The Hvigor plug-in can be mounted when the Hvigor build tool compiles and builds the HarmonyOS application.
[0065] The target decorator is an ArkTS decorator. AikTS decorator is a metaprogramming syntax feature based on TypeScript. It can mark classes, methods, properties or parameters with the @ symbol to extend their functions or behaviors in a declarative way.
[0066] By modifying the target custom component with a target decorator, you can mark the parameters of interest in the target custom component.
[0067] S120: Analyze the parameter information of the target custom component using the abstract syntax tree parsing technology to obtain metadata of the target code.
[0068] The target code includes the registration class code of the registration management center and the specific implementation class code of the abstract adapter.
[0069] In an embodiment of the present application, after identifying the target custom component modified by the predefined target decorator, the parameter information of the target custom component can be further analyzed using the Abstract Syntax Tree (AST) parsing technology. Optionally, the parameter information of the target custom component can be analyzed using the abstract syntax tree parsing technology through the Hvigor plug-in. Optionally, the abstract syntax tree parsing technology may include TypeScript abstract syntax tree parsing technology. TypeScript abstract syntax tree parsing technology can achieve static analysis of the code, metadata extraction and automatic code generation by analyzing the grammatical structure of the source code.
[0070] Analyzing the parameter information of the target custom component using the abstract syntax tree parsing technology can be understood as analyzing the parameter information modified by the target decorator in the target custom component and the parameter information associated with the file, module, etc. using the abstract syntax tree parsing technology.
[0071] By analyzing the parameter information of the target custom component, the metadata of the target code can be obtained.
[0072] The metadata of the target code may include: identification information of the target custom component, and data model entity information associated with the target custom component. Among them, the identification information of the target custom component may include the name information of the target custom component and the type name information of the target custom component. The data model entity information associated with the target custom component may include the name information of the data model entity associated with the target custom component. The metadata of the target code may also include at least one of the configuration information for indicating whether the automatic exposure tracking point reporting function is enabled, the file information associated with the target custom component, the module information associated with the target custom component, and the custom adapter information of the target custom component. Exposure tracking points can be understood as tracking points reported when the UI component appears within the visible range of the view.
[0073] The target code can include the registration class code of the registration management center and the specific implementation class code of the abstract adapter. The registration class code of the registration management center can be used to globally manage the registration and retrieval of adapter instances, and the specific implementation class code of the abstract adapter can be used to dynamically bind data model entities to target custom components.
[0074] S130: Input the metadata into the template engine, use the predefined registration class to generate the template and the adapter to implement the class to generate the template, and generate the target code.
[0075] In the embodiment of the present application, a registration class generation template and an adapter implementation class generation template may be predefined.
[0076] Abstract syntax tree parsing technology is used to analyze the parameter information of the target custom component. After obtaining the metadata of the target code, the metadata can be further input into the template engine. The registration class generation template and the adapter implementation class generation template can call the target custom component based on the metadata and generate the target code so that the generated target code can automatically locate the target custom component.
[0077] Optionally, the template engine may include a Handlebars template engine, which can automatically generate code through its declarative template syntax and data-driven rendering mechanism.
[0078] Optionally, metadata can be input into the template engine through the Hvigor plug-in, and the predefined registration class generation template and adapter implementation class generation template are used to generate the target code.
[0079] S140: During the running phase of the HarmonyOS application, the target code is combined with the target custom component for running.
[0080] During the compilation and construction phase of the HarmonyOS application, after the target custom component is identified and the target code is generated, during the running phase of the HarmonyOS application, the target code can be combined with the target custom component to run to achieve the corresponding interface rendering.
[0081] By applying the method provided in the embodiments of the present application, during the compilation and construction phase of a HarmonyOS application, the target custom component modified by the predefined target decorator is identified, and the parameter information of the target custom component is analyzed using abstract syntax tree parsing technology to obtain metadata of the target code. The target code includes the registration class code of the registration management center and the specific implementation class code of the abstract adapter. The metadata is input into the template engine, and the target code is generated using the predefined registration class generation template and the adapter implementation class generation template. During the runtime phase of the HarmonyOS application, the target code is combined with the target custom component for operation. For different custom components, there is no need to repeatedly write the target code, and the target code can be automatically generated, which helps reduce the repeated coding work and shorten the development cycle. In addition, using templates to generate the target code can unify code specifications, constrain code structure, reduce the difficulty of error detection, and reduce maintenance costs.
[0082] In some embodiments of the present application, the parameter information of the target custom component may include:
[0083] Identification information of the target custom component;
[0084] The data model entity information associated with the target custom component.
[0085] The identification information of the target custom component may include the name information of the target custom component and the type name information of the target custom component. The data model entity information associated with the target custom component may include the name information of the data model entity associated with the target custom component.
[0086] Optionally, the parameter information of the target custom component may further include at least one of the following:
[0087] Configuration information indicating whether to enable the automatic exposure tracking reporting function;
[0088] File information associated with the target custom component;
[0089] Module information associated with the target custom component;
[0090] Custom adapter information for the target custom component.
[0091] By analyzing the above parameter information of the target custom component using abstract syntax tree parsing technology, the metadata of the target code can be accurately obtained to generate the target code based on the metadata.
[0092] like Figure 2As shown, after identifying the target custom component modified by the predefined target decorator, an abstract syntax tree can be generated based on the target custom component. Then, by traversing the branch nodes of the abstract syntax tree, the file information associated with the target custom component can be collected, the module information associated with the target custom component can be recorded, and the parameter information modified by the target decorator can be found. The parameter information modified by the target decorator may include: type name information of the target custom component, data model entity information associated with the target custom component, custom adapter information of the target custom component, and configuration information for indicating whether the automatic exposure tracking reporting function is enabled. Then, based on the file information associated with the target custom component, the module information associated with the target custom component, and the parameter information modified by the target decorator, the metadata of the target code can be generated.
[0093] In some embodiments of the present application, step S130 inputs metadata into a template engine, generates a template using a predefined registration class and an adapter implementation class, and generates a target code, which may include the following steps:
[0094] Input the metadata into the template engine, use the predefined registration class to generate a template, and generate the registration class code of the registration management center based on the first information in the metadata;
[0095] Using the predefined adapter implementation class generation template, based on the second information in the metadata, generate the concrete implementation class code of the abstract adapter;
[0096] The first information includes identification information of the target custom component; the second information includes identification information of the target custom component and data model entity information associated with the target custom component;
[0097] Alternatively, the first information includes identification information of the target custom component; the second information includes configuration information for indicating whether to enable the automatic exposure point reporting function, file information associated with the target custom component, module information associated with the target custom component, at least one item of custom adapter information of the target custom component, as well as identification information of the target custom component and data model entity information associated with the target custom component.
[0098] For the convenience of description, the above steps are combined for explanation.
[0099] In an embodiment of the present application, the parameter information of the target custom component is analyzed using abstract syntax tree parsing technology. After obtaining the metadata of the target code, the metadata can be input into the template engine, and a template can be generated using a predefined registration class. Based on the identification information of the target custom component in the metadata, the registration class code of the registration management center is generated.
[0100] The predefined adapter implementation class generation template is used to generate the specific implementation class code of the abstract adapter based on the identification information of the target custom component in the metadata and the data model entity information associated with the target custom component.
[0101] Alternatively, a predefined adapter implementation class generation template is used to generate the specific implementation class code of the abstract adapter based on the configuration information in the metadata indicating whether the automatic exposure tracking point reporting function is enabled, the file information associated with the target custom component, the module information associated with the target custom component, at least one item of the custom adapter information of the target custom component, as well as the identification information of the target custom component and the data model entity information associated with the target custom component.
[0102] By using the registration class generation template and the adapter implementation class generation template, the registration class code of the registration management center and the specific implementation class code of the abstract adapter can be automatically generated based on the relevant information in the metadata, making the generated code standardized.
[0103] In some embodiments of the present application, step S110 of identifying a target custom component decorated by a predefined target decorator may include the following steps:
[0104] Scan the code file within a predetermined scanning range to obtain a scanning result;
[0105] In the scan results, filter out target custom components modified by predefined target decorators.
[0106] For the convenience of description, the above steps are combined for explanation.
[0107] In the embodiment of the present application, the scanning range may be determined first. Alternatively, the scanning range may be determined based on configuration information provided by the developer (such as project path configuration information).
[0108] After determining the scan scope, the code files within the scan scope are scanned to obtain scan results, which include one or more code files. In the scan results, target custom components modified by predefined target decorators can be filtered out.
[0109] Scanning and filtering target custom components modified by predefined target decorators within a predetermined scanning range helps improve recognition accuracy.
[0110] In some embodiments of the present application, step S140, in which the target code is combined with the target custom component and executed, may include the following steps:
[0111] Run the registration class code of the registration management center to register the concrete implementation class of the abstract adapter with the registration management center;
[0112] When there is a need for interface rendering of the target custom component, obtain the abstract adapter through the registration management center;
[0113] Run the specific implementation class code of the abstract adapter and call the target custom component to complete the interface rendering.
[0114] For the convenience of description, the above steps are combined for explanation.
[0115] In an embodiment of the present application, after identifying the target custom component and generating the registration class code of the registration management center and the specific implementation class code of the abstract adapter, during the running phase of the Harmony application, the registration class code of the registration management center can be run to register the specific implementation class of the abstract adapter to the registration management center.
[0116] When there is a need for interface rendering for the target custom component, such as rendering the data items corresponding to the target custom component, you can obtain the abstract adapter through the registration management center, then run the specific implementation class code of the abstract adapter, call the target custom component, and add the instance of the target custom component to the interface rendering application scenario to complete the interface rendering.
[0117] By combining the target code with the target custom component and running it, the interface rendering can be quickly achieved.
[0118] In some embodiments of the present application, during the running phase of the Hongmeng application, the method may further include the following steps:
[0119] Inject the environment context into the target custom component. The environment context has a built-in hash table for maintaining exposure tracking points.
[0120] In an embodiment of the present application, during the runtime phase of a HarmonyOS application, when an abstract adapter is obtained from the registration management center and a target custom component is called through the abstract adapter, the environment context can be injected into the target custom component. The environment context includes a built-in hash table for maintaining exposure tracking points. By injecting the environment context, the target custom component can be decoupled from the environment.
[0121] The embodiment of the present application implements the processing of custom components through code generation technology based on the Harmony system, is adapted to the ArkUI framework, and combined with the Hvigor plug-in, can enable the Harmony application to automatically generate code that needs to be rewritten during compilation and construction.
[0122] like Figure 3 As shown, taking the target decorator as the @Cell decorator as an example, the overall process of the embodiment of the present application is as follows:
[0123] Developers write custom components based on business needs;
[0124] Developers use the predefined @Cell decorator to modify the target custom component and flexibly configure parameters according to needs;
[0125] During the compilation and construction phase, the target custom component decorated with the @Cell decorator is identified through the custom Hvigor plug-in;
[0126] Analyze the parameter information of the target custom component to obtain metadata. Based on the metadata, generate the registration class code of the registration management center and the specific implementation class code of the abstract adapter. The specific implementation class code of the abstract adapter can be used for data model parsing, providing component builders, and reporting exposure points. The registration class code of the registration management center can be used to register the abstract adapter.
[0127] Package the generated code and run it together.
[0128] Run the framework as Figure 4 As shown, it includes the following parts:
[0129] Registration management center (HsCellManager);
[0130] Basic data model interface (HsBean), all data needs to implement this interface;
[0131] Environment context (HsContext), created externally and containing environment-related information, such as a hash table for maintaining exposure tracking points;
[0132] The abstract adapter (HsCell) is used to connect application scenarios (such as sliding lists) and custom components, acting as a link. Specifically, it can implement the following functions: data model parsing, exposure tracking point reporting, and converting custom components according to the data model.
[0133] When accessing the framework, you can add a custom Hvigor plug-in to the Hvigor plug-in configuration and pass in the plug-in's custom configuration items to control the plug-in scope and behavior.
[0134] The embodiment of the present application implements code generation through the Hvigor plug-in, which can effectively reduce the repetitive code writing work in the development of custom components. Through the parameter configuration of the predefined ArkTS decorator, the opening and closing of related functions can be flexibly configured. By injecting the environment context, the custom component can be decoupled from the environment. The automatic code generation method helps to standardize the code and reduce the probability of human writing errors.
[0135] Corresponding to the above method embodiment, the embodiment of the present application further provides a code processing device. The code processing device described below and the code processing method described above can refer to each other.
[0136] See also Figure 5 As shown, the code processing device 500 may include the following units:
[0137] The identification unit 510 is used to identify the target custom component modified by the predefined target decorator during the compilation and construction phase of the Hongmeng application;
[0138] The obtaining unit 520 is used to analyze the parameter information of the target custom component using the abstract syntax tree parsing technology to obtain the metadata of the target code, which includes the registration class code of the registration management center and the specific implementation class code of the abstract adapter;
[0139] The generating unit 530 is used to input the metadata into the template engine, generate the template using the predefined registration class and adapter implementation class, and generate the target code;
[0140] The running unit 540 is used to combine the target code with the target custom component for running during the running phase of the Harmony application.
[0141] By using the apparatus provided in the embodiments of the present application, during the compilation and construction phase of a HarmonyOS application, the target custom component modified by the predefined target decorator is identified, and the parameter information of the target custom component is analyzed using abstract syntax tree parsing technology to obtain metadata of the target code. The target code includes the registration class code of the registration management center and the specific implementation class code of the abstract adapter. The metadata is input into the template engine, and the target code is generated using the predefined registration class generation template and the adapter implementation class generation template. During the runtime phase of the HarmonyOS application, the target code is combined with the target custom component for operation. For different custom components, there is no need to repeatedly write the target code; the target code can be automatically generated, which helps reduce the repeated coding work and shorten the development cycle. In addition, using templates to generate the target code can unify code specifications, constrain code structure, reduce the difficulty of error detection, and reduce maintenance costs.
[0142] In some embodiments of the present application, the parameter information of the target custom component includes:
[0143] Identification information of the target custom component;
[0144] The data model entity information associated with the target custom component.
[0145] In some embodiments of the present application, the parameter information of the target custom component further includes at least one of the following:
[0146] Configuration information indicating whether to enable the automatic exposure tracking reporting function;
[0147] File information associated with the target custom component;
[0148] Module information associated with the target custom component;
[0149] Custom adapter information for the target custom component.
[0150] In some embodiments of the present application, the generating unit 530 is specifically configured to:
[0151] Input the metadata into the template engine, use the predefined registration class to generate a template, and generate the registration class code of the registration management center based on the first information in the metadata;
[0152] Using the predefined adapter implementation class generation template, based on the second information in the metadata, generate the concrete implementation class code of the abstract adapter;
[0153] The first information includes identification information of the target custom component; the second information includes identification information of the target custom component and data model entity information associated with the target custom component;
[0154] Alternatively, the first information includes identification information of the target custom component; the second information includes configuration information for indicating whether to enable the automatic exposure point reporting function, file information associated with the target custom component, module information associated with the target custom component, at least one item of custom adapter information of the target custom component, as well as identification information of the target custom component and data model entity information associated with the target custom component.
[0155] In some embodiments of the present application, the identification unit 510 is specifically configured to:
[0156] Scan the code file within a predetermined scanning range to obtain a scanning result;
[0157] In the scan results, filter out target custom components modified by predefined target decorators.
[0158] In some embodiments of the present application, the operation unit 540 is specifically configured to:
[0159] Run the registration class code of the registration management center to register the concrete implementation class of the abstract adapter with the registration management center;
[0160] When there is a need for interface rendering of the target custom component, obtain the abstract adapter through the registration management center;
[0161] Run the specific implementation class code of the abstract adapter and call the target custom component to complete the interface rendering.
[0162] In some embodiments of the present application, an injection unit is further included for:
[0163] During the running phase of the HarmonyOS application, the environment context is injected into the target custom component. The environment context has a built-in hash table for maintaining exposure tracking points.
[0164] Regarding the apparatus in the above embodiment, the specific manner in which each unit performs operations has been described in detail in the embodiment of the method, and will not be elaborated on here.
[0165] Corresponding to the above method embodiment, the embodiment of the present application also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and runnable on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned code processing method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0166] like Figure 6 6 is a schematic diagram of the structure of an electronic device, which may include: a processor 610, a memory 611, a communication interface 612 and a communication bus 613. The processor 610, the memory 611 and the communication interface 612 communicate with each other via the communication bus 613.
[0167] In the embodiment of the present application, the processor 610 may be a central processing unit (CPU), an application-specific integrated circuit, a digital signal processor, a field programmable gate array, or other programmable logic devices.
[0168] The processor 610 may call a computer program stored in the memory 611 . Specifically, the processor 610 may execute operations in the embodiment of the code processing method.
[0169] The memory 611 is used to store one or more programs. The program may include program code, and the program code includes computer operating instructions. In the embodiment of the present application, the memory 611 stores at least a program for implementing the following functions:
[0170] During the compilation and construction phase of HarmonyOS applications, identify target custom components modified by predefined target decorators;
[0171] Analyze the parameter information of the target custom component using abstract syntax tree parsing technology to obtain the metadata of the target code, which includes the registration class code of the registration management center and the specific implementation class code of the abstract adapter;
[0172] Input metadata into the template engine, use predefined registration class to generate template and adapter implementation class to generate template, and generate target code;
[0173] During the running phase of the HarmonyOS application, the target code is combined with the target custom component for running.
[0174] In one possible implementation, the memory 611 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function, etc.; the data storage area may store data created during use.
[0175] In addition, the memory 611 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device or other volatile solid-state storage device.
[0176] The communication interface 612 may be an interface of a communication module, used to connect to other devices or systems.
[0177] Of course, it needs to be explained that Figure 6 The structure shown does not constitute a limitation on the electronic device in the embodiment of the present application. In actual applications, the electronic device may include Figure 6 More or fewer components than shown, or combinations of certain components.
[0178] The present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the various processes of the above-mentioned code processing method embodiment are implemented, and the same technical effects are achieved. To avoid repetition, the details are not described here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0179] In addition, an embodiment of the present application further provides a computer program product or a computer program, which may include computer instructions, which may be stored in a computer-readable storage medium. The processor of the electronic device reads the computer instructions from the computer-readable storage medium, and the processor may execute the computer instructions so that the electronic device executes the description of the code processing method in the corresponding embodiment above, and therefore, it will not be repeated here. In addition, the description of the beneficial effects of adopting the same method will not be repeated. For technical details not disclosed in the computer program product or computer program embodiment involved in this application, please refer to the description of the method embodiment of this application.
[0180] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0181] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0182] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.
[0183] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the embodiments of this application can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0184] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0185] In the embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0186] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0187] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0188] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a magnetic disk, or an optical disk.
[0189] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of 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 processing method, characterized in that: include: During the compilation and construction phase of HarmonyOS applications, identify target custom components modified by predefined target decorators; Analyzing the parameter information of the target custom component using abstract syntax tree parsing technology to obtain metadata of the target code, wherein the target code includes the registration class code of the registration management center and the specific implementation class code of the abstract adapter; Inputting the metadata into a template engine, generating the target code by using a predefined registration class generation template and an adapter implementation class generation template; During the running phase of the HarmonyOS application, the target code is combined with the target custom component for running.
2. The method according to claim 1, characterized in that The parameter information of the target custom component includes: Identification information of the target custom component; The data model entity information associated with the target custom component.
3. The method according to claim 2, characterized in that The parameter information of the target custom component also includes at least one of the following: Configuration information indicating whether to enable the automatic exposure tracking reporting function; File information associated with the target custom component; Module information associated with the target custom component; The custom adapter information of the target custom component.
4. The method according to claim 1, wherein The step of inputting the metadata into a template engine, generating a template using a predefined registration class and an adapter implementation class, and generating the target code comprises: Inputting the metadata into a template engine, using a predefined registration class to generate a template, and generating a registration class code for the registration management center based on the first information in the metadata; Generate a specific implementation class code of the abstract adapter based on the second information in the metadata using a predefined adapter implementation class generation template; Wherein, the first information includes the identification information of the target custom component; the second information includes the identification information of the target custom component and the data model entity information associated with the target custom component; Alternatively, the first information includes identification information of the target custom component; the second information includes configuration information for indicating whether the automatic exposure point reporting function is enabled, file information associated with the target custom component, module information associated with the target custom component, at least one item of custom adapter information of the target custom component, as well as identification information of the target custom component and data model entity information associated with the target custom component.
5. The method according to claim 1, wherein The identifying target custom component modified by the predefined target decorator includes: Scan the code file within a predetermined scanning range to obtain a scanning result; In the scanning results, target custom components modified by predefined target decorators are filtered out.
6. The method according to claim 1, characterized in that The combining the target code with the target custom component for running includes: Run the registration class code of the registration management center to register the specific implementation class of the abstract adapter with the registration management center; When there is a need for interface rendering of the target custom component, obtaining the abstract adapter through the registration management center; Run the specific implementation class code of the abstract adapter and call the target custom component to complete the interface rendering.
7. The method according to any one of claims 1 to 6, characterized in that During the running phase of the Hongmeng application, the method further includes: An environment context is injected into the target custom component, wherein the environment context has a built-in hash table for maintaining exposure tracking points.
8. A code processing device, characterized in that: include: The identification unit is used to identify the target custom components modified by the predefined target decorator during the compilation and construction phase of the HarmonyOS application; An obtaining unit, configured to analyze parameter information of the target custom component using an abstract syntax tree parsing technique to obtain metadata of a target code, wherein the target code includes a registration class code of a registration management center and a specific implementation class code of an abstract adapter; A generating unit, configured to input the metadata into a template engine, generate the target code by using a predefined registration class generation template and an adapter implementation class generation template; The running unit is used to combine the target code with the target custom component for operation during the running phase of the Harmony application.
9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the code processing method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the code processing method according to any one of claims 1 to 7.
Citation Information
Cited By
Decorator driving component generation method of visual programming system
CN121300781A