API interface parameter analysis method and device, equipment and storage medium
By converting the code files of the API interface into an abstract syntax tree, and traversing and parsing its nodes, and automatically obtaining API interface parameters, the problems of low efficiency and low accuracy of manual viewing and entry are solved, and efficient and accurate API interface parameter analysis is achieved.
Patent Information
- Application Number
- CN202411918866.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-24
- Publication Date
- 2025-04-01
AI Technical Summary
In the prior art, the manual viewing and entry of API interface parameters is low efficiency and low accuracy, and it is easy to cause missed or misrecorded.
By obtaining the code file corresponding to the API interface, calling the parsing tool to convert the code file into an abstract syntax tree (AST), then traversing and parsing the nodes in the AST, and automatically obtaining the API interface parameters.
It realizes automatic analysis of API interface parameters, improves analysis efficiency, accuracy and coverage, supports code files in multiple programming languages, and does not require running programs.
Smart Images

Figure CN119739422A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of program analysis, and in particular to a method, device, equipment and storage medium for parsing API interface parameters. Background Art
[0002] In the field of cloud computing, cloud vendors need to provide tens of thousands of application programming interfaces (APIs), each of which is associated with parameter information such as interface parameters, response parameters, and error code information.
[0003] In related technologies, after completing the development of API interface functions, developers manually check the parameter information defined in the code, and then enter the relevant parameter information into OpenAPI Explorer, so that customers can complete parameter input according to the parameter information when needed, thereby realizing the call of the API interface. OpenAPI Explorer is an API interface management system for customers of various cloud vendors, with functions such as API management, API online calling, and error code query.
[0004] However, this manual review and entry method is inefficient, inaccurate, and prone to omissions or errors. Summary of the invention
[0005] In order to solve the above technical problems, the present disclosure provides a method, device, equipment and storage medium for parsing API interface parameters.
[0006] In a first aspect, the present disclosure provides a method for parsing API interface parameters, comprising:
[0007] Obtain the code file corresponding to the API interface; call a parsing tool to parse the code file to obtain a first abstract syntax tree; traverse the nodes in the first abstract syntax tree, and when traversing to the class definition node and the child nodes of the class definition node contain a function definition node corresponding to the API interface, parse the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node to obtain the parsing results corresponding to each node; obtain the API interface parameters from the parsing results.
[0008] In an optional embodiment, the method further comprises:
[0009] When a field definition node exists in the child node of the class definition node, a field definition code corresponding to the field definition node is obtained; the field definition code is parsed to obtain a field dictionary, and the field dictionary is stored in a preset storage space.
[0010] In an optional implementation, when the child nodes of the function definition node include input parameter nodes and / or return value nodes, the parsing result is the input parameter and / or return value.
[0011] In an optional implementation, when the child nodes of the function definition node include a function body node, and the child nodes of the function body node include an exception throwing node, the parsing result is error code information.
[0012] In an optional implementation, when the child nodes of the function definition node include a function body node and the function body node is a function call node, the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node are parsed to obtain parsing results corresponding to each node, including:
[0013] Obtain the file path of the code file and the calling address of the function calling code in the code file; generate request information according to the file path and the calling address, and send the request information to the language server; receive the response information fed back by the language server based on the request information, and obtain the jump file and jump address from the response information, the jump file is the code file to which the called function belongs, and the jump address is the address of the function definition code segment corresponding to the called function in the jump file; parse the jump file in combination with the jump address, and store the parsed result in a preset storage space.
[0014] In an optional implementation, when the child nodes of the function definition node include a function body node and the child nodes of the function body node include a control flow node and / or a loop node, the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node are parsed to obtain parsing results corresponding to each node, including:
[0015] According to the parsing method of the function body node, the code corresponding to the control flow node and / or the loop node is parsed to obtain the parsing result; it is determined whether the parsing result contains the API interface parameter; when the parsing result does not contain the API interface parameter, the parsing result is cleared.
[0016] In an optional embodiment, the method further comprises:
[0017] When a code file is monitored to have changed, the API interface parameters are parsed again based on the changed code file.
[0018] In a second aspect, the present disclosure provides a device for parsing API interface parameters, including:
[0019] The first acquisition module is used to obtain the code file corresponding to the API interface; the conversion module is used to call the parsing tool to parse the code file to obtain the first abstract syntax tree; the first parsing module is used to traverse the nodes in the first abstract syntax tree, and when traversing to the class definition node and there is a function definition node corresponding to the API interface in the child node of the class definition node, the code corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node is parsed to obtain the parsing results corresponding to each node; the second acquisition module is used to obtain API interface parameters from the parsing results.
[0020] In a third aspect, the present disclosure provides a computer device, comprising:
[0021] The memory and the processor are communicatively connected with each other, the memory stores computer instructions, and the processor executes the method for parsing API interface parameters corresponding to the first aspect of the invention and any one of its embodiments by executing the computer instructions.
[0022] In a fourth aspect, the present disclosure provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute a method for parsing API interface parameters corresponding to the first aspect of the invention and any one of its embodiments.
[0023] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has the following advantages:
[0024] The API interface parameter parsing method provided in this embodiment, after obtaining the code file corresponding to the API interface, calls the parsing tool to parse the code file to obtain a first abstract syntax tree; then, traverses the nodes in the first abstract syntax tree, and when traversing to the class definition node and there is a function definition node corresponding to the API interface in the child nodes of the class definition node, parses the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node to obtain the parsing results corresponding to each node; finally, obtains the API interface parameters from the parsing results; this embodiment completes the automatic parsing of the API interface parameters by converting the code file into the first abstract syntax tree, and then traversing and parsing the nodes in the first abstract syntax tree; in addition, this method also supports code files in multiple programming languages, and the parsing process does not require running the program, thereby improving the parsing efficiency, accuracy and coverage of the API interface parameters. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0027] Figure 1 A flowchart of a method for parsing API interface parameters provided in an embodiment of the present disclosure;
[0028] Figure 2 An example diagram of the parsing process provided by the embodiment of the present disclosure;
[0029] Figure 3 A schematic diagram of a parsing process for codes corresponding to function call nodes provided in an embodiment of the present disclosure;
[0030] Figure 4 A structural connection diagram of an API interface parameter parsing device provided in an embodiment of the present disclosure;
[0031] Figure 5 A structural connection diagram of a computer device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0032] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0033] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0034] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0035] In the field of cloud computing, cloud vendors need to provide thousands of application programming interfaces (APIs), each of which is associated with a set of API parameters (such as input parameters, response parameters, and error code information). After the API interface function is developed, the relevant parameters of the API interface need to be entered into the OpenAPI Explorer so that customers can enter the corresponding parameters according to the prompts in the OpenAPI Explorer to correctly call the API interface.
[0036] In the related art, there are two ways to parse API interface parameters. The first is that the developer manually checks the API interface parameters in the code and then enters these parameters into the OpenAPI Explorer. The second is to use the reflection mechanism of the program to automatically parse the API interface code to obtain the API interface parameters.
[0037] However, the manual method has the problems of low efficiency, low accuracy and low coverage. Not only can the reflection mechanism not obtain the program logic, it can only be started during the program running process. Moreover, the reflection mechanism needs to be written in the same language as the code. When the code language changes, the reflection mechanism needs to be rewritten.
[0038] To this end, the present disclosure provides a method for parsing API interface parameters, which completes the automatic parsing of API interface parameters by converting the code file into a first abstract syntax tree, and then traversing and parsing the nodes in the first abstract syntax tree; in addition, this method also supports code files in multiple programming languages, and the parsing process does not require running the program, thereby improving the parsing efficiency, accuracy and coverage of API interface parameters.
[0039] According to an embodiment of the present disclosure, an embodiment of a method for parsing API interface parameters is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0040] In this embodiment, a method for parsing API interface parameters is provided, which can be used for parameter parsers. Figure 1 is a flowchart of a method for parsing API interface parameters according to an embodiment of the present disclosure, such as Figure 1 As shown, the process includes the following steps:
[0041] S101, obtaining the code file corresponding to the API interface.
[0042] The code file corresponding to the API interface is the program code written by the developer to process API requests, execute related logic and return response data. The program code can be written in any programming language.
[0043] Specifically, the parameter parser obtains the code file corresponding to the API interface uploaded by the developer.
[0044] S102: Call a parsing tool to parse the code file to obtain a first abstract syntax tree.
[0045] The parsing tool may be a multi-language parser, a parser for a specific language, or other document parsers. This embodiment does not limit the parsing tool, and those skilled in the art may select one according to actual needs.
[0046] Specifically, the parameter parser calls the parsing tool to read the code file, and constructs an abstract syntax tree (Abstract Syntax Tree, AST for short), ie, the first abstract syntax tree, according to the read text information.
[0047] S103, traverse the nodes in the first abstract syntax tree, and when traversing to the class definition node and there is a function definition node corresponding to the API interface in the child nodes of the class definition node, parse the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node to obtain the parsing results corresponding to each node.
[0048] Specifically, Figure 2As shown, after obtaining the first abstract syntax tree through S101, starting from the root node of the first abstract syntax tree, the nodes in the first abstract syntax tree are traversed in sequence. During the node traversal process, it is determined whether there is a class definition node in the first abstract syntax tree. If there is a class definition node in the first abstract syntax tree, it is further determined whether the child nodes of the class definition node contain a function definition node corresponding to the API interface.
[0049] When there is a class definition node in the first abstract syntax tree and there is a function definition node corresponding to the API interface in the child node of the class definition node, the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node are parsed to obtain the parsing results corresponding to each node.
[0050] Specifically, when parsing the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node, the parsing can be performed according to the hierarchical order of the abstract syntax subtree nodes. Figure 2 In the example, the nodes at the first level in the abstract syntax subtree are child nodes of the function definition node, such as the input parameter node, the return value node, and the function body node. The nodes at the second level in the abstract syntax subtree are child nodes of the function body node, such as the variable declaration node, the function call node, the control flow node, the loop node, and the exception throwing node. It is understandable that in actual applications, the levels in the abstract syntax subtree and the nodes at each level are not limited to the above examples.
[0051] After determining the nodes corresponding to each level in the abstract syntax subtree, you can get the code (or code segment) corresponding to each node from the code file, and parse the code corresponding to the node. For example, in the first level of the abstract syntax subtree, parse the code corresponding to the input parameter node, and the parsing result is the input parameter, and the input parameter is stored in the result container. Parse the code corresponding to the return value node, and the parsing result is the return value, and the return value is stored in the result container. Parse the code (or code segment) corresponding to the function body node to obtain a node list composed of each child node in the function body node, and the node list is composed of child nodes corresponding to the second level in the abstract syntax subtree. For example Figure 2 As shown, the code corresponding to the variable declaration node is parsed, and the parsing result obtained is a variable dictionary, which is stored in a preset storage space. The variable dictionary includes information such as the variable name, the data type of the variable, and the initial value of the variable. The code corresponding to the exception throwing node is parsed, and the parsing result obtained is error code information, which is stored in the result container. When all nodes in the abstract syntax subtree are traversed and parsed, the parameters stored in the result container are the API interface parameters.
[0052] In another optional embodiment, if the class definition node is not traversed in the first abstract syntax tree, or if the class definition node is traversed in the first abstract syntax tree, but the function definition node corresponding to the API interface does not exist in the child nodes of the class definition node, it means that the current code file is not the code file corresponding to the API interface, so the traversal and parsing operations on other nodes can be directly terminated. In this case, an abnormal signal can also be issued to enable the developer to re-verify the accuracy of the code file.
[0053] In another optional embodiment, if a class definition node is traversed in the first abstract syntax tree, and there is a field definition node in the child node of the class definition node, the field definition code corresponding to the field definition node can be obtained from the code file. The field definition code is parsed to obtain a field dictionary, and the field dictionary is stored in a preset storage space, so that when subsequent nodes reference the field, the field information corresponding to the field can be extracted from the preset storage space. It should be noted that the field dictionary includes information such as field name, field type, field length, and whether the field is allowed to be empty.
[0054] S104, obtaining API interface parameters from the parsing result.
[0055] Specifically, after obtaining the parsing result, it is determined whether there are API interface parameters in the parsing result. When there are API interface parameters in the parsing result, the API interface parameters can be stored in the result container, and the API interface parameters in the result container can be output, thereby obtaining the API interface parameters. The API interface parameters include but are not limited to input parameters, return values, error code information, etc.
[0056] In an optional embodiment, after S104, the obtained API interface parameters are entered into the OpenAPI Explorer.
[0057] In an optional embodiment, a code monitoring tool is called to monitor the code file. When changes are detected in the code file, the parameter parser re-performs parameter parsing operations on the changed code file according to the API interface parameter parsing method provided by the present invention to ensure that the parameters entered into the OpenAPI Explorer are consistent with the actual situation.
[0058] The API interface parameter parsing method provided in this embodiment, after obtaining the code file corresponding to the API interface, calls the parsing tool to parse the code file to obtain a first abstract syntax tree; then, traverses the nodes in the first abstract syntax tree, and when traversing to the class definition node and there is a function definition node corresponding to the API interface in the child nodes of the class definition node, parses the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node to obtain the parsing results corresponding to each node; finally, obtains the API interface parameters from the parsing results; this embodiment completes the automatic parsing of the API interface parameters by converting the code file into the first abstract syntax tree, and then traversing and parsing the nodes in the first abstract syntax tree; in addition, this method also supports code files in multiple programming languages, and the parsing process does not require running the program, thereby improving the parsing efficiency, accuracy and coverage of the API interface parameters.
[0059] In an optional embodiment, the abstract syntax subtree with the function definition node as the root node includes a function call node. This embodiment optimizes the parsing process of the code corresponding to the function call node, such as Figure 3 As shown, the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node are parsed to obtain the parsing results corresponding to each node, including the following steps:
[0060] S301, obtaining a file path of a code file and a calling address of a function calling code in the code file.
[0061] The calling address is the address of the function calling code in the code file, for example, it can be the line number in the code file. The file path of the code file is the path of the code file in the parameter parser. It should be noted that after the code file is uploaded to the parameter parser by the developer, it is downloaded by the parameter parser and stored in the preset storage space.
[0062] S302: Generate request information according to the file path and the calling address, and send the request information to the language server.
[0063] The request information is request information that complies with the language server protocol.
[0064] Specifically, request information that complies with the language server protocol, namely (LSP information), is generated according to the file path and the calling address, and the request information is sent to the language server, so that the language server obtains the code file according to the file path, determines the called function from the code file according to the calling address, and sends the jump file to which the called function belongs and the jump address of the called function in the jump file to the parameter parser.
[0065] S303, receiving response information fed back by the language server based on the request information, and obtaining a jump file and a jump address from the response information.
[0066] The jump file is the code file to which the called function belongs, and the jump address is the address of the function definition code segment corresponding to the called function in the jump file.
[0067] Specifically, when response information fed back by the language server based on the request information is received, the jump file and the jump address are obtained from the response information.
[0068] S304, analyzing the jump file in combination with the jump address, and storing the analysis result in a preset storage space.
[0069] Specifically, after obtaining the jump file, first, call the parsing tool to parse the jump file to obtain the second abstract syntax tree. Then, determine the code portion corresponding to the called function in the jump file according to the jump address, and find the node corresponding to the called function from the second abstract syntax tree. Finally, starting from the root node of the second abstract syntax tree, traverse the nodes in the second abstract syntax tree in a top-down order. Focus on parsing the nodes corresponding to the called function and the fields or variables referenced in the called function, and store the parsing results in the preset storage space, so that during the API interface call process, information can be extracted from the preset storage space at any time.
[0070] The API interface parameter parsing method provided in this embodiment realizes the jump between codes by combining static code analysis and language server, solves the problems in related technologies that the logical relationship between files cannot be established, and the call chain between classes and functions is difficult to establish, and completes the analysis of all dependent codes of the API interface.
[0071] In an optional embodiment, the abstract syntax subtree with the function definition node as the root node includes control flow nodes and / or loop nodes. This embodiment optimizes the parsing process of the code corresponding to the control flow node and / or loop node, and parses the code corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node to obtain the parsing results corresponding to each node, including:
[0072] According to the parsing method of the function body node, the code corresponding to the control flow node and / or the loop node is parsed to obtain the parsing result; it is determined whether the parsing result contains the API interface parameter; when the parsing result does not contain the API interface parameter, the parsing result is cleared.
[0073] Specifically, the parsing method for control flow nodes and / or loop nodes is the same as the parsing method for function body nodes. That is, first, the control flow nodes and / or loop nodes are parsed to obtain a node list corresponding to the control flow nodes and / or loop nodes. And each node in the node list is parsed to obtain a parsing result corresponding to each node. Then it is determined whether the parsing result contains API interface parameters. When the parsing result does not contain API interface parameters, the parsing result is cleared. When the parsing result contains API interface parameters, the API interface parameters are written into the result container, and when all nodes in the abstract syntax subtree with the function definition node as the root node complete the parsing operation, they are output together with other API interface parameters stored in the result container.
[0074] In this embodiment, a device for parsing API interface parameters is also provided, which is used to implement the above embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0075] This embodiment provides a device for parsing API interface parameters, such as Figure 4 As shown, including:
[0076] The first acquisition module 401 is used to acquire the code file corresponding to the API interface.
[0077] The conversion module 402 is used to call a parsing tool to parse the code file to obtain a first abstract syntax tree.
[0078] The first parsing module 403 is used to traverse the nodes in the first abstract syntax tree. When traversing to the class definition node and there is a function definition node corresponding to the API interface in the child nodes of the class definition node, the code corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node is parsed to obtain the parsing results corresponding to each node.
[0079] The second acquisition module 404 is used to acquire API interface parameters from the parsing result.
[0080] In an optional embodiment, the device further comprises:
[0081] The third acquisition module is used to obtain the field definition code corresponding to the field definition node when there is a field definition node in the child node of the class definition node; the second parsing module is used to parse the field definition code, obtain the field dictionary, and store the field dictionary in a preset storage space.
[0082] In an optional implementation, when the child nodes of the function definition node include input parameter nodes and / or return value nodes, the parsing result is the input parameter and / or return value.
[0083] In an optional implementation, when the child nodes of the function definition node include a function body node, and the child nodes of the function body node include an exception throwing node, the parsing result is error code information.
[0084] In an optional implementation, when the child nodes of the function definition node include a function body node and the function body node is a function call node, the first parsing module 403 includes:
[0085] The acquisition submodule is used to obtain the file path of the code file and the calling address of the function calling code in the code file; the generation submodule is used to generate request information according to the file path and the calling address, and send the request information to the language server; the receiving submodule is used to receive the response information fed back by the language server based on the request information, and obtain the jump file and jump address from the response information, the jump file is the code file to which the called function belongs, and the jump address is the address of the function definition code segment corresponding to the called function in the jump file; the first parsing submodule is used to parse the jump file in combination with the jump address, and store the parsed result in a preset storage space.
[0086] In an optional implementation, when the child nodes of the function definition node include a function body node and the child nodes of the function body node include a control flow node and / or a loop node, the first parsing module 403 includes:
[0087] The second parsing submodule is used to parse the code corresponding to the control flow node and / or loop node according to the parsing method of the function body node to obtain the parsing result; the judgment submodule is used to judge whether the parsing result contains API interface parameters; the clearing submodule is used to clear the parsing result when the parsing result does not contain API interface parameters.
[0088] In an optional embodiment, the device further comprises:
[0089] The third parsing module is used to re-parse the API interface parameters according to the changed code file when a change is detected in the code file.
[0090] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0091] The API interface parameter parsing device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0092] The present disclosure also provides a computer device having the above Figure 4 The API interface parameters are shown in the parsing device.
[0093] See also Figure 5 , Figure 5 is a schematic diagram of a computer device provided by an optional embodiment of the present disclosure, such as Figure 5 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 5 A processor 10 is taken as an example.
[0094] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0095] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0096] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0097] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0098] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0099] The embodiments of the present disclosure also provide a computer-readable storage medium. The above-mentioned method according to the embodiments of the present disclosure can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium and downloaded through a network, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state drive, etc.; further, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0100] In addition to the above-mentioned computer device and computer-readable storage medium, the embodiments of the present application may also be a computer program product, which includes computer program instructions. When the computer program instructions are executed by a processor, the processor executes the steps of the sound source localization method provided by any embodiment of the present application.
[0101] The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0102] The above are only specific embodiments of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to these embodiments herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for parsing API interface parameters, characterized in that: include: Get the code file corresponding to the API interface; Calling a parsing tool to parse the code file to obtain a first abstract syntax tree; Traversing the nodes in the first abstract syntax tree, when traversing to a class definition node and a function definition node corresponding to the API interface exists in the child nodes of the class definition node, parsing the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node to obtain parsing results corresponding to each node; The API interface parameters are obtained from the parsing result.
2. The method according to claim 1, characterized in that The method further comprises: When a field definition node exists in the child node of the class definition node, obtaining a field definition code corresponding to the field definition node; The field definition code is parsed to obtain a field dictionary, and the field dictionary is stored in a preset storage space.
3. The method according to claim 1, characterized in that When the child nodes of the function definition node include input parameter nodes and / or return value nodes, the parsing result is the input parameter and / or return value.
4. The method according to any one of claims 1 to 3, characterized in that When the child nodes of the function definition node include a function body node, and the child nodes of the function body node include an exception throwing node, the parsing result is error code information.
5. The method according to any one of claims 1 to 3, characterized in that When the child nodes of the function definition node include a function body node and the function body node is a function call node, the code corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node is parsed to obtain parsing results corresponding to each node, including: Obtaining the file path of the code file and the calling address of the function calling code in the code file; Generate request information according to the file path and the calling address, and send the request information to the language server; Receiving response information fed back by the language server based on the request information, and obtaining a jump file and a jump address from the response information, wherein the jump file is a code file to which the called function belongs, and the jump address is an address of a function definition code segment corresponding to the called function in the jump file; In combination with the jump address, the jump file is parsed, and the parsed result is stored in a preset storage space.
6. The method according to any one of claims 1 to 3, characterized in that When the child nodes of the function definition node include a function body node and the child nodes of the function body node include a control flow node and / or a loop node, the code corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node is parsed to obtain parsing results corresponding to each node, including: Parsing the code corresponding to the control flow node and / or loop node according to the parsing method of the function body node to obtain the parsing result; Determine whether the analysis result contains the API interface parameters; When the parsing result does not contain the API interface parameter, the parsing result is cleared.
7. The method according to claim 1, characterized in that The method further comprises: When it is monitored that the code file has changed, the API interface parameter parsing operation is performed again according to the changed code file.
8. An API interface parameter parsing device, characterized in that: include: The first acquisition module is used to obtain the code file corresponding to the API interface; A conversion module, configured to call a parsing tool to parse the code file to obtain a first abstract syntax tree; A first parsing module is used to traverse the nodes in the first abstract syntax tree, and when traversing to a class definition node and there is a function definition node corresponding to the API interface in the child nodes of the class definition node, parse the codes corresponding to all nodes in the abstract syntax subtree with the function definition node as the root node to obtain parsing results corresponding to each node; The second acquisition module is used to obtain API interface parameters from the parsing result.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method for parsing API interface parameters described in any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method for parsing API interface parameters according to any one of claims 1 to 7.