An interface scanning method, device, and storage medium

An automated interface scanning method addresses the inefficiencies in managing multiple interfaces by parsing and structuring interface information, enhancing accuracy and efficiency in interface organization.

CN113377353BActive Publication Date: 2025-07-15BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110511941.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-11
Publication Date
2025-07-15
Estimated Expiration
2041-05-11

AI Technical Summary

Technical Problem

In the prior art, the collation of external interfaces and functions in engineering projects is inefficient and easy to miss, and the existing methods cannot efficiently organize external interfaces and function information.

Method used

By scanning the target file in the target project directory, parsing interface function information, including attribute type, attribute name and method body, using attribute annotation and regular matching to determine the target attribute type and method body, automatically sorting out the interface functions, and generating interface function tables.

Benefits of technology

It realizes the accuracy and efficiency of external interfaces in automated sorting projects, ensuring the integrity and consistency of interface functions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113377353B_ABST
    Figure CN113377353B_ABST
Patent Text Reader

Abstract

An embodiment of the present application provides an interface scanning method, a device, and a storage medium. The method includes: scanning target files in a target project directory; parsing the target files to obtain interface function information in the target files; the interface function information at least includes an attribute type, an attribute name, and a method body corresponding to the interface function; when a target attribute type is found from the attribute types, determining a target attribute name corresponding to the target attribute type from the attribute names; traversing the method body according to the target attribute name, and when a target method body containing the target attribute name is found from the method body, determining a function of a target interface corresponding to the target method body; and outputting the function of the target interface.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular, to an interface scanning method, device, and storage medium. Background Art

[0002] With the development of computer technology, current engineering projects are getting larger and larger, and there are more and more external interfaces relied on in the project and functions of the called external interfaces. When manually sorting out these external interfaces and the corresponding functions, there are often problems of omission, and the efficiency of sorting out the interfaces is low. Summary of the Invention

[0003] Embodiments of this application provide an interface scanning method, device, and storage medium, which can automatically sort out the external interfaces in the project, achieving the purpose of improving the accuracy and efficiency of sorting out the external interfaces.

[0004] The technical solution of this application is implemented as follows:

[0005] In a first aspect, embodiments of this application provide an interface scanning method, and the method includes:

[0006] Scan the target files in the target project directory;

[0007] Parse the target files to obtain interface function information in the target files; the interface function information at least includes the attribute type, attribute name, and method body corresponding to the interface function;

[0008] When a target attribute type is found from the attribute types, determine the target attribute name corresponding to the target attribute type from the attribute names;

[0009] Traverse the method body according to the target attribute name, and when a target method body containing the target attribute name is found from the method body, determine the function of the target interface corresponding to the target method body according to the target method body;

[0010] Output the function of the target interface.

[0011] In the above interface scanning method, after parsing the target files to obtain the interface function information in the target files and before determining the target attribute name corresponding to the target attribute type from the attribute names, the method further includes:

[0012] When an external dependency attribute type is found from the attribute types, determine the attribute annotation corresponding to the external dependency attribute type;

[0013] If the attribute annotation is a preset attribute annotation, determine the external dependency attribute type as the target attribute type.

[0014] In the above interface scanning method, when the target method body containing the target attribute name is found in the method body, determining the function of the target interface corresponding to the target method body according to the target method body includes:

[0015] When a first method body with the same field as the target attribute name is found in the method body, determining the first method body as the target method body;

[0016] Determining the target method function corresponding to the target attribute name and the first interface function corresponding to the target method body from the target method body through regular matching;

[0017] Determining the target method function and the first interface function as the function of the target interface corresponding to the target method body.

[0018] In the above interface scanning method, after parsing the target file to obtain the interface function information in the target file, and before determining the target attribute name corresponding to the target attribute type from the attribute names when the target attribute type is found in the attribute types, the method further includes:

[0019] Dividing the interface function information into at least one interface function information set according to the preset function modules corresponding to the target project;

[0020] Correspondingly, when the target attribute type is found in the attribute types, determining the target attribute name corresponding to the target attribute type from the attribute names includes:

[0021] Sequentially determining whether the attribute type in each parsing result set among the at least one parsing result set is the target attribute type;

