Import file processing method and device, storage medium and electronic device

By automatically filtering and annotating unused import files and deciding whether to delete them based on the compilation results, the slow compilation speed problem caused by importing header files in iOS development is solved, achieving the effect of reducing redundant code and improving compilation speed.

CN113918169BActive Publication Date: 2025-09-12NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111308909.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-05
Publication Date
2025-09-12
Estimated Expiration
2041-11-05

AI Technical Summary

Technical Problem

In iOS development, the extensive use of imported header files in projects leads to slow compilation speed, and existing technologies lack effective solutions.

Method used

By obtaining the target file, filtering out unused import files, annotating them, and determining whether to delete them based on the results after compilation, the automatic verification and deletion of useless import files is achieved.

Benefits of technology

Reduce redundant code in project files, increase compilation speed, avoid developers' manual tedious verification, and improve compilation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113918169B_ABST
    Figure CN113918169B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for processing imported files, a storage medium, and an electronic device. The method comprises: obtaining a target file, wherein the target file includes: multiple imported files; screening out an unused first imported file from the multiple imported files; annotating data corresponding to the first imported file in the target file to obtain an annotated target file; compiling the annotated target file to obtain a compilation result; and determining whether to delete the data corresponding to the first imported file based on the compilation result. The present invention solves the technical problem in related arts of slow compilation speeds caused by project files containing a large number of imported header files.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for processing imported files, a storage medium, and an electronic device. Background Art

[0002] In iOS development, #import is commonly used to indicate the import of header files. Importing a header file copies the entire contents of the target .h file into the current file. Using a large number of imported header files in a project can slow down the overall compilation process and increase compilation time.

[0003] To address the above-mentioned problems, no effective solutions have been proposed so far.

[0004] Invention Data

[0005] The embodiments of the present invention provide a method and device for processing imported files, a storage medium, and an electronic device, so as to at least solve the technical problem in the related art that a large number of imported header files are included in a project file, resulting in a slow compilation speed.

[0006] According to one aspect of an embodiment of the present invention, a method for processing an imported file is provided, comprising: obtaining a target file, wherein the target file comprises: multiple imported files; filtering out an unused first imported file from the multiple imported files; annotating data corresponding to the first imported file in the target file to obtain an annotated target file; compiling the annotated target file to obtain a compilation result; and determining whether to delete the data corresponding to the first imported file based on the compilation result.

[0007] Optionally, determining whether to delete data corresponding to the first imported file based on the compilation result includes: if the compilation result is successful, determining to delete the data corresponding to the first imported file; if the compilation result is failed, determining to retain the data corresponding to the first imported file.

[0008] Optionally, after determining to retain the data corresponding to the first imported file, the data corresponding to the first imported file is restored.

[0009] Optionally, the data corresponding to the first imported file in the target file is annotated to obtain the annotated target file, including: traversing the target area of ​​the target file, and obtaining the class name of the second imported file corresponding to the current row data from the target area; when the class name of the second imported file is the same as the class name of the first imported file, determining that the current row data is the data corresponding to the first imported file, and annotating the current row data to obtain the annotated target file.

[0010] Optionally, before traversing the target area of ​​the target file, the method further includes: obtaining a first position of a preset marker in the target file, and determining an area between the start position and the first position of the target file as the target area.

[0011] Optionally, obtaining the target file includes: obtaining a file address set; reading a first file address in the file address set; and determining that the file corresponding to the first file address is the target file.

[0012] Optionally, when multiple first import files are screened out from multiple import files, the data corresponding to the first import file is annotated to obtain the annotated target file, including: obtaining a target class name array corresponding to the target file from multiple class name arrays, wherein each class name array is used to store the class names of multiple unused import files in the file corresponding to each class name array; reading the first class name stored in the target class name array; annotating the import file corresponding to the first class name to obtain the annotated target file.

[0013] Optionally, before obtaining the target class name array corresponding to the target file, the method also includes: obtaining a first number of file addresses contained in the file address set; determining a second number of multiple class name arrays; when the first number is the same as the second number, obtaining the target class name array corresponding to the target file.

