Interface display method and device, equipment and storage medium
By constructing the abstract syntax tree and call chain of the interface, code combing is simplified, which solves the problems of cumbersome display of call levels and difficulty of multiple interfaces in the existing technology, achieves fast and accurate interface positioning and hierarchical relationship display, and improves code combing. Efficiency and analytical efficiency.
Patent Information
- Application Number
- CN202410699223.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-08-30
AI Technical Summary
In the existing technology, a large number of non-important call chains are displayed at the call level during code sorting, which results in long user screening time and inability to effectively compare similar interfaces. In addition, only one interface method is displayed at a time, which lacks the convenience of multi-interface comparison.
By reading the class file of the preset path, scanning the target class containing the preset annotations, building an abstract syntax tree for each interface, identifying the annotations, constructing the interface address and method, forming a call chain, and constructing a call hierarchy forest based on the call chain. Simplify the tree structure, delete non-default path nodes, add default structure leaf nodes, and display the hierarchical relationship and calling relationship of multiple interfaces.
It can quickly and accurately locate interfaces, improve code sorting efficiency, clearly display interface levels and calling relationships, facilitate comparison of multiple interfaces, discover differences and commonalities of similar interfaces, and reduce unnecessary time overhead.
Smart Images

Figure CN118567757A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer network architecture technology, and in particular to interface display methods, devices, equipment and storage media. Background Art
[0002] In order to optimize the code and improve the performance and response speed of the application, code combing is usually required to optimize the code structure and improve development efficiency and quality.
[0003] At present, code combing mainly adopts the mainstream call hierarchy, that is, based on a certain method, the call chain of all subordinate methods is displayed in a tree structure upward or downward. However, this method only displays the methods of one interface at a time, which is not convenient for comparison of similar interfaces. Summary of the invention
[0004] The present application provides an interface display method, apparatus, device and storage medium, which can facilitate the comparison of multiple interfaces.
[0005] In a first aspect, the present application provides an interface display method, the method comprising:
[0006] Read the class file in the preset path, and scan the target class containing the preset annotation from the class file;
[0007] Get all interfaces of the target class and construct the corresponding abstract syntax tree for each interface in turn;
[0008] Based on the abstract syntax tree corresponding to each interface, identify the annotations of each interface in turn, obtain the interface address and method corresponding to each interface, and build the call chain corresponding to each interface according to the interface address-class-method parameters;
[0009] Based on the call chains of all interfaces, a call hierarchy forest is constructed.
[0010] Its further technical solution is that the method further comprises:
[0011] Traverse the abstract syntax trees of all interfaces and delete the nodes outside the preset path in the abstract syntax trees.
[0012] Its further technical solution is that the method further comprises:
[0013] If the method body leaf node in the abstract syntax tree contains the target method, a leaf node of a preset structure is added to the abstract syntax tree.
[0014] A further technical solution is that the preset structure includes object methods, formal parameters, actual parameters, and request types.
[0015] A further technical solution is that each interface includes multiple methods, and a corresponding abstract syntax tree is constructed for each interface in turn, including:
[0016] Take each method as the root node of the abstract syntax tree;
[0017] The method package path, method name, formal parameters, and method body included in the lexical unit of each method are taken as leaf nodes of the abstract syntax tree.
[0018] Its further technical solution is that the method further comprises:
[0019] If the target class contains a default method annotation, the lexical unit also includes the interface address in the default method annotation.
[0020] A further technical solution is that the preset path is a path within the package.
[0021] In a second aspect, the present application provides an interface display device, the interface display device comprising:
[0022] An acquisition unit is used to read a class file in a preset path and scan a target class containing a preset annotation from the class file;
[0023] The first construction unit is used to obtain all interfaces of the target class and construct a corresponding abstract syntax tree for each interface in turn;
[0024] The identification unit is used to identify the annotations of each interface in turn based on the abstract syntax tree corresponding to each interface, obtain the interface address and method corresponding to each interface, and construct the call chain corresponding to each interface according to the interface address-class-method parameters;
[0025] The second construction unit is used to construct a call hierarchy forest based on the call chains of all interfaces.
[0026] In a third aspect, the present application provides a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the steps of any of the above methods when executing the computer program.
[0027] In a fourth aspect, the present application provides a computer-readable storage medium, characterized in that the computer-readable storage medium stores program data, and when the program data is executed by a processor, it is used to implement the steps of any of the above methods.
[0028] The beneficial effects of the present application are as follows: Different from the prior art, the present application can quickly and accurately locate the required interface by scanning the target class containing preset annotations, avoiding the tedious process of searching one by one in a large amount of code, and improving the efficiency of code combing; secondly, by constructing a corresponding abstract syntax tree for each interface, the hierarchical relationship and calling relationship of the interface can be clearly displayed, so as to more intuitively understand the dependency relationship and calling process between interfaces, facilitate comparison of multiple interfaces, and then discover the differences and commonalities between similar interfaces. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:
[0030] Figure 1 It is a flowchart of the first embodiment of the interface display method provided by the present application;
[0031] Figure 2 It is a flowchart of the second embodiment of the interface display method provided by the present application;
[0032] Figure 3 It is a flowchart of the third embodiment of the interface display method provided by the present application;
[0033] Figure 4 It is a flowchart of the fourth embodiment of the interface display method provided by the present application;
[0034] Figure 5 It is a flowchart of the fifth embodiment of the interface display method provided by the present application;
[0035] Figure 6 This is an interface diagram of the prior art;
[0036] Figure 7 An interface display diagram of an embodiment provided by the present application;
[0037] Figure 8 It is a structural schematic diagram of an embodiment of a computer-readable storage medium provided by the present application. DETAILED DESCRIPTION
[0038] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It will be understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for ease of description, only some but not all structures related to the present application are shown in the drawings. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0039] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0040] In order to optimize the code and improve the performance and response speed of the application, code combing is usually required to optimize the code structure and improve development efficiency and quality.
[0041] The current code combing mainly adopts the mainstream call hierarchy, that is, based on a certain method, the call chain of all subordinate methods is displayed in a tree structure upward or downward.
[0042] However, when combing the backend code of a project, people usually start from the top-level interface and go down layer by layer to check which data is queried in the process and which third-party interfaces are called, without paying attention to other specific processing logic. Therefore, the call hierarchy will display a large number of non-important call chains, causing users to spend time filtering them during use, and only displaying the methods of one interface at a time, which is not convenient for comparison of similar interfaces.
[0043] Therefore, in order to solve the technical problems in the prior art that a large number of non-important call chains are displayed due to the call hierarchy, which causes users to spend time filtering them during use, and only one interface method is displayed each time, which is not convenient for comparing similar interfaces, the present application provides an interface display method. Please refer to the following embodiments for details.
[0044] See also Figure 1 , Figure 1 This is a flow chart of the first embodiment of the interface display method provided by this application. The method includes:
[0045] Step 110: Read the class file in the preset path, and scan the target class containing the preset annotation from the class file.
[0046] The preset path may be a path in a package or a path specified in advance, such as a path of a folder or a specific file path. The purpose of reading the class file is to subsequently analyze the target class in the class file and construct an abstract syntax tree.
[0047] Among them, the preset annotation can be a specific mark, tag or keyword, which is used to identify the class that needs to construct an abstract syntax tree. Exemplarily, the preset annotation can be the @RestController annotation. @RestController is an annotation of Spring MVC, which is used to mark the class as a REST controller. This class will process all HTTP requests and return RESTful responses. The @RestController annotation is equivalent to combining the functions of @Controller and @ResponseBody. When the @RestController annotation is used on a class, Spring can write the return values of all methods in this class directly into the HTTP response body instead of the view. If the preset annotation is the @RestController annotation, the target class can be a controller class.
[0048] In some embodiments, scanning target classes may be implemented through regular expression matching, parser parsing, etc. The specific implementation method may be selected according to actual needs and development environment.
[0049] Step 120: Obtain all interfaces of the target class, and construct a corresponding abstract syntax tree for each interface in turn.
[0050] After determining the target classes, you need to obtain all interfaces of these target classes.
[0051] After obtaining all interfaces of the target class, the corresponding abstract syntax tree can be constructed for each interface in turn. The abstract syntax tree is a tree representation of the abstract syntax structure of the source code, and each node on the tree represents a structure in the source code. The construction of the abstract syntax tree can be achieved by recursively traversing all interfaces of the target class and building the corresponding tree structure. In the process of constructing the abstract syntax tree, the nodes of the tree can be added, deleted, modified, etc. according to actual needs to adapt to different project requirements and development environments.
[0052] Step 130: Based on the abstract syntax tree corresponding to each interface, identify the annotations of each interface in turn, obtain the interface address and method corresponding to each interface, and construct the call chain corresponding to each interface according to the interface address-class-method parameters.
[0053] Among them, the abstract syntax tree can include the interface address, path, method name, formal parameters, method body, etc. in the preset method annotation. Therefore, after the interface annotation is identified, the interface address and method corresponding to the interface can be obtained from the abstract syntax tree, and then the call chain corresponding to each interface can be constructed according to the interface address-class-method parameters.
[0054] Step 140: Construct a call hierarchy forest based on the call chains of all interfaces.
[0055] Among them, each root node in the call chain can be composed of method name + parameter identifier, and the leaf node can add the called party ur l + parameter according to the type.
[0056] This embodiment can quickly and accurately locate the required interface by scanning the target class containing preset annotations, avoiding the tedious process of searching one by one in a large amount of code, and improving the efficiency of code combing; secondly, by constructing a corresponding abstract syntax tree for each interface, the hierarchical relationship and calling relationship of the interface can be clearly displayed, so as to more intuitively understand the dependency relationship and calling process between interfaces, facilitate comparison of multiple interfaces, and then discover the differences and commonalities between similar interfaces.
[0057] In addition, since the abstract syntax tree of the present application is constructed based on the interfaces of the target classes after the target classes are determined, the call chain constructed based on the abstract syntax tree can not only accurately reflect the code structure, but also quickly lock the core business logic through annotation information, making the display of the call chain more focused, thereby improving analysis efficiency and reducing unnecessary time expenditure, and further improving the current mainstream call hierarchy, which is based on a method to display the call chain of all subordinate methods in a tree structure upward or downward, and requires time-consuming and labor-intensive screening from a large number of non-important call chains displayed.
[0058] In some embodiments, each interface includes multiple methods, see Figure 2 , Figure 2 This is a flow chart of the second embodiment of the interface display method provided by this application. The method includes:
[0059] Step 210: Read the class file in the preset path.
[0060] Step 220: Scan the class file for a target class containing a preset annotation.
[0061] Step 230: Get all interfaces of the target class.
[0062] Among them, step 210, step 220 and step 230 have the same or similar technical solutions as the above embodiment, and are not described in detail here.
[0063] Step 240: Take each method as the root node of the abstract syntax tree.
[0064] Step 250: The method package path, method name, formal parameters, and method body included in the lexical unit of each method are used as leaf nodes of the abstract syntax tree.
[0065] In some embodiments, if the target class includes a preset method annotation, the lexical unit also includes the interface address in the preset method annotation.
[0066] The preset method annotation can be @XXMapping annotation, for example, @XXMapping annotation can be @RequestMapping annotation and @GetMapping annotation. @RequestMapping annotation is an annotation used to define URL mapping and can be used on methods. When @RequestMapping annotation is used on a method, it specifies a more specific URL path that the method handles.
[0067] That is, if a method in the target class contains the @XXMapping annotation, the attributes in the @XXMapping annotation, such as the interface path, can be additionally recorded in the lexical unit of the method.
[0068] This embodiment can quickly and accurately locate the required interface by scanning the target class containing preset annotations, avoiding the tedious process of searching one by one in a large amount of code, and improving the efficiency of code combing; secondly, by constructing a corresponding abstract syntax tree for each interface and taking each method in each interface as the root node of the abstract syntax tree, the hierarchical relationship and calling relationship of the interface can be clearly displayed, so as to more intuitively understand the dependency relationship and calling process between interfaces, facilitate comparison of multiple similar interfaces, and then discover the differences and commonalities between similar interfaces.
[0069] In addition, this embodiment additionally records the interface address in the preset method annotation in the lexical unit of the target class containing the preset method annotation. When there is a change or problem with the interface, the properties of the @XXMapping annotation on the method can be quickly viewed to understand the specific path to which the method is mapped and to make corresponding modifications. In addition, the configuration of new functions can be dynamically added during operation or development without modifying the source code or recompiling, thereby speeding up the iteration of functions.
[0070] See also Figure 3 , Figure 3 : is a flowchart of the third embodiment of the interface display method provided by this application. The method includes:
[0071] Step 310: Read the class file in the preset path.
[0072] Step 320: Scan the class file for a target class containing a preset annotation.
[0073] Step 330: Get all interfaces of the target class.
[0074] Step 340: construct a corresponding abstract syntax tree for each interface in turn.
[0075] Step 350: traverse the abstract syntax trees of all interfaces and delete nodes outside the preset path in the abstract syntax trees.
[0076] The preset path may be a path within the package or another path specified in advance.
[0077] Exemplarily, each node of the abstract syntax tree may be traversed, and the type and attribute of the node may be checked to determine whether it belongs to a preset path.
[0078] For nodes that do not belong to the preset path, starting from the root node, recursively delete the root node and its related leaf nodes.
[0079] After deleting the nodes outside the preset path in the abstract syntax tree, the corresponding abstract syntax tree structure is updated.
[0080] Among them, step 310, step 320, step 330 and step 340 have the same or similar technical solutions as the above embodiment, and are not described in detail here.
[0081] This embodiment can quickly and accurately locate the required interface by scanning the target class containing preset annotations, avoiding the tedious process of searching one by one in a large amount of code, and improving the efficiency of code combing; secondly, by constructing a corresponding abstract syntax tree for each interface and taking each method in each interface as the root node of the abstract syntax tree, the hierarchical relationship and calling relationship of the interface can be clearly displayed, so as to more intuitively understand the dependency relationship and calling process between interfaces, facilitate comparison of multiple similar interfaces, and then discover the differences and commonalities between similar interfaces.
[0082] And by deleting nodes outside the preset path, the structure of the abstract syntax tree can be simplified, avoiding the display of a large number of non-important nodes, reducing the screening workload, and improving processing efficiency.
[0083] See also Figure 4 , Figure 4 : is a flowchart of the fourth embodiment of the interface display method provided by the present application. The method includes:
[0084] Step 410: Read the class file in the preset path.
[0085] Step 420: Scan the class file for a target class containing a preset annotation.
[0086] Step 430: Get all interfaces of the target class.
[0087] Step 440: construct a corresponding abstract syntax tree for each interface in turn.
[0088] Step 450: If the method body leaf node in the abstract syntax tree includes the target method, a leaf node of a preset structure is added to the abstract syntax tree.
[0089] The target method may be fl uentHC.call() or other construction methods of http request.
[0090] If the actual project uses the fl uent-hc method to build HTTP requests, the code is unified as fl uentHC.call(). Assuming that only the use of the fl uentHC.call() method is an HTTP request, the target method is fl luentHC.call().
[0091] In some embodiments, the preset structure includes object methods, formal parameters, actual parameters, and request types.
[0092] The object method is the ur l() method, and the request type is the http request type, including post or get.
[0093] Among them, step 410, step 420, step 430 and step 440 have the same or similar technical solutions as the above-mentioned embodiment, and are not described in detail here.
[0094] This embodiment can quickly and accurately locate the required interface by scanning the target class containing preset annotations, avoiding the tedious process of searching one by one in a large amount of code, and improving the efficiency of code combing; secondly, by constructing a corresponding abstract syntax tree for each interface and taking each method in each interface as the root node of the abstract syntax tree, the hierarchical relationship and calling relationship of the interface can be clearly displayed, so as to more intuitively understand the dependency relationship and calling process between interfaces, facilitate comparison of multiple similar interfaces, and then discover the differences and commonalities between similar interfaces.
[0095] Based on the above embodiments and Figure 5 , Figure 5 This is a flowchart of the fifth embodiment of the interface display method provided by this application. Figure 5 As shown, the interface display method provided by this application mainly includes the following steps:
[0096] S1: Read the class file in the preset path.
[0097] The preset path may be a path in a custom-configured package or a pre-specified path, such as a folder path or a specific file path. The purpose of reading the class file is to subsequently analyze the target class in the class file and construct an abstract syntax tree.
[0098] S2: Scan classes annotated with @RestController.
[0099] Among them, the @RestController annotation is a preset annotation, and the class containing the @RestController annotation is the target class.
[0100] S3: Determine whether there is a next interface, if so, execute S4, otherwise execute S6.
[0101] Among them, after scanning the class annotated with @RestController, all interfaces of the class annotated with @RestController are obtained.
[0102] S4: Construct an abstract syntax tree with the current method as the root node.
[0103] That is, each method is taken as the root node of the abstract syntax tree and the corresponding abstract syntax tree is constructed for each interface in sequence.
[0104] The method package path, method name, formal parameters, and method body included in the lexical unit of each method may also be used as leaf nodes of the abstract syntax tree.
[0105] For classes containing the @XXMapping annotation, you can additionally record the attributes in the @XXMapping annotation (i.e., the interface path).
[0106] S5: Traversal pruning.
[0107] The abstract syntax tree with the current method as the root node may be traversed, and nodes outside a preset path on the abstract syntax tree may be deleted.
[0108] The preset path may be a path within the package or another path specified in advance.
[0109] Exemplarily, all nodes of the abstract syntax tree may be traversed, and the types and attributes of the nodes may be checked to determine whether they belong to a preset path.
[0110] For nodes that do not belong to the preset path, starting from the root node, recursively delete the root node and its related leaf nodes.
[0111] After the abstract syntax tree corresponding to the current method is pruned, return to S3 and continue to determine whether there is a next interface. If so, execute S4, otherwise execute S6.
[0112] Until the abstract syntax trees of all interfaces are traversed, the nodes outside the preset path on the abstract syntax tree are deleted. If the method body leaf node in the abstract syntax tree contains the target method, a leaf node of the preset structure is added to the abstract syntax tree.
[0113] In some embodiments, if fl uent-hc is used in actual projects to construct http requests, the code is unified as fl uentHC.ca ll(). It is assumed that only the requests using the fl uentHC.ca ll() method are http requests. Then, when traversing and pruning, if the method body contains fl uentHC.ca ll(), a leaf node with a node structure including {ur l() method parameters, actual parameters, http request type - post or get, etc.} can be added to the abstract syntax tree.
[0114] S6: Output the tree structure.
[0115] That is, after all interfaces have constructed abstract syntax trees, the output tree structure is the call hierarchy forest.
[0116] See also Figure 6 and Figure 7 , Figure 6 This is an interface diagram of the prior art. Figure 7 This is an interface display diagram of an embodiment provided in the present application.
[0117] in, Figure 6 The gray nodes in are useless nodes, and the white nodes are useful nodes. Figure 6 As shown, the interface display diagram of the prior art only displays the call chain of the method of one interface at a time, and the call chain contains many useless nodes.
[0118] Looking at the interface display diagram of this application, Figure 7 As shown, / xxx / preview and / xxx / start are two root nodes respectively. The first root node / xxx / preview can represent the method of the first interface, and the second root node / xxx / start can represent the method of the second interface. The number of root nodes can be set accordingly according to actual conditions, and this application does not limit it here.
[0119] That is, the present application can use multiple methods as root nodes to construct a corresponding abstract syntax tree for each interface, which can clearly display the hierarchical relationship and calling relationship of the interface, so as to more intuitively understand the dependency relationship and calling process between interfaces, facilitate comparison of multiple interfaces, and then discover the differences and commonalities between similar interfaces.
[0120] Corresponding to the interface display method of the above embodiment, the present application also provides an interface display device, which includes an acquisition unit, a first construction unit, an identification unit and a second construction unit.
[0121] Among them, the acquisition unit is used to read the class file of the preset path, and scan the target class containing the preset annotation from the class file; the first construction unit is used to obtain all interfaces of the target class, and construct the corresponding abstract syntax tree for each interface in turn; the identification unit is used to identify the annotation of each interface in turn based on the abstract syntax tree corresponding to each interface, obtain the interface address and method corresponding to each interface, and construct the call chain corresponding to each interface according to the interface address-class-method parameters; the second construction unit is used to construct a call hierarchy forest based on the call chains of all interfaces.
[0122] It can be understood that the above-mentioned units are also used to implement the technical solution of any embodiment in the present application.
[0123] The present application also provides a computer device, the computer device comprising a memory and a processor, wherein the memory stores a computer program; and the processor is used to implement the following method steps when executing the computer program:
[0124] Read the class file in the preset path, and scan the target class containing the preset annotation from the class file;
[0125] Get all interfaces of the target class and construct the corresponding abstract syntax tree for each interface in turn;
[0126] Based on the abstract syntax tree corresponding to each interface, identify the annotations of each interface in turn, obtain the interface address and method corresponding to each interface, and build the call chain corresponding to each interface according to the interface address-class-method parameters;
[0127] Based on the call chains of all interfaces, a call hierarchy forest is constructed.
[0128] It can be understood that the processor is also used to execute the technical solution of any embodiment in the present application.
[0129] See also Figure 8 , Figure 8 The structure of an embodiment of a computer-readable storage medium provided by the present application is shown in FIG. 7 . The computer-readable storage medium 70 is used to store a computer program 71. When the computer program 71 is executed by a processor, it is used to implement the following method steps:
[0130] Read the class file in the preset path, and scan the target class containing the preset annotation from the class file;
[0131] Get all interfaces of the target class and construct the corresponding abstract syntax tree for each interface in turn;
[0132] Based on the abstract syntax tree corresponding to each interface, identify the annotations of each interface in turn, obtain the interface address and method corresponding to each interface, and build the call chain corresponding to each interface according to the interface address-class-method parameters;
[0133] Based on the call chains of all interfaces, a call hierarchy forest is constructed.
[0134] It can be understood that when the computer program 71 is executed by the processor, it is also used to implement the technical solution of any embodiment of the present application.
[0135] In the several embodiments provided in this application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only illustrative, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as two units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0136] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on two network units. Some or all of the units may be selected according to actual needs to achieve the purpose of this embodiment.
[0137] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0138] If the integrated units in the above other embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-On lyMemory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0139] The above are only implementation methods of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. An interface display method, characterized in that: The method comprises: Reading a class file in a preset path, and scanning the class file for a target class containing a preset annotation; Obtain all interfaces of the target class, and construct a corresponding abstract syntax tree for each interface in turn; Based on the abstract syntax tree corresponding to each interface, identify the annotations of each interface in turn, obtain the interface address and method corresponding to each interface, and build the call chain corresponding to each interface according to the interface address-class-method parameters; Based on the call chains of all interfaces, a call hierarchy forest is constructed.
2. The interface display method according to claim 1, characterized in that: The method further comprises: The abstract syntax trees of all interfaces are traversed, and nodes outside a preset path in the abstract syntax trees are deleted.
3. The interface display method according to claim 2, characterized in that: The method further comprises: If the method body leaf node in the abstract syntax tree includes the target method, a leaf node of a preset structure is added to the abstract syntax tree.
4. The interface display method according to claim 3, characterized in that: The preset structure includes object method, formal parameter, actual parameter and request type.
5. The interface display method according to claim 1, characterized in that: Each interface includes multiple methods, and the corresponding abstract syntax tree is constructed for each interface in turn, including: Taking each method as the root node of the abstract syntax tree; The method package path, method name, formal parameters, and method body included in the lexical unit of each method are used as leaf nodes of the abstract syntax tree.
6. The interface display method according to claim 5, characterized in that: The method further comprises: If the target class includes a preset method annotation, the lexical unit also includes the interface address in the preset method annotation.
7. The interface display method according to claim 2, characterized in that: The preset path is a path within the package.
8. An interface display device, characterized in that: The interface display device comprises: An acquisition unit is used to read a class file in a preset path and scan a target class containing a preset annotation from the class file; The first construction unit is used to obtain all interfaces of the target class and construct a corresponding abstract syntax tree for each interface in turn; The identification unit is used to identify the annotations of each interface in turn based on the abstract syntax tree corresponding to each interface, obtain the interface address and method corresponding to each interface, and construct the call chain corresponding to each interface according to the interface address-class-method parameters; The second construction unit is used to construct a call hierarchy forest based on the call chains of all interfaces.
9. A computer device, characterized in that: It includes a memory and a processor, the memory stores a computer program, and the processor implements the interface display method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program data, and when the program data is executed by a processor, it is used to implement the interface display method as described in any one of claims 1 to 7.