[0022] When the attribute type is the target attribute type, determining the target attribute type and the target attribute name corresponding to the target attribute type.

[0023] In the above interface scanning method, when traversing the method body according to the target attribute name and the target method body containing the target attribute name is found in the method body, determining the function of the target interface corresponding to the target method body according to the target method body includes:

[0024] Searching, from the at least one interface function information set, for a first interface function information set corresponding to a target function module; the target function module is a function module in the preset function modules;

[0025] When a second interface function that calls the first interface function is found in the method body included in the first interface function information set, add the second interface function to the functions of the target interface.

[0026] In the above interface scanning method, the output of the functions of the target interface includes:

[0027] Write the functions of the target interface into a preset initial table to obtain a target interface function table;

[0028] Output the target interface function table.

[0029] In a second aspect, an embodiment of the present application provides an interface scanning device, and the device includes:

[0030] A scanning unit for scanning target files in a target project directory;

[0031] An analysis unit for analyzing the target file to obtain interface function information in the target file; the interface function information at least includes an attribute type, an attribute name, and a method body corresponding to the interface function;

[0032] A determination unit for, when a target attribute type is found in the attribute type, determining a target attribute name corresponding to the target attribute type from the attribute name;

[0033] The determination unit is further configured to traverse the method body according to the target attribute name, and when a target method body including the target attribute name is found in the method body, determine a function of a target interface corresponding to the target method body according to the target method body;

[0034] An output unit for outputting the functions of the target interface.

[0035] In the above interface scanning device, the determination unit is further configured to, when an external dependency attribute type is found in the attribute type, determine an attribute annotation corresponding to the external dependency attribute type; if the attribute annotation is a preset attribute annotation, determine the external dependency attribute type as the target attribute type.

[0036] In a third aspect, an embodiment of the present application provides an interface scanning device, characterized in that the device includes: a processor, a memory, and a communication bus; when the processor executes a running program stored in the memory, the interface scanning method described in any one of the above is implemented.

[0037] In a fourth aspect, an embodiment of the present application provides a storage medium, on which a computer program is stored, characterized in that when the computer program is executed by a processor, the interface scanning method described in any one of the above is implemented.

[0038] The embodiments of the present application provide an interface scanning method, a device, and a storage medium. The interface scanning method includes: scanning target files in a target project directory; parsing the target files to obtain interface function information in the target files; the interface function information at least includes an attribute type, an attribute name, and a method body corresponding to the interface function; when a target attribute type is found from the attribute types, determining a target attribute name corresponding to the target attribute type from the attribute names; traversing the method body according to the target attribute name, and when a target method body containing the target attribute name is found from the method body, determining a function of a target interface corresponding to the target method body; and outputting the function of the target interface. With the above implementation solution, since the target files in the project directory store relevant information of the interface function, and the target interface corresponds to a specified target attribute type, it is possible to obtain the attribute type, the attribute name, and the method body corresponding to the interface function in the target files by scanning and parsing the target files, and then find the target method body corresponding to the target interface from the interface function information according to the target attribute type, and filter out the function of the target interface from the target method body, which can achieve automatic sorting of the target interface in the project and achieve the purpose of improving the accuracy and efficiency of sorting the target interface. Description of the Drawings

[0039] Figure 1 is a flowchart of an interface scanning method provided by an embodiment of the present application;

[0040] Figure 2 is a flowchart of an exemplary Java file interface scanning method provided by an embodiment of the present application;

[0041] Figure 3 is a schematic composition structure of an interface scanning device 1 provided by an embodiment of the present application Figure 1 ;

[0042] Figure 4 is a schematic composition structure of an interface scanning device 1 provided by an embodiment of the present application Figure 2 . Detailed Embodiments

[0043] It should be understood that the specific embodiments described herein are only used to explain the present application. They are not used to limit the present application.

[0044] Embodiment 1

[0045] The embodiments of the present application provide an interface scanning method, which is applied to an interface scanning device, Figure 1 is a flowchart of an interface scanning method provided by an embodiment of the present application. As Figure 1 shown, the interface scanning method may include:

[0046] S101. Scan the target files in the target project directory.

[0047] In the embodiment of the present application, the interface scanning device scans the target files in the target project directory through the root path of the target project and reads the target files.