[0014] Optionally, after determining whether to delete the data corresponding to the first imported file based on the compilation result, delete the class name corresponding to the first imported file stored in the target class name array, and re-execute the steps of reading the first class name stored in the target class name array, annotating the import file corresponding to the first class name, and obtaining the annotated target file until the target class name array is an empty array.

[0015] Optionally, when the target class name array is an empty array, delete the file address corresponding to the target file in the file address set, and re-execute the step of reading the first file address in the file address set to determine that the file corresponding to the first file address is the target file until the file address set is an empty set.

[0016] According to another aspect of an embodiment of the present invention, a device for processing imported files is also provided, including: an acquisition module for acquiring a target file, wherein the target file includes: multiple imported files; a screening module for screening out an unused first imported file from the multiple imported files; an annotation module for annotating data corresponding to the first imported file in the target file to obtain an annotated target file; a compilation module for compiling the annotated target file to obtain a compilation result; and a deletion module for determining whether to delete the data corresponding to the first imported file based on the compilation result.

[0017] Optionally, the deletion module is further configured to, when the compilation result is successful, determine to delete the data corresponding to the first import file; when the compilation result is failed, determine to retain the data corresponding to the first import file.

[0018] Optionally, the device further includes: a restoration module, configured to restore the data corresponding to the first imported file after determining to retain the data corresponding to the first imported file.

[0019] Optionally, the annotation module includes: a traversal unit, used to traverse the target area of ​​the target file and obtain the class name of the second imported file corresponding to the current row data from the target area; an annotation unit, used to determine that the current row data is the data corresponding to the first imported file when the class name of the second imported file is the same as the class name of the first imported file, and annotate the current row data to obtain the annotated target file.

[0020] Optionally, the annotation module further includes: an area determination unit, configured to obtain a first position of a preset marker in the target file, and determine an area between a start position and the first position of the target file as the target area.

[0021] Optionally, the acquisition module includes: a set acquisition unit for acquiring a file address set; an address reading unit for reading the first file address in the file address set; and a file determination unit for determining that the file corresponding to the first file address is the target file.

[0022] Optionally, the annotation module includes: an array acquisition unit, used to obtain a target class name array corresponding to the target file from multiple class name arrays, wherein each class name array is used to store the class names of multiple unused imported files in the files corresponding to each class name array; a class name reading unit, used to read the first class name stored in the target class name array; the annotation unit is also used to annotate the imported file corresponding to the first class name to obtain the annotated target file.

[0023] Optionally, the annotation module also includes: a quantity acquisition unit, used to obtain a first quantity of file addresses contained in the file address set; a quantity determination unit, used to determine a second quantity of multiple class name arrays; the array acquisition unit is also used to obtain a target class name array corresponding to the target file when the first quantity is the same as the second quantity.

[0024] Optionally, the annotation module also includes: a class name deletion unit, which is used to delete the class name corresponding to the first imported file stored in the target class name array after determining whether to delete the data corresponding to the first imported file based on the compilation result; a class name execution unit, which is used to re-execute the functions of the class name reading unit and the annotation unit until the target class name array is an empty array.

[0025] Optionally, the annotation module also includes: an address deletion unit, used to delete the file address corresponding to the target file in the file address set when the target class name array is an empty array; an address execution unit, used to re-execute the functions of the address reading unit and the file determination unit until the file address set is an empty set.

[0026] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium includes a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute the above-mentioned method for processing imported files.

[0027] According to another aspect of an embodiment of the present invention, an electronic device is also provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a program that can be executed by the at least one processor, and when the program is executed by the at least one processor, the above-mentioned method for processing imported files is executed.

[0028] In an embodiment of the present invention, after obtaining a target file including multiple import files, an unused first import file can be screened out from the multiple import files, and the data corresponding to the first import file in the target file can be further annotated to obtain the annotated target file, and the annotated target file can be compiled to obtain a compilation result, and finally, based on the compilation result, it is determined whether to delete the data corresponding to the first import file. It is easy to notice that the automatic verification of useless import files can be achieved by annotating and compiling the data corresponding to the first import file, and it can be determined based on the compilation result whether to delete the data corresponding to the first import file, thereby achieving the purpose of deleting useless import files in the target file, thereby achieving the technical effect of reducing redundant code of the project file and improving the compilation speed, and solving the technical problem in the related art that the project file contains a large number of import header files, resulting in a slow compilation speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0030] Figure 1 is a flowchart of a method for processing an imported file according to an embodiment of the present invention;

