Data processing method, device, electronic device, storage medium and product
By generating switch information files and removing switch code based on confirmation information, the problem of low efficiency in removing switch control code is solved, achieving efficient and comprehensive code cleanup, reducing application package size and computational resource waste.
Patent Information
- Application Number
- CN202111620200.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2041-12-27
AI Technical Summary
The removal of switch control code in the existing technology is inefficient, consumes a lot of manpower, and incomplete removal leads to an increase in application package size, resulting in a waste of computing resources.
By generating a preset list of switches, obtaining switch information from the code file and generating a switch information file, obtaining confirmation information indicating the switches to be removed, and removing the switch code based on the switch information.
It simplifies the removal process of switch codes, saves manpower costs, achieves more comprehensive and accurate removal of switch codes, reduces the size of application packages, and saves computing resources.
Smart Images

Figure CN114489595B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a data processing method, device, electronic device, storage medium and product. Background Art
[0002] With the continuous development of computer technology, various application projects are also constantly derived and promoted. In the process of application projects, most application functions have their corresponding switch control codes, which still exist in the project in the later stage.
[0003] In the prior art, the removal of switch control codes is usually performed by developers. However, due to factors such as project personnel changes and application version cycle iterations, the search process for developers is cumbersome and inefficient, which consumes a lot of manpower costs. At the same time, the number of switch control codes manually removed by developers is limited, and there are still a large number of unused codes in the project, which increases the size of the application package and wastes computing resources. Summary of the invention
[0004] In order to overcome the problems existing in the related art, the present disclosure provides a data processing method, device, electronic device, storage medium and product.
[0005] According to a first aspect of an embodiment of the present disclosure, there is provided a data processing method, including:
[0006] In the case where the code file of the project to be processed includes a switch calling method defined in a preset switch list, obtaining switch information corresponding to the switch calling method in the code file, and generating a switch information file;
[0007] Acquire confirmation information of the switch settings represented by each switch information in the switch information file;
[0008] The switch for which the confirmation information indicates a removal operation is taken as a switch to be removed, a switch code corresponding to the switch to be removed is obtained, and the switch code is removed based on the switch information.
[0009] Optionally, before obtaining the switch information corresponding to the switch calling method in the code file, the method further includes:
[0010] Traversing all code files in the project to be processed to obtain grammatical structures corresponding to each code file;
[0011] Based on the grammatical structure, determining a node whose node type of the code file is a method call node as a first candidate node;
[0012] In a case where the preset switch list includes the calling method of the first candidate node, it is determined that the code file corresponding to the first candidate node includes the switch calling method defined in the preset switch list.
[0013] Optionally, the obtaining switch information corresponding to the switch calling method in the code file includes:
[0014] In the case where the preset switch list includes the calling method of the first candidate node, obtaining an expression list corresponding to the first candidate node; the expression list includes all expressions under the first candidate node;
[0015] Based on the expression list, switch information corresponding to the switch calling method is determined.
[0016] Optionally, the switch information includes a switch name; and obtaining a switch code corresponding to the switch to be removed includes:
[0017] Traversing all code files of the project to be processed, and determining a target code file including the switch name of the switch to be removed;
[0018] The switch code corresponding to the switch name of the switch to be removed in the target code file is used as the switch code to be removed.
[0019] Optionally, traversing all code files of the project to be processed to determine a target code file including the switch name of the switch to be removed includes:
[0020] Traversing all code files in the project to be processed to obtain grammatical structures corresponding to each code file;
[0021] Based on the grammatical structure, determining a node whose node type of the code file is a method call node as a second candidate node;
[0022] In a case where the calling method of the second candidate node includes the switch name, the code file corresponding to the second candidate node is used as the target code file.
[0023] Optionally, the switch information also includes a switch target value;
[0024] Before removing the switch code based on the switch information, the method further includes:
[0025] Parsing the switch code to be removed to obtain a current switch target value of the switch code to be removed;
[0026] In a case where the current switch target value is equal to the switch target value in the switch information corresponding to the switch to be removed, the step of removing the switch code based on the switch information is performed.
[0027] Optionally, the switch information file complies with a data exchange format corresponding to a JAVA operating environment.
[0028] According to a second aspect of an embodiment of the present disclosure, there is provided a data processing device, including:
[0029] A first acquisition module is configured to, when a code file of the project to be processed includes a switch calling method defined in a preset switch list, acquire switch information corresponding to the switch calling method in the code file and generate a switch information file;
[0030] A second acquisition module is configured to acquire confirmation information of the switch setting represented by each switch information in the switch information file;
[0031] The removal module is configured to take the switch for which the confirmation information indicates a removal operation as a switch to be removed, obtain a switch code corresponding to the switch to be removed, and remove the switch code based on the switch information.
[0032] Optionally, the device further comprises:
[0033] The first traversal module is configured to traverse all code files in the project to be processed to obtain the grammatical structure corresponding to each code file;
[0034] A first determination module is configured to determine, based on the grammatical structure, a node whose node type of the code file is a method call node as a first candidate node;
[0035] The third determining module is configured to determine, when the preset switch list includes the calling method of the first candidate node, that the code file corresponding to the first candidate node includes the switch calling method defined in the preset switch list.
[0036] Optionally, the first acquisition module is specifically configured to:
[0037] In the case where the preset switch list includes the calling method of the first candidate node, obtaining an expression list corresponding to the first candidate node; the expression list includes all expressions under the first candidate node;
[0038] Based on the expression list, switch information corresponding to the switch calling method is determined.
[0039] Optionally, the switch information includes a switch name; and the removal module is specifically configured to:
[0040] Traversing all code files of the project to be processed, and determining a target code file including the switch name of the switch to be removed;
[0041] The switch code corresponding to the switch name of the switch to be removed in the target code file is used as the switch code to be removed.
[0042] Optionally, the removal module is further specifically configured to:
[0043] Traversing all code files in the project to be processed to obtain grammatical structures corresponding to each code file;
[0044] Based on the grammatical structure, determining a node whose node type of the code file is a method call node as a second candidate node;
[0045] In a case where the calling method of the second candidate node includes the switch name, the code file corresponding to the second candidate node is used as the target code file.
[0046] Optionally, the switch information further includes a switch target value; and the device further includes:
[0047] A parsing module is configured to parse the switch code to be removed to obtain a current switch target value of the switch code to be removed;
[0048] The execution module is configured to execute the step of removing the switch code based on the switch information when the current switch target value is equal to the switch target value in the switch information corresponding to the switch to be removed.
[0049] Optionally, the switch information file complies with a data exchange format corresponding to a JAVA operating environment.
[0050] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0051] processor;
[0052] a memory for storing instructions executable by the processor;
[0053] The processor is configured to execute the instructions to implement the data processing method as described in any one of the above items.
[0054] According to a fourth aspect of the present disclosure, a storage medium is provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device executes a data processing method as described in any one of the above items.
[0055] According to a fifth aspect of the present disclosure, a computer program product is provided, the computer program product comprising readable program instructions, and when the readable program instructions are executed by a processor of an electronic device, the electronic device executes any of the data processing methods described above.
[0056] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0057] In the embodiment of the present disclosure, when the code file of the project to be processed includes a switch calling method defined in a preset switch list, the switch information corresponding to the switch calling method in the code file is obtained, and a switch information file is generated; the confirmation information set for the switch represented by each switch information in the switch information file is obtained; the switch whose confirmation information indicates a removal operation is taken as the switch to be removed, the switch code corresponding to the switch to be removed is obtained, and the switch code is removed based on the switch information. Compared with the technical means for developers to manually find and remove codes, in the embodiment of the present disclosure, the switch information file is generated by collecting the switch information in the project to be processed, and the corresponding switch code is uniformly removed by setting the confirmation information in the switch information file. The operation is relatively simple and efficient, saving labor costs; at the same time, the switch removal is more comprehensive and accurate, reducing the size of the application package, and saving computing resources to a certain extent.
[0058] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0060] Figure 1 is a flowchart of the steps of a data processing method according to an embodiment of the present disclosure;
[0061] Figure 2 is a schematic diagram of a generation process of a switch information file according to an embodiment of the present disclosure;
[0062] Figure 3 is a schematic diagram of a switch removal process according to an embodiment of the present disclosure;
[0063] Figure 4 is a block diagram of a data processing device according to an embodiment of the present disclosure;
[0064] Figure 5 is a block diagram of an electronic device according to an embodiment of the present disclosure;
[0065] Figure 6 is a block diagram of another electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0066] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0067] Figure 1 A flowchart of the steps of a data processing method in an embodiment of the present disclosure. The execution subject of the method can be an electronic device, specifically a smart phone, a computer, a notebook, a tablet computer, a car computer, etc., which is not limited in the embodiment of the present disclosure. Figure 1 As shown, the data processing method specifically includes the following steps:
[0068] Step 101: When a code file of a project to be processed includes a switch calling method defined in a preset switch list, obtain switch information corresponding to the switch calling method in the code file, and generate a switch information file.
[0069] In the embodiments of the present disclosure, the project to be processed may refer to an engineering project in the process of application development, etc. The code file may refer to a file formed by various codes in the engineering project. The preset switch list is a list preset in advance, which may include various common switch calling methods. The switch calling method may refer to a specific expression used when calling various switches. Exemplarily, the switch method call includes:
[0070] 1. SwitchConfigManager.getInstance().getBoolean
[0071] 2. SwitchConfigManager.getInstance().getInt
[0072] Among them, Boolean and Int are specific switch calling methods. Since the specific name of the switch calling method can be customized, the embodiment of the present disclosure does not limit the specific type and name of the switch calling method.
[0073] The switch information may refer to various information corresponding to the switches in the project to be processed, including the switch name, etc. The switch information file may refer to a document formed by collecting various switches in the project to be processed, and the user may subsequently process the switches in the project to be processed in a unified manner based on the switch information file.
[0074] In this step, a preset switch list can be pre-set, which includes multiple switch calling methods; then the electronic device reads and stores the preset switch list, and then searches the code file of the project to be processed for a code file including the switch calling method defined in the preset switch list; then, the switch information in each code file including the switch calling method defined in the preset switch list is counted, and a switch information file is generated based on the counted switch information.
[0075] Step 102: Acquire confirmation information of the switch settings represented by each switch information in the switch information file.
[0076] In the embodiment of the present disclosure, the confirmation information may refer to the indication information indicating whether the switch corresponds to a delete operation or a retain operation. After the switch information file is generated, the switch information file may receive and save the confirmation information set for each switch, so that the switch codes in the pending items can be uniformly deleted, which is more convenient and efficient.
[0077] Step 103: taking the switch for which the confirmation information indicates a removal operation as a switch to be removed, obtaining a switch code corresponding to the switch to be removed, and removing the switch code based on the switch information.
[0078] In the embodiment of the present disclosure, the switch to be removed may refer to a switch to be deleted. The switch code may refer to a specific code corresponding to the switch to be removed.
[0079] Specifically, in this step, after saving corresponding confirmation information for each switch in the switch information file, the electronic device can read the switch information file, and when the confirmation information indicates a removal operation, use the switch corresponding to the confirmation information as a switch to be removed, obtain the switch code of the switch to be removed in the project to be processed, and perform a removal operation. In this way, all switches to be removed included in the project to be processed and corresponding to the confirmation information can be deleted, thereby realizing a unified deletion operation of the switch code.
[0080] In summary, a data processing method provided by an embodiment of the present disclosure obtains switch information corresponding to the switch calling method in the code file and generates a switch information file when the code file of the project to be processed includes a switch calling method defined in a preset switch list; obtains confirmation information set for the switch represented by each switch information in the switch information file; takes the switch whose confirmation information indicates a removal operation as the switch to be removed, obtains the switch code corresponding to the switch to be removed, and removes the switch code based on the switch information. Compared with the technical means for developers to manually find and remove codes, in the embodiment of the present disclosure, the switch information file is generated by collecting the switch information in the project to be processed, and the corresponding switch code is uniformly removed by setting confirmation information in the switch information file. The operation is relatively simple and efficient, saving labor costs; at the same time, the switch removal is more comprehensive and accurate, reducing the size of the application package, and saving computing resources to a certain extent.
[0081] Optionally, in the embodiment of the present disclosure, before step 101, the data processing method may further include the following steps S21 to S23:
[0082] Step S21, traverse all code files in the project to be processed to obtain the grammatical structures corresponding to each code file.
[0083] In the disclosed embodiment, the grammatical structure may refer to the Program Structure Interface (PSI) of each code file in the project to be processed. The PSI is a layer in the IntelliJ platform (an integrated environment for JAVA language development) responsible for parsing files and creating syntactic and semantic code models, which can support multiple functions of the platform.
[0084] In this step, when obtaining the switch information corresponding to the switch calling method in the code file, it is first necessary to determine which code files in the project to be processed include the switch calling method. After reading the preset switch method list, the electronic device can traverse all the code files in the project to be processed, and obtain the PSI syntax structure corresponding to each code file based on the SDK environment of the IntelliJ platform. The SDK environment is a JAVA operating environment. The PSI syntax structure is a tree structure, and by traversing the PSI structure of each code file, the subsequent judgment process can be performed concisely and conveniently.
[0085] Step S22: Based on the grammatical structure, determine that the node type of the code file is a node of a method call node as a first candidate node.
[0086] In the disclosed embodiment, the node type may refer to the type corresponding to the code file. The method call node (PsiMethodCallExpression) may refer to the node of the method call in the PSI syntax structure of JAVA. The first candidate node may refer to the method call node, and it is still necessary to further determine whether the method called by the first candidate node is a switch call method.
[0087] In this step, after obtaining the PSI syntax structure corresponding to each code file, the electronic device can traverse the PSI syntax structure of each code file from top to bottom, and during the traversal process, determine whether the node type of the current PSI syntax structure is a method call node. If so, the node corresponding to the current PSI syntax structure is used as the first candidate node, and the first candidate node still needs to be determined later.
[0088] Step S23: When the preset switch list includes the calling method of the first candidate node, determine that the code file corresponding to the first candidate node includes the switch calling method defined in the preset switch list.
[0089] In the disclosed embodiment, the calling method may refer to the calling method actually adopted by the first candidate node, and may be determined based on the content prefix of the first candidate node, and the content prefix may refer to the code expression included in the first candidate node and used to represent the calling method. Specifically, after determining the first candidate node belonging to the method calling node, it may be further determined whether the method called in the first candidate node is the same as one of the switch calling methods defined in the preset switch list. If so, it is determined that the code file corresponding to the first candidate node includes the switch calling method defined in the preset switch list, and the switch information acquisition operation may be performed subsequently to count the switch information in the first candidate node.
[0090] In the disclosed embodiment, all code files in the project to be processed are traversed to obtain the grammatical structures corresponding to each code file; based on the grammatical structure, the node type of the code file is determined to be a node of a method call node as the first candidate node; when the preset switch list includes the call method of the first candidate node, it is determined that the code file corresponding to the first candidate node includes the switch call method defined in the preset switch list. In this way, by obtaining the PSI grammatical structure of each code file and traversing it, the code file including the switch call method defined in the preset switch list is determined, which ensures the comprehensiveness of the switch information collection, and at the same time, traversal based on the grammatical structure is more concise and efficient.
[0091] Optionally, in the embodiment of the present disclosure, step 101 may specifically include the following steps 1011 to 1012:
[0092] Step 1011: When the preset switch list includes the calling method of the first candidate node, obtain an expression list corresponding to the first candidate node; the expression list includes all expressions under the first candidate node.
[0093] In the embodiment of the present disclosure, the expression list (PsiExpressionList) may refer to a list formed by all expressions in the code file where the first candidate node is located. The expression may specifically refer to a text description of various codes in the code file, such as a function name, a switch name, etc. The embodiment of the present disclosure does not limit the specific type of the expression.
[0094] Step 1012: Based on the expression list, determine the switch information corresponding to the switch calling method.
[0095] In an embodiment of the present disclosure, after determining the expression list of the code file corresponding to the first alternative node, the electronic device can further search for the PsiLiteralExpression nodes corresponding to all the switch calling methods and the corresponding codes therein based on the expression list, and then determine the switch information corresponding to the switch calling method in the code file and generate a switch information file.
[0096] In the embodiment of the present disclosure, when the preset switch list includes the calling method of the first candidate node, the expression list corresponding to the first candidate node is obtained; the expression list includes all expressions under the first candidate node; based on the expression list, the switch information corresponding to the switch calling method is determined. In this way, by obtaining the expression list of the first candidate node, the switch information corresponding to the switch calling method in the first candidate node can be quickly and accurately determined, thereby improving the efficiency and accuracy of determining the switch information.
[0097] Optionally, in the embodiment of the present disclosure, the switch information includes the switch name. Accordingly, step 103 may specifically include the following steps 1031 to 1032:
[0098] Step 1031: traverse all code files of the project to be processed to determine a target code file including the switch name of the switch to be removed.
[0099] In the disclosed embodiment, the switch name may refer to the switch name corresponding to the confirmation information indicating the removal operation. The target code file may refer to the code file including the switch to be removed. Specifically, after the switch information file is generated, the switch information file may receive and save the confirmation information set for each switch. Afterwards, the electronic device may read the switch information file and traverse all the code files in the project to be processed to determine the code file including the switch to be removed as the target code file.
[0100] Step 1032: Use the switch code corresponding to the switch name of the switch to be removed in the target code file as the switch code to be removed.
[0101] In the disclosed embodiment, the switch code to be removed may refer to the code to be deleted. Since the code file includes many codes, after determining the target code file, it is necessary to further determine the switch code in the target code file as the switch code to be removed to ensure the accuracy of the removal operation.
[0102] In the embodiment of the present disclosure, all code files of the project to be processed are traversed to determine the target code file including the switch name of the switch to be removed; the switch code corresponding to the switch name of the switch to be removed in the target code file is used as the switch code to be removed. In this way, by traversing all code files of the project to be processed and determining the switch code to be removed, the comprehensiveness and accuracy of the switch removal in the project code is guaranteed.
[0103] Optionally, step 1031 may specifically include the following steps S31 to S33:
[0104] Step S31, traverse all code files in the project to be processed to obtain the grammatical structures corresponding to each code file.
[0105] In the disclosed embodiment, after the switch information file is generated, the switch information file receives and saves the confirmation information to implement the switch removal operation. The removal operation ultimately deletes the switch code in the code file of the project to be processed, so it is necessary to re-traverse all the code files in the project to be processed to determine the switch code to be deleted. Specifically, in this step, all the code files in the project to be processed are traversed, and the PSI structure corresponding to each code file is obtained with the help of IntelliJ SDK. The PSI structure corresponds to a tree structure, and the PSI of each code file must be traversed from top to bottom.
[0106] Step S32: Based on the grammatical structure, determine that the node type of the code file is a node of a method call node as a second candidate node.
[0107] In the embodiment of the present disclosure, the second candidate node may refer to a node whose node type is a method call node. It may be further determined later whether the second candidate node includes a switch to be removed.
[0108] Step S33: When the calling method of the second candidate node includes the switch name, the code file corresponding to the second candidate node is used as the target code file.
[0109] In the embodiment of the present disclosure, after the second candidate node is determined, the actual calling method of the second candidate node can be compared with the switch name. If the two are the same, it means that the second candidate node includes the switch name, and the code file corresponding to the second candidate node is the target code file.
[0110] It should be noted that in the embodiments of the present disclosure, there is a certain change process in the process of project advancement and iteration of the pending project, and the specific engineering code files in the early, middle and late stages may be inconsistent. Assuming that a switch information file is generated based on the pending project in the middle stage of the project, and then the project is continued to be advanced, and in the later stage of the project, a switch removal operation is performed on the pending project in the later stage of the project based on the switch information file, at this time, the first candidate node determined in the middle stage of the project advancement and the second candidate node determined in the later stage of the project are not necessarily exactly the same. Of course, the switch information file can also be regenerated for the pending project in the later stage of the project, in which case the first candidate node and the second candidate node can be the same, and the embodiments of the present disclosure do not limit this.
[0111] In the embodiment of the present disclosure, all code files in the project to be processed are traversed to obtain the grammatical structures corresponding to each code file; based on the grammatical structure, a node of the code file whose node type is a method call node is determined as a second candidate node; when the calling method of the second candidate node includes a switch name, the code file corresponding to the second candidate node is used as the target code file. In this way, by traversing all engineering code files in the project to be processed to determine the target code file, the accuracy of switch removal can be improved.
[0112] Optionally, the switch information also includes a switch target value.
[0113] Accordingly, before step 103, the data processing method may include the following steps S41 to S42:
[0114] Step S41: parsing the switch code to be removed to obtain the current switch target value of the switch code to be removed.
[0115] In the disclosed embodiment, the switch target value may refer to the target value corresponding to the switch code in the code file. Since the function of the switch is to control the opening or closing of a specific function, and to play the role of conduction or shutdown, the switch target value may characterize whether the function of the switch is on or off. The current switch target value may refer to the current target value of the switch to be removed in the project to be processed. In this step, the electronic device may perform parsing operation based on the switch code to be removed, determine the target value corresponding to the switch code to be removed, and obtain the current switch target value.
[0116] Step S42: When the current switch target value is equal to the switch target value in the switch information corresponding to the switch to be removed, performing the step of removing the switch code based on the switch information.
[0117] In the disclosed embodiment, due to the advancement of the project, the target value of the switch code may change. At this time, it is necessary to determine whether the current target value of the switch to be removed in the pending project is the same as the switch target value in the switch information file. If they are the same, it means that the switch to be removed has not changed before and after, and the removal operation can be performed. If they are not the same, it means that the switch to be removed has changed before and after, and cannot be directly removed. In this step, if the current switch target value is equal to the switch target value in the switch information, it means that the switch to be removed has not changed, and the removal operation can be performed.
[0118] In the disclosed embodiment, the switch code to be removed is parsed to obtain the current switch target value of the switch code to be removed; when the current switch target value is equal to the switch target value in the switch information corresponding to the switch to be removed, the step of removing the switch code based on the switch information is performed. In this way, by determining whether the current switch target value is the same as the switch target value in the switch information file to determine whether to perform the removal operation, it is possible to avoid the switch removal operation from having a negative impact on the normal operation of the code file, and improve the rationality and accuracy of the switch code deletion.
[0119] Optionally, in an embodiment of the present disclosure, the switch information file complies with a data exchange format corresponding to a JAVA operating environment.
[0120] In the disclosed embodiment, when generating the switch information file, a format that complies with the JAVA operating environment may be generated so that JAVA can directly read and run it, thereby improving the efficiency of data generation and reading and facilitating flexible modification by users.
[0121] Exemplarily, the switch information file may be JavaScript Object Notation (json), which is a lightweight data exchange format that uses a text format that is completely independent of the programming language to store and represent data, making it easy for users to read and write, and also easy for electronic devices to parse and generate.
[0122] Specifically, in the embodiment of the present disclosure, when generating a switch information file based on the switch information, the switch information corresponding to each switch may be stored in the following manner:
[0123]
[0124] Among them, key can be used to represent the switch name, which can be determined based on the expression list of the first candidate node; value can be used to represent the switch target value, which can be determined based on the expression list of the first candidate node. Specifically, the target value of the switch can be determined by obtaining the code under the switch name in the expression list and parsing and running it. confirmed can be used to represent confirmation information, which can be manually written by the user. When the user sets confirmed to true, it can indicate that the user needs to remove the switch corresponding to the confirmation information.
[0125] In addition, after reading the confirmation information and determining the switch code to be removed in the engineering code file based on the switch name corresponding to the confirmation information, it can be determined whether the current target value of the switch code to be removed is equal to the switch target value of the switch information in the switch information file, that is, the value. If they are equal, the PsiMethodCallExpression node corresponding to the switch to be removed can be deleted, and a PsiLiteralExpression node is added at the PsiMethodCallExpression, where the value is the value of value in the switch information. That is to say, in the embodiment of the present disclosure, the switch to be removed is directly replaced with the switch target value in the switch information, which can not only realize the function of the switch itself, but also realize the removal of the switch code.
[0126] For example, Figure 2 FIG. 2 is a schematic diagram showing a generation process of a switch information file according to an embodiment of the present disclosure. Figure 2As shown, the electronic device reads a preset switch list and stores the data therein, and the preset switch list includes a variety of switch calling methods. Afterwards, all code files in the project to be processed are traversed, and the PSI tree syntax structure corresponding to each code file is obtained with the help of IntelliJ SDK. The PSI structure corresponds to a tree structure, and the PSI of each code file is traversed from top to bottom. During the traversal process, it is determined whether the node type of the current PSI is a method call node, that is, PsiMethodCallExpression. If not, continue to traverse the next PSI structure and make a judgment. If so, the node corresponding to the PSI structure is used as the first candidate node. Afterwards, it is further determined whether the preset switch list includes the calling method of the first candidate node. If not, the first candidate node is not a switch method call, and the next candidate node is continued to be judged. If so, the first candidate node includes the switch calling method in the preset switch list, then the expression list composed of all expressions under the first candidate node is obtained, and the switch information is determined. After the traversal is completed, the switch information document corresponding to the project to be processed can be generated. In this way, by collecting and counting all existing switches in the project to be processed and forming a document, it is convenient for users to perform unified operation and maintenance, and at the same time, users do not need to manually search for switches, thereby improving the efficiency of switch search.
[0127] For example, Figure 3 FIG. 2 shows a schematic diagram of a switch removal process according to an embodiment of the present disclosure. Figure 3 As shown, the electronic device reads the switch information file, and when the confirmation information indicates the removal operation, traverses all the code files in the project, and obtains the corresponding PSI structure with the help of IntelliJ SDK. After that, the PSI of each code file is traversed to determine the second candidate node whose node type is the method call node. Then, it is further determined whether the second candidate node includes the switch name corresponding to the confirmation information. If so, it is determined that the code file corresponding to the second candidate node is the target code file, and the switch code to be removed is determined. Then the switch code to be removed is parsed and run to obtain the current switch target value corresponding to the switch code to be removed. When the current switch target value is equal to the switch target value in the switch information file, the switch code to be removed is directly replaced with the switch target value in the switch information file. In this way, the embodiment of the present disclosure generates a switch information file by detecting all the switch information in the project to be processed, and supports users to uniformly modify and remove switches based on the switch information file, so that when compiling with the help of JAVA virtual machine (Java Virtual Machine, JVM), the call of the corresponding function can be reduced, the application package volume can be reduced, and computing resources can be saved.
[0128] Figure 4is a block diagram of a data processing device according to an exemplary embodiment. Figure 4 As shown, the data processing device 40 may include:
[0129] The first acquisition module 401 is configured to acquire switch information corresponding to the switch calling method defined in the preset switch list in the code file of the project to be processed, and generate a switch information file;
[0130] The second acquisition module 402 is configured to acquire confirmation information of the switch setting represented by each switch information in the switch information file;
[0131] The removal module 403 is configured to take the switch for which the confirmation information indicates a removal operation as a switch to be removed, obtain a switch code corresponding to the switch to be removed, and remove the switch code based on the switch information.
[0132] The switch removal device provided in the embodiment of the present disclosure obtains the switch information corresponding to the switch calling method in the code file and generates a switch information file when the code file of the project to be processed includes the switch calling method defined in the preset switch list; obtains the confirmation information set for the switch represented by each switch information in the switch information file; takes the switch whose confirmation information indicates the removal operation as the switch to be removed, obtains the switch code corresponding to the switch to be removed, and removes the switch code based on the switch information. Compared with the technical means for developers to manually find and remove codes, in the embodiment of the present disclosure, the switch information file is generated by collecting the switch information in the project to be processed, and the corresponding switch code is uniformly removed by setting the confirmation information in the switch information file. The operation is relatively simple and efficient, saving labor costs; at the same time, the switch removal is more comprehensive and accurate, reducing the size of the application package, and saving computing resources to a certain extent.
[0133] Optionally, the device 40 further includes:
[0134] The first traversal module is configured to traverse all code files in the project to be processed to obtain the grammatical structure corresponding to each code file;
[0135] A first determination module is configured to determine, based on the grammatical structure, a node whose node type of the code file is a method call node as a first candidate node;
[0136] The third determining module is configured to determine, when the preset switch list includes the calling method of the first candidate node, that the code file corresponding to the first candidate node includes the switch calling method defined in the preset switch list.
[0137] Optionally, the first acquisition module 401 is specifically configured to:
[0138] In the case where the preset switch list includes the calling method of the first candidate node, obtaining an expression list corresponding to the first candidate node; the expression list includes all expressions under the first candidate node;
[0139] Based on the expression list, switch information corresponding to the switch calling method is determined.
[0140] Optionally, the switch information includes a switch name; the removal module 403 is specifically configured to:
[0141] Traversing all code files of the project to be processed, and determining a target code file including the switch name of the switch to be removed;
[0142] The switch code corresponding to the switch name of the switch to be removed in the target code file is used as the switch code to be removed.
[0143] Optionally, the removal module 403 is further specifically configured to:
[0144] Traversing all code files in the project to be processed to obtain grammatical structures corresponding to each code file;
[0145] Based on the grammatical structure, determining a node whose node type of the code file is a method call node as a second candidate node;
[0146] In a case where the calling method of the second candidate node includes the switch name, the code file corresponding to the second candidate node is used as the target code file.
[0147] Optionally, the switch information further includes a switch target value; and the device 40 further includes:
[0148] A parsing module is configured to parse the switch code to be removed to obtain a current switch target value of the switch code to be removed;
[0149] The execution module is configured to execute the step of removing the switch code based on the switch information when the current switch target value is equal to the switch target value in the switch information corresponding to the switch to be removed.
[0150] Optionally, the switch information file complies with a data exchange format corresponding to a JAVA operating environment.
[0151] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0152] According to one embodiment of the present disclosure, an electronic device is provided, comprising: a processor and a memory for storing processor executable instructions, wherein the processor is configured to implement the steps in the data processing method in any of the above embodiments when executing.
[0153] According to an embodiment of the present disclosure, a storage medium is further provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the steps in the data processing method in any of the above embodiments.
[0154] According to one embodiment of the present disclosure, a computer program product is also provided. The computer program product includes readable program instructions. When the readable program instructions are executed by a processor of an electronic device, the electronic device can execute the steps in the data processing method in any of the above embodiments.
[0155] Figure 5 4 is a block diagram of a terminal according to an exemplary embodiment. For example, the terminal 400 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0156] Reference Figure 5 , the device 500 may include one or more of the following components: a processing component 502 , a memory 504 , a power component 506 , a multimedia component 508 , an audio component 510 , an input / output (I / O) interface 512 , a sensor component 514 , and a communication component 516 .
[0157] The processing component 502 generally controls the overall operation of the device 500, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 502 may include one or more processors 520 to execute instructions to complete all or part of the steps of the above-mentioned data processing method. In addition, the processing component 502 may include one or more modules to facilitate the interaction between the processing component 502 and other components. For example, the processing component 502 may include a multimedia module to facilitate the interaction between the multimedia component 508 and the processing component 502.
[0158] The memory 504 is configured to store various types of data to support operations on the device 500. Examples of such data include instructions for any application or method operating on the device 500, contact data, phone book data, messages, pictures, videos, etc. The memory 504 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0159] The power supply component 506 provides power to the various components of the device 500. The power supply component 506 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 500.
[0160] The multimedia component 508 includes a screen that provides an output interface between the device 500 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 508 includes a front camera and / or a rear camera. When the device 500 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0161] The audio component 510 is configured to output and / or input audio signals. For example, the audio component 510 includes a microphone (MIC), and when the device 500 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 504 or sent via the communication component 516. In some embodiments, the audio component 510 also includes a speaker for outputting audio signals.
[0162] I / O interface 512 provides an interface between processing component 502 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0163] The sensor assembly 514 includes one or more sensors for providing various aspects of status assessment for the device 500. For example, the sensor assembly 514 can detect the open / closed state of the device 500, the relative positioning of components, such as the display and keypad of the device 500, and the sensor assembly 514 can also detect the position change of the device 500 or a component of the device 500, the presence or absence of user contact with the device 500, the orientation or acceleration / deceleration of the device 500, and the temperature change of the device 500. The sensor assembly 514 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 514 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 514 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0164] The communication component 516 is configured to facilitate wired or wireless communication between the device 500 and other devices. The device 500 can access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 516 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 516 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0165] In an exemplary embodiment, the apparatus 500 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above-mentioned data processing method.
[0166] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 504 including instructions, and the instructions can be executed by the processor 520 of the device 500 to complete the above data processing method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0167] Figure 6 600 is a block diagram of a switch removal device according to an exemplary embodiment. For example, the device 600 may be provided as a server. Figure 6 , the apparatus 600 includes a processing component 622, which further includes one or more processors, and a memory resource represented by a memory 632 for storing instructions, such as an application, that can be executed by the processing component 622. The application stored in the memory 632 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 622 is configured to execute instructions to perform the above-mentioned data processing method.
[0168] The device 600 may also include a power supply component 626 configured to perform power management of the device 600, a wired or wireless network interface 650 configured to connect the device 600 to a network, and an input / output (I / O) interface 658. The device 600 may operate based on an operating system stored in the memory 632, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or the like.
[0169] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0170] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A data processing method, characterized in that: include: In the case where the code file of the project to be processed includes a switch calling method defined in a preset switch list, obtaining switch information corresponding to the switch calling method in the code file, and generating a switch information file; Acquire confirmation information of the switch settings represented by each switch information in the switch information file; The switch for which the confirmation information indicates a removal operation is taken as a switch to be removed, a switch code corresponding to the switch to be removed is obtained, and the switch code is removed based on the switch information; The switch information file is a document formed by the switches in the project to be processed; The confirmation information is the indication information representing the corresponding operation of the switch; The switch information includes a switch name; The obtaining the switch code corresponding to the switch to be removed includes: Traversing all code files of the project to be processed, and determining a target code file including the switch name of the switch to be removed; The switch code corresponding to the switch name of the switch to be removed in the target code file is used as the switch code to be removed.
2. The method according to claim 1, characterized in that Before obtaining the switch information corresponding to the switch calling method in the code file, the method further includes: Traversing all code files in the project to be processed to obtain grammatical structures corresponding to each code file; Based on the grammatical structure, determining a node whose node type of the code file is a method call node as a first candidate node; In a case where the preset switch list includes the calling method of the first candidate node, it is determined that the code file corresponding to the first candidate node includes the switch calling method defined in the preset switch list.
3. The method according to claim 2, characterized in that The obtaining the switch information corresponding to the switch calling method in the code file includes: In the case where the preset switch list includes the calling method of the first candidate node, obtaining an expression list corresponding to the first candidate node; the expression list includes all expressions under the first candidate node; Based on the expression list, switch information corresponding to the switch calling method is determined.
4. The method according to claim 1, characterized in that The traversing all code files of the project to be processed and determining the target code file including the switch name of the switch to be removed includes: Traversing all code files in the project to be processed to obtain grammatical structures corresponding to each code file; Based on the grammatical structure, determining a node whose node type of the code file is a method call node as a second candidate node; In a case where the calling method of the second candidate node includes the switch name, the code file corresponding to the second candidate node is used as the target code file.
5. The method according to claim 1, characterized in that The switch information also includes a switch target value; Before removing the switch code based on the switch information, the method further includes: Parsing the switch code to be removed to obtain a current switch target value of the switch code to be removed; In a case where the current switch target value is equal to the switch target value in the switch information corresponding to the switch to be removed, the step of removing the switch code based on the switch information is performed.
6. The method according to any one of claims 1 to 5, characterized in that: The switch information file complies with the data exchange format corresponding to the JAVA operating environment.
7. A data processing device, characterized in that: include: A first acquisition module is configured to, when a code file of the project to be processed includes a switch calling method defined in a preset switch list, acquire switch information corresponding to the switch calling method in the code file and generate a switch information file; A second acquisition module is configured to acquire confirmation information of the switch setting represented by each switch information in the switch information file; a removal module configured to take the switch for which the confirmation information indicates a removal operation as a switch to be removed, obtain a switch code corresponding to the switch to be removed, and remove the switch code based on the switch information; The switch information file is a document formed by the switches in the project to be processed; The confirmation information is the indication information representing the corresponding operation of the switch; The switch information includes a switch name; the removal module is specifically configured to: Traversing all code files of the project to be processed, and determining a target code file including the switch name of the switch to be removed; The switch code corresponding to the switch name of the switch to be removed in the target code file is used as the switch code to be removed.
8. The device according to claim 7, characterized in that The device also includes: The first traversal module is configured to traverse all code files in the project to be processed to obtain the grammatical structure corresponding to each code file; A first determination module is configured to determine, based on the grammatical structure, a node whose node type of the code file is a method call node as a first candidate node; The third determining module is configured to determine, when the preset switch list includes the calling method of the first candidate node, that the code file corresponding to the first candidate node includes the switch calling method defined in the preset switch list.
9. The device according to claim 8, characterized in that The first acquisition module is specifically configured as follows: In the case where the preset switch list includes the calling method of the first candidate node, obtaining an expression list corresponding to the first candidate node; the expression list includes all expressions under the first candidate node; Based on the expression list, switch information corresponding to the switch calling method is determined.
10. The device according to claim 7, characterized in that The removal module is further specifically configured to: Traversing all code files in the project to be processed to obtain grammatical structures corresponding to each code file; Based on the grammatical structure, determining a node whose node type of the code file is a method call node as a second candidate node; In a case where the calling method of the second candidate node includes the switch name, the code file corresponding to the second candidate node is used as the target code file.
11. The device according to claim 7, characterized in that The switch information also includes a switch target value; and the device also includes: A parsing module is configured to parse the switch code to be removed to obtain a current switch target value of the switch code to be removed; The execution module is configured to execute the step of removing the switch code based on the switch information when the current switch target value is equal to the switch target value in the switch information corresponding to the switch to be removed.
12. The device according to any one of claims 7 to 11, characterized in that The switch information file complies with the data exchange format corresponding to the JAVA operating environment.
13. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the data processing method according to any one of claims 1 to 6.
14. A storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device executes the data processing method as claimed in any one of claims 1 to 6.
15. A computer program product, characterized in that The computer program product comprises readable program instructions, and when the readable program instructions are executed by a processor of an electronic device, the electronic device executes the data processing method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Program switch control method and device and electronic equipment
CN110347403A
Script updating method and device
CN110347416A