[0048] Specifically, the target files can be all the files in the target project directory or specified partial target files. Exemplarily, assuming that the computer programming language Java files need to be scanned, the target files are all the Java files in the target project directory. The specific files can be determined according to the actual situation, and the embodiments of the present application do not make any limitations here.

[0049] S102. Parse the target files to obtain the interface function information in the target files; the interface function information at least includes the attribute type, attribute name, and method body corresponding to the interface function.

[0050] In the embodiment of the present application, the interface scanning device calls a file parsing tool to parse the read target files, and after parsing, obtains the interface function information in the target files; the interface function information at least includes the attribute type, attribute name, and method body corresponding to the interface function in the target files.

[0051] Exemplarily, assuming that the target files are all the Java files in the target project directory, the interface scanning device reads all the Java files through the input root path of the target project, and then calls the Java file parsing tool to parse all the read Java files to obtain the interface function information, and the interface function information at least includes the attribute type, attribute name, and method body corresponding to the interface function in the target files.

[0052] In the embodiment of the present application, after parsing the target files to obtain the interface function information in the target files, according to the preset function modules corresponding to the target project, the interface function information is divided into at least one set of interface function information.

[0053] It should be noted that the preset function modules corresponding to the target project are the modules pre-divided by the target project itself. The interface function information is divided according to the preset function modules. Exemplarily, assuming that there are two preset function modules, namely a business logic module and a data access module, the interface function information corresponding to the business logic module is divided into one set, and the interface function information corresponding to the data access module is divided into one set. The specific number of preset function modules can be determined according to the actual situation, and the embodiments of the present application do not make any limitations here.

[0054] It should be noted that after the interface function information is divided according to the preset function modules, the preset function modules and the interface function information are correspondingly stored in a key-value data structure, where the name of the preset function module is stored in the key, and the set of interface function information corresponding to the preset function module is stored in the value.

[0055] S103. In the case where the target attribute type is found from the attribute types, determine the target attribute name corresponding to the target attribute type from the attribute names.

[0056] In the embodiment of the present application, after the interface scanning device obtains the interface function information in the target file, it searches for the target attribute type through the attribute types of all the interface functions included in the interface function information. In the case where the target attribute type is found from the attribute types, it determines the target attribute name corresponding to the target attribute type from the attribute names.

[0057] In the embodiment of the present application, when the interface scanning device finds the external dependency attribute type from the attribute types, it determines the attribute annotation corresponding to the external dependency attribute type; if the attribute annotation is a preset attribute annotation, it determines the external dependency attribute type as the target attribute type.

[0058] Exemplarily, assume that the interface function information is encapsulated as a Java Class. By traversing each Java Class, first exclude the Java Class files within this project, and then determine whether the attribute type of the remaining Java Classes is a basic type attribute, such as basic type attributes like integer int, long integer long, byte type byte, string type String, etc. If it is a basic type attribute, then exclude this Java Class and continue to determine the attribute type of the next Java Class until the attribute type of the Java Class is not a basic type attribute, and then determine the attribute type of this Java Class as the external dependency attribute type.

[0059] It should be noted that in the case where the external dependency attribute type is found, it is also necessary to determine whether the attribute annotation of this external dependency attribute type is a preset attribute annotation.

[0060] Specifically, in the case where the external dependency attribute type is found, it is determined whether the preset attribute annotation is included in the attribute annotation corresponding to this external dependency attribute type, such as preset attribute annotations like the by-name assembly annotation Resouce and the by-type assembly annotation Autowired. If the preset attribute annotation is included in the attribute annotation, the external dependency attribute type is determined as the target attribute type.

[0061] It should be noted that whether the property annotation of the external dependency property type is a preset property annotation can be whether it contains a preset property annotation or whether it is a preset property annotation. This application embodiment does not make a limitation here.

[0062] It should be noted that the preset property annotation is a property annotation set in advance before judging the property annotation.

[0063] In the embodiment of this application, after determining the target property type, the target property name corresponding to the target property type is determined from the property names.

[0064] It should be noted that since the interface function information is stored item by item, therefore, after determining that the property type in this piece of interface function information is the target property type, the target property name corresponding to this target property type can be found by looking up this piece of interface function information.