[0031] Figure 2 1 is a schematic diagram of an implementation module of an optional process for troubleshooting useless imported files according to an embodiment of the present invention;

[0032] Figure 3 is a schematic diagram of an optional annotation restoration module according to an embodiment of the present invention;

[0033] Figure 4 is a schematic diagram of an optional implementation function of a compilation verification module according to an embodiment of the present invention;

[0034] Figure 5 is a flowchart of an optional implementation process of a compilation verification module according to an embodiment of the present invention;

[0035] Figure 6 1 is a schematic diagram of an optional implementation function of deleting a useless import file module according to an embodiment of the present invention;

[0036] Figure 7 2 is a schematic diagram of a device for processing imported files according to an embodiment of the present invention. DETAILED DESCRIPTION

[0037] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only 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 making creative efforts should fall within the scope of protection of the present invention.

[0038] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0039] In order to reduce the compilation time of the project, one optimization method is to exclude useless import header files in the project. The relevant technology provides a technical solution for determining the useless imports in some files in the project. However, this solution requires developers to manually check. If the number of useless imports is large, developers need to tediously verify and delete the useless imports, which is time-consuming and labor-intensive.

[0040] According to an embodiment of the present invention, a method for processing imported files is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0041] Figure 1 is a flow chart of a method for processing an imported file according to an embodiment of the present invention. Figure 1 As shown, the method includes the following steps:

[0042] Step S100: Acquire a target file, wherein the target file includes: multiple import files.

[0043] The target file in the above steps can be any code file in the project that uses multiple import files. Since there are many target files that use multiple import files, in order to reduce the number of checks, in an optional embodiment, the code file that needs to be checked for useless import files in the project can be used as the target file.

[0044] The role of the import file in the above steps can be to copy all the contents of the import file to the target file. For example, it can be an import header file, an import library file, etc., but is not limited to this.

[0045] Step S102: Filter out an unused first import file from a plurality of import files.

[0046] In an optional embodiment, a technical solution in related art may be used to filter out useless import files in the target file, namely, the first import file mentioned above.

[0047] Step S104 , annotating the data corresponding to the first imported file in the target file to obtain an annotated target file.

[0048] The data corresponding to the first imported file in the above step may be code data. For example, taking the import of a header file as an example, if the class name of the imported header file is ClassA, the corresponding code line may be #import "ClassA.h".

[0049] In an optional embodiment, a line of code can be commented out by adding two " / " symbols in front of the line of code, so that the line of code will not be compiled during subsequent code compilation. For example, taking the example of importing a header file, the line of code #import "ClassA.h" will become / / #import "ClassA.h" after being commented out.

[0050] It should be noted that since a large number of useless import files are filtered out, a class name array can be set up in advance for each file. The class names of the filtered out useless import files can be stored in the class name array, and then the import files corresponding to each class name in the class name array can be annotated and compiled in turn to achieve the purpose of automatically verifying and troubleshooting all useless import files.

[0051] Step S106: compile the annotated target file to obtain a compilation result.

[0052] The compilation result in the above steps can refer to the result of the compilation command success or failure. For useless import files, commenting out the corresponding code lines will not affect the normal compilation process of the entire file, so the compilation result will be successful. For useful import files, commenting out the corresponding code lines will affect the normal compilation process of the entire file, so the compilation result will be failed, and the specific cause of the failure can be checked.

[0053] In an optional embodiment, the purpose of automatically checking and verifying the filtered useless import files can be achieved by annotating the filtered useless import files and checking whether the compilation command is executed successfully.

[0054] Step S108: Determine whether to delete the data corresponding to the first imported file based on the compilation result.

[0055] Since the compilation result can accurately reflect whether the import file is used by the target file, in an optional embodiment, it can be determined whether to delete the code line in the target file based on the compilation result. If the compilation result is a successful compilation, it indicates that the target file does not use the import file and the import file is a useless import file, so the import file can be deleted; if the compilation result is a failed compilation, it indicates that the target file uses the import file and the import file is not a useless import file, so it needs to be retained.

