View component management class generation method, device, equipment and storage medium
Patent Information
- Application Number
- CN202210928520.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-03
- Publication Date
- 2026-09-29
- Estimated Expiration
- 2042-08-03
AI Technical Summary
[0003]其中,key为自定义参数,每次新建一个view组件,都需要自定义一个key,并向ViewFactoryUtil类注册该key对应的视图组件,缺少统一管理和规范化,存在组件构建效率低和代码维护效率差的问题
[0025]本发明提供的技术方案中,响应针对目标软件项目的代码编译指令,在编译环境中执行与所述代码编译指令对应的注解处理函数,所述目标软件项目包括多个视图组件;通过所述注解处理函数扫描解析所述多个视图组件,得到各视图组件对应的组件注解数据,所述组件注解数据包括组件唯一标识;当所述组件唯一标识不为空值时,基于各视图组件对应的组件注解数据生成视图组件管理类。本发明实施例中,在目标软件项目编译过程中,通过注解处理函数扫描解析多个视图组件,得到各视图组件对应的组件注解数据,当组件唯一标识不为空值时,基于各视图组件对应的组件注解数据生成视图组件管理类,在业务层通过视图组件管理类统一调用多个视图组件,减少了代码维护易错性和复杂性,并提高了视图组件构建效率。
Smart Images