[0065] S104. Traverse the method body according to the target property name. When the target method body containing the target property name is found from the method body, determine the function of the target interface corresponding to the target method body according to the target method body.

[0066] In the embodiment of this application, after the interface scanning device determines the target property name corresponding to the target property type, it traverses the method body according to the target property name. When the target method body containing the target property name is found from the method body, determine the function of the target interface corresponding to the target method body according to the target method body.

[0067] It should be noted that since all method bodies in all interface functions can be obtained through all interface function information, therefore, after determining the target property name, traverse all method bodies once according to each target property name.

[0068] In the embodiment of this application, the interface scanning device traverses all method bodies once according to each target property name. When the same field as the target property name is found in the first method body in the method body, the first method body is determined as the target method body.

[0069] Specifically, traverse all method bodies according to the target property name, and judge whether the method body contains the target property name through regular matching. If the current method body does not contain the target property name, filter this method body and judge the next method body. If the current method body contains the target property name, determine the current method body as the target method body.

[0070] In an embodiment of the present application, after determining the target method body, through regular matching, the target method function corresponding to the target attribute name and the first interface function corresponding to the target method body are determined from the target method body; the target method function and the first interface function are determined as the functions of the target interface corresponding to the target method body.

[0071] Specifically, after determining the target method body, through regular matching, the target method function corresponding to the target attribute name is determined from the target method body, and the first interface function corresponding to the target method body is obtained according to the target method body. Then, the currently obtained target method function and first interface function are encapsulated and stored in a new set item by item.

[0072] It should be noted that the target method function obtained at this time and the first interface function that calls the target method function are both the functions of the target interface required by the present application.

[0073] In an embodiment of the present application, after determining the first interface function, according to the division of preset function modules, the function set that calls this first interface function in the target function module is searched.

[0074] Specifically, from at least one interface function information set, the first interface function information set corresponding to the target function module is searched; the target function module is a function module in the preset function module; in the case where a second interface function that calls the first interface function is found in the method body included in the first interface function information set; the second interface function is added to the functions of the target interface.

[0075] Exemplarily, assuming that at this time it is necessary to find the function set that calls the first interface function in the interface module within the project, then according to all the first interface functions in the obtained new set, all the method bodies in the first interface function information set corresponding to the target function module are recursively traversed one by one, and in the case where a second interface function that calls the first interface function is found in the method body included in the first interface function information set, the function information corresponding to this second interface function is determined, and this function information is added to the above new set until all the method bodies in the first interface function information set are found according to all the first interface functions, and finally all the functions of the target interface corresponding to the target module are obtained.

[0076] It should be noted that in an embodiment of the present application, the second interface function can be searched module by module, or all interface function information can be traversed to search for the second interface function. Specifically, it can be determined according to the actual situation, and the embodiment of the present application does not limit this here.

[0077] S105. Output the functions of the target interface.

[0078] In an embodiment of the present application, after obtaining the function of the target interface, the interface scanning device writes the function of the target interface into a preset initial table to obtain a target interface function table, and outputs the target interface function table.

[0079] It should be noted that the target interface function table at this time includes all target method functions and the interface functions that call the target method functions.

[0080] The embodiment of the present application provides an interface scanning method, which includes: scanning target files in a target project directory; parsing the target files to obtain interface function information in the target files; the interface function information at least includes the attribute type, attribute name, and method body corresponding to the interface function; when a target attribute type is found from the attribute types, determining a target attribute name corresponding to the target attribute type from the attribute names; traversing the method body according to the target attribute name, and when a target method body containing the target attribute name is found from the method body, determining the function of the target interface corresponding to the target method body according to the target method body; outputting the function of the target interface. With the above implementation solution, since the target files in the project directory store the relevant information of the interface functions, and the target interface corresponds to a specified target attribute type, it is possible to scan and parse the target files to obtain the attribute type, attribute name, and method body corresponding to the interface functions in the target files, and then find the target method body corresponding to the target interface from the interface function information according to the target attribute type, and screen out the function of the target interface from the target method body, which can realize the automatic sorting of the target interfaces in the project and achieve the purpose of improving the accuracy and efficiency of sorting the target interfaces.