[0056] Through the above steps, after obtaining the target file including multiple import files, the unused first import file can be screened out from the multiple import files, and the data corresponding to the first import file in the target file can be further annotated to obtain the annotated target file, and the annotated target file can be compiled to obtain the compilation result, and finally, based on the compilation result, it is determined whether to delete the data corresponding to the first import file. It is easy to notice that the automatic verification of useless import files can be achieved by annotating and compiling the data corresponding to the first import file, and it can be determined based on the compilation result whether to delete the data corresponding to the first import file, thereby achieving the purpose of deleting useless import files in the target file, thereby achieving the technical effect of reducing redundant code of the project file and improving the compilation speed, and solving the technical problem in the related art that the project file contains a large number of import header files, resulting in slow compilation speed.

[0057] In the above embodiment of the present invention, determining whether to delete the data corresponding to the first imported file based on the compilation result includes: if the compilation result is compilation success, determining to delete the data corresponding to the first imported file; if the compilation result is compilation failure, determining to retain the data corresponding to the first imported file.

[0058] In an optional embodiment, if the compilation result is successful compilation, it indicates that the target file does not use the first import file, and it is verified that the first import file is a useless import file, so the data corresponding to the first import file can be deleted; if the compilation result is failed compilation, it indicates that the target file uses the first import file, and it is verified that the first import file is not a useless import file, so the data corresponding to the first import file needs to be retained.

[0059] In the above embodiment of the present invention, after determining to retain the data corresponding to the first imported file, the data corresponding to the first imported file is restored.

[0060] Since the above commenting process is performed directly on the code lines in the target file, to avoid the situation where the target file cannot compile successfully due to the commenting of the import file used by the target file, after verifying that the first import file is not a useless import file, that is, the target file will use the first import file, the commented code lines can be uncommented. For example, using the example of importing a header file, for the code line #import "ClassA.h", after uncommenting, the line of code will become #import "ClassA.h".

[0061] It should be noted that errors in comments or comment restoration can be avoided by replacing and retaining the comments or the code after comment restoration and rewriting them into the target file.

[0062] In the above embodiment of the present invention, annotating the data corresponding to the first imported file in the target file to obtain the annotated target file includes: traversing the target area of ​​the target file, and obtaining the class name of the second imported file corresponding to the current row data from the target area; when the class name of the second imported file is the same as the class name of the first imported file, determining that the current row data is the data corresponding to the first imported file, and annotating the current row data to obtain the annotated target file.

[0063] The target area in the above steps may be the area in the target file where the imported file is located. The area may be located at the header of the target file or at a specific position in the target file.

[0064] In an optional embodiment, the data corresponding to all the imported files contained in the target file are located in the target area. In order to annotate the data corresponding to the first imported file, all the code lines in the target area can be traversed, and the class name of the second imported file corresponding to the current code line can be obtained through regular expressions. If the class name of the second imported file is the same as the class name of the first imported file, or the class name of the second imported file is the same as the first class name read in the target array, the current code line can be annotated.

[0065] In the above embodiment of the present invention, before traversing the target area of ​​the target file, the method further includes: obtaining a first position of a preset marker in the target file, and determining an area between the start position and the first position of the target file as the target area.

[0066] The preset identifier in the above steps can be used to identify the end position of the target area. Since the target file implementation code area starts with @implementation, the preset identifier can be @implementation.

[0067] In an optional embodiment, the import file (such as the import header file) is generally placed at the beginning of the target file. Therefore, it is possible to traverse from the beginning of the target file to the position of the first preset identifier, that is, the target area is the area between the start position of the target file and the position corresponding to the first preset identifier. For example, the target area can be the middle area with the start position of the target file as the head and @implementation as the tail.

[0068] In the above embodiment of the present invention, obtaining the target file includes: obtaining a file address set; reading a first file address in the file address set; and determining that the file corresponding to the first file address is the target file.

[0069] The file address set in the above steps can be a set consisting of the addresses of all code files in the project, or a set consisting of the addresses of code files that need to be checked for useless import files.

