A method and apparatus for normalizing file naming
By filtering and renaming the categorized files in large-scale terminal projects, the naming conflict problem was resolved, ensuring that the categorization method conforms to development specifications, avoiding crashes and duplicate name risks, and achieving project standardization and pre-processing.
Patent Information
- Application Number
- CN202111289965.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-02
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2041-11-02
AI Technical Summary
During the development of large-scale terminal projects, although the naming of all classes in the project is processed, there are still cases where the classification methods are not named according to the project naming conventions, which may lead to naming conflicts with third-party libraries and crashes.
By executing a preset script, the classification files in the project are filtered, the classification methods that do not conform to the naming conventions are located and renamed, and a naming prefix is added to all classification methods to conform to the development company's development guidelines and specifications.
Ensure that the naming of classification methods conforms to the development company's development guidelines, avoid naming conflicts, prevent users from encountering method name duplication issues, and achieve project standardization and pre-planning.
Smart Images

Figure CN114003557B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a method and device for standardizing file naming. BACKGROUND
[0002] In the development process of a terminal large project, the function of namespace is realized by processing the naming of all classes in the project, so as to avoid the problems or crashes caused by naming conflicts in the use of third-party libraries.
[0003] However, although the naming of all classes in the project is processed in the development process, it is still unavoidable that the classification method is not named according to the rules of the project naming specification, and it is still unavoidable that the problems or crashes caused by naming conflicts in the use of third-party libraries. SUMMARY
[0004] In view of the above problems, the present application is proposed to provide a method and device for standardizing file naming to overcome the above problems or at least partially solve the above problems.
[0005] The present application discloses a method for standardizing file naming, which comprises:
[0006] The method comprises the following steps:
[0007] The method comprises the following steps:
[0008] Optionally, the project comprises declaration files and implementation files, and the step of screening the classification files in the project comprises:
[0009] The method comprises the following steps:
[0010] The method comprises the following steps:
[0011] Optionally, the step of screening the classification files from the declaration files based on the path set of the declaration files comprises:
[0012] traversing the path set of the declaration file, determining the classification file from the declaration file based on the file name of each declaration file in the path set;
[0013] The determining the classification file from the declaration file based on the file name of each declaration file in the path set comprises:
[0014] The path of each declaration file is inversely cut to obtain each file name, and the corresponding file in each file name that meets the first regular expression is determined as the classification file.
[0015] Optionally, the classification file is filtered from the imported file of the implementation file based on the path set of the implementation file, comprising:
[0016] The path set of the implementation file is traversed to obtain the imported header file in each implementation file in the path set;
[0017] The classification file is determined from the implementation file based on each text area of the imported header file in the implementation file;
[0018] The determining the classification file from the implementation file based on each text area of the imported header file in the implementation file comprises:
[0019] The text area of the imported header file is determined by using a regular expression for the imported header file, and the corresponding file that meets the first regular expression in the text area of the imported header file is determined as the classification file; wherein the regular expression for the imported header file is the beginning and end identifier that meets the fixed format of the imported header file.
[0020] Optionally, the project includes a declaration file, the determination of the classification method that does not meet the naming specification in the classification file, and the specification processing of the naming information of the classification method that does not meet the naming specification, comprising:
[0021] The naming information of the classification method that does not meet the naming specification is processed in the declaration file.
[0022] Optionally, the specification processing of the naming information of the classification method that does not meet the naming specification in the declaration file comprises:
[0023] A regular expression for the classification file is used to determine the classification code area in the classification file; the regular expression for the classification file is the beginning and end identifier that meets the fixed format of the classification file;
[0024] The declared classification method and the naming information of the classification method are obtained in the classification code area;
[0025] If the naming information of the classification method does not have a name prefix, a name prefix is added to the naming information of the classification method that does not conform to the naming specification, so that the modified naming information conforms to the naming specification.
[0026] Optionally, the project further comprises:
[0027] The classification method that does not conform to the naming specification in each classification file of the declaration file is output to obtain a classification method collection.
[0028] Optionally, the project further comprises an implementation file that imports the classification file.
[0029] The classification method that does not conform to the naming specification in the classification file is determined, and the naming information of the classification method that does not conform to the naming specification is processed according to the naming specification, comprising:
[0030] The classification method called or encapsulated in the classification file imported by the implementation file is obtained.
[0031] Based on the classification method collection, the classification method called or encapsulated is traversed to determine the classification method that is the same as in the classification method collection, and a name prefix is added to the naming information of the classification method that is the same as in the classification method collection, so that the modified naming information conforms to the naming specification.
[0032] The embodiment of the application further discloses a specification file naming device, which comprises:
[0033] The classification file screening module is configured to execute a preset script program to screen the classification file in the project; the classification file comprises classes and methods used in the project development process.
[0034] The classification method specification processing module is configured to determine the classification method that does not conform to the naming specification in the classification file, and to process the naming information of the classification method that does not conform to the naming specification according to the naming specification; the naming specification is that the naming information of the classification method has a name prefix.
[0035] Optionally, the project comprises a declaration file and an implementation file, and the classification file screening module comprises:
[0036] The first classification file screening submodule is configured to obtain the entry path information of the project, screen the declaration file according to the entry path information to obtain a path set of the declaration file, and screen the classification file from the declaration file based on the path set of the declaration file.
[0037] The second classified file screening submodule is configured to screen the implementation files according to the entry path information, obtain a path set of the implementation files, and screen classified files from the files imported by the implementation files based on the path set of the implementation files.
[0038] Optionally, the first classified file screening submodule comprises:
[0039] The first classified file determination unit is configured to traverse the path set of the declaration files, and determine classified files from the declaration files based on the file names of the declaration files in the path set.
[0040] Optionally, the first classified file determination unit comprises:
[0041] The first classified file sub-determination unit is configured to inversely cut the path of each declaration file to obtain a file name, and determine the corresponding file in the file name that meets the first regular expression as a classified file.
[0042] Optionally, the second classified file screening submodule comprises:
[0043] The import header file acquisition unit is configured to traverse the path set of the implementation files, and acquire the import header file in each implementation file in the path set.
[0044] The second classified file determination unit is configured to determine classified files from the implementation files based on the text area of the import header file in the implementation files.
[0045] Optionally, the second classified file determination unit comprises:
[0046] The second classified file sub-determination unit is configured to determine the text area of the import header file by using a regular expression for the import header file, and determine the corresponding file in the text area of the import header file that meets the first regular expression as a classified file; wherein the regular expression for the import header file is a head-tail identifier that meets the fixed format of the import header file.
[0047] Optionally, the project comprises declaration files, and the classified method specification processing module comprises:
[0048] The first classified method specification processing submodule is configured to perform specification processing on the naming information of the classified method that does not meet the naming specification in the declaration files.
[0049] Optionally, the first classified method specification processing submodule comprises:
[0050] The classification code region determining unit is configured to determine a classification code region in a classification file by using a regular expression for the classification file, wherein the regular expression for the classification file is a head and tail identifier conforming to a fixed format of the classification file.
[0051] The naming information obtaining unit is configured to obtain a declared classification method and naming information of the classification method in the classification code region.
[0052] The first classification method specification processing unit is configured to add a name prefix to the naming information of the classification method that does not conform to the specification, so that the modified naming information conforms to the naming specification.
[0053] Optionally, the project further comprises:
[0054] The classification method output module is configured to output the classification methods that do not conform to the naming specification in each classification file of the declaration file, so as to obtain a classification method collection.
[0055] Optionally, the project further comprises an implementation file in which the classification file is imported, and the classification method specification processing module comprises:
[0056] The calling method obtaining submodule is configured to obtain a classification method that is called or encapsulated in the classification file imported by the implementation file.
[0057] The second classification method specification processing submodule is configured to traverse the classification method that is called or encapsulated based on the classification method collection, determine a classification method that is the same as the classification method in the classification method collection, and add a name prefix to the naming information of the classification method that is the same as the classification method in the classification method collection, so that the modified naming information conforms to the naming specification.
[0058] The embodiment of the application further discloses an electronic device, comprising a processor, a memory, and a computer program stored in the memory and capable of running on the processor, and the computer program is executed by the processor to implement the steps of the specification file naming method.
[0059] The embodiment of the application further discloses a computer readable storage medium, and the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the specification file naming method.
[0060] The embodiment of the application has the following advantages:
[0061] In the embodiment of the present application, the classification files in the project are screened by executing a preset script program, and when it is determined that the classification method in the classification file does not conform to the naming specification, i.e., the classification method does not have a name prefix in the naming information of the classification method, the naming information of the classification method that does not conform to the naming specification can be standardized to make the modified classification method conform to the naming specification. Based on the positioning of the classification method with non-standard naming in the classification file and the renaming of the classification method, by uniformly adding a name prefix to all classification methods in the project, not only can the naming of the classification method conform to the development guidelines and specifications of the development company, but also can avoid the risk of classification method name conflict for the user due to the name prefix. BRIEF DESCRIPTION OF DRAWINGS
[0062] Figure 1 is a step flow chart of a file naming standardization method provided by an embodiment of the present application;
[0063] Figure 2 is a step flow chart of another file naming standardization method provided by an embodiment of the present application;
[0064] Figure 3 is a step flow chart of still another file naming standardization method provided by an embodiment of the present application;
[0065] Figure 4 is a structural block diagram of a file naming standardization device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0066] In order to make the above-mentioned objects, features and advantages of the present application more apparent and easy to understand, the present application will be further described in detail below with reference to the drawings and specific embodiments.
[0067] In the development process of a terminal large project, there are usually multiple technical personnel who jointly maintain the same type of classification required to be used in the project, which will cause the current classification to become more complex and difficult to distinguish the methods included in the same classification as the project is developed. At this time, the classification in the terminal system can be used to solve this problem. However, in the development of some systems, such as iOS (a mobile operating system developed by Apple Inc.), there is no concept of namespace.
[0068] Generally, the function of the namespace can be realized by adding a specific prefix to the naming of all classes in the project to avoid the possible naming conflict in the use of third-party libraries, such as the problem or crash caused by the naming of the method in the project being the same as the naming of the method in the third-party library. At this time, a specific prefix is mainly added to the classification in the project and all the methods in the classification, and the prefix is the same as the prefix used in other projects in the application library. Generally, the company name or the application name can be used to determine the prefix.
[0069] However, although the classification method is named in the project, in the actual development process, the classification method is not named according to the naming rules of the project.
[0070] In order to avoid the problems that may occur and the resulting crashes caused by using the same method name in the third-party library, and also to further standardize the project, one of the core ideas of the embodiments of the application is to locate the classification method with non-standard naming in the classification file and to rename the classification method. By uniformly adding a name prefix to all classification methods in the project, the naming of the classification method can be ensured to comply with the development guidelines and standards of the development company, and the standardization of the project can be realized. Since the ordinary encapsulation method generally does not have a name prefix, the methods involved in the project can be distinguished from the ordinary encapsulation method based on the name prefix, ensuring the difference between the two methods. In the case of encapsulating the classification method into an SDK (Software Development Kit), since the method has a name prefix, it will not cause the problem of duplicate classification methods for the user, avoiding risks in advance and realizing the preposition of the method in the project.
[0071] Referring to Figure 1 , a step flow chart of a method for standardizing file naming provided by an embodiment of the application is shown, which can specifically include the following steps:
[0072] Step 101, a pre-set script program is executed to screen the classification file in the project;
[0073] In the embodiments of the application, the classification method with non-standard naming in the classification file can be located and the classification method can be renamed to ensure the standardization of the project during development. At this time, the classification file in the project needs to be screened first to locate the classification method with non-standard naming in the classification file.
[0074] The classification file in the project can include all classes and methods used in the project development process, that is, it includes the classes and methods originally used in the project, as well as the classes and methods in the third-party library imported or referenced during the project development process. Therefore, when judging whether the naming information of the classification method in the classification file is standardized, the naming of all classes and methods used in the project development process is also judged and processed.
[0075] In practical application, the project can include declaration files and implementation files. The declaration file refers to information used to describe classes and methods used in the development process of the project. Inevitably, other third-party libraries are referenced in the development process. Although the classes and methods of the library can be called by direct reference, the type checking and other special features cannot be used. At this time, the functions and method bodies in the library can be removed to retain only the exported type declaration, and a declaration file describing the third-party library and module information is generated. By referencing the declaration file, the various features of the third-party library can be used.
[0076] The classification file can refer to the implementation of the method being divided into a series of separate files. The text of the classification file can include one or more methods in the implementation, and the implementation file can be used to implement the methods in the classification file. Correspondingly, the text of the implementation file can also include multiple methods, and the multiple methods can be in different classification files or the same classification file, that is, imported into the implementation file by the classification files.
[0077] In a specific implementation, when the classification files in the project are screened, a script program for standardizing the naming of the classification methods can be pre-written, that is, a preset script program is executed to screen the classification files in the declaration files and the implementation files.
[0078] Step 102, determining the classification methods in the classification files that do not conform to the naming specification, and standardizing the naming information of the classification methods that do not conform to the naming specification.
[0079] In an embodiment of the present application, after the classification files in the project are screened, the classification methods with non-standard naming in the classification files are located, that is, the classification methods that do not conform to the specification in the screened classification files are determined, and then the naming information of the classification methods that do not conform to the naming specification is renamed to realize the naming specification processing of the classification methods.
[0080] Specifically, the classification methods that do not conform to the naming specification in the declaration files are determined, the naming information of the classification methods that do not conform to the naming specification is standardized, and the naming information of the classification methods that do not conform to the naming specification in the classification files imported by the implementation files is also standardized.
[0081] In a specific implementation, the naming specification processing of the classification methods refers to the standardization of the project in the development process. The naming specification to which the classification methods conform is that the naming information of the classification methods has a naming prefix, that is, the naming method of adding a naming prefix to all classification methods in the project is in line with the development guidelines of the development company and the development specification in the project.
[0082] It should be noted that the above positioning operation of the classification method with non-standard naming in the classification file and the renaming operation of the classification method performed by the preset script program are generally not performed in the actual development process. The positioning operation and the renaming operation need to scan the project, and are generally used as an optimization scheme of the project, that is, they are generally performed after the project is developed for a period of time and problems caused by naming conflicts are exposed. In an optional embodiment, the above positioning and renaming operations performed by the preset script program can also be performed on the project before the project is developed to avoid optimizing the project after problems caused by naming conflicts are exposed, so as to avoid risks in advance. The embodiments of the present application are not limited in this regard.
[0083] In the embodiments of the present application, the classification files in the project are screened by executing the preset script program. When it is determined that the classification method in the classification file does not conform to the naming specification, that is, the classification method does not have a naming prefix in the naming information of the classification method, the naming information of the classification method that does not conform to the naming specification can be standardized to make the modified classification method conform to the naming specification. Based on the positioning of the classification method with non-standard naming in the classification file and the renaming of the classification method, by uniformly adding a naming prefix to all classification methods in the project, the naming of the classification method can conform to the development guidelines and specifications of the development company, and the classification method with the naming prefix will not cause the problem of duplicate classification methods for the user, thereby avoiding risks in advance.
[0084] Referring to Figure 2 , another step flowchart of the method for standardizing the file naming provided by the embodiments of the present application is shown, which focuses on the searching process of the classification method that does not conform to the naming specification, and can specifically include the following steps:
[0085] In step 201, the classification files in the declaration file are screened based on the entry path information of the project.
[0086] In the embodiments of the present application, the positioning of the classification method with non-standard naming in the classification file and the renaming of the classification method can ensure the standardization of the project during the development process. At this time, the classification files in the project need to be screened first to position the classification method with non-standard naming in the classification file.
[0087] Specifically, the classification files in the declaration file can be screened by executing a preset script program.
[0088] In actual application, the screening of the classification files in the declaration files can be realized by scanning the project. The project is scanned based on the entry path information of the project to obtain the declaration files, and then the declaration files are scanned to obtain the classification files, so that the classification methods can be further scanned to obtain the classification methods, so as to determine the naming specification of the classification methods and locate the classification methods with non-standard naming.
[0089] In a specific implementation, the scanning of the project to obtain the declaration files can be based on the entry path information of the project to screen the declaration files. Generally, the identifier of the declaration file is a file with “.h” extension. Therefore, according to this feature, all declaration files in the project can be found by using the command “find path-name ‘*.h’” (wherein path refers to the obtained entry path information), so as to screen the path of the declaration file and obtain the path set of the declaration file.
[0090] The obtained entry path information can be the project entry path or a sub-path of a part of the project implementation. During the development of the project, the path information is judged. The path information of the project cannot be null or a file path, but only a folder path.
[0091] After the scanning of the project to obtain the declaration files, the declaration files can be scanned to obtain the classification files. Specifically, the classification files can be screened from the declaration files based on the path set of the declaration files.
[0092] Specifically, the path set of the declaration files can be traversed, and the classification files can be determined from the declaration files based on the file names of the declaration files in the path set. Specifically, the paths of the declaration files can be reversely cut to obtain the file names, and the corresponding files in the file names that meet the first regular expression are determined as the classification files.
[0093] For example, the declaration file path traversed can be reversely cut by “ / ” to obtain the specific file name. For example, the declaration file path is / Users / project / Class.h, and the file name is Class.h obtained by reversely cutting by “ / ”. Then, the first regular expression “\w+\+\w+.h” is used to determine whether the current file is a classification file. If yes, the classification method with non-standard naming in the classification file is located. If not, the next declaration file path in the path set of the declaration files is determined.
[0094] Step 202, in the declaration file, the naming information of the classification method that does not meet the naming specification is standardized.
[0095] After the scanning of the project to obtain the declaration file and the scanning of the declaration file to obtain the classification file, the classification file can be scanned to obtain the classification method, so as to locate the classification method with non-standard naming in the classification file, mainly to determine the classification method that does not meet the standard in the classification file screened, and then to rename the naming information of the classification method that does not meet the naming standard, so as to realize the naming standard processing of the classification method.
[0096] In actual application, the classification file is scanned to obtain the classification method, first the classification code area can be determined, and then the classification method used in the classification code area is determined.
[0097] Specifically, in order to prevent the class file from being changed during analysis and affecting the implementation of the method in the class file, the classification file is analyzed in read-only mode, and the specific method name is judged in the case of the defined method.
[0098] In actual application, the classification file is read line by line, and the regular expression for the classification file is used to determine the classification code area in the classification file, and the declared classification method in the classification code area is obtained, wherein the regular expression for the classification file can be the beginning and end identifier that meets the fixed format of the classification file, then the declared classification method in the classification code area and the naming information of the classification method can be obtained; if the naming information of the classification method does not have a name prefix, the naming information of the classification method that does not meet the standard can be added with a name prefix, so that the modified naming information meets the naming standard.
[0099] Illustratively, assuming that the naming information of the classification file is ClassA+Category.h, the classification code area in the classification file can be the area starting with "@interface ClassA(Category)" and ending with "@end", that is, the regular expression for the classification file "@interface\s*\w+\s*\(\w+\)" can be used to judge whether the current line is the beginning of the classification, and the regular "@end" can be used to judge whether the current line is the end of the classification. In the case that the current line is the classification code area, the current line can be further judged whether it is a declared classification method, if the current line is a declared classification method, it can be further judged whether the naming of the classification method meets the standard, if not, the classification method that does not meet the naming standard is stored, so as to find and check the classification and method that do not meet the naming standard later, and the classification method that does not meet the standard can also be modified to add a name prefix to meet the standard.
[0100] It should be noted that the current line in the classification code area in the classification file can be an attribute or a method, at this time, the regular expression of "\s*[-|+]\s*" can be used to determine whether it is a declared classification method.
[0101] In a preferred embodiment, while modifying the classification method that does not conform to the specification and adding a prefix to the name to make it conform to the specification, the classification method that does not conform to the specification contained in each classification file can also be output, that is, the classification method that does not conform to the naming specification in each classification file of the declaration file is output to obtain a classification method collection.
[0102] After the classification method with non-standard naming in the classification file of the declaration file is located and the classification method is renamed by executing the preset script program, the classification method that does not conform to the naming specification found and stored, that is, the classification method collection output can be used for subsequent replacement of the classification method with non-standard naming in the implementation file.
[0103] In the embodiment of the application, based on the positioning of the classification method with non-standard naming in the classification file and the renaming of the classification method, by uniformly adding a name prefix to all classification methods in the project, the naming of the classification method can be ensured to conform to the development guidelines and specifications of the development company, and the standardization of the project can be realized. Since the ordinary encapsulation method generally does not have a name prefix, the method involved in the project can be distinguished from the ordinary encapsulation method based on the name prefix, and the difference between the two methods can be ensured. In the case of encapsulating the classification method into an SDK, since the name prefix is provided, the problem of duplicate classification methods for the user is avoided, the risk is avoided in advance, and the preposition of the method in the project is realized.
[0104] Referring to Figure 3 , a step flowchart of another kind of specification file naming method provided by the embodiment of the application is shown, which focuses on the replacement process of the classification method in the implementation file, and can specifically include the following steps:
[0105] Step 301, based on the entry path information of the project, the classification file imported in the implementation file is screened;
[0106] In the embodiment of the application, after the classification method with non-standard naming in the classification file of the declaration file is located and the classification method is renamed by executing the preset script program, the classification method that does not conform to the naming specification found and stored, that is, the classification method collection output can be used for subsequent replacement of the classification method with non-standard naming in the implementation file.
[0107] Specifically, the preset script program can be executed to screen the classification file in the implementation file.
[0108] In practical application, the implementation file is filtered according to the project, and the scanning of the project is implemented. The project is scanned based on the same entry path information of the project to obtain the implementation file, and the implementation file is scanned to obtain the classification file, so that the classification method can be further scanned to obtain the classification method, so as to realize the positioning and replacement of the classification method with non-standard naming.
[0109] In specific implementation, the implementation file is obtained by scanning the project, and the implementation file can be filtered based on the entry path information of the project. Generally, the identifier of the implementation file is a file with “.m” extension, so according to this characteristic, all implementation files in the project can be found by using the command “findpath-name‘*.m’” (wherein path refers to the obtained entry path information), so as to filter the path of the implementation file and obtain the path set of the implementation file.
[0110] After the implementation file is obtained by scanning the project, the classification file can be obtained by scanning the implementation file. Specifically, the classification file can be filtered from the imported file of the implementation file based on the path set of the implementation file.
[0111] Specifically, the path set of the implementation file can be traversed to obtain the imported header file in each implementation file in the path set, and then the classification file can be determined from the implementation file based on the text area of the imported header file in the implementation file.
[0112] In practical application, the implementation file in the implementation file path set is read line by line, and the text area of the imported header file is determined by using the regular expression for the imported header file, wherein the regular expression for the imported header file is the first and last identifier of the fixed format of the imported header file. The corresponding file that meets the first regular expression in the text area of the imported header file is determined as the classification file.
[0113] Exemplarily, the imported header file is generally located in the header area of the implementation file, and the judgment of the end of the imported header file area is usually made by using the regular expression for the imported header file, such as the existence of “@interface” or “@implementation” in the current line. The imported header file has a fixed format, such as “#import ClassA.h” indicating the imported header file ClassA, and “#import ClassA+Category.h” indicating the imported classification file ClassA+Category. At this time, the first regular expression ““(\w+\+\w+.h)”” can be used to judge the imported header file area to obtain the classification file imported by the current file, and the imported classification file set is obtained.
[0114] In step 302, the naming information of the classification method not conforming to the naming specification is processed in the implementation file.
[0115] In an embodiment of the present application, after the implementation file is obtained by scanning the project, and the classification file is obtained by scanning the implementation file, the classification method can be obtained by scanning the classification file, so as to locate and replace the classification method not conforming to the naming specification, and to process the naming of the classification method.
[0116] In practical application, the classification method can be obtained by scanning the classification file, which can be mainly determined based on the related behavior of the encapsulation method or the calling method existing in the implementation file importing the classification file.
[0117] Specifically, the classification method calling or encapsulating in the classification file imported by the implementation file can be obtained, and then the classification method calling or encapsulating is traversed based on the classification method collection, the same classification method in the classification method collection is determined, and the name prefix is added in the naming information of the same classification method in the classification method collection, so that the modified naming information conforms to the naming specification, and the classification method not conforming to the naming specification in the implementation file is located and replaced.
[0118] Exemplarily, it can be judged whether the current line has the behavior of calling the method, such as “[classA method]”, which indicates that the class classA calls the method method, or whether the current line has the behavior of encapsulating the method, such as “-(void)method”, which indicates that the current class encapsulates the method method, if the current line has the encapsulation method or the calling method, the classification method can be determined, so as to locate the classification method not conforming to the naming specification from the classification method.
[0119] In practical application, the classification method collection imported by the implementation file can be traversed, and it is judged whether the current classification method is in the output classification method collection not conforming to the specification, since there is no modification permission to operate the system classification or the third-party classification imported by the implementation file, if there is the same classification method in the classification method collection, the classification method not conforming to the specification contained in the classification can be taken out for traversal, and the method not conforming to the specification in the current line is corrected, so as to realize the compliance processing of the traversed method.
[0120] In the embodiment of the present application, based on positioning the classification method with non-standard naming in the classification file and implementing the renaming of the classification method, by uniformly adding a name prefix to all classification methods in the project, not only can the naming of the classification method meet the development guidelines and specifications of the development company, but also can realize the standardization of the project. Since the general encapsulation method generally does not have a name prefix, the method involved in the project can be distinguished from the general encapsulation method based on the name prefix, ensuring the difference between the two methods. In addition, when the classification method needs to be encapsulated into an SDK, since it has a name prefix, it will not cause the problem of classification method duplication for the user, avoiding risks in advance and realizing the preposition of the method in the project.
[0121] In order to facilitate those skilled in the art to further understand the specification file naming method proposed in the embodiment of the present application, the implementation process of the specification file naming method is as follows:
[0122] In the embodiment of the present application, based on positioning the classification method with non-standard naming in the classification file and implementing the renaming of the classification method, by uniformly adding a name prefix to all classification methods in the project, not only can the naming of the classification method meet the development guidelines and specifications of the development company, but also can avoid the problem of classification method duplication for the user in advance, thereby avoiding risks in advance. It mainly involves the process of obtaining the classification method in the classification file, and the process of replacing the classification method in the implementation file, specifically:
[0123] (1) The process of obtaining the classification method in the classification file mainly executes the feature based on the declaration file extension through a preset script program to filter the declaration file in the given path (i.e. the project entry path); then the obtained declaration file path set is traversed, and based on the use of “ / ” for reverse cutting and regular expression on the traversed declaration file path, it is judged whether the current file is a classification file; the classification file is read line by line, if the current line is a classification code area, it is judged whether the current line is a declared classification method, if the current line is a declared classification method, it is further judged whether the naming is standard, if not, it is stored for later checking; at the same time, the classification method not meeting the standard is modified to add a name prefix to make it meet the standard, and the classification method not meeting the standard contained in each classification file is output.
[0124] (2) the process of replacing the classification method in the implementation file, mainly through the preset script program to execute the characteristics based on the implementation file extension, to filter the implementation file in the given path (i.e. the project entry path), then traverse the implementation file path set obtained, use the regular expression "(\w+\+\w+.h)" to judge the import header file area, to obtain the classification file imported by the current file, obtain the imported classification file set; judge whether the current line has the behavior of method call or the current line has the behavior of encapsulating the method, if it exists, then traverse the imported classification, judge whether the current classification is in the system classification or the third party classification imported by the implementation file, if it is, then take out the non-standard classification method contained in the classification and traverse, correct the non-standard method of the current line, complete the processing of the non-standard method.
[0125] In the embodiment of the application, based on the positioning of the non-standard naming classification method in the classification file and the renaming of the classification method, by uniformly adding a name prefix to all classification methods in the project, the standardization, differentiation and prepositioning of the project in the development process are realized.
[0126] It should be noted that, for the method embodiment, in order to simply describe, it is expressed as a series of action combinations, but those skilled in the art should know that the embodiment of the application is not limited by the described action sequence, because according to the embodiment of the application, certain steps can be performed in other order or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification all belong to preferred embodiments, and the actions involved are not necessarily the necessary of the embodiment of the application.
[0127] Referring to Figure 4 , a structural block diagram of a specification file naming device provided by an embodiment of the application is shown, which can specifically include the following modules:
[0128] The classification file filtering module 401 is used to execute the preset script program to filter the classification file in the project; the classification file includes the class and method used in the project development process;
[0129] The classification method specification processing module 402 is used to determine the classification method that does not conform to the naming specification in the classification file, and to perform specification processing on the naming information of the classification method that does not conform to the naming specification; the naming specification is that the naming information of the classification method has a name prefix.
[0130] In an embodiment of the application, the project includes a declaration file and an implementation file, and the classification file filtering module 401 can include the following sub-modules:
[0131] The first classified file screening submodule is configured to obtain entry path information of the project, screen the declaration file according to the entry path information, obtain a path set of the declaration file, and screen the classified file from the declaration file based on the path set of the declaration file.
[0132] The second classified file screening submodule is configured to screen the implementation file according to the entry path information, obtain a path set of the implementation file, and screen the classified file from the imported file of the implementation file based on the path set of the implementation file.
[0133] In an embodiment of the present application, the first classified file screening submodule can include the following units:
[0134] The first classified file determination unit is configured to traverse the path set of the declaration file, and determine the classified file from the declaration file based on the file name of each declaration file in the path set.
[0135] In an embodiment of the present application, the first classified file determination unit can include the following sub-units:
[0136] The first classified file sub-determination unit is configured to reverse cut the path of each declaration file to obtain each file name, and determine the corresponding file in each file name that meets the first regular expression as the classified file.
[0137] In an embodiment of the present application, the second classified file screening submodule can include the following units:
[0138] The imported header file acquisition unit is configured to traverse the path set of the implementation file, and acquire the imported header file in each implementation file in the path set.
[0139] The second classified file determination unit is configured to determine the classified file from the implementation file based on each text area of the imported header file in the implementation file.
[0140] In an embodiment of the present application, the second classified file determination unit can include the following sub-units:
[0141] The second classified file sub-determination unit is configured to determine the text area of the imported header file by using the regular expression for the imported header file, and determine the corresponding file in the text area of the imported header file that meets the first regular expression as the classified file; wherein the regular expression for the imported header file is the head and tail identifier that meets the fixed format of the imported header file.
[0142] In an embodiment of the present application, the project includes the declaration file, and the classified method specification processing module 402 can include the following submodule:
[0143] The first classification method specification processing submodule is configured to perform specification processing on the naming information of the classification method that does not conform to the naming specification in the declaration file.
[0144] In an embodiment of the present application, the first classification method specification processing submodule can include the following units:
[0145] A classification code region determining unit is configured to determine a classification code region in the classification file by using a regular expression for the classification file, wherein the regular expression for the classification file is a head and tail identifier conforming to the fixed format of the classification file.
[0146] A naming information obtaining unit is configured to obtain the declared classification method and the naming information of the classification method in the classification code region.
[0147] A first classification method specification processing unit is configured to add a name prefix to the naming information of the classification method that does not conform to the specification, so that the modified naming information conforms to the naming specification.
[0148] In an embodiment of the present application, the following modules can also be included:
[0149] A classification method output module is configured to output the classification methods that do not conform to the naming specification in each classification file of the declaration file, so as to obtain a classification method collection.
[0150] In an embodiment of the present application, the project further includes an implementation file in which the classification file is imported; and the classification method specification processing module 402 can include the following submodules:
[0151] A calling method obtaining submodule is configured to obtain the classification method that is called or encapsulated in the classification file imported by the implementation file.
[0152] A second classification method specification processing submodule is configured to traverse the classification method that is called or encapsulated based on the classification method collection, determine the classification method that is the same as in the classification method collection, and add a name prefix to the naming information of the classification method that is the same as in the classification method collection, so that the modified naming information conforms to the naming specification.
[0153] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the related parts refer to the part of the description of the method embodiment.
[0154] The embodiment of the present application further provides an electronic device, which includes:
[0155] The specification file naming method embodiment is implemented by a processor, a memory, and a computer program stored on the memory and capable of running on the processor. When the computer program is executed by the processor, each process of the specification file naming method embodiment is implemented, and the same technical effect is achieved. To avoid repetition, details are not described here.
[0156] The specification file naming method embodiment is implemented by a processor, a memory, and a computer program stored on the memory and capable of running on the processor. When the computer program is executed by the processor, each process of the specification file naming method embodiment is implemented, and the same technical effect is achieved. To avoid repetition, details are not described here.
[0157] Each embodiment in the specification is described in a progressive manner, and each embodiment focuses on the difference from other embodiments. The same and similar parts of each embodiment can be referred to each other.
[0158] Those skilled in the art should understand that the embodiments of the present embodiment can be provided as a method, an apparatus, or a computer program product. Therefore, the embodiments of the present embodiment can be in the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the embodiments of the present embodiment can be in the form of a computer program product implemented on one or more computer usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer usable program code.
[0159] The embodiments of the present embodiment are described with reference to flowcharts and / or block diagrams of the method, terminal device (system), and computer program product according to the embodiments of the present embodiment. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device produce a means for implementing the functions specified in the flowchart and / or block diagram. Figure 1 one or more flows and / or blocks Figure 1 an apparatus for performing the functions specified in one or more flows and / or blocks.
[0160] These computer program instructions can also be stored in a computer readable memory that can guide the computer or other programmable data processing terminal device to work in a specific way, so that the instructions stored in the computer readable memory produce a product including instruction apparatus, which implements the functions specified in the flowchart and / or block diagram. Figure 1 one or more flows and / or blocks Figure 1 an apparatus for performing the functions specified in one or more flows and / or blocks.
[0161] These computer program instructions can also be loaded into a computer or other programmable data processing terminal device, so that a series of operational steps are performed on the computer or other programmable terminal device to generate a computer-implemented process, so that the instructions executed on the computer or other programmable terminal device provide a process for implementing the functions specified in the flowchart Figure 1 one flowchart or multiple flowcharts and / or blocks Figure 1 one flowchart or multiple flowcharts and / or blocks
[0162] Although the preferred embodiments of the present application have been described, those skilled in the art will be able to make additional changes and modifications to these embodiments once they grasp the basic inventive concepts. Therefore, the appended claims are intended to cover all changes and modifications that fall within the scope of the embodiments of the present application.
[0163] Finally, it should be noted that the terms such as first and second, etc., are used herein merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between such entities or operations. Moreover, the terms "comprising", "including", or any other variant thereof are intended to cover a non-exclusive inclusion, so that a process, method, article, or terminal device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or other elements inherent to such a process, method, article, or terminal device. Without more limitations, an element defined by the statement "comprising a" does not exclude the presence of additional identical elements in the process, method, article, or terminal device including the element.
[0164] The above describes in detail a specification file naming method and a specification file naming device provided by the present application. The principles and implementation manners of the present application are described by using specific examples. The above description of the embodiments is only used to help understand the method of the present application and its core idea. Meanwhile, for those skilled in the art, according to the idea of the present application, the specific implementation manners and application ranges will be changed. In summary, the content of the present description should not be understood as a limitation of the present application.
Claims
1. A standardized file naming method, characterized in that, The method comprises: performing a preset script program to screen a classification file in a project; the classification file comprises a class and a method used in a project development process, and the project further comprises a declaration file and an implementation file in which the classification file is imported; determining a classification method that does not conform to a naming specification in the classification file, and performing specification processing on naming information of the classification method that does not conform to the naming specification; the naming specification is that a naming prefix is included in the naming information of the classification method; outputting a classification method that does not conform to the naming specification in each classification file of the declaration file to obtain a classification method collection; wherein, the screening of the classification file in the project comprises: obtaining entry path information of the project, screening the declaration file according to the entry path information to obtain a path set of the declaration file, and traversing the path set of the declaration file to obtain each file name by reversely cutting each path of the declaration file, and determining that a corresponding file conforming to a first regular expression in the each file name is the classification file; and / or, screening the implementation file according to the entry path information to obtain a path set of the implementation file, and screening the classification file from files imported by the implementation file based on the path set of the implementation file; wherein, the determination of the classification method that does not conform to the naming specification in the classification file and the specification processing on the naming information of the classification method that does not conform to the naming specification comprise: obtaining a classification method that is called or encapsulated in a classification file imported by the implementation file; traversing the classification method that is called or encapsulated based on the classification method collection, determining a classification method that is the same as the classification method collection, and adding a naming prefix to the naming information of the classification method that is the same as the classification method collection to make the modified naming information conform to the naming specification.
2. The method of claim 1, wherein, The screening of the classification file from the files imported by the implementation file based on the path set of the implementation file comprises: traversing the path set of the implementation file to obtain an import header file in each implementation file in the path set; determining the classification file from the implementation file based on each text area of the import header file in the implementation file.
3. The method of claim 2, wherein, The determination of the classification file from the implementation file based on each text area of the import header file in the implementation file comprises: determining a text area of the import header file by using a regular expression for the import header file, and determining that a corresponding file conforming to a first regular expression in the text area of the import header file is the classification file; wherein, the regular expression for the import header file is a first and last identifier conforming to a fixed format of the import header file.
4. The method of claim 1, wherein, The project comprises a declaration file, and the determination of the classification method that does not conform to the naming specification in the classification file and the specification processing on the naming information of the classification method that does not conform to the naming specification comprise: performing specification processing on the naming information of the classification method that does not conform to the naming specification in the declaration file.
5. The method of claim 4, wherein, The naming information of the classification method not meeting the naming specification is standardized in the declaration file, including: A regular expression for the classification file is used to determine a classification code region in the classification file; the regular expression for the classification file is a head and tail identifier meeting a fixed format of the classification file; A declared classification method in the classification code region and naming information of the classification method are obtained; If the naming information of the classification method does not have a name prefix, the naming information of the classification method not meeting the specification is added with a name prefix so that the modified naming information meets the naming specification.
6. A file naming apparatus for normalizing, characterized by, The device comprises: A classification file screening module is configured to screen classification files in a project by using a preset script program; the classification files include classes and methods used in a project development process; the project further includes declaration files and implementation files importing the classification files; A classification method standardization processing module is configured to determine a classification method not meeting a naming specification in the classification files and to standardize naming information of the classification method not meeting the naming specification; the naming specification is that the naming information of the classification method has a name prefix; A classification method output module is configured to output the classification method not meeting the naming specification in each classification file of the declaration files to obtain a classification method collection; The classification file screening module comprises: A first classification file screening submodule is configured to obtain entry path information for the project, screen the declaration files according to the entry path information to obtain a path set of the declaration files, traverse the path set of the declaration files, inversely cut each path of the declaration files to obtain each file name, and determine that a corresponding file meeting a first regular expression in the each file name is the classification file; A second classification file screening submodule is configured to screen the implementation files according to the entry path information to obtain a path set of the implementation files, and screen the classification files from files imported by the implementation files based on the path set of the implementation files; The classification method standardization processing module comprises: A calling method obtaining submodule is configured to obtain a classification method called or encapsulated in a classification file imported by the implementation file; A second classification method standardization processing submodule is configured to traverse the classification method called or encapsulated based on the classification method collection, determine a classification method same as the classification method in the classification method collection, and add a name prefix to the naming information of the classification method same as the classification method in the classification method collection so that the modified naming information meets the naming specification.
7. An electronic device, comprising: The device comprises: A processor, a memory, and a computer program stored on the memory and capable of running on the processor, the computer program being executed by the processor to implement the steps of the specification file naming method according to any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, A computer program is stored on the computer readable storage medium, the computer program being executed by the processor to implement the steps of the specification file naming method according to any one of claims 1-5.
Citation Information
Patent Citations
File detection method and device
CN111782220A
File filtering method and device, electronic equipment and storage medium
CN111813749A
Method and system for intelligently detecting and repairing codes
CN112947985A