[0081] In a practical application, the present application is exemplarily described by scanning Java file interfaces in a target project, but the present application is not limited to the scanning of Java file interfaces. Figure 2 The following shows a flow chart of an exemplary Java file interface scanning method provided by the present application, as Figure 2 shown:

[0082] 1. According to the root path in the target project directory, find all Java files in the target project directory, and use a parsing tool to parse all Java files to obtain a parsing result;

[0083] Specifically, since the Java files in the target project are stored in the same root path, all Java files in the target project directory can be found through the input root path. After finding all Java files, scan all Java files, and then call the Java file parsing tool to parse all the scanned Java files to obtain the parsing result corresponding to the Java files.

[0084] 2. Package the parsing results into Java Class files one by one, and divide and store the Java Class files into a preset functional module set according to the preset functional modules;

[0085] Specifically, package the parsed parsing results into Java Class files, that is, package the package name, class name, attribute type, attribute name, attribute comment, method name, method body, method annotation, method comment and class-related information of the Java file into Java Class files one by one, and store the corresponding preset functional modules and Java Class files in a key-value data structure, where the name of the preset functional module is stored in the key, and the set of Java Class files corresponding to the preset functional module is stored in the value.

[0086] 3. Exclude the Java Class files corresponding to this project and the Java Class files with the attribute type of basic attributes to obtain the Java Class files with the attribute type of external dependent attributes;

[0087] Specifically, by traversing each Java Class file, first exclude the Java Class files corresponding to this project, and then judge whether the attribute type of the remaining Java Class files is a basic type attribute. For example, basic type attributes such as integer int, long integer long, byte byte, string String, etc. If it is a basic type attribute, then exclude this Java Class file and continue to judge the attribute type of the next Java Class file until the attribute type of the Java Class is not a basic type attribute, then determine that the attribute type of this Java Class file is an external dependent attribute type.

[0088] 4. Obtain the attribute annotations corresponding to the Java Class files with the attribute type of external dependent attributes;

[0089] Specifically, obtain the attribute annotations corresponding to the attribute type of external dependent attributes by searching the attribute annotations of all Java Class files.

[0090] 5. In the case where it is judged that the attribute annotation contains a preset attribute annotation, determine the external dependent attribute type as the target attribute type;

[0091] Specifically, by searching whether the attribute annotation corresponding to the external dependent attribute type contains a preset attribute annotation, such as preset attribute annotations such as the annotation Resouce for assembly by name and the annotation Autowired for assembly by type. In the case where it is judged that the attribute annotation contains a preset attribute annotation, then determine the external dependent attribute type as the target attribute type.

[0092] 6. Determine the target attribute name corresponding to the target attribute type;

[0093] Specifically, after determining that the attribute type in this Java Class file is the target attribute type, find the target attribute name corresponding to this target attribute type by searching for the Java Class file corresponding to this target attribute type.

[0094] 7. When it is determined by regular matching that the first method body in the method body contains the target attribute name, determine the first method body as the target method body;

[0095] Specifically, traverse the method bodies of all Java Class files according to the target attribute name, and determine whether the first method body contains the target attribute name by regular matching. If the first method body does not contain the target attribute name, filter this method body and judge the next method body. If the first method body contains the target attribute name, determine the first method body as the target method body.

[0096] 8. Extract the first interface function of the target method body and the target method function corresponding to the target attribute name by regular matching;

[0097] Specifically, after determining the target method body, determine the target method function corresponding to the target attribute name from the target method body by regular matching, and obtain the first interface function corresponding to the target method body according to the target method body.

[0098] 9. Repackage and store the obtained first interface function and target method function into a new set;

[0099] Specifically, encapsulate the currently obtained target method function and function into a new Java Class item by item in the form of class name className, first interface function funName, method explanation comment, target dependency class rpcClass, target method function rpcFunction, call module set invokeApp, call module class name invokeClass, call module function name invokeFunc, and the current module module, and store it in a new set.

[0100] It should be noted that the call module set invokeApp, call module class name invokeClass, and call module function name invokeFunc need to be further extracted when matching the first interface function by module.

[0101] 10. Search for the second interface function that calls the first interface function from the preset interface module set;