[0070] In an optional embodiment, since there are a large number of file addresses in the file address set, in order to ensure the accuracy and efficiency of the screening, it can be implemented by screening files one by one, that is, the first file address in the file address combination can be read, and then the file corresponding to the first file address can be used as the target file. After the target file screening is completed, the file address of the file can be deleted from the file address set, and the files corresponding to other file addresses in the file address set can continue to be screened.

[0071] In the above embodiment of the present invention, when multiple first import files are screened out from multiple import files, the data corresponding to the first import file is annotated to obtain the annotated target file, including: obtaining a target class name array corresponding to the target file from multiple class name arrays, wherein each class name array is used to store the class names of multiple unused import files in the file corresponding to each class name array; reading the first class name stored in the target class name array; annotating the import file corresponding to the first class name to obtain the annotated target file.

[0072] In an optional embodiment, for files corresponding to all file addresses included in the file address set, if screening reveals that there may be useless import files, a corresponding class name array can be constructed for them, and the class names of the filtered useless import files can be stored in the class name array, facilitating automatic screening of the import files corresponding to each class name stored in the class name array. Therefore, the aforementioned multiple class name arrays can be arrays constructed for the possible presence of useless import files, each array storing the class names of the useless import files in the corresponding file.

[0073] The files corresponding to all file addresses in the file address set can be screened, and the first imported file screened out can be stored in the class name array. After all files in all file address sets have been screened out, all the first imported files screened out can be automatically screened out. On this basis, the first class name can be read from the class name array corresponding to the current screening, and the imported file corresponding to the class name can be used as the object of annotation and compilation. After the screening of the imported file is completed, the class name corresponding to the imported file can be deleted to avoid the situation where the screening process cannot be completed due to the class name being stored in the class name array.

[0074] It should be noted that the process of annotating and compiling the imported file corresponding to the first class name can refer to the above steps S104 to S108, which will not be described in detail here.

[0075] In the above embodiment of the present invention, before obtaining the target class name array corresponding to the target file, the method also includes: obtaining a first number of file addresses contained in the file address set; determining a second number of multiple class name arrays; when the first number is the same as the second number, obtaining the target class name array corresponding to the target file.

[0076] In an optional embodiment, the process of checking useless imported files needs to obtain the useless imported files corresponding to each file based on the correspondence between the file address and the class name array. For example, the file address set is: [ / Users / Desktop / file1.m, / Users / Desktop / file2.m, / Users / Desktop / file3.m], and the multiple class name arrays are [[class1A, class1B, class1C], [class2A, class2B], [class3A]].

[0077] Therefore, it is first necessary to determine whether the first number of file addresses in the address file set is the same as the second number of the constructed multiple class name arrays. If they are the same, the troubleshooting process can continue, obtain the target class name array, read the first class name, and then annotate the data corresponding to the imported file corresponding to the first class name; if they are different, the troubleshooting process ends.

[0078] In the above embodiment of the present invention, after determining whether to delete the data corresponding to the first import file based on the compilation result, the class name corresponding to the first import file stored in the target class name array is deleted, and the steps of reading the first class name stored in the target class name array and annotating the import file corresponding to the first class name to obtain the annotated target file are re-executed until the target class name array is an empty array.

[0079] In an optional embodiment, in order to avoid the situation where class names are always stored in the class name array, resulting in the inability to complete the troubleshooting process, after checking the first import file, that is, after determining whether to delete the data corresponding to the first import file or retain the data corresponding to the first import file, the class name corresponding to the first import file needs to be deleted from the target class name array. At this time, the original second class name in the target class name array becomes the current first class name, and the first class name stored in the target class name array can be read again, and the troubleshooting process can be continued to achieve the purpose of checking the import files corresponding to all class names stored in the target class name array.

[0080] In the above embodiment of the present invention, when the target class name array is an empty array, the file address corresponding to the target file in the file address set is deleted, and the step of reading the first file address in the file address set and determining that the file corresponding to the first file address is the target file is re-executed until the file address set is an empty set.

