Method, device, electronic device and storage medium for generating component configuration table
By generating and filtering nodes in the abstract syntax tree, obtaining constructors and generating component configuration tables, the problems of low efficiency and poor accuracy of manually writing component configuration tables are solved, and fast and stable component configuration table generation is achieved.
Patent Information
- Application Number
- CN202110009515.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-05
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2041-01-05
AI Technical Summary
The existing method of manually writing component configuration tables is very laborious, inefficient, and prone to typos, which affects the accuracy of the configuration table.
By obtaining the source code files in the target project, an abstract syntax tree of each source code file is generated, the nodes are filtered based on the whitelist, the constructor of the target node is obtained, and the component configuration table is generated.
It realizes fast and stable generation of component configuration tables, avoids errors in manual generation, and improves the correctness and generation efficiency of configuration tables.
Smart Images

Figure CN112667223B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for generating a component configuration table. Background Art
[0002] As a new software update method, dynamic update can reduce the cost of reaching users, make changes to software content easier, and meet the needs of quickly launching some content into the market. For software developers, proper dynamic update is beneficial to product iteration while ensuring security. In order to develop dynamic update capabilities, the support of component configuration tables is required to meet the needs of querying component configurations during dynamic parsing.
[0003] The current component configuration table generation method basically remains in the manual writing stage, that is, referring to the component configuration in the project, and writing the corresponding registry of each component configuration one by one. However, the manual writing process requires brute force to enumerate all components, which is very labor-intensive and inefficient, and may cause typos, affecting the accuracy of the component configuration table. Summary of the invention
[0004] The embodiments of the present invention provide a method, device, electronic device and storage medium for generating a component configuration table to solve the problem that the existing manual writing of component configuration is labor-intensive and inefficient, and may result in typos, thus affecting the accuracy of the component configuration table.
[0005] In order to solve the above-mentioned technical problems, the present invention is achieved as follows:
[0006] In a first aspect, an embodiment of the present invention provides a method for generating a component configuration table, comprising:
[0007] Obtain each source code file in the target project and generate an abstract syntax tree for each source code file;
[0008] For an abstract syntax tree of any of the source code files, filtering nodes in the abstract syntax tree based on a whitelist to obtain a target node; wherein the whitelist includes at least one type identifier;
[0009] Obtain a constructor for each of the target nodes, and generate a component configuration table for the target project based on the constructor; wherein the component configuration table contains a key-value pair corresponding to each target node, the key value represents the correspondence between the identity identifier of the target node and the instantiation function, and the instantiation function generates a component corresponding to the target node by calling the constructor of the target node when executed.
[0010] Optionally, for the abstract syntax tree of any of the source code files, the step of filtering the nodes in the abstract syntax tree based on a whitelist to obtain a target node includes:
[0011] For any of the abstract syntax trees of the source code files, based on the type identifiers included in the whitelist, obtaining a node under the type identifier in the abstract syntax tree as the first node of the source code file, wherein the type identifier includes at least one of a type identifier of an object type and a type identifier of an enumeration type;
[0012] Filter out invalid nodes in the first nodes to obtain the target node of the source code file;
[0013] The invalid nodes include at least one of private nodes, abstract nodes, implicitly generated nodes, and nodes used for testing.
[0014] Optionally, the target project includes at least one of a Flutter framework and a Flutter project created based on the Flutter framework.
[0015] Optionally, when the target project is a Flutter framework, the step of obtaining a constructor of each target node and generating a component configuration table of the target project based on the constructor includes:
[0016] For any source code file in the Flutter framework, obtain the constructor of each target node under the source code file, and generate a component configuration table of the source code file based on the constructor;
[0017] According to the data packet to which each of the source code files belongs, the component configuration tables of the source code files are merged, and the component configuration tables of the source code files belonging to the same data packet are merged into one component configuration table to obtain the component configuration table of the Flutter framework.
[0018] Optionally, the step of obtaining a constructor of each target node under the source code file and generating a component configuration table of the source code file based on the constructor includes:
[0019] Obtaining a constructor of the target node, and generating an initial component configuration table of the source code file based on the constructor of each target node included in the source code file;
[0020] Obtaining a source code converter adapted to the initial component configuration table, editing the instantiation function in the initial component configuration table, and obtaining a final component configuration table of the source code file;
[0021] The editing operation includes at least one of adding a referenced member declaration, adding a package import reference, and parameter type conversion.
[0022] Optionally, when the target project is a flutter project created based on the Flutter framework, the step of obtaining a constructor of each of the target nodes and generating a component configuration table of the target project based on the constructor includes:
[0023] Obtaining a constructor of each of the target nodes, and generating an initial component configuration table of the target project based on the constructor;
[0024] Obtaining a source code converter adapted to the initial component configuration table, editing the instantiation function in the initial component configuration table, and obtaining a final component configuration table of the target project;
[0025] The editing operation includes at least one of adding a referenced member declaration, adding a package import reference, and parameter type conversion.
[0026] Optionally, the method further comprises:
[0027] A configuration list of the target project is generated according to each component configuration table under the target project, and is used to retrieve and reference each component configuration table under the target project at runtime.
[0028] Optionally, for the abstract syntax tree of any of the source code files, the step of filtering the nodes in the abstract syntax tree based on a whitelist to obtain a target node includes:
[0029] For an abstract syntax tree of any of the source code files, filtering nodes in the abstract syntax tree based on a whitelist to obtain target nodes, and confirming component attributes of each of the target nodes, wherein the component attributes include at least one of component type attributes and non-component type attributes;
[0030] The step of generating a configuration list of the target project according to each component configuration table under the target project, for retrieving and referencing each component configuration table under the target project at runtime, comprises:
[0031] A configuration list of the target project is generated according to each component configuration table under the target project and the component attributes of each target node.
[0032] Optionally, the step of obtaining the constructor of each target node includes:
[0033] For each target node, obtaining a first constructor of the target node from the node information of the target node;
[0034] Filter out invalid functions in the first constructor to obtain the constructor of the target node;
[0035] The invalid function includes at least one of a private function and a function used for testing.
[0036] In a second aspect, an embodiment of the present invention provides a device for generating a component configuration table, including:
[0037] An AST generation module is used to obtain each source code file in the target project and generate an abstract syntax tree for each source code file;
[0038] A node filtering module, for filtering nodes in an abstract syntax tree of any of the source code files based on a whitelist to obtain a target node; wherein the whitelist includes at least one type identifier;
[0039] A configuration table generation module is used to obtain the constructor of each target node and generate a component configuration table of the target project based on the constructor; wherein the component configuration table contains a key-value pair corresponding to each target node, and the key value represents the correspondence between the identity identifier of the target node and the instantiation function. When the instantiation function is executed, it generates a component corresponding to the target node by calling the constructor of the target node.
[0040] Optionally, the node filtering module includes:
[0041] A first node filtering submodule is configured to obtain, for an abstract syntax tree of any of the source code files, a node under the type identifier in the abstract syntax tree based on a type identifier included in a whitelist as a first node of the source code file, wherein the type identifier includes at least one of a type identifier of an object type and a type identifier of an enumeration type;
[0042] A second node filtering submodule, used to filter out invalid nodes in the first nodes to obtain a target node of the source code file;
[0043] The invalid nodes include at least one of private nodes, abstract nodes, implicitly generated nodes, and nodes used for testing.
[0044] Optionally, the target project includes at least one of a Flutter framework and a Flutter project created based on the Flutter framework.
[0045] Optionally, when the target project is a Flutter framework, the configuration table generating module includes:
[0046] A first configuration table generation submodule is used to obtain, for any source code file in the Flutter framework, a constructor of each target node under the source code file, and generate a component configuration table of the source code file based on the constructor;
[0047] The second configuration table generation submodule is used to merge the component configuration tables of the source code files according to the data packet to which each of the source code files belongs, merge the component configuration tables of the source code files belonging to the same data packet into one component configuration table, and obtain the component configuration table of the Flutter framework.
[0048] Optionally, the first configuration table generating submodule is specifically used to:
[0049] Obtaining a constructor of the target node, and generating an initial component configuration table of the source code file based on the constructor of each target node included in the source code file;
[0050] Obtaining a source code converter adapted to the initial component configuration table, editing the instantiation function in the initial component configuration table, and obtaining a final component configuration table of the source code file;
[0051] The editing operation includes at least one of adding a referenced member declaration, adding a package import reference, and parameter type conversion.
[0052] Optionally, when the target project is a flutter project created based on the flutter framework, the configuration table generation module includes:
[0053] A third configuration table generating submodule is used to obtain a constructor of each of the target nodes and generate an initial component configuration table of the target project based on the constructor;
[0054] The fourth configuration table generating submodule is used to obtain a source code converter adapted to the initial component configuration table, edit the instantiation function in the initial component configuration table, and obtain the final component configuration table of the target project;
[0055] The editing operation includes at least one of adding a referenced member declaration, adding a package import reference, and parameter type conversion.
[0056] Optionally, the device further comprises:
[0057] The configuration list generation module is used to generate the configuration list of the target project according to each component configuration table under the target project, and is used to retrieve and reference each component configuration table under the target project during runtime.
[0058] Optionally, the node filtering module is specifically used to:
[0059] For an abstract syntax tree of any of the source code files, filtering nodes in the abstract syntax tree based on a whitelist to obtain target nodes, and confirming component attributes of each of the target nodes, wherein the component attributes include at least one of component type attributes and non-component type attributes;
[0060] The configuration list generation module is specifically used for:
[0061] A configuration list of the target project is generated according to each component configuration table under the target project and the component attributes of each target node.
[0062] Optionally, the configuration table generating module includes:
[0063] A first constructor acquisition submodule, used for acquiring, for each target node, a first constructor of the target node from the node information of the target node;
[0064] A second constructor acquisition submodule is used to filter out invalid functions in the first constructor to obtain the constructor of the target node;
[0065] The invalid function includes at least one of a private function and a function used for testing.
[0066] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising: a memory, a processor, 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 method for generating a component configuration table as described in the first aspect are implemented.
[0067] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method for generating a component configuration table as described in the first aspect are implemented.
[0068] In the embodiment of the present invention, the component configuration table is automatically generated by a script, which is fast and stable, can effectively avoid the problem of writing errors in the manual generation process, and improve the correctness and generation efficiency of the component configuration table.
[0069] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0071] Figure 1 is a flowchart of the steps of a method for generating a component configuration table in an embodiment of the present invention;
[0072] Figure 2 is a flowchart of another method for generating a component configuration table in an embodiment of the present invention;
[0073] Figure 3 It is a schematic diagram of a process of automatically generating a component configuration table through a script in an embodiment of the present invention;
[0074] Figure 4 It is a structural schematic diagram of a device for generating a component configuration table in an embodiment of the present invention;
[0075] Figure 5 It is a structural schematic diagram of another device for generating a component configuration table in an embodiment of the present invention;
[0076] Figure 6 It is a schematic diagram of the hardware structure of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0077] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0078] Reference Figure 1 , showing a flowchart of the steps of a method for generating a component configuration table in an embodiment of the present invention.
[0079] Step 110, obtaining each source code file in the target project, and generating an abstract syntax tree for each source code file;
[0080] Step 120, for any of the abstract syntax trees of the source code files, filtering the nodes in the abstract syntax tree based on a whitelist to obtain a target node; wherein the whitelist includes at least one type identifier;
[0081] Step 130, obtain the constructor of each of the target nodes, and generate a component configuration table of the target project based on the constructor; wherein the component configuration table contains a key-value pair corresponding to each target node, and the key value represents the correspondence between the identity of the target node and the instantiation function, and the instantiation function generates a component corresponding to the target node by calling the constructor of the target node when executed.
[0082] In an embodiment of the present invention, a component configuration table is automatically generated by a script, and by modifying the source code location, a component configuration table can be generated for different versions of Flutter and user code. For example, when obtaining parameters input by a user to specify information such as the directory and version of a target project, the parameters input by the user can be parsed by obtaining a script adapted to the version of the target project to obtain the directory where the target project is located, and then the various steps in the embodiment of the present invention can be executed to obtain the component configuration table of the target project.
[0083] Specifically, after starting the script, you can parse various input parameters that represent the source code path by executing the script to obtain all location parameters that can locate the component source code, thereby locking the source code directory location of the target project, and then generate an abstract syntax tree object for each source code file in the target project through any available method such as analyzer.
[0084] Among them, the component configuration table is a registration table, and the corresponding component configuration (such as Widget) can be queried through a string identifier. In actual applications, components and component configurations are two different dimensions. Through component configuration, the final component can be generated. Most of the development only requires writing component configurations for page development. The Abstract Syntax Tree (AST) is an abstract expression of the code, and the Abstract Syntax Tree can be considered as a representation of the source code.
[0085] In practical applications, a source code file may include a lot of content, and it is necessary to filter out the source code that needs to generate the component configuration table. Then, according to the actual needs, a whitelist can be defined, which contains the type identifiers of the nodes that need to generate the component configuration table. Then, for the abstract syntax tree of any source code file, the nodes in the abstract syntax tree can be filtered based on the whitelist, and the nodes under each type identifier contained in the whitelist are the target nodes that need to be referenced for generating the component configuration table in the source code file. For example, each node in the abstract syntax tree can be traversed in turn to determine whether the type identifier of the type of each node is in the whitelist. If so, the corresponding node is considered to be in the target node. Of course, in an embodiment of the present invention, a blacklist containing at least one type identifier can also be set to filter out the nodes in the abstract syntax tree whose types are consistent with the type identifiers in the blacklist to obtain the final target node, and this embodiment of the present invention is not limited to this.
[0086] The type identifiers specifically included in the whitelist can be customized according to the requirements, which is not limited in the embodiment of the present invention. For example, the whitelist can be set to include type identifiers of object types (i.e., Class types), enumeration types, etc., and in actual applications, there may be type identifiers of multiple object types and type identifiers of enumeration types, such as Widget, StatefullWidget, StatelessWidget, etc.
[0087] The role of the whitelist is to effectively filter out the target node. When filtering, each node is traversed in turn for determination based on the type of the object (i.e., node) by recursive parent type, etc., which is not limited in the embodiment of the present invention.
[0088] In actual applications, to instantiate an object, the constructor of the object is needed. If there are multiple constructors, all of them need to be collected. Therefore, for each target node, its constructor can be obtained, and then the component configuration table of the target project can be generated based on the constructor of each target node.
[0089] The constructor of the target node may be obtained by any available method, which is not limited in the embodiment of the present invention. For example, each function node in the node information of each target node may be traversed to obtain the constructor node therein, and the constructor of the target node may be obtained. In addition, in order to facilitate the subsequent construction of the component configuration table, a corresponding constructor object may be further generated based on the constructor to facilitate calling the constructor object to perform the corresponding instantiation operation.
[0090] As mentioned above, in the registration table as the component configuration table, the corresponding component configuration can be queried through the string identifier. Therefore, in order to construct the component configuration table, a key-value pair corresponding to each target node can be set in the component configuration table, and the key value represents the correspondence between the identity identifier of the target node and the instantiation function. The instantiation function generates the component corresponding to the corresponding target node by calling the constructor of the target node when executed. Then at this time, through the identity identifier of the target node in the component configuration table, the corresponding instantiation function can be called, and the instantiation function can call the constructor of the corresponding target node (which can also be the above-mentioned constructor object, etc.) during the instantiation process, thereby generating a component corresponding to the corresponding target node.
[0091] In the component configuration table, the identity of the target node may be represented in any available form, for example, the identity of the target node may be the name of the target node, a hash value, etc. Moreover, in the embodiment of the present invention, an instantiation function that can call each constructor may be generated in any available manner, which is not limited by the embodiment of the present invention.
[0092] For example, the basic template of the instantiation function can be set in advance according to needs, and then the constructor-related information required to call the constructor (such as constructor name, constructor path, etc.) is filled into the corresponding position in the basic template of the instantiation function, so as to obtain an instantiation function that can call the corresponding constructor, and so on.
[0093] In an embodiment of the present invention, when the code of the component configuration table is generated according to the target node collected in the previous step, the component configuration table can be simply regarded as a hash table. Through the table signature, the constructor for constructing the optimal component can be obtained, and a component can be instantiated by executing the constructor.
[0094] Reference Figure 2 In the embodiment of the present invention, the step 120 may further include:
[0095] Step 121, for any of the abstract syntax trees of the source code files, based on the type identifiers included in the whitelist, obtaining a node under the type identifier in the abstract syntax tree as the first node of the source code file, wherein the type identifier includes at least one of an object type type identifier and an enumeration type type identifier;
[0096] Step 122, filtering out invalid nodes in the first nodes to obtain the target node of the source code file;
[0097] The invalid nodes include at least one of private nodes, abstract nodes, implicitly generated nodes, and nodes used for testing.
[0098] In actual applications, functions specifically used for testing, private functions automatically generated by the compiler, abstract nodes, implicitly generated nodes, etc. cannot be called in normal development. Therefore, it is not necessary to generate configuration tables for the above functions, which can reduce the number of invalid configurations.
[0099] Specifically, for the abstract syntax tree of any of the source code files, based on the type identifier contained in the whitelist, the node under the type identifier in the abstract syntax tree is obtained as the first node of the source code file, and the type identifier may include but is not limited to the type identifier of the object type and the type identifier of the enumeration type; and after filtering based on the whitelist, invalid nodes in the first node can be further screened out and filtered out, and the remaining nodes are the target nodes of the corresponding source code file.
[0100] Among them, the invalid nodes may include but are not limited to at least one of private function nodes (that is, nodes representing private functions such as private functions automatically generated by the compiler), function nodes used for testing (that is, nodes representing functions used for testing), abstract nodes, and implicitly generated nodes, that is, the final target node is a shared node.
[0101] Of course, in the embodiment of the present invention, the first node may be directly used as the target node without executing the above step 122 for further filtering, which is not limited in the embodiment of the present invention.
[0102] In an embodiment of the present invention, in addition to a whitelist of limited types, a node whitelist can also be provided to limit a target node and what contents need to be paid attention to. As mentioned above, to instantiate an object, only its constructor is needed. If there are multiple constructors, all of them need to be collected. The whitelist can be used to define the required function / node types (such as constructors, constant members, etc.). After filtering, some invalid nodes need to be eliminated, such as nodes of functions specifically used for testing, nodes of private functions automatically generated by the compiler, and so on.
[0103] Optionally, in an embodiment of the present invention, the target project includes at least one of the Flutter framework itself and a Flutter project created based on the Flutter framework.
[0104] Flutter is a cross-platform software development framework. Programs developed using Flutter can run on Android, iOS, and browsers. Generally speaking, only one version of the Flutter framework, namely Fluttersdk (Software Development Kit), is installed on a computer, and then multiple Flutter projects can be created based on this installed version. Analyzer is a tool provided by Flutter to generate a source code abstract syntax tree. In an embodiment of the present invention, a script for executing the above steps can be pre-set, and the above steps can be implemented by executing the script, and the component configuration table of the target project can be automatically obtained. Moreover, in order to adapt to different versions of Flutter, scripts for adapting to different versions of Flutter can also be preset, so that the script adapted to the target project can be selected according to the Flutter version to execute the various steps in the embodiment of the present invention, and the embodiment of the present invention is not limited to this.
[0105] Optionally, in this embodiment of the present invention, when the target project is a Flutter framework, step 130 may further include:
[0106] Step A131: for any source code file in the Flutter framework, obtain the constructor of each target node under the source code file, and generate a component configuration table of the source code file based on the constructor;
[0107] Step A132, according to the data package to which each of the source code files belongs, the component configuration tables of the source code files are merged, and the component configuration tables of the source code files belonging to the same data package are merged into one component configuration table to obtain the component configuration table of the Flutter framework.
[0108] For the Flutter framework, since it contains a large amount of data, there may be multiple different data packets, and each data packet contains many source code files, if a component configuration table is set for the Flutter framework, it is easy to cause the component configuration table to contain a large amount of data, affecting the retrieval efficiency.
[0109] Therefore, in an embodiment of the present invention, a component configuration table can be generated first in units of resource files, and then convergence processing can be performed on each component configuration table. Specifically, for any source code file in the Flutter framework, the constructor of each target node under the source code file can be obtained, and the component configuration table of the source code file can be generated based on the constructor.
[0110] After generating a component configuration table for each source code file, since each source code file corresponds to a component configuration table, when the target project contains a large number of source code files, the number of component configuration tables is also large, the fragmentation is very serious, and the content distribution of each component configuration table is uneven. Therefore, in an embodiment of the present invention, the component configuration table of each source code file can be further merged according to the data packet to which each source code file belongs, and the component configuration tables of the source code files belonging to the same data packet can be merged into one component configuration table. For example, according to the data packet to which each source code file belongs, a convergence can be performed, and the component configuration table codes of the same data packet can be merged into one file, that is, the converged file, and the fragmented files before the merge can be cleared after completion. Through the convergence action, thousands of files can be finally sorted into less than 10 files, which is more convenient for development and reference.
[0111] Among them, whether the source code files belong to the same data packet can be confirmed by the directory structure of the source code files in the Flutter framework, which is not limited in this embodiment of the present invention.
[0112] Of course, in the embodiment of the present invention, when merging component configuration tables, the component configuration tables may be merged by referring to whether each component configuration table belongs to the same data packet, or the relationship between each component configuration table, etc., which is not limited in the embodiment of the present invention. For example, N component configuration tables generated continuously are merged into one component configuration table, where N is a positive integer greater than 1.
[0113] Optionally, in the embodiment of the present invention, step A131 may further include:
[0114] Step 1311, obtaining a constructor of the target node, and generating an initial component configuration table of the source code file based on the constructor of each target node included in the source code file;
[0115] Step 1312, obtaining a source code converter adapted to the initial component configuration table, editing the instantiation function in the initial component configuration table, and obtaining the final component configuration table of the source code file;
[0116] The editing operation includes at least one of adding a referenced member declaration, adding a package import reference, and parameter type conversion.
[0117] During the component construction process, components vary greatly. Some need to add parameters, and some parameters need to be passed in from outside. There are also default parameters, and default parameters may be private attributes that cannot be referenced from outside. When generating instantiation functions, due to different contexts, the corresponding references cannot be obtained, which will cause code compilation failure, thus affecting component generation.
[0118] In order to solve the above problems, a list of source code converters can be maintained through multiple analysis and observation. When generating the component configuration table of the source code file, the registration table generated based on the constructor of each target node contained in the source code file can be considered as the initial component configuration table of the corresponding source code file, and then the source code converter adapted to each initial component configuration table can be obtained, and the instantiation function in the initial component configuration table can be edited to obtain the final component configuration table of the source code file. The editing operation can include but is not limited to at least one of adding referenced member declarations, adding package references, and parameter type conversion.
[0119] For example, the source code converter can filter out the component configurations with missing references in the initial component configuration table, and then inject the missing references (such as the member declarations of adding references, adding package import references, etc.) for the component configuration. Finally, the modified registry is returned, which is the final component configuration table of the corresponding source code file.
[0120] Among them, when setting the source code converter list, the conditions that each source code converter needs to meet in the initial component configuration table adapted can be set at the same time, for example, different source code converters are adapted to the initial component configuration table of source code files under different paths. When the target project is a Flutter project, different source code converters can also be set to adapt to different versions of Flutter, etc. In addition, different source code converters are provided with code logic that can perform different editing operations, which is not limited in the embodiment of the present invention.
[0121] Of course, in an embodiment of the present invention, the above step 1312 may also be executed after the merging process to edit the instantiation function in the merged component configuration table to obtain the final component configuration table of the target project, which is not limited by the embodiment of the present invention.
[0122] Optionally, in the embodiment of the present invention, when the target project is a flutter project created based on the flutter framework, step 130 may further include:
[0123] Step B131, obtaining a constructor of each target node, and generating an initial component configuration table of the target project based on the constructor;
[0124] Step B132, obtaining a source code converter adapted to the initial component configuration table, editing the instantiation function in the initial component configuration table, and obtaining the final component configuration table of the target project;
[0125] The editing operation includes at least one of adding a referenced member declaration, adding a package import reference, and parameter type conversion.
[0126] Generally speaking, the flutter project created based on the Flutter framework can be understood as a data packet. Compared with the Flutter framework itself, the amount of data in the flutter project is small, so a registry can be generated as a component configuration table. At this time, the above-mentioned merging and convergence process is not required. The constructor of each target node in the flutter project can be directly obtained, and the initial component configuration table of the target project can be generated based on the constructor. Then, a source code converter adapted to the initial component configuration table can be obtained, and the instantiation function in the initial component configuration table can be edited to obtain the final component configuration table of the target project. For details, please refer to the above content, which will not be repeated here.
[0127] Reference Figure 2 In an embodiment of the present invention, the method further includes:
[0128] Step 140: Generate a configuration list of the target project according to each component configuration table under the target project, for retrieving and referencing each component configuration table under the target project during runtime.
[0129] In addition, a configuration list can be generated according to each component configuration table under the target project, which can be used to retrieve and reference each component configuration table under the target project at runtime. The configuration list can include the total number of component configuration tables under the corresponding target project, the file identification, file path, reference method and other basic information of each component configuration table, and can also include the number of components contained in each component configuration table, the identity identification of the components and other basic information. The configuration list is equivalent to an overview of each component configuration table under a corresponding target project. Through the configuration list, you can understand the general information of each component configuration table contained in the target project, such as which components are supported, which are components, which are constant references, etc. This is convenient for retrieving and referencing each of the component configuration tables when running the target project later, and even retrieving and referencing any instantiation function in any component configuration table to build components, etc.
[0130] Optionally, in the embodiment of the present invention, the step 120 may further include: for an abstract syntax tree of any of the source code files, filtering nodes in the abstract syntax tree based on a whitelist to obtain target nodes, and confirming component attributes of each of the target nodes, wherein the component attributes include at least one of component type attributes and non-component type attributes;
[0131] The step 140 may further include: generating a configuration list of the target project according to each component configuration table under the target project and the component attributes of each target node.
[0132] In actual applications, when building a component configuration table, in order to filter the target nodes, it is necessary to traverse each node in the abstract syntax tree in turn, and the target nodes may include nodes of component types that can be seen on the page, and nodes of non-component types related to configuration information (such as constants, etc.) that will not be displayed on the page. For example, the above-mentioned Widget, StatefullWidget, StatelessWidget, etc. are all type identifiers of component types. And when generating the configuration list of the target project, in order to facilitate relevant personnel to understand whether the components that can be constructed by each component configuration table are component types or non-component types through the configuration list, it is necessary to predetermine the component attributes of each target node, that is, whether it is a component type or a non-component type. Generally, the component type references the non-component type.
[0133] Moreover, in order to improve efficiency, the component attributes of each target node can be confirmed while filtering the target node. Specifically, the nodes in the abstract syntax tree can be filtered based on the whitelist for any of the source code files to obtain the target node and confirm the component attributes of each target node. This can improve the filtering speed and reduce the time of recursing to the parent node multiple times.
[0134] Specifically, the target node is filtered based on the node type, so multiple fine-grained type identifiers can be added to the whitelist. At this time, if the recursive parent type is used to traverse each node in turn for judgment, the target node can be filtered and the component attributes of the target node can be determined by traversing the parent node once recursively, which effectively reduces the time of recursing to the parent node multiple times, and can effectively improve the overall efficiency.
[0135] For example, assuming that the whitelist contains multiple fine-grained type identifiers, identifier 1, identifier 2, and identifier 3, and identifier 1 and identifier 2 are also component type identifiers, and identifier 3 is a non-component type identifier, then when traversing each node in the abstract syntax tree, if the type of a node satisfies any type identifier in the whitelist, it is identified as the target node, and the type identifier of the target node can be further obtained. Assuming that its type identifier is the above-mentioned identifier 1 or identifier 2, the target node is identified as a component type. Assuming that its type identifier is the above-mentioned identifier 3, the target node is identified as a non-component type.
[0136] In addition, the process of filtering the nodes in the abstract syntax tree based on the whitelist to obtain the target node may also refer to the above steps 121-122, which is not limited in this embodiment of the present invention.
[0137] Then, when generating the configuration list of the target project, the configuration list of the target project can be generated according to each component configuration table under the target project and the component attributes of each target node. At this time, the component attributes of each corresponding target node can be quickly understood through the configuration list, such as which of them are component types visible on the page, which are constant references, etc.
[0138] Optionally, in the embodiment of the present invention, the process of obtaining the constructor of each target node may specifically include:
[0139] S1, for each target node, obtaining a first constructor of the target node from the node information of the target node;
[0140] S2, filtering out invalid functions in the first constructor to obtain the constructor of the target node;
[0141] The invalid function includes at least one of a private function and a function used for testing.
[0142] For each target node, that is, the target object, there are node information such as members, functions, constructors, parent classes, etc. on the target object. When generating the component configuration table, the constructor is needed. Therefore, for each target node, its constructor can be obtained from the node information of the target node as the first constructor of the target node. However, correspondingly, some invalid constructors need to be eliminated, such as those functions specifically used for testing, private functions automatically generated by the compiler, non-public functions, etc. That is, the invalid functions in the first constructor can be further filtered out to obtain the final constructor of the target node. Among them, the invalid functions include at least one of private functions and functions used for testing.
[0143] Specifically, invalid functions in the first constructor may be filtered out by any available method, which is not limited in the embodiment of the present invention. For example, a method signature check may be performed to confirm whether the signature of the node representing the constructor is in a preset whitelist containing available signatures, and if so, it is confirmed to be a valid function, and if not, it is an invalid function.
[0144] like Figure 3The flowchart of a component configuration table of a Flutter framework is shown in an embodiment of the present invention. After obtaining the parameters input by the user, the parameters can be parsed by a preset automation script to locate the installation directory of Flutter, that is, the location of the Flutter SDK to be processed, and then locate the location of each source code file, and generate an abstract syntax tree for each source code file. For each abstract syntax tree, each node can be traversed in turn to determine whether the node type of the node is in a preset white list containing a type identifier. If so, it is used as the target node and subsequent operations are performed, otherwise the node can be ignored. For each target node, its function node (that is, the node representing the function) can be further parsed, and a method signature check can be performed to filter out invalid function nodes and obtain valid nodes representing constructors. For example, a white list containing a valid signature can be set separately, and then a method signature check is performed based on the white list. If the signature is in the white list, the subsequent operation can continue to be performed, otherwise the node can be ignored, that is, the node is considered to be an invalid function node and filtered out, and then the next target node is continued to be checked. For each function node that passes the method signature verification, its constructor object can be generated to prepare for the subsequent generation of the component configuration table.
[0145] When generating a component configuration table, a registry can be created for each source code file in advance, and then for each target node in the source code file, its instantiation function is generated based on its constructor object and stored in the registry in combination with the identity of each target node. In order to avoid code compilation failure, the instantiation function can also be modified through a source code converter (adding referenced member declarations, adding package import references, parameter type conversion, etc.), for example, filtering out component configurations with missing references for each instantiation function in the registry, and then injecting missing references to the configuration. Finally, the modified registry is returned. The required file header information can also be added to the final registry.
[0146] In addition, each component configuration table in the form of a registry can be merged. For example, the component configuration tables under the same functional module can be merged into one component configuration table. Specifically, after obtaining each component configuration table, it can be determined whether the component configuration table and the previously obtained component configuration table belong to the same module. If so, it can be merged into the previously obtained file of the same module. If the component configuration table belongs to a new module, a new aggregate file can be created for the module, and the component configuration table can be merged into the newly created aggregate file, so that the component configuration tables of the same module are merged into the same file as one component configuration table.
[0147] In addition, a configuration list can be generated based on each component configuration table under the same project, and persisted to a local disk, which can be used for runtime retrieval to determine which components are supported, which are components, which are constant references, etc. Moreover, the above-mentioned component configuration table can also be persisted to a local disk, which is not limited in the embodiment of the present invention.
[0148] Reference Figure 4 , showing a schematic structural diagram of a device for generating a component configuration table in an embodiment of the present invention.
[0149] The device for generating a component configuration table according to the embodiment of the present invention includes: an AST generation module 210 , a node filtering module 220 and a configuration table generation module 230 .
[0150] The functions of each module and the interactions between them are introduced in detail below.
[0151] AST generation module 210, used to obtain each source code file in the target project and generate an abstract syntax tree for each source code file;
[0152] A node filtering module 220, for filtering nodes in an abstract syntax tree of any of the source code files based on a whitelist to obtain a target node; wherein the whitelist includes at least one type identifier;
[0153] The configuration table generation module 230 is used to obtain the constructor of each target node and generate a component configuration table of the target project based on the constructor; wherein the component configuration table contains a key-value pair corresponding to each target node, and the key value represents the correspondence between the identity of the target node and the instantiation function, and the instantiation function generates a component corresponding to the target node by calling the constructor of the target node when executed.
[0154] Reference Figure 5 In this embodiment of the present invention, the node filtering module 220 may include:
[0155] A first node filtering submodule 221 is used for obtaining, for any abstract syntax tree of the source code file, a node under the type identifier in the abstract syntax tree based on the type identifier included in the whitelist as the first node of the source code file, wherein the type identifier includes at least one of a type identifier of an object type and a type identifier of an enumeration type;
[0156] A second node filtering submodule 222, configured to filter out invalid nodes in the first nodes to obtain a target node of the source code file;
[0157] The invalid nodes include at least one of private nodes, abstract nodes, implicitly generated nodes, and nodes used for testing.
[0158] Optionally, the target project includes at least one of a Flutter framework and a Flutter project created based on the Flutter framework.
[0159] Optionally, when the target project is a Flutter framework, the configuration table generating module 230 includes:
[0160] A first configuration table generation submodule is used to obtain, for any source code file in the Flutter framework, a constructor of each target node under the source code file, and generate a component configuration table of the source code file based on the constructor;
[0161] The second configuration table generation submodule is used to merge the component configuration tables of the source code files according to the data packet to which each of the source code files belongs, merge the component configuration tables of the source code files belonging to the same data packet into one component configuration table, and obtain the component configuration table of the Flutter framework.
[0162] Optionally, the first configuration table generating submodule is specifically used to:
[0163] Obtaining a constructor of the target node, and generating an initial component configuration table of the source code file based on the constructor of each target node included in the source code file;
[0164] Obtaining a source code converter adapted to the initial component configuration table, editing the instantiation function in the initial component configuration table, and obtaining a final component configuration table of the source code file;
[0165] The editing operation includes at least one of adding a referenced member declaration, adding a package import reference, and parameter type conversion.
[0166] Optionally, when the target project is a flutter project created based on the flutter framework, the configuration table generating module 230 includes:
[0167] A third configuration table generating submodule is used to obtain a constructor of each of the target nodes and generate an initial component configuration table of the target project based on the constructor;
[0168] The fourth configuration table generating submodule is used to obtain a source code converter adapted to the initial component configuration table, edit the instantiation function in the initial component configuration table, and obtain the final component configuration table of the target project;
[0169] The editing operation includes at least one of adding a referenced member declaration, adding a package import reference, and parameter type conversion.
[0170] Reference Figure 5 In an embodiment of the present invention, the device may further include:
[0171] The configuration list generating module 240 is used to generate the configuration list of the target project according to each component configuration table under the target project, and is used to retrieve and reference each component configuration table under the target project during runtime.
[0172] Optionally, the node filtering module 220 is specifically configured to:
[0173] For an abstract syntax tree of any of the source code files, filtering nodes in the abstract syntax tree based on a whitelist to obtain target nodes, and confirming component attributes of each of the target nodes, wherein the component attributes include at least one of component type attributes and non-component type attributes;
[0174] The configuration list generating module 220 is specifically used for:
[0175] A configuration list of the target project is generated according to each component configuration table under the target project and the component attributes of each target node.
[0176] Optionally, the configuration table generating module 230 includes:
[0177] A first constructor acquisition submodule, used for acquiring, for each target node, a first constructor of the target node from the node information of the target node;
[0178] A second constructor acquisition submodule is used to filter out invalid functions in the first constructor to obtain the constructor of the target node;
[0179] The invalid function includes at least one of a private function and a function used for testing.
[0180] The device for generating a component configuration table provided in the embodiment of the present invention can realize Figure 1 to Figure 2 To avoid repetition, the various processes implemented in the method embodiment are not described here.
[0181] Preferably, an embodiment of the present invention further provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned component configuration table generation method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0182] The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, each process of the above-mentioned component configuration table generation method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0183] Figure 6 A schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention.
[0184] The electronic device 500 includes but is not limited to: a radio frequency unit 501, a network module 502, an audio output unit 503, an input unit 504, a sensor 505, a display unit 506, a user input unit 507, an interface unit 508, a memory 509, a processor 510, and a power supply 511. Those skilled in the art will appreciate that Figure 6 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and the electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. In the embodiments of the present invention, the electronic device includes but is not limited to a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted terminal, a wearable device, and a pedometer.
[0185] It should be understood that in the embodiment of the present invention, the radio frequency unit 501 can be used for receiving and sending signals during information transmission or communication. Specifically, after receiving downlink data from the base station, it is sent to the processor 510 for processing; in addition, uplink data is sent to the base station. Generally, the radio frequency unit 501 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier, a duplexer, etc. In addition, the radio frequency unit 501 can also communicate with the network and other devices through a wireless communication system.
[0186] The electronic device provides users with wireless broadband Internet access through the network module 502, such as helping users to send and receive emails, browse web pages, and access streaming media.
[0187] The audio output unit 503 can convert the audio data received by the RF unit 501 or the network module 502 or stored in the memory 509 into an audio signal and output it as sound. Moreover, the audio output unit 503 can also provide audio output related to a specific function performed by the electronic device 500 (for example, a call signal reception sound, a message reception sound, etc.). The audio output unit 503 includes a speaker, a buzzer, a receiver, etc.
[0188] The input unit 504 is used to receive audio or video signals. The input unit 504 may include a graphics processor (GPU) 5041 and a microphone 5042. The graphics processor 5041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The processed image frame can be displayed on the display unit 506. The image frame processed by the graphics processor 5041 can be stored in the memory 509 (or other storage medium) or sent via the radio frequency unit 501 or the network module 502. The microphone 5042 can receive sound and can process such sound into audio data. The processed audio data can be converted into a format output that can be sent to a mobile communication base station via the radio frequency unit 501 in the case of a telephone call mode.
[0189] The electronic device 500 also includes at least one sensor 505, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor and a proximity sensor, wherein the ambient light sensor can adjust the brightness of the display panel 5061 according to the brightness of the ambient light, and the proximity sensor can turn off the display panel 5061 and / or the backlight when the electronic device 500 is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when stationary, which can be used to identify the posture of the electronic device (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; the sensor 505 can also include a fingerprint sensor, a pressure sensor, an iris sensor, a molecular sensor, a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, etc., which will not be repeated here.
[0190] The display unit 506 is used to display information input by the user or information provided to the user. The display unit 506 may include a display panel 5061, which may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0191] The user input unit 507 can be used to receive input digital or character information, and to generate key signal input related to user settings and function control of the electronic device. Specifically, the user input unit 507 includes a touch panel 5071 and other input devices 5072. The touch panel 5071, also known as a touch screen, can collect the user's touch operation on or near it (such as the user's operation on the touch panel 5071 or near the touch panel 5071 using any suitable object or accessory such as a finger, stylus, etc.). The touch panel 5071 may include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the contact point coordinates, and then sends it to the processor 510, receives the command sent by the processor 510 and executes it. In addition, the touch panel 5071 can be implemented using multiple types such as resistive, capacitive, infrared and surface acoustic waves. In addition to the touch panel 5071, the user input unit 507 may also include other input devices 5072. Specifically, other input devices 5072 may include but are not limited to a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be described in detail here.
[0192] Furthermore, the touch panel 5071 may be overlaid on the display panel 5061. When the touch panel 5071 detects a touch operation on or near it, it transmits the information to the processor 510 to determine the type of the touch event. Then, the processor 510 provides a corresponding visual output on the display panel 5061 according to the type of the touch event. Figure 6 In the figure, the touch panel 5071 and the display panel 5061 are used as two independent components to realize the input and output functions of the electronic device. However, in some embodiments, the touch panel 5071 and the display panel 5061 can be integrated to realize the input and output functions of the electronic device, which is not limited here.
[0193] The interface unit 508 is an interface for connecting an external device to the electronic device 500. For example, the external device may include a wired or wireless headset port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device with an identification module, an audio input / output (I / O) port, a video I / O port, a headphone port, etc. The interface unit 508 may be used to receive input (e.g., data information, power, etc.) from an external device and transmit the received input to one or more elements within the electronic device 500 or may be used to transmit data between the electronic device 500 and an external device.
[0194] The memory 509 can be used to store software programs and various data. The memory 509 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 509 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0195] The processor 510 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 509 and calling data stored in the memory 509, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. The processor 510 may include one or more processing units; preferably, the processor 510 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 510.
[0196] The electronic device 500 may also include a power supply 511 (such as a battery) for supplying power to each component. Preferably, the power supply 511 may be logically connected to the processor 510 through a power management system, thereby implementing functions such as charging, discharging, and power consumption management through the power management system.
[0197] In addition, the electronic device 500 includes some functional modules not shown, which will not be described in detail here.
[0198] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0199] 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 a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, 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, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0200] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
[0201] Those of ordinary skill 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 the present invention 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 the present invention.
[0202] Those skilled in the art can 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.
[0203] In the embodiments provided in the present 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 only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, 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.
[0204] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0205] In addition, each functional unit in each embodiment of the present invention 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.
[0206] 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 invention, 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, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, ROM, RAM, magnetic disks, or optical disks.
[0207] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A method for generating a component configuration table, characterized in that: include: Obtain each source code file in the target project and generate an abstract syntax tree for each source code file; For the abstract syntax tree of any of the source code files, the nodes in the abstract syntax tree are filtered based on a whitelist to obtain a target node; wherein the whitelist includes at least one type identifier; the step of filtering the nodes in the abstract syntax tree for any of the source code files based on the whitelist to obtain the target node comprises: for the abstract syntax tree of any of the source code files, based on the type identifier included in the whitelist, obtaining the node under the type identifier in the abstract syntax tree as the first node of the source code file, the type identifier including at least one of the type identifier of the object type and the type identifier of the enumeration type; filtering out invalid nodes in the first node to obtain the target node of the source code file; wherein the invalid nodes include at least one of private nodes, abstract nodes, implicitly generated nodes, and nodes used for testing; Obtain a constructor for each of the target nodes, and generate a component configuration table for the target project based on the constructor; wherein the component configuration table contains a key-value pair corresponding to each target node, the key value represents the correspondence between the identity identifier of the target node and the instantiation function, and the instantiation function generates a component corresponding to the target node by calling the constructor of the target node when executed.
2. The method according to claim 1, characterized in that The target project includes at least one of a Flutter framework and a Flutter project created based on the Flutter framework.
3. The method according to claim 2, characterized in that In the case where the target project is a Flutter framework, the step of obtaining a constructor of each target node and generating a component configuration table of the target project based on the constructor includes: For any source code file in the Flutter framework, obtain the constructor of each target node under the source code file, and generate a component configuration table of the source code file based on the constructor; According to the data packet to which each of the source code files belongs, the component configuration tables of the source code files are merged, and the component configuration tables of the source code files belonging to the same data packet are merged into one component configuration table to obtain the component configuration table of the Flutter framework.
4. The method according to claim 3, characterized in that: The step of obtaining the constructor of each target node under the source code file and generating the component configuration table of the source code file based on the constructor comprises: Obtaining a constructor of the target node, and generating an initial component configuration table of the source code file based on the constructor of each target node included in the source code file; Obtaining a source code converter adapted to the initial component configuration table, editing the instantiation function in the initial component configuration table, and obtaining a final component configuration table of the source code file; The editing operation includes at least one of adding a referenced member declaration, adding a package import reference, and parameter type conversion.
5. The method according to claim 2, characterized in that: In the case where the target project is a flutter project created based on the flutter framework, the step of obtaining a constructor of each of the target nodes and generating a component configuration table of the target project based on the constructor includes: Obtaining a constructor of each of the target nodes, and generating an initial component configuration table of the target project based on the constructor; Obtaining a source code converter adapted to the initial component configuration table, editing the instantiation function in the initial component configuration table, and obtaining a final component configuration table of the target project; The editing operation includes at least one of adding a referenced member declaration, adding a package import reference, and parameter type conversion.
6. The method according to claim 1, characterized in that The method further comprises: A configuration list of the target project is generated according to each component configuration table under the target project, and is used to retrieve and reference each component configuration table under the target project at runtime.
7. The method according to claim 6, characterized in that The step of filtering the nodes in the abstract syntax tree for any of the source code files based on the whitelist to obtain the target node comprises: For an abstract syntax tree of any of the source code files, filtering nodes in the abstract syntax tree based on a whitelist to obtain target nodes, and confirming component attributes of each of the target nodes, wherein the component attributes include at least one of component type attributes and non-component type attributes; The step of generating a configuration list of the target project according to each component configuration table under the target project, for retrieving and referencing each component configuration table under the target project at runtime, comprises: A configuration list of the target project is generated according to each component configuration table under the target project and the component attributes of each target node.
8. The method according to claim 1, characterized in that The step of obtaining the constructor of each target node includes: For each target node, obtaining a first constructor of the target node from the node information of the target node; Filter out invalid functions in the first constructor to obtain the constructor of the target node; The invalid function includes at least one of a private function and a function used for testing.
9. A device for generating a component configuration table, characterized in that: include: An AST generation module is used to obtain each source code file in the target project and generate an abstract syntax tree for each source code file; A node filtering module, for filtering the nodes in the abstract syntax tree of any of the source code files based on a whitelist to obtain a target node; wherein the whitelist includes at least one type identifier; the node filtering module includes: a first node filtering submodule, for obtaining the node under the type identifier in the abstract syntax tree of any of the source code files based on the type identifier included in the whitelist as the first node of the source code file, wherein the type identifier includes at least one of an object type type identifier and an enumeration type type identifier; a second node filtering submodule, for filtering out invalid nodes in the first node to obtain a target node of the source code file; wherein the invalid node includes at least one of a private node, an abstract node, an implicitly generated node, and a node used for testing; A configuration table generation module is used to obtain the constructor of each target node and generate a component configuration table of the target project based on the constructor; wherein the component configuration table contains a key-value pair corresponding to each target node, and the key value represents the correspondence between the identity identifier of the target node and the instantiation function. When the instantiation function is executed, it generates a component corresponding to the target node by calling the constructor of the target node.
10. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the method for generating a component configuration table as claimed in any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for generating a component configuration table according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Method, device and equipment for executing dynamic codes on page and storage medium
CN111045678A
Project development method and device, server and medium
CN111506314A