[0102] Specifically, the preset interface module set at this time is the module set corresponding to the interface modules in the preset function module set. Suppose it is necessary to find the function set that calls the first interface function in the preset interface modules within this project. Then, according to all the first interface functions in the obtained new set, recursively traverse all the method bodies in the first interface function information set corresponding to the target function module one by one. And when a second interface function that calls the first interface function is found in the method bodies included in the first interface function information set, determine the call module set invokeApp, call module class name invokeClass, and second interface function name invokeFunc corresponding to this second interface function.

[0103] 11. Store the function information corresponding to the second interface function into the above new set;

[0104] Specifically, add the obtained call module set invokeApp, call module class name invokeClass, and second interface function name invokeFunc information corresponding to the second interface function to the above new Java Class until all the method bodies in the first interface function information set are found according to all the first interface functions. At this time, the new Java Class already includes the target method function, the first interface function that calls the target method function, and the second interface function that calls the first interface function, and finally obtains all the functions of the target interfaces corresponding to the target module.

[0105] 12. Output the new set in the form of a table.

[0106] Embodiment 2

[0107] In another embodiment of the present application, an interface scanning device 1 is provided. Figure 3 It is a schematic diagram of the composition structure of an interface scanning device 1 provided by the present application. Figure 1 As Figure 3 shown, the interface scanning device 1 includes:

[0108] A scanning unit 10 for scanning target files in a target project directory;

[0109] An analysis unit 11 for analyzing the target files to obtain interface function information in the target files; the interface function information includes the attribute type, attribute name, and method body corresponding to the interface function;

[0110] A determination unit 12 for determining the target attribute name corresponding to the target attribute type from the attribute names when the target attribute type is found in the attribute types;

[0111] The determining unit 12 is further configured to traverse the method body according to the target attribute name, and in the case of finding a target method body containing the target attribute name from the method body, determine a function of a target interface corresponding to the target method body according to the target method body;

[0112] An output unit 13 is configured to output the function of the target interface.

[0113] Wherein, the determining unit 12 is further configured to, in the case of finding an external dependency attribute type from the attribute types, determine an attribute annotation corresponding to the external dependency attribute type; if the attribute annotation is a preset attribute annotation, determine the external dependency attribute type as the target attribute type.

[0114] Wherein, the determining unit 12 is further configured to, in the case of finding a same field as the target attribute name in a first method body in the method body, determine the first method body as the target method body; determine a target method function corresponding to the target attribute name and a first interface function corresponding to the target method body from the target method body through regular matching; and determine the target method function and the first interface function as the function of the target interface corresponding to the target method body.

[0115] Optionally, the interface scanning device 1 further includes: a partitioning unit;

[0116] The partitioning unit is configured to partition the interface function information into at least one interface function information set according to a preset functional unit corresponding to the target project;

[0117] The determining unit 12 is further configured to sequentially determine whether an attribute type in each parsing result set in the at least one parsing result set is a target attribute type, and in the case of the attribute type being the target attribute type, determine the target attribute type and a target attribute name corresponding to the target attribute type.

[0118] Optionally, the interface scanning device 1 further includes: a searching unit, an adding unit;

[0119] The searching unit is configured to search, from the at least one interface function information set, for a first interface function information set corresponding to a target functional unit; the target functional unit is a functional unit in the preset functional unit;

[0120] The adding unit is configured to, in the case of finding a second interface function that calls the first interface function from a method body included in the first interface function information set, add the second interface function to the function of the target interface.

[0121] Optionally, the interface scanning device 1 further includes: a writing unit;

[0122] The writing unit is configured to write the functions of the target interface into a preset initial table to obtain a target interface function table;

[0123] The output unit 13 is further configured to output the target interface function table.

[0124] The embodiment of the present application provides an interface scanning device. The interface scanning device includes: scanning target files in a target project directory; parsing the target files to obtain interface function information in the target files; the interface function information at least includes an attribute type, an attribute name, and a method body corresponding to the interface function; when a target attribute type is found from the attribute types, determining a target attribute name corresponding to the target attribute type from the attribute names; traversing the method body according to the target attribute name, and when a target method body including the target attribute name is found from the method body, determining the function of the target interface corresponding to the target method body according to the target method body; outputting the function of the target interface. By adopting the above implementation solution, since the target files in the project directory store the relevant information of the interface functions, and the target interface corresponds to a specified target attribute type, it is possible to scan and parse the target files to obtain the attribute type, the attribute name, and the method body corresponding to the interface functions in the target files, and then find the target method body corresponding to the target interface from the interface function information according to the target attribute type, and filter out the functions of the target interface from the target method body, which can realize the automatic sorting of the target interfaces in the project and achieve the purpose of improving the accuracy and efficiency of sorting the target interfaces.