[0081] In an optional embodiment, in order to prevent the troubleshooting process from being terminated due to the file addresses being stored in the file address set, after all imported files filtered out by the target file are checked, the file address corresponding to the target file needs to be deleted from the file address set. At this time, the original second file address in the file address set becomes the current first file address, and the first file address in the file address set can be read again, and the troubleshooting process can be continued, thereby achieving the purpose of troubleshooting the files corresponding to all file addresses in the file address set.

[0082] The following combination Figures 2 to 6 A preferred embodiment of the present invention is described in detail. The process of screening out useless import files that may exist in the target file is not described in detail here. Through screening, a set of file addresses where useless import files may exist and a class name array storing the class names corresponding to the useless import files can be determined.

[0083] The troubleshooting process for useless imported files can be done as follows: Figure 2 The given parameter verification module, the zero-time parameter acquisition module, the annotation restoration module, the compilation verification module and the useless import file deletion module are implemented as shown. Among them, the given parameter verification module can determine whether the number of file address sets and class name arrays is consistent. If they are consistent, the zero-time parameter acquisition module can obtain the first file address of the file address set, determine the target category array corresponding to the file address, and read out the first class name, and pass the file address and the first class name as parameters to the annotation restoration module.

[0084] The implementation function of the annotation restoration module is as follows Figure 3As shown, this module can pass in three parameters, namely file path, useless import file, and useful import file. The specific functions are as follows: check parameters, read file import area, comment useless import, restore useful import and file rewrite. Among them, the check parameter function can be used to determine whether the file path parameter exists. If it exists, the subsequent process will be carried out. If it does not exist, the current module will be ended directly; the read file import area function can be used to read the name of the currently imported class in the file import area; the comment useless import function can be used to determine whether the currently imported class name and the passed in useless import file are consistent. If they are consistent, the current line of code will be commented; the restore useful import function can be used to determine whether the currently imported class name and the passed in useful import file are consistent, and the line must be commented. If they are consistent, the current line will be commented and restored; the file rewrite function can be used to replace and retain the commented or restored code and rewrite it into the current file.

[0085] The implementation function of the compilation verification module is as follows Figure 4 As shown, the module will execute in a loop until the array of the given file address is empty before the current module process ends. The specific functions are as follows: execute compilation, the current useless import set is zero, and the current useless import set is not zero. The specific implementation process is as follows Figure 5 As shown. Among them, by executing the compilation function, the compilation command can be executed to obtain the compilation result. If the compilation is successful, the current file address is added to the deletable file set, and finally output to the module for deleting useless import files for use. Through the function of setting the current useless import set to zero, when the useless import set (i.e. the above-mentioned class name array) is zero, if the current compilation fails, it is necessary to restore the last annotation process, delete the first element in the file address set, and delete the class name array corresponding to the file address at the same time. After deletion, the file address set is judged again. If it is empty, the current module process ends; if it is not empty, the first element of the current file address set is obtained, the target category array corresponding to the file address is determined, and the first class name is read out, and the file address and the first class name are passed as parameters to the annotation restoration module. The current useless import set is not zero function can be used to read the next useless import file and annotate it when the useless import set (i.e. the class name array mentioned above) is not zero. If the current compilation is successful, the current file address and the next useless import file are passed as parameters to the comment restoration module; if the current compilation fails, the current file address, the next useless import file, and the current useless import file are passed as parameters to the comment restoration module. Finally, the first element of the useless import set is deleted.

[0086] Delete useless import file module implementation function such as Figure 6As shown in the figure, this module traverses the array of deletable file addresses output by the compilation verification module and deletes the commented imports in the current file address. Its specific functions are as follows: verifying parameters, reading the file import area, and deleting useless imports. The functions of verifying parameters and reading the file import area are the same as those of the comment restoration module and are not detailed here. The useless import deletion function can delete the current line in the header file import area if it contains commented import code, and finally save the current file.

[0087] Through the above solution, useless import files can be verified, saving developers the tedious time of verifying useless imports, and the useless import files found can be deleted, reducing redundant code and further improving the compilation speed.

[0088] According to an embodiment of the present invention, a device for processing imported files is also provided. The device can execute the method for processing imported files in the above embodiment. The specific implementation scheme and preferred application scenario of the device are the same as those in the above embodiment and will not be repeated here.