Figure CN115495149B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, device, and storage medium for generating view component management classes. Background Technology
[0002] The existing Android client project is under continuous development and has accumulated some utility classes. One of these utility classes is ViewFactoryUtil, which is used to render the corresponding view by using a unique identifier string key, that is, to instantiate different view components. The view components include methods for setting view-related data, etc.
[0003] Here, the key is a custom parameter. Every time a new view component is created, a custom key needs to be defined and the view component corresponding to the key needs to be registered with the ViewFactoryUtil class. This lack of unified management and standardization leads to problems such as low component construction efficiency and poor code maintenance efficiency. Summary of the Invention
[0004] This invention provides a method, apparatus, device, and storage medium for generating a view component management class, which is used to uniformly call multiple view components through the view component management class at the business layer, reducing the error-proneness and complexity of code maintenance, and improving the efficiency of view component construction.
[0005] To achieve the above objectives, a first aspect of the present invention provides a method for generating a view component management class, comprising: responding to a code compilation instruction for a target software project; executing an annotation processing function corresponding to the code compilation instruction in a compilation environment, wherein the target software project includes multiple view components; scanning and parsing the multiple view components through the annotation processing function to obtain component annotation data corresponding to each view component, wherein the component annotation data includes a unique component identifier; and generating a view component management class based on the component annotation data corresponding to each view component when the unique component identifier is not null.
[0006] In one feasible implementation, before responding to the code compilation instructions for the target software project and executing the annotation processing function corresponding to the code compilation instructions in the compilation environment, and before the target software project includes multiple view components, the view component management class generation method further includes: creating the annotation processing function for the target software project, the annotation processing function inheriting from the abstract parser AbstractProcessor; adding custom annotation data to the source code corresponding to the multiple view components respectively, the custom annotation data including preset annotation element names and the component annotation data.
[0007] In one feasible implementation, the step of scanning and parsing the multiple view components through the annotation processing function to obtain the component annotation data corresponding to each view component includes: scanning and parsing multiple view component classes containing preset annotation element names through the annotation processing function to obtain the component annotation data corresponding to each view component, wherein each view component corresponds one-to-one with each view component class.
[0008] In one feasible implementation, the component annotation data further includes: component function description information, component instantiation alias, component input parameters, and business parameters corresponding to the target software project.
[0009] In one feasible implementation, the step of generating a view component management class based on the component annotation data corresponding to each view component when the component unique identifier is not null includes: constructing view component class structure data based on the component annotation data corresponding to each view component when the component unique identifier is not null; and converting the view component class structure data into a view component management class through a preset code generation framework.
[0010] In one feasible implementation, the step of constructing view component class structure data based on the component annotation data corresponding to each view component when the component unique identifier is not null includes: setting member variables based on the component unique identifier in the component annotation data corresponding to each view component when the component unique identifier is not null; initializing parameter data, and constructing a view component generation interface function according to the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component, wherein the other annotation data is annotation data other than the component unique identifier; and merging the member variables and the view component generation interface function into view component class structure data.
[0011] In one feasible implementation, the step of constructing the view component generation interface function based on the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component includes: setting a preset function name as the function name corresponding to the view component generation interface function; sequentially setting the parameter data as the interface parameters corresponding to the view component generation interface function based on the parameter name and parameter type order; determining the view component class corresponding to each view component according to the other annotation data in the component annotation data corresponding to each view component; and mapping the member variables and the view component classes corresponding to each view component one by one based on the interface parameters to obtain the function body corresponding to the view component generation interface function.
[0012] In one feasible implementation, the step of converting the view component class structure data into a view component management class using a preset code generation framework includes: initializing the view component management class according to a preset component management class name; adding the view component class structure data to the view component management class; and exporting the view component management class to a view component management file using a file generation function in the preset code generation framework.
[0013] In one feasible implementation, after generating a view component management class based on the component annotation data corresponding to each view component when the component unique identifier is not null, the view component management class generation method further includes: referencing the view component management file corresponding to the view component management class in the target business application; instantiating the view component management class to obtain a target management class object; obtaining the target view component identifier value corresponding to the target business application, and calling the view component generation interface function corresponding to the target management class object according to the target management class object and the target view component identifier value, so as to realize the user interface rendering processing of the target view component.
[0014] A second aspect of the present invention provides a view component management class generation apparatus, comprising: an execution module, configured to respond to code compilation instructions for a target software project and execute an annotation processing function corresponding to the code compilation instructions in a compilation environment, wherein the target software project includes multiple view components; a scanning and parsing module, configured to scan and parse the multiple view components through the annotation processing function to obtain component annotation data corresponding to each view component, wherein the component annotation data includes a unique component identifier; and a generation module, configured to generate a view component management class based on the component annotation data corresponding to each view component when the unique component identifier is not null.
[0015] In one feasible implementation, the view component management class generation device further includes: a creation module for creating the annotation processing function for the target software project, wherein the annotation processing function inherits from the abstract parser AbstractProcessor; and an adding module for adding custom annotation data to the source code corresponding to the plurality of view components respectively, wherein the custom annotation data includes a preset annotation element name and the component annotation data.
[0016] In one feasible implementation, the scanning and parsing module is specifically used to: scan and parse multiple view component classes containing preset annotation element names through the annotation processing function, and obtain the component annotation data corresponding to each view component, with each view component corresponding to each view component class.
[0017] In one feasible implementation, the component annotation data further includes: component function description information, component instantiation alias, component input parameters, and business parameters corresponding to the target software project.
[0018] In one feasible implementation, the generation module further includes: a construction unit, used to construct view component class structure data based on the component annotation data corresponding to each view component when the component unique identifier is not null; and a conversion unit, used to convert the view component class structure data into a view component management class through a preset code generation framework.
[0019] In one feasible implementation, the construction unit further includes: a setting subunit, used to set member variables based on the component unique identifier in the component annotation data corresponding to each view component when the component unique identifier is not null; a construction subunit, used to initialize parameter data and construct a view component generation interface function according to the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component, wherein the other annotation data is annotation data other than the component unique identifier; and a merging subunit, used to merge the member variables and the view component generation interface function into view component class structure data.
[0020] In one feasible implementation, the construction subunit is specifically used for: setting a preset function name as the function name corresponding to the view component generation interface function; sequentially setting the parameter data as the interface parameters corresponding to the view component generation interface function based on the parameter name and parameter type order; determining the view component class corresponding to each view component according to other annotation data in the component annotation data corresponding to each view component; and mapping the member variables and the view component classes corresponding to each view component one by one based on the interface parameters to obtain the function body corresponding to the view component generation interface function.
[0021] In one feasible implementation, the conversion unit is specifically used to: initialize a view component management class according to a preset component management class name; add the view component class structure data to the view component management class; and export the view component management class to a view component management file through a file generation function in a preset code generation framework.
[0022] In one feasible implementation, the view component management class generation device further includes: a referencing module, used to reference the view component management file corresponding to the view component management class in the target business application; an instantiation module, used to instantiate the view component management class to obtain a target management class object; and a calling module, used to obtain the target view component identifier value corresponding to the target business application, and call the view component generation interface function corresponding to the target management class object according to the target management class object and the target view component identifier value, so as to realize the user interface rendering processing of the target view component.
[0023] A third aspect of the present invention provides a view component management class generation device, comprising: a memory and at least one processor, wherein the memory stores instructions, and the memory and the at least one processor are interconnected via a line; the at least one processor invokes the instructions in the memory to cause the view component management class generation device to execute the view component management class generation method described above.
[0024] A fourth aspect of the present invention provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the above-described view component management class generation method.
[0025] In the technical solution provided by this invention, in response to code compilation instructions for a target software project, an annotation processing function corresponding to the code compilation instructions is executed in the compilation environment. The target software project includes multiple view components. The annotation processing function scans and parses the multiple view components to obtain component annotation data corresponding to each view component. The component annotation data includes a unique component identifier. When the unique component identifier is not null, a view component management class is generated based on the component annotation data corresponding to each view component. In this embodiment of the invention, during the compilation process of the target software project, the annotation processing function scans and parses multiple view components to obtain component annotation data corresponding to each view component. When the unique component identifier is not null, a view component management class is generated based on the component annotation data corresponding to each view component. Multiple view components are then uniformly called through the view component management class at the business layer, reducing code maintenance error-proneness and complexity, and improving the efficiency of view component construction. Attached Figure Description
[0026] Figure 1 This is a schematic diagram of an embodiment of the view component management class generation method in this invention;
[0027] Figure 2 This is a schematic diagram of another embodiment of the view component management class generation method in this invention;
[0028] Figure 3This is a schematic diagram of an embodiment of the view component management class generation device in this invention;
[0029] Figure 4 This is a schematic diagram of another embodiment of the view component management class generation device in this invention;
[0030] Figure 5 This is a schematic diagram of an embodiment of the view component management class generation device in this invention. Detailed Implementation
[0031] This invention provides a method, apparatus, device, and storage medium for generating a view component management class, which is used to uniformly call multiple view components through the view component management class at the business layer, reducing code maintenance error and complexity, and improving the efficiency of view component construction.
[0032] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” or “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0033] For ease of understanding, the specific process of the embodiments of the present invention is described below. Please refer to [link / reference]. Figure 1 One embodiment of the view component management class generation method in this invention includes:
[0034] 101. Respond to code compilation instructions for the target software project and execute the annotation processing function corresponding to the code compilation instructions in the compilation environment. The target software project includes multiple view components.
[0035] The target software project can be a game software project, which includes a character details page. The character details page includes multiple view components, such as a character introduction view component, a character selling price view component, a character status view component, a skill view component, an item view component, and a magic weapon view component.
[0036] Specifically, the server responds to code compilation instructions for the target software project. These instructions include annotation processors corresponding to the code compilation instructions. The server calls the annotation processor (i.e., the abstract parser) corresponding to the code compilation instructions in the compilation environment and executes the annotation processing function corresponding to the annotation processor. The target software project includes multiple view components. Further, before step 101, the server creates annotation processing functions for the target software project, which inherit from the abstract parser (AbstractProcessor). The server adds custom annotation data to the source code corresponding to each of the multiple view components. This custom annotation data includes a preset annotation element name and component annotation data. The preset annotation element name can be `@ViewFactory`, and the component annotation data can be as follows: `(key = "new_role_info_view", hasproductFactory = true, alias = "createViewDelegate")`, where the annotation parameter `key` represents the unique identifier of the component, the annotation parameter `hasproductFactory` indicates the business parameters corresponding to the target software project, and the annotation parameter `alias` indicates the component instantiation alias. It should be noted that all annotation parameters in the component annotation data are represented as key-value pairs. Correspondingly, the data format for custom annotations can be represented as `@ViewFactory(key = "new_role_info_view", hasproductFactory = true, alias = "createViewDelegate")`.
[0037] It is understood that the executing entity of this invention can be a view component management class generation device, a terminal, or a server; no specific limitation is made here. This embodiment of the invention will be described using a server as an example.
[0038] 102. Scan and parse multiple view components through the annotation processing function to obtain the component annotation data corresponding to each view component. The component annotation data includes the component's unique identifier.
[0039] For example, the homepage content of a target software project includes advertising view components, instruction view components, and recommendation view components. The source code for each view component is annotated with component annotation data, which includes a unique component identifier (key). Specifically, the server intercepts and processes the annotations using an annotation processor, and then sequentially scans multiple view components using an annotation processing function to obtain the custom annotation data corresponding to each view component. The server then performs string truncation and data format conversion on the custom annotation data for each view component according to a preset data format to obtain the component annotation data for each view component, which includes the unique component identifier. The data format of the component annotation data for each view component remains consistent; the data format can be an array format or other data formats, which are not specifically limited here.
[0040] 103. When the component's unique identifier is not null, generate a view component management class based on the component annotation data corresponding to each view component.
[0041] It's important to note that the view component management class is a multi-view componentization code generation plugin based on an Android annotation processing tool. The server dynamically generates a global view componentization management class (i.e., the view component management class) by scanning and processing custom annotation data with preset annotation element names during the target software project's compilation. The source code for this class includes instantiation of each view component in the target software, unique component identifier keys, and parsing code for each view component instance. This provides a unified entry point for managing multiple view components in the target software project, avoiding code maintenance errors and complexity. Simultaneously, the view component management class is called uniformly in the business layer, establishing usage standards and improving view component development efficiency.
[0042] In some embodiments, when the component unique identifier is not null, the server obtains the parameter data corresponding to the preset annotation element name, and sets the member variables corresponding to each view component in the view component management class based on the component unique identifier. The server generates the corresponding target interface function (view component generation interface function) according to the parameter data and the component annotation data corresponding to each view component, and converts the member variables and target interface function into a view component management class according to the preset class code generation rules. The server exports the view component management class to a file according to the preset code generation logic and saves it in a preset file directory. In this view component management class, one component unique identifier corresponds to one view component.
[0043] Understandably, the server renders the corresponding view component using the unique identifier key of each component in the view component management class, i.e., instantiating different view components. For the functional views of each module in the target software project, the server can distribute unique component identifiers to the terminal via an array, dynamically adding or removing corresponding view functions online, increasing the flexibility and operability of the terminal view layout.
[0044] In this embodiment of the invention, during the compilation of the target software project, multiple view components are scanned and parsed through the annotation processing function to obtain the component annotation data corresponding to each view component. When the unique identifier of the component is not null, a view component management class is generated based on the component annotation data corresponding to each view component. Multiple view components are called uniformly through the view component management class in the business layer, which reduces the error-proneness and complexity of code maintenance and improves the efficiency of view component construction.
[0045] Please see Figure 2 Another embodiment of the view component management class generation method in this invention includes:
[0046] 201. Respond to code compilation instructions for the target software project and execute the annotation processing function corresponding to the code compilation instructions in the compilation environment. The target software project includes multiple view components.
[0047] The specific execution process of step 201 is similar to that of step 101, and will not be described in detail here.
[0048] 202. Scan and parse multiple view components through the annotation processing function to obtain the component annotation data corresponding to each view component. The component annotation data includes the component's unique identifier.
[0049] It's important to note that there's a one-to-one correspondence between each view component and its annotation data, with each view component corresponding to a unique component identifier. Multiple view components are used to indicate multiple view component classes annotated with the same preset annotation element name. For example, the unique component identifier for the similar product line chart view component is key_fast_sell_chat, the unique component identifier for the similar product exposure increase view component is key_similarity_equip, the unique component identifier for the product price suggestion change view component is key_change_price, and the unique component identifier for the role information view component is new_role_info_view.
[0050] In some embodiments, the server scans and parses multiple view component classes containing preset annotation element names using an annotation processing function to obtain component annotation data corresponding to each view component, with each view component corresponding to a view component class. Further, the server calls the annotation retrieval function `getElementAnnotation()` using the annotation processing function `process` to scan and parse multiple view component classes containing preset annotation element names to obtain component annotation data corresponding to each view component.
[0051] 203. When the component's unique identifier is not null, construct the view component class structure data based on the component annotation data corresponding to each view component.
[0052] The view component class structure data includes member variables and corresponding interface functions (that is, view component generation interface functions). In some embodiments, when the component unique identifier is not null, the server sets member variables based on the component unique identifier in the component annotation data corresponding to each view component. Specifically, the server converts the component unique identifier in the component annotation data corresponding to each view component to uppercase letters to obtain the converted component identifier string corresponding to each view component. Then, the server declares variables based on the converted component identifier string and the component unique identifier in the component annotation data corresponding to each view component to obtain member variables. For example, the component unique identifier in the component annotation data corresponding to each view component includes key_fast_sell_chat, key_similarity_equip, key_change_price, and new_role_info_view. Correspondingly, the member variables include val KEY_FAST_SELL_CHAT:String="key_fast_sell_chat", val KEY_SIMILARITY_EQUIP:String="key_similarity_equip", val KEY_CHANGE_PRICE:String="key_change_price", and val NEW_ROLE_INFO_VIEW: String = "new_role_info_view"; The server initializes the parameter data and constructs the view component generation interface function based on member variables, parameter data, and other annotation data in the component annotation data corresponding to each view component. Other annotation data includes annotation data other than the component's unique identifier. The server merges the member variables and the view component generation interface function into the view component class structure data. It should be noted that the component's unique identifier key is a required parameter. Other annotation data in the component annotation data corresponding to each view component may also include: component function description information desc, component instantiation alias alias, component input parameter hasExtraData, and the business parameter hasproductFactory corresponding to the target software project. Other annotation parameters may also be included in the component annotation data corresponding to each view component; specific limitations are not specified here.
[0053] Furthermore, when the server performs the step of merging member variables and view component generation interface functions into view component class structure data, in some embodiments, the server sets the preset function name to the function name corresponding to the view component generation interface function, wherein the preset function name is createViewHolder; the server sets the parameter data to the interface parameters corresponding to the view component generation interface function in sequence based on the parameter name and parameter type. For example, the interface parameters include key: String, parent: ViewGroup, productFactory:ProductFactory? = null, and extraData: Any? =null, etc.; the server determines the view component class corresponding to each view component according to other annotation data in the component annotation data corresponding to each view component; the service maps member variables and view component classes corresponding to each view component one by one based on interface parameters to obtain the function body corresponding to the view component generation interface function. For example, the function body corresponding to the view component generation interface function includes: KEY_FAST_SELL_CHAT->return ChatViewHolder(parent,productFactory), KEY_SIMILARITY_EQUIP:->return SimilarityEquipViewHolder(parent,productFactory), KEY_CHANGE_PRICE:->return ChangePriceViewHolder(parent,productFactory), and NEW_ROLE_INFO_VIEW:->return RoleBaseInfoCardViewDelegate.createViewDelegate(parent,productFactory). That is, the server instantiates different view component classes according to the unique identifier of the component, and manages and calls multiple view components in a unified manner through the view component classes, which improves code maintenance efficiency.
[0054] 204. Convert the view component class structure data into a view component management class using a preset code generation framework.
[0055] The preset code generation framework can be configured according to actual business needs. For example, the preset code generation framework can be KotlinPoet or JavaPoet; the specific choice is not limited here. This embodiment uses KotlinPoet as an example. In some embodiments, the server initializes the view component management class according to a preset component management class name, where the preset component management class name is AutoViewFactory. The server adds the view component class structure data to the view component management class; that is, the view component management class is object AutoViewFactory{view component class structure data}. The server exports the view component management class to a view component management file using the file generation function in the preset code generation framework; for example, the view component management file is AutoViewFactory.kt. It is understood that the view component management file facilitates the application of the view component management class to the target software project, improving the flexibility of the view component management class application.
[0056] Furthermore, the server references the view component management file corresponding to the view component management class in the target business application; the server instantiates the view component management class to obtain a target management class object; the server obtains the target view component identifier value corresponding to the target business application, and calls the view component generation interface function (e.g., createViewHolder) corresponding to the target management class object based on the target management class object and the target view component identifier value key to realize the user interface rendering processing of the target view component. In other words, multiple view components are uniformly called through the view component management class at the business layer, reducing code maintenance errors and complexity, and improving the efficiency of view component construction.
[0057] In this embodiment of the invention, during the compilation of the target software project, multiple view components are scanned and parsed through the annotation processing function to obtain the component annotation data corresponding to each view component. When the unique identifier of the component is not null, a view component management class is generated based on the component annotation data corresponding to each view component. Multiple view components are called uniformly through the view component management class in the business layer, which reduces the error-proneness and complexity of code maintenance and improves the efficiency of view component construction.
[0058] The above describes the method for generating view component management classes in embodiments of the present invention. The following describes the apparatus for generating view component management classes in embodiments of the present invention. Please refer to [link / reference]. Figure 3 One embodiment of the view component management class generation device in this invention includes:
[0059] The execution module 301 is used to respond to code compilation instructions for a target software project and execute annotation processing functions corresponding to the code compilation instructions in the compilation environment. The target software project includes multiple view components.
[0060] The scanning and parsing module 302 is used to scan and parse the multiple view components through the annotation processing function to obtain the component annotation data corresponding to each view component. The component annotation data includes a unique component identifier.
[0061] The generation module 303 is used to generate a view component management class based on the component annotation data corresponding to each view component when the unique identifier of the component is not null.
[0062] In this embodiment of the invention, during the compilation of the target software project, multiple view components are scanned and parsed through the annotation processing function to obtain the component annotation data corresponding to each view component. When the unique identifier of the component is not null, a view component management class is generated based on the component annotation data corresponding to each view component. Multiple view components are called uniformly through the view component management class in the business layer, which reduces the error-proneness and complexity of code maintenance and improves the efficiency of view component construction.
[0063] Please see Figure 4 Another embodiment of the view component management class generation device in this invention includes:
[0064] The execution module 301 is used to respond to code compilation instructions for a target software project and execute annotation processing functions corresponding to the code compilation instructions in the compilation environment. The target software project includes multiple view components.
[0065] The scanning and parsing module 302 is used to scan and parse the multiple view components through the annotation processing function to obtain the component annotation data corresponding to each view component. The component annotation data includes a unique component identifier.
[0066] The generation module 303 is used to generate a view component management class based on the component annotation data corresponding to each view component when the unique identifier of the component is not null.
[0067] In one feasible implementation, the view component management class generation device further includes:
[0068] A module 304 is created to create the annotation processing function for the target software project. The annotation processing function inherits from the abstract parser AbstractProcessor.
[0069] Add module 305, which is used to add custom annotation data to the source code corresponding to the multiple view components respectively. The custom annotation data includes preset annotation element names and component annotation data.
[0070] In one feasible implementation, the scanning and parsing module 302 is specifically used to: scan and parse multiple view component classes containing preset annotation element names through the annotation processing function, and obtain the component annotation data corresponding to each view component, with each view component corresponding to each view component class.
[0071] In one feasible implementation, the component annotation data further includes: component function description information, component instantiation alias, component input parameters, and business parameters corresponding to the target software project.
[0072] In one feasible implementation, the generation module 303 further includes:
[0073] Construction unit 3031 is used to construct view component class structure data based on the component annotation data corresponding to each view component when the component unique identifier is not null.
[0074] The conversion unit 3032 is used to convert the view component class structure data into a view component management class through a preset code generation framework.
[0075] In one feasible implementation, the construction unit 3031 further includes:
[0076] Set up subunit 30311 to set member variables based on the component unique identifier in the component annotation data corresponding to each view component when the component unique identifier is not null.
[0077] Subunit 30312 is constructed to initialize parameter data and construct view component generation interface functions based on the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component. The other annotation data are annotation data other than the component unique identifier.
[0078] Merging subunit 30313 is used to merge the member variables and the view component generation interface function into view component class structure data.
[0079] In one feasible implementation, the construction subunit 30312 is specifically used for:
[0080] Set the preset function name to the function name corresponding to the view component's generated interface function;
[0081] Based on the parameter name and parameter type, the parameter data are set sequentially as the interface parameters corresponding to the view component's generation interface function.
[0082] Determine the view component class corresponding to each view component based on other annotation data in the component annotation data corresponding to each view component;
[0083] Based on the interface parameters, the member variables and the view component classes corresponding to each view component are mapped one by one to obtain the function body corresponding to the view component generation interface function.
[0084] In one feasible implementation, the conversion unit 3032 is specifically used for:
[0085] Initialize the view component management class according to the preset component management class name;
[0086] Add the view component class structure data to the view component management class;
[0087] The view component management class is exported to the view component management file using the file generation function in the preset code generation framework.
[0088] In one feasible implementation, the view component management class generation device further includes:
[0089] Reference module 306 is used to reference the view component management file corresponding to the view component management class in the target business application;
[0090] Instantiation module 307 is used to instantiate the view component management class to obtain a target management class object;
[0091] The calling module 308 is used to obtain the target view component identifier value corresponding to the target business application, and to call the view component generation interface function corresponding to the target management class object according to the target management class object and the target view component identifier value, so as to realize the user interface rendering process of the target view component.
[0092] In this embodiment of the invention, during the compilation of the target software project, multiple view components are scanned and parsed through the annotation processing function to obtain the component annotation data corresponding to each view component. When the unique identifier of the component is not null, a view component management class is generated based on the component annotation data corresponding to each view component. Multiple view components are called uniformly through the view component management class in the business layer, which reduces the error-proneness and complexity of code maintenance and improves the efficiency of view component construction.
[0093] above Figure 3 and Figure 4 The view component management class generation device in this embodiment of the invention will be described in detail from a modular perspective. The view component management class generation device in this embodiment of the invention will be described in detail from a hardware processing perspective.
[0094] Figure 5This is a schematic diagram of a view component management class generation device provided in an embodiment of the present invention. The view component management class generation device 500 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 510 (e.g., one or more processors) and a memory 520, and one or more storage media 530 (e.g., one or more mass storage devices) for storing application programs 533 or data 532. The memory 520 and storage media 530 can be temporary or persistent storage. The program stored in the storage media 530 may include one or more modules (not shown in the diagram), each module including a series of computer program operations on the view component management class generation device 500. Furthermore, the processor 510 may be configured to communicate with the storage media 530 and execute a series of computer program operations on the storage media 530 on the view component management class generation device 500, so that the library file generation device 500 executes the steps of the view component management class generation method, for example:
[0095] In response to code compilation instructions for a target software project, an annotation processing function corresponding to the code compilation instructions is executed in the compilation environment. The target software project includes multiple view components. The annotation processing function scans and parses the multiple view components to obtain component annotation data corresponding to each view component. The component annotation data includes a unique component identifier. When the unique component identifier is not null, a view component management class is generated based on the component annotation data corresponding to each view component.
[0096] In this embodiment of the invention, during the compilation of the target software project, multiple view components are scanned and parsed through the annotation processing function to obtain the component annotation data corresponding to each view component. When the unique identifier of the component is not null, a view component management class is generated based on the component annotation data corresponding to each view component. Multiple view components are called uniformly through the view component management class in the business layer, which reduces the error-proneness and complexity of code maintenance and improves the efficiency of view component construction.
[0097] In one feasible implementation, before responding to the code compilation instructions for the target software project and executing the annotation processing function corresponding to the code compilation instructions in the compilation environment, and before the target software project includes multiple view components, the view component management class generation method further includes: creating the annotation processing function for the target software project, the annotation processing function inheriting from the abstract parser AbstractProcessor; adding custom annotation data to the source code corresponding to the multiple view components respectively, the custom annotation data including preset annotation element names and the component annotation data.
[0098] In one feasible implementation, the step of scanning and parsing the multiple view components through the annotation processing function to obtain the component annotation data corresponding to each view component includes: scanning and parsing multiple view component classes containing preset annotation element names through the annotation processing function to obtain the component annotation data corresponding to each view component, wherein each view component corresponds one-to-one with each view component class.
[0099] In one feasible implementation, the component annotation data further includes: component function description information, component instantiation alias, component input parameters, and business parameters corresponding to the target software project.
[0100] In one feasible implementation, the step of generating a view component management class based on the component annotation data corresponding to each view component when the component unique identifier is not null includes: constructing view component class structure data based on the component annotation data corresponding to each view component when the component unique identifier is not null; and converting the view component class structure data into a view component management class through a preset code generation framework.
[0101] In one feasible implementation, the step of constructing view component class structure data based on the component annotation data corresponding to each view component when the component unique identifier is not null includes: setting member variables based on the component unique identifier in the component annotation data corresponding to each view component when the component unique identifier is not null; initializing parameter data, and constructing a view component generation interface function according to the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component, wherein the other annotation data is annotation data other than the component unique identifier; and merging the member variables and the view component generation interface function into view component class structure data.
[0102] In one feasible implementation, the step of constructing the view component generation interface function based on the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component includes: setting a preset function name as the function name corresponding to the view component generation interface function; sequentially setting the parameter data as the interface parameters corresponding to the view component generation interface function based on the parameter name and parameter type order; determining the view component class corresponding to each view component according to the other annotation data in the component annotation data corresponding to each view component; and mapping the member variables and the view component classes corresponding to each view component one by one based on the interface parameters to obtain the function body corresponding to the view component generation interface function.
[0103] In one feasible implementation, the step of converting the view component class structure data into a view component management class using a preset code generation framework includes: initializing the view component management class according to a preset component management class name; adding the view component class structure data to the view component management class; and exporting the view component management class to a view component management file using a file generation function in the preset code generation framework.
[0104] In one feasible implementation, after generating a view component management class based on the component annotation data corresponding to each view component when the component unique identifier is not null, the view component management class generation method further includes: referencing the view component management file corresponding to the view component management class in the target business application; instantiating the view component management class to obtain a target management class object; obtaining the target view component identifier value corresponding to the target business application, and calling the view component generation interface function corresponding to the target management class object according to the target management class object and the target view component identifier value, so as to realize the user interface rendering processing of the target view component.
[0105] The view component management class generation device 500 may also include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input / output interfaces 560, and / or one or more operating systems 531, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that... Figure 5 The illustrated view component management class generation device structure does not constitute a limitation on the view component management class generation device, and may include more or fewer components than illustrated, or combine certain components, or have different component arrangements.
[0106] The present invention also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions that, when executed on a computer, cause the computer to perform the steps of the view component management class generation method, for example:
[0107] In response to code compilation instructions for a target software project, an annotation processing function corresponding to the code compilation instructions is executed in the compilation environment. The target software project includes multiple view components. The annotation processing function scans and parses the multiple view components to obtain component annotation data corresponding to each view component. The component annotation data includes a unique component identifier. When the unique component identifier is not null, a view component management class is generated based on the component annotation data corresponding to each view component.
[0108] In this embodiment of the invention, during the compilation of the target software project, multiple view components are scanned and parsed through the annotation processing function to obtain the component annotation data corresponding to each view component. When the unique identifier of the component is not null, a view component management class is generated based on the component annotation data corresponding to each view component. Multiple view components are called uniformly through the view component management class in the business layer, which reduces the error-proneness and complexity of code maintenance and improves the efficiency of view component construction.
[0109] In one feasible implementation, before responding to the code compilation instructions for the target software project and executing the annotation processing function corresponding to the code compilation instructions in the compilation environment, and before the target software project includes multiple view components, the view component management class generation method further includes: creating the annotation processing function for the target software project, the annotation processing function inheriting from the abstract parser AbstractProcessor; adding custom annotation data to the source code corresponding to the multiple view components respectively, the custom annotation data including preset annotation element names and the component annotation data.
[0110] In one feasible implementation, the step of scanning and parsing the multiple view components through the annotation processing function to obtain the component annotation data corresponding to each view component includes: scanning and parsing multiple view component classes containing preset annotation element names through the annotation processing function to obtain the component annotation data corresponding to each view component, wherein each view component corresponds one-to-one with each view component class.
[0111] In one feasible implementation, the component annotation data further includes: component function description information, component instantiation alias, component input parameters, and business parameters corresponding to the target software project.
[0112] In one feasible implementation, the step of generating a view component management class based on the component annotation data corresponding to each view component when the component unique identifier is not null includes: constructing view component class structure data based on the component annotation data corresponding to each view component when the component unique identifier is not null; and converting the view component class structure data into a view component management class through a preset code generation framework.
[0113] In one feasible implementation, the step of constructing view component class structure data based on the component annotation data corresponding to each view component when the component unique identifier is not null includes: setting member variables based on the component unique identifier in the component annotation data corresponding to each view component when the component unique identifier is not null; initializing parameter data, and constructing a view component generation interface function according to the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component, wherein the other annotation data is annotation data other than the component unique identifier; and merging the member variables and the view component generation interface function into view component class structure data.
[0114] In one feasible implementation, the step of constructing the view component generation interface function based on the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component includes: setting a preset function name as the function name corresponding to the view component generation interface function; sequentially setting the parameter data as the interface parameters corresponding to the view component generation interface function based on the parameter name and parameter type order; determining the view component class corresponding to each view component according to the other annotation data in the component annotation data corresponding to each view component; and mapping the member variables and the view component classes corresponding to each view component one by one based on the interface parameters to obtain the function body corresponding to the view component generation interface function.
[0115] In one feasible implementation, the step of converting the view component class structure data into a view component management class using a preset code generation framework includes: initializing the view component management class according to a preset component management class name; adding the view component class structure data to the view component management class; and exporting the view component management class to a view component management file using a file generation function in the preset code generation framework.
[0116] In one feasible implementation, after generating a view component management class based on the component annotation data corresponding to each view component when the component unique identifier is not null, the view component management class generation method further includes: referencing the view component management file corresponding to the view component management class in the target business application; instantiating the view component management class to obtain a target management class object; obtaining the target view component identifier value corresponding to the target business application, and calling the view component generation interface function corresponding to the target management class object according to the target management class object and the target view component identifier value, so as to realize the user interface rendering processing of the target view component.
[0117] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0118] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0119] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications 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 the present invention.
Claims
1. A method for generating a view component management class, characterized in that, The method for generating the view component management class includes: In response to code compilation instructions for a target software project, an annotation processing function corresponding to the code compilation instructions is executed in the compilation environment. The target software project includes multiple view components. The annotation processing function scans and parses the multiple view components to obtain the component annotation data corresponding to each view component. The component annotation data includes a unique component identifier. When the unique identifier of the component is not null, a view component management class is generated based on the component annotation data corresponding to each view component. When the component's unique identifier is not null, a view component management class is generated based on the component annotation data corresponding to each view component, including: When the component unique identifier is not null, member variables are set based on the component unique identifier in the component annotation data corresponding to each view component; parameter data is initialized, and a view component generation interface function is constructed based on the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component. The other annotation data are annotation data other than the component unique identifier. The member variables and the view component generation interface function are merged into view component class structure data. The view component class structure data is converted into a view component management class through a preset code generation framework. The member variables and the view component generation interface function are merged into view component class structure data. The step of setting member variables based on the unique identifier of the component in the component annotation data corresponding to each view component includes: Convert the unique component identifier in the component annotation data corresponding to each view component to uppercase letters to obtain the converted component identifier string for each view component. Then, declare variables based on the converted component identifier string and the unique component identifier in the component annotation data corresponding to each view component to obtain member variables.
2. The view component management class generation method according to claim 1, characterized in that, Before the method of responding to code compilation instructions for a target software project and executing annotation processing functions corresponding to those instructions in the compilation environment, and before the target software project includes multiple view components, the view component management class generation method further includes: The annotation processing function is created for the target software project, and the annotation processing function inherits from the abstract parser AbstractProcessor; Custom annotation data is added to the source code corresponding to the multiple view components. The custom annotation data includes preset annotation element names and component annotation data.
3. The view component management class generation method according to claim 1, characterized in that, The step of scanning and parsing the multiple view components through the annotation processing function to obtain the component annotation data corresponding to each view component includes: The annotation processing function scans and parses multiple view component classes containing preset annotation element names to obtain the component annotation data corresponding to each view component, with each view component corresponding to each view component class.
4. The view component management class generation method according to claim 3, characterized in that, The component annotation data also includes: component function description information, component instantiation alias, component input parameters, and business parameters corresponding to the target software project.
5. The view component management class generation method according to claim 1, characterized in that, The step of constructing the view component generation interface function based on the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component includes: Set the preset function name to the function name corresponding to the view component's generated interface function; Based on the parameter name and parameter type, the parameter data is set sequentially as the interface parameters corresponding to the view component's generation interface function; The view component class corresponding to each view component is determined based on other annotation data in the component annotation data corresponding to each view component. Based on the interface parameters, the member variables and the view component classes corresponding to each view component are mapped one by one to obtain the function body corresponding to the view component generation interface function.
6. The view component management class generation method according to claim 1, characterized in that, The step of converting the view component class structure data into a view component management class using a preset code generation framework includes: Initialize the view component management class according to the preset component management class name; Add the view component class structure data to the view component management class; The view component management class is exported to the view component management file using the file generation function in the preset code generation framework.
7. The method for generating a view component management class according to any one of claims 1-6, characterized in that, After generating a view component management class based on the component annotation data corresponding to each view component when the component unique identifier is not null, the view component management class generation method further includes: Reference the view component management file corresponding to the view component management class in the target business application; Instantiate the view component management class to obtain the target management class object; Obtain the target view component identifier value corresponding to the target business application, and call the view component generation interface function corresponding to the target management class object according to the target management class object and the target view component identifier value to realize the user interface rendering process of the target view component.
8. A view component management class generation device, characterized in that, The view component management class generation device includes: An execution module is used to respond to code compilation instructions for a target software project and execute annotation processing functions corresponding to the code compilation instructions in the compilation environment. The target software project includes multiple view components. The scanning and parsing module is used to scan and parse the multiple view components through the annotation processing function to obtain the component annotation data corresponding to each view component. The component annotation data includes a unique component identifier. The generation module is used to generate a view component management class based on the component annotation data corresponding to each view component when the unique identifier of the component is not null. The generation module is used to: set member variables based on the unique component identifier in the component annotation data corresponding to each view component when the component unique identifier is not null; initialize parameter data; and construct a view component generation interface function based on the member variables, the parameter data, and other annotation data in the component annotation data corresponding to each view component, wherein the other annotation data is annotation data other than the component unique identifier; merge the member variables and the view component generation interface function into view component class structure data; convert the view component class structure data into a view component management class through a preset code generation framework; and merge the member variables and the view component generation interface function into view component class structure data. The generation module is used to convert the unique component identifier in the component annotation data corresponding to each view component to uppercase letters, so as to obtain the converted component identifier string corresponding to each view component. Then, based on the converted component identifier string and the unique component identifier in the component annotation data corresponding to each view component, the module declares variables to obtain member variables.
9. A view component management class generation device, characterized in that, The view component management class generation device includes: a memory and at least one processor, wherein the memory stores a computer program; The at least one processor invokes the computer program in the memory to cause the view component management class generation device to perform the view component management class generation method as described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the view component management class generation method as described in any one of claims 1-7.
Citation Information
Patent Citations
Component processing method and device, server and storage medium
CN112214219A