[0125] Figure 4 This is a schematic diagram of the composition structure of an interface scanning device 1 provided by an embodiment of the present application Figure 2 In practical applications, based on the same inventive concept of the above embodiment, as Figure 4 shown, the interface scanning device 1 of this embodiment includes: a processor 14, a memory 15, and a communication bus 16.

[0126] During the process of a specific embodiment, the above-mentioned scanning unit 10, parsing unit 11, determination unit 12, output unit 13, division unit, search unit, addition unit, and writing unit can be implemented by a processor 14 located on the interface scanning device 1. The above-mentioned processor 14 can be at least one of an application specific integrated circuit (ASIC), a digital signal processor (DSP), a digital signal processing image processing device (DSPD), a programmable logic image processing device (PLD), a field programmable gate array (FPGA), a CPU, a controller, a microcontroller, and a microprocessor. It can be understood that for different interface scanning devices, the electronic devices used to implement the above-mentioned processor functions can also be other, and the specific limitations are not made in this embodiment.

[0127] In the embodiment of the present application, the above-mentioned communication bus 16 is used to realize the connection and communication between the processor 14 and the memory 15; when the processor 14 executes the running program stored in the memory 15, the following interface scanning method is realized:

[0128] Scan the target file in the target project directory;

[0129] Parse the target file to obtain the interface function information in the target file; the interface function information includes the attribute type, attribute name, and method body corresponding to the interface function;

[0130] In the case of finding the target attribute type from the attribute types, determine the target attribute name corresponding to the target attribute type from the attribute names;

[0131] Traverse the method body according to the target attribute name, and in the case of finding the target method body containing the target attribute name from the method body, determine the function of the target interface corresponding to the target method body according to the target method body;

[0132] Output the function of the target interface.

[0133] Optionally, the processor 14 is further configured to determine the attribute annotation corresponding to the external dependency attribute type in the case of finding the external dependency attribute type from the attribute types; if the attribute annotation is a preset attribute annotation, determine the external dependency attribute type as the target attribute type.

[0134] Optionally, the processor 14 is further configured to, when finding a field that is the same as the target attribute name in the first method body of the method body, determine the first method body as the target method body; determine, through regular matching, the target method function corresponding to the target attribute name and the first interface function corresponding to the target method body from the target method body; and determine the target method function and the first interface function as the functions of the target interface corresponding to the target method body.

[0135] Optionally, the processor 14 is further configured to divide the interface function information into at least one interface function information set according to the preset function modules corresponding to the target project; correspondingly, when finding a target attribute type in the attribute types, determining the target attribute name corresponding to the target attribute type from the attribute names includes: sequentially determining whether the attribute type in each parsing result set of the at least one parsing result set is the target attribute type, and when the attribute type is the target attribute type, determining the target attribute type and the target attribute name corresponding to the target attribute type.

[0136] Optionally, the processor 14 is further configured to find, from the at least one interface function information set, a first interface function information set corresponding to a target function module; the target function module is a function module in the preset function modules; when finding a second interface function that calls the first interface function in the method body included in the first interface function information set; adding the second interface function to the functions of the target interface.

[0137] Optionally, the processor 14 is further configured to write the functions of the target interface into a preset initial table to obtain a target interface function table; and output the target interface function table.

[0138] An embodiment of the present application provides a storage medium, on which a computer program is stored. The above computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors and are applied to an interface scanning device. The computer program implements the interface scanning method as described above.

[0139] It should be noted that in this article, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the element.

[0140] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-described example methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present disclosure, in essence or the part that contributes to the related technology, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc), and includes several instructions for causing an image display device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the interface scanning method described in each embodiment of the present disclosure.

[0141] The above is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application.

Claims