[0089] Figure 7 is a schematic diagram of a processing device for importing files according to an embodiment of the present invention. Figure 7 As shown, the device includes:

[0090] The acquisition module 70 is used to acquire a target file, wherein the target file includes: a plurality of import files.

[0091] The screening module 72 is configured to screen out unused first import files from a plurality of import files.

[0092] The annotation module 74 is used to annotate the data corresponding to the first imported file in the target file to obtain the annotated target file.

[0093] The compiling module 76 is used to compile the annotated target file to obtain a compilation result.

[0094] The deletion module 78 is configured to determine whether to delete the data corresponding to the first imported file based on the compilation result.

[0095] Optionally, the deletion module is further configured to, when the compilation result is successful, determine to delete the data corresponding to the first import file; when the compilation result is failed, determine to retain the data corresponding to the first import file.

[0096] Optionally, the device further includes: a restoration module, configured to restore the data corresponding to the first imported file after determining to retain the data corresponding to the first imported file.

[0097] Optionally, the annotation module includes: a traversal unit, used to traverse the target area of ​​the target file and obtain the class name of the second imported file corresponding to the current row data from the target area; an annotation unit, used to determine that the current row data is the data corresponding to the first imported file when the class name of the second imported file is the same as the class name of the first imported file, and annotate the current row data to obtain the annotated target file.

[0098] Optionally, the annotation module further includes: an area determination unit, configured to obtain a first position of a preset marker in the target file, and determine an area between a start position and the first position of the target file as the target area.

[0099] Optionally, the acquisition module includes: a set acquisition unit for acquiring a file address set; an address reading unit for reading the first file address in the file address set; and a file determination unit for determining that the file corresponding to the first file address is the target file.

[0100] Optionally, the annotation module includes: an array acquisition unit, used to obtain a target class name array corresponding to the target file from multiple class name arrays, wherein each class name array is used to store the class names of multiple unused imported files in the files corresponding to each class name array; a class name reading unit, used to read the first class name stored in the target class name array; the annotation unit is also used to annotate the imported file corresponding to the first class name to obtain the annotated target file.

[0101] Optionally, the annotation module also includes: a quantity acquisition unit, used to obtain a first quantity of file addresses contained in the file address set; a quantity determination unit, used to determine a second quantity of multiple class name arrays; the array acquisition unit is also used to obtain a target class name array corresponding to the target file when the first quantity is the same as the second quantity.

[0102] Optionally, the annotation module also includes: a class name deletion unit, which is used to delete the class name corresponding to the first imported file stored in the target class name array after determining whether to delete the data corresponding to the first imported file based on the compilation result; a class name execution unit, which is used to re-execute the functions of the class name reading unit and the annotation unit until the target class name array is an empty array.

[0103] Optionally, the annotation module also includes: an address deletion unit, used to delete the file address corresponding to the target file in the file address set when the target class name array is an empty array; an address execution unit, used to re-execute the functions of the address reading unit and the file determination unit until the file address set is an empty set.

[0104] According to an embodiment of the present invention, a computer-readable storage medium is further provided. The computer-readable storage medium includes a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute the method for processing imported files in the above embodiment.

[0105] According to an embodiment of the present invention, an electronic device is also provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a program that can be executed by the at least one processor, and when the program is executed by the at least one processor, the method for processing imported files in the above embodiment is executed.

[0106] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0107] In the several embodiments provided in this application, it should be understood that the disclosed technical data can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of the units can be a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0108] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0109] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0110] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk, etc. Various media that can store program codes.

[0111] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.

Claims

1. A method for processing an imported file, characterized in that: include: Obtaining a target file, wherein the target file includes: a plurality of import files; Filter out an unused first import file from the multiple import files; Annotating the data corresponding to the first imported file in the target file to obtain an annotated target file; Compiling the annotated target file to obtain a compilation result; Determining whether to delete data corresponding to the first imported file based on the compilation result; Wherein, the determining whether to delete the data corresponding to the first imported file based on the compilation result includes: determining whether to delete the code line in the first imported file based on the compilation result; In the case where one first import file is selected from the multiple import files, annotating the data corresponding to the first import file in the target file to obtain the annotated target file includes: Traversing a target area of ​​the target file, and obtaining a class name of a second imported file corresponding to the current row of data from the target area, wherein the head of the target area is the starting position of the target file, and the tail of the target area is the first position of a preset identifier in the target file; when the class name of the second imported file is the same as the class name of the first imported file, determining that the current row of data is the data corresponding to the first imported file, and annotating the current row of data to obtain the annotated target file; In the case where a plurality of first import files are screened out from the plurality of import files, the data corresponding to the first import file in the target file is annotated to obtain the annotated target file, including: Obtain a target class name array corresponding to the target file from multiple class name arrays, wherein each class name array is used to store class names of multiple unused imported files in the file corresponding to each class name array; read the first class name stored in the target class name array; annotate the imported file corresponding to the first class name to obtain the annotated target file.

2. The method according to claim 1, characterized in that The determining whether to delete the data corresponding to the first imported file based on the compilation result includes: If the compilation result is successful, determine to delete the data corresponding to the first imported file; When the compilation result is compilation failure, it is determined to retain data corresponding to the first imported file.

3. The method according to claim 2, characterized in that After determining to retain the data corresponding to the first imported file, the data corresponding to the first imported file is restored.

4. The method according to claim 1, wherein Before traversing the target area of ​​the target file, the method further includes: A first position of the preset marker in the target file is obtained, and an area between a start position of the target file and the first position is determined as the target area.

5. The method according to any one of claims 1 to 4, characterized in that The obtaining of the target file includes: Get the file address collection; Read the first file address in the file address set; Determine that the file corresponding to the first file address is the target file.

6. The method according to claim 5, characterized in that Before obtaining the target class name array corresponding to the target file, the method further includes: Obtaining a first number of file addresses included in the file address set; determining a second number of the plurality of class name arrays; When the first number is the same as the second number, an array of target class names corresponding to the target file is obtained.

7. The method according to claim 5, characterized in that After determining whether to delete the data corresponding to the first import file based on the compilation result, delete the class name corresponding to the first import file stored in the target class name array, and re-execute the steps of reading the first class name stored in the target class name array, annotating the import file corresponding to the first class name, and obtaining the annotated target file, until the target class name array is an empty array.

8. The method according to claim 7, characterized in that When the target class name array is an empty array, delete the file address corresponding to the target file in the file address set, and re-execute the step of reading the first file address in the file address set to determine that the file corresponding to the first file address is the target file until the file address set is an empty set.

9. A device for processing imported files, characterized in that: include: An acquisition module is used to acquire a target file, wherein the target file includes: a plurality of import files; A screening module, configured to screen out an unused first import file from the plurality of import files; an annotation module, configured to annotate the data corresponding to the first imported file in the target file to obtain an annotated target file; A compilation module, used for compiling the annotated target file to obtain a compilation result; a deletion module, configured to determine whether to delete the data corresponding to the first imported file based on the compilation result; The deletion module is further configured to determine whether to delete the code line in the first imported file based on the compilation result; The annotation module is further configured to, when one of the first import files is selected from the multiple import files, traverse a target area of ​​the target file and obtain, from the target area, a class name of a second import file corresponding to the current row of data, wherein the head of the target area is the start position of the target file and the tail of the target area is the first position of a preset identifier in the target file; when the class name of the second import file is the same as the class name of the first import file, determine that the current row of data is data corresponding to the first import file, and annotate the current row of data to obtain the annotated target file; The annotation module is also used to obtain a target class name array corresponding to the target file from multiple class name arrays when multiple first import files are screened out from the multiple import files, wherein each class name array is used to store the class names of multiple unused import files in the files corresponding to each class name array; read the first class name stored in the target class name array; annotate the import file corresponding to the first class name to obtain the annotated target file.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method for processing imported files according to any one of claims 1 to 8.

11. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores a program that can be executed by the at least one processor, and when the at least one processor executes the method for processing an imported file according to any one of claims 1 to 8, the program is executed.

Citation Information

Patent Citations

  • Code file processing method and system, computer equipment and readable storage medium

    CN109918076A

  • Class file import code management system and method

    CN112988137A