1. An interface scanning method, characterized in that, The method includes: Scanning the target files in the target project directory; Parsing the target files to obtain interface function information in the target files; the interface function information at least includes the attribute type, attribute name, and method body corresponding to the interface function; When a target attribute type is found from the attribute types, determining the target attribute name corresponding to the target attribute type from the attribute names; Traversing the method body according to the target attribute name, and when a target method body containing the target attribute name is found from the method body, determining the function of the target interface corresponding to the target method body according to the target method body; Outputting the function of the target interface; Among them, the step of, when a target method body containing the target attribute name is found from the method body, determining the function of the target interface corresponding to the target method body according to the target method body, includes: When a first method body with the same field as the target attribute name is found from the method body, determining the first method body as the target method body; Determining the target method function corresponding to the target attribute name and the first interface function corresponding to the target method body from the target method body through regular matching; Determining the target method function and the first interface function as the function of the target interface corresponding to the target method body.

2. According to the method described in claim 1, after parsing the target files to obtain the interface function information in the target files and before determining the target attribute name corresponding to the target attribute type from the attribute names, the method further includes: When an external dependency attribute type is found from the attribute types, determining the attribute annotation corresponding to the external dependency attribute type; If the attribute annotation is a preset attribute annotation, determining the external dependency attribute type as the target attribute type.

3. The method according to claim 1, wherein After parsing the target files to obtain the interface function information in the target files and before determining the target attribute name corresponding to the target attribute type from the attribute names when a target attribute type is found from the attribute types, the method further includes: Dividing the interface function information into at least one interface function information set according to the preset function module corresponding to the target project; Correspondingly, the step of, when a target attribute type is found from the attribute types, determining the target attribute name corresponding to the target attribute type from the attribute names, includes: Sequentially determining whether the attribute type in each parsing result set among at least one parsing result set is the target attribute type; When the attribute type is the target attribute type, determining the target attribute type and the target attribute name corresponding to the target attribute type.

4. The method according to claim 3, characterized in that The step of traversing the method body according to the target attribute name, and when a target method body containing the target attribute name is found from the method body, determining the function of the target interface corresponding to the target method body according to the target method body, includes: Search for a first set of interface function information corresponding to a target functional module from the at least one set of interface function information; the target functional module is a functional module among the preset functional modules; In the case where a second interface function that calls the first interface function is found in the method body included in the first set of interface function information, add the second interface function to the functions of the target interface.

5. The method according to claim 1, wherein the outputting the functions of the target interface comprises: Write the functions of the target interface into a preset initial table to obtain a target interface function table; Output the target interface function table.

6. An interface scanning device, characterized in that, The device comprises: A scanning unit, configured to scan target files in a target project directory; An analysis unit, configured to analyze the target files to obtain interface function information in the target files; the interface function information at least includes an attribute type, an attribute name, and a method body corresponding to the interface function; A determination unit, configured to, in the case where a target attribute type is found from the attribute types, determine a target attribute name corresponding to the target attribute type from the attribute names; The determination unit is further configured to traverse the method body according to the target attribute name, and in the case where a target method body including the target attribute name is found from the method body, determine a function of a target interface corresponding to the target method body according to the target method body; An output unit, configured to output the functions of the target interface; Specifically, the determination unit is configured to, in the case where a first method body having the same field as the target attribute name is found from the method body, determine the first method body as the target method body; determine a target method function corresponding to the target attribute name and a first interface function corresponding to the target method body from the target method body through regular matching; and determine the target method function and the first interface function as the functions of the target interface corresponding to the target method body.

7. The device according to claim 6, characterized in that, The determination unit is further configured to, in the case where an external dependency attribute type is found from the attribute types, determine an attribute annotation corresponding to the external dependency attribute type; and if the attribute annotation is a preset attribute annotation, determine the external dependency attribute type as the target attribute type.

8. An interface scanning device, characterized in that, The device comprises: a processor, a memory, and a communication bus; when the processor executes a running program stored in the memory, the interface scanning method according to any one of claims 1-5 is implemented.

9. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, the interface scanning method according to any one of claims 1-5 is implemented.

Citation Information

Patent Citations

  • Code calling method and device, terminal and storage medium

    CN110764748A

  • Application program interface document generation method and device, computer equipment and medium

    CN111488174A