Class inheritance relationship analysis method and device, computer device and storage medium

By using a hash table to store class names and class information in an Android project, and traversing and comparing the subclasses of Activity and BaseActivity, the problem of quickly and stably determining the Activity code that needs to be modified is solved, thus simplifying the code modification process.

CN115421699BActive Publication Date: 2026-05-01SHENZHEN YISHIHUOLALA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN YISHIHUOLALA TECH CO LTD
Filing Date
2022-09-02
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

In Android projects containing a large number of classes, quickly and reliably identifying the Activity code that needs to be modified becomes a pressing issue.

Method used

By storing the class name and class information of each class in the target project into a hash table in the form of key-value pairs, the hash table is traversed to obtain all subclasses of the Activity class and the BaseActivity class, and all subclasses belonging only to the Activity class are determined by comparison.

Benefits of technology

It enables the rapid and stable identification of all subclasses belonging solely to the Activity class from the target project, simplifying the code modification process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115421699B_ABST
    Figure CN115421699B_ABST
Patent Text Reader

Abstract

The application relates to a class inheritance relationship analysis method and device, computer equipment and a storage medium. The method comprises the following steps: storing the class name and class information of each class in a target project in a hash table in the form of a key-value pair; wherein the key and value in the key-value pair are the class name and class information of each class; traversing the hash table to obtain all subclasses of a first target class and all subclasses of a second target class; and determining all subclasses belonging only to the first target class according to all subclasses of the first target class and all subclasses of the second target class. The embodiment of the application can quickly and stably determine all subclasses belonging only to the first target class from the target project.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computers, and in particular to a method, apparatus, computer device, and storage medium for analyzing class inheritance relationships. Background Technology

[0002] Activity is an Android system class, generally translated as "activity". Each page in an Android application (Application, App) is an activity.

[0003] In some development activities, in order to simplify the complexity of subclass code, enforce the behavior of subclasses, and / or implement page nesting as a UI (User Interface) framework, a BaseActivity is created, which is set as an abstract class or base class, and all Activities in the project need to inherit from BaseActivity.

[0004] In some existing projects, which contain a large number of classes, finding the Activity code that needs to be modified quickly and reliably becomes an urgent problem to solve. Summary of the Invention

[0005] To address the aforementioned deficiencies or disadvantages, this application provides a method, apparatus, computer device, and storage medium for class inheritance relationship analysis. The embodiments of this application can quickly and reliably identify all subclasses belonging solely to the first target class from a target project.

[0006] This application provides a method for analyzing class inheritance relationships according to a first aspect. In one embodiment, the method includes:

[0007] Store the class name and class information of each class in the target project in a hash table as key-value pairs; where the key and value in the key-value pair are the class name and class information of each class, respectively.

[0008] Traverse the hash table to obtain all subclasses of the first target class and all subclasses of the second target class;

[0009] Based on all subclasses of the first target class and all subclasses of the second target class, determine all subclasses that belong only to the first target class.

[0010] In one embodiment, the first target class refers to the Activity class, and the second target class refers to the BaseActivity class.

[0011] In one embodiment, the hash table is traversed to obtain all subclasses of the first target class and all subclasses of the second target class, including:

[0012] Traverse the hash table based on the class name of the first target class to obtain all subclasses of the first target class;

[0013] Traverse the hash table based on the class name of the second target class to obtain all subclasses of the second target class.

[0014] In one embodiment, the hash table is traversed based on the class name of the first target class to obtain all subclasses of the first target class, including:

[0015] Iterate through the class name of each class in the hash table;

[0016] For each class name encountered during iteration, perform the following operations:

[0017] Set the class name of the class encountered in this iteration as the first target class name;

[0018] Query the corresponding class information in the hash table based on the first target class name;

[0019] If no corresponding class information is found, it is determined that the class traversed this time is not a subclass of the first target class;

[0020] When the parent class name in the queried class information is the same as the class name of the first target class, the class traversed this time is determined to be a subclass of the first target class, and the queried class information is added to the first set.

[0021] When the parent class name in the retrieved class information is different from the class name of the first target class, set the parent class name as the first target class name and return the steps of querying the corresponding class information in the hash table based on the first target class name.

[0022] In one embodiment, the hash table is traversed based on the class name of the second target class to obtain all subclasses of the second target class, including:

[0023] Iterate through the class name of each class in the hash table;

[0024] For each class name encountered during iteration, perform the following operations:

[0025] Set the class name of the class encountered in this iteration as the second target class name;

[0026] Query the corresponding class information in the hash table based on the second target class name;

[0027] If no corresponding class information is found, it is determined that the class traversed in this iteration is not a subclass of the second target class;

[0028] When the parent class name in the queried class information is the same as the class name of the second target class, the class traversed this time is determined to be a subclass of the second target class, and the queried class information is added to the second set.

[0029] When the parent class name in the retrieved class information is different from the class name of the second target class, set the parent class name as the second target class name and return the step of querying the corresponding class information in the hash table based on the second target class name.

[0030] In one embodiment, determining all subclasses belonging exclusively to the first target class based on all subclasses of the first target class and all subclasses of the second target class includes:

[0031] Compare the class information in the first set with the class information in the second set;

[0032] Based on the comparison results, determine all subclasses that belong only to the first target class.

[0033] In one embodiment, the class name and class information of each class in the target project are stored in a hash table as key-value pairs, including:

[0034] Use a bytecode manipulation framework to scan each class file in the target project;

[0035] The class name and class information of each scanned class are stored in a hash table as key-value pairs.

[0036] This application provides a class inheritance relationship analysis apparatus according to a second aspect. In one embodiment, the apparatus includes:

[0037] Store the class name and class information of each class in the target project in a hash table as key-value pairs; where the key and value in the key-value pair are the class name and class information of each class, respectively.

[0038] Traverse the hash table to obtain all subclasses of the first target class and all subclasses of the second target class;

[0039] Based on all subclasses of the first target class and all subclasses of the second target class, determine all subclasses that belong only to the first target class.

[0040] This application provides a computer device according to a third aspect, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of any of the above-described methods.

[0041] According to a fourth aspect, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the above-described methods.

[0042] In this embodiment, the class name and class information of each class in the target project are first stored in a hash table as key-value pairs. Then, the hash table is traversed to obtain all subclasses of the first target class and all subclasses of the second target class. Finally, based on all subclasses of the first and second target classes, all subclasses in the target project that belong exclusively to the first target class can be determined. This embodiment can quickly and reliably determine all subclasses belonging exclusively to the first target class from the target project, i.e., the relevant code that needs to be modified. Attached Figure Description

[0043] Figure 1 This is a flowchart illustrating a class inheritance relationship analysis method in one embodiment;

[0044] Figure 2 This is a flowchart illustrating the process of collecting class names and class information for all classes in one embodiment.

[0045] Figure 3 A flowchart for determining all subclasses of a first target class or a second target class in one embodiment;

[0046] Figure 4 This is a flowchart in one embodiment for determining whether the class traversed this time is a subclass of the first target class or the second target class;

[0047] Figure 5 This is a structural block diagram of a class inheritance relationship analysis device in one embodiment;

[0048] Figure 6 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0049] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0050] This application provides a method for analyzing class inheritance relationships to determine all subclasses belonging solely to a first target class. In one embodiment, the method includes: Figure 1 The steps shown are described below, and the method will be explained in detail below.

[0051] S110: Store the class name and class information of each class in the target project into a hash table as key-value pairs. The key and value in the above key-value pairs are the class name and class information of each class, respectively.

[0052] The target project can be any project used for developing Android applications that requires analysis of class inheritance relationships. When a class has a corresponding parent class, the class information of that class will include the name of the corresponding parent class.

[0053] In one implementation, the step of storing the class name and class information of each class in the target project into a hash table as key-value pairs may include: using a bytecode manipulation framework to scan each class file in the target project; and storing the class name and class information of each scanned class into a hash table as key-value pairs.

[0054] The hash table mentioned above can be called a Map dictionary or a class information dictionary. The bytecode manipulation framework mentioned above refers to the Asm framework. This implementation uses the Asm framework to manipulate and modify class files in the target project. Specifically, the system-provided Gradle plugin (a build tool used by the Android system to build applications) and Transform API (an Android system-provided tool that allows third-party plugins to modify class file information during packaging) can be used to scan all .class files (or bytecode files) in the target project, and then the Asm framework is used to analyze the bytecode in each .class file.

[0055] For example, the process of using the ASM framework to store the class names and class information of various types in the target project into a Map dictionary can be found in [link to documentation]. Figure 2 As shown.

[0056] S120: Traverse the hash table to obtain all subclasses of the first target class and all subclasses of the second target class.

[0057] In one implementation, the first target class refers to the Activity class, and the second target class refers to the BaseActivity class. It should be noted that the class inheritance relationship analysis method provided in this embodiment can also be used to determine the inheritance relationships of other classes, in order to identify the code in those other classes that needs modification.

[0058] In one implementation, the step of traversing the hash table to obtain all subclasses of the first target class and all subclasses of the second target class may include the following steps S121 and S122:

[0059] Step S121: Traverse the hash table according to the class name of the first target class to obtain all subclasses of the first target class.

[0060] Step S121 may include:

[0061] (A1) Iterate through the class name of each class in the hash table;

[0062] (A2) For each class name encountered during iteration, perform the following operations:

[0063] (A2.1) Set the class name of the class encountered in this traversal as the first target class name;

[0064] (A2.2) Query the corresponding class information in the hash table based on the first target class name;

[0065] (A2.31) When no corresponding class information is found, determine that the class traversed this time is not a subclass of the first target class;

[0066] (A2.32) When the parent class name contained in the queried class information is the same as the class name of the first target class, determine that the class traversed this time is a subclass of the first target class, and add the queried class information to the first set;

[0067] (A2.33) When the parent class name contained in the queried class information is different from the class name of the first target class, set the parent class name as the first target class name and return the step of querying the corresponding class information in the hash table based on the first target class name.

[0068] Step S122: Traverse the hash table according to the class name of the second target class to obtain all subclasses of the second target class.

[0069] Step S122 may include:

[0070] (B1) Iterate through the class name of each class in the hash table;

[0071] (B2) For each class name encountered during iteration, perform the following operations:

[0072] (B2.1) Set the class name of the class encountered in this iteration as the first target class name;

[0073] (B2.2) Query the corresponding class information in the hash table based on the first target class name;

[0074] (B2.31) When no corresponding class information is found, determine that the class traversed this time is not a subclass of the first target class;

[0075] (B2.32) When the parent class name contained in the queried class information is the same as the class name of the first target class, determine that the class traversed this time is a subclass of the first target class, and add the queried class information to the first set;

[0076] (B2.33) When the parent class name contained in the queried class information is different from the class name of the first target class, set the parent class name as the first target class name and return the step of querying the corresponding class information in the hash table based on the first target class name.

[0077] For example, the process of traversing the hash table to find all subclasses of the first target class or the second target class in the target project during step S121 or step S122 can be found in [reference needed]. Figure 3 ,exist Figure 3 In this process, the hash table (i.e., the class information dictionary in the diagram) is traversed. Upon encountering a class, it is determined whether class A (which could be the first or second target class) is a parent class of that class. If yes, it is added to a set (correspondingly, it could be the first or second set). If no, the process moves to the next class and repeats until all classes have been traversed. Further details regarding the process of determining whether class A is a parent class upon encountering a class can be found in [link to documentation]. Figure 4 ,exist Figure 4 In this scenario, assuming the class name encountered each time is "Class B Name", it is assigned to the variable "name". Then, using "name" as the key (referring to the key in a key-value pair), the corresponding value in the hash table is queried, which is the class information. If no corresponding class information is found, it means that the class encountered this time is not a subclass of class A. If corresponding class information is found, and the parent class name in the class information is exactly the same as the name of class A, it means that the class encountered this time is a subclass of class A. If corresponding class information is found, and the parent class name in the class information is different from the name of class A, then the parent class name is assigned to "name", and the above operation is performed again until the result is obtained (i.e., the class encountered this time is a subclass of class A, or the class encountered this time is not a subclass of class A).

[0078] S130: Determine all subclasses belonging only to the first target class based on all subclasses of the first target class and all subclasses of the second target class.

[0079] In this embodiment, when it is necessary to determine all subclasses belonging exclusively to the first target class based on all subclasses of the first target class and all subclasses of the second target class, the class information in the first set can be compared with the class information in the second set first. Then, based on the comparison result, all subclasses belonging exclusively to the first target class can be determined. For example, for each piece of class information in the first set, it is determined whether the piece of class information belongs to both the first and second sets simultaneously. If the piece of class information belongs to both sets, it is removed from the first set. This process is repeated for each piece of class information in the first set, and the remaining class information represents all subclasses belonging exclusively to the first target class. This embodiment can quickly and reliably determine all subclasses belonging exclusively to the first target class from the target project.

[0080] Figure 1 This is a flowchart illustrating a class inheritance relationship analysis method in one embodiment. It should be understood that, although... Figure 1 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 1At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0081] Based on the same inventive concept, this application also provides a class inheritance relationship analysis apparatus. In one embodiment, such as Figure 5 As shown, this inheritance relationship analysis device includes the following modules:

[0082] The information storage module 110 is used to store the class name and class information of each class in the target project into a hash table in the form of key-value pairs; wherein the key and value in the key-value pair are the class name and class information of each class, respectively.

[0083] Traversal module 120 is used to traverse the hash table to obtain all subclasses of the first target class and all subclasses of the second target class;

[0084] The determination module 130 is used to determine all subclasses belonging only to the first target class based on all subclasses of the first target class and all subclasses of the second target class.

[0085] In one embodiment, the first target class refers to the Activity class, and the second target class refers to the BaseActivity class.

[0086] In one embodiment, traversing module 120 includes:

[0087] The first traversal submodule is used to traverse the hash table based on the class name of the first target class to obtain all subclasses of the first target class;

[0088] The second traversal submodule is used to traverse the hash table based on the class name of the second target class to obtain all subclasses of the second target class.

[0089] In one embodiment, the first traversal submodule is specifically used for:

[0090] Iterate through the class name of each class in the hash table;

[0091] For each class name encountered during iteration, perform the following operations:

[0092] Set the class name of the class encountered in this iteration as the first target class name;

[0093] Query the corresponding class information in the hash table based on the first target class name;

[0094] If no corresponding class information is found, it is determined that the class traversed this time is not a subclass of the first target class;

[0095] When the parent class name in the queried class information is the same as the class name of the first target class, the class traversed this time is determined to be a subclass of the first target class, and the queried class information is added to the first set.

[0096] When the parent class name in the retrieved class information is different from the class name of the first target class, set the parent class name as the first target class name and return the steps of querying the corresponding class information in the hash table based on the first target class name.

[0097] In one embodiment, the second traversal submodule is specifically used for:

[0098] Iterate through the class name of each class in the hash table;

[0099] For each class name encountered during iteration, perform the following operations:

[0100] Set the class name of the class encountered in this iteration as the second target class name;

[0101] Query the corresponding class information in the hash table based on the second target class name;

[0102] If no corresponding class information is found, it is determined that the class traversed in this iteration is not a subclass of the second target class;

[0103] When the parent class name in the queried class information is the same as the class name of the second target class, the class traversed this time is determined to be a subclass of the second target class, and the queried class information is added to the second set.

[0104] When the parent class name in the retrieved class information is different from the class name of the second target class, set the parent class name as the second target class name and return the step of querying the corresponding class information in the hash table based on the second target class name.

[0105] In one embodiment, the determining module 130 is specifically used for:

[0106] Compare the class information in the first set with the class information in the second set;

[0107] Based on the comparison results, determine all subclasses that belong only to the first target class.

[0108] In one embodiment, the information storage module 110 is specifically used for:

[0109] Use a bytecode manipulation framework to scan each class file in the target project;

[0110] The class name and class information of each scanned class are stored in a hash table as key-value pairs.

[0111] For specific limitations regarding the class inheritance relationship analysis device, please refer to the limitations on the class inheritance relationship analysis method above, which will not be repeated here. Each module in the aforementioned class inheritance relationship analysis device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0112] In one embodiment, a computer device is provided, the internal structure of which can be shown as follows: Figure 6 As shown. The computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system, computer programs, and the database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage medium. The database stores data such as the class name and class information of each class in the target project; the specific stored data can also be found in the limitations of the above method embodiments. The network interface is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements a class inheritance relationship analysis method.

[0113] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0114] This embodiment also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the method provided in any of the above method embodiments.

[0115] Specifically, in one implementation, the processor performs the following steps when executing a computer program:

[0116] Store the class name and class information of each class in the target project in a hash table as key-value pairs; where the key and value in the key-value pair are the class name and class information of each class, respectively; traverse the hash table to obtain all subclasses of the first target class and all subclasses of the second target class; determine all subclasses that belong only to the first target class based on all subclasses of the first target class and all subclasses of the second target class.

[0117] In one implementation, the first target class refers to the Activity class, and the second target class refers to the BaseActivity class.

[0118] In one implementation, the processor executes a computer program to traverse the hash table to obtain all subclasses of the first target class and all subclasses of the second target class, and also performs the following steps:

[0119] Traverse the hash table based on the class name of the first target class to obtain all subclasses of the first target class; traverse the hash table based on the class name of the second target class to obtain all subclasses of the second target class.

[0120] In one implementation, when the processor executes a computer program to traverse a hash table based on the class name of the first target class to obtain all subclasses of the first target class, it also performs the following steps:

[0121] Iterate through the class name of each class in the hash table. For each class name encountered during iteration, perform the following operations: Set the class name encountered this time as the first target class name; Query the corresponding class information in the hash table based on the first target class name; If no corresponding class information is found, determine that the class encountered this time is not a subclass of the first target class; If the parent class name in the queried class information is the same as the class name of the first target class, determine that the class encountered this time is a subclass of the first target class, and add the queried class information to the first set; If the parent class name in the queried class information is different from the class name of the first target class, set the parent class name as the first target class name, and return to the step of querying the corresponding class information in the hash table based on the first target class name.

[0122] In one implementation, when the processor executes a computer program to traverse a hash table based on the class name of the second target class to obtain all subclasses of the second target class, it also performs the following steps:

[0123] Iterate through the class name of each class in the hash table. For each class name encountered during iteration, perform the following operations: set the class name encountered this time as the second target class name; query the corresponding class information in the hash table based on the second target class name; if no corresponding class information is found, determine that the class encountered this time is not a subclass of the second target class; if the parent class name in the queried class information is the same as the class name of the second target class, determine that the class encountered this time is a subclass of the second target class, and add the queried class information to the second set; if the parent class name in the queried class information is different from the class name of the second target class, set the parent class name as the second target class name, and return to the step of querying the corresponding class information in the hash table based on the second target class name.

[0124] In one implementation, when the processor executes a computer program to determine all subclasses belonging only to the first target class based on all subclasses of the first target class and all subclasses of the second target class, it further performs the following steps:

[0125] Compare the class information in the first set with the class information in the second set; based on the comparison result, determine all subclasses that belong only to the first target class.

[0126] In one implementation, when the processor executes a computer program to store the class name and class information of each class in the target project into a hash table as key-value pairs, it also performs the following steps:

[0127] The bytecode manipulation framework scans each class file in the target project; the class name and class information of each scanned class are stored in a hash table as key-value pairs.

[0128] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the method provided in any of the above method embodiments.

[0129] Specifically, in one implementation, the computer program performs the following steps when executed by the processor:

[0130] Store the class name and class information of each class in the target project in a hash table as key-value pairs; where the key and value in the key-value pair are the class name and class information of each class, respectively; traverse the hash table to obtain all subclasses of the first target class and all subclasses of the second target class; determine all subclasses that belong only to the first target class based on all subclasses of the first target class and all subclasses of the second target class.

[0131] In one implementation, the first target class refers to the Activity class, and the second target class refers to the BaseActivity class.

[0132] In one implementation, the computer program is executed by a processor to traverse the hash table to obtain all subclasses of a first target class and all subclasses of a second target class, and also performs the following steps:

[0133] Traverse the hash table based on the class name of the first target class to obtain all subclasses of the first target class; traverse the hash table based on the class name of the second target class to obtain all subclasses of the second target class.

[0134] In one implementation, when the computer program is executed by the processor to traverse the hash table based on the class name of the first target class to obtain all subclasses of the first target class, it also performs the following steps:

[0135] Iterate through the class name of each class in the hash table. For each class name encountered during iteration, perform the following operations: Set the class name encountered this time as the first target class name; Query the corresponding class information in the hash table based on the first target class name; If no corresponding class information is found, determine that the class encountered this time is not a subclass of the first target class; If the parent class name in the queried class information is the same as the class name of the first target class, determine that the class encountered this time is a subclass of the first target class, and add the queried class information to the first set; If the parent class name in the queried class information is different from the class name of the first target class, set the parent class name as the first target class name, and return to the step of querying the corresponding class information in the hash table based on the first target class name.

[0136] In one implementation, when the computer program is executed by the processor to traverse the hash table based on the class name of the second target class to obtain all subclasses of the second target class, the following steps are also performed:

[0137] Iterate through the class name of each class in the hash table. For each class name encountered during iteration, perform the following operations: set the class name encountered this time as the second target class name; query the corresponding class information in the hash table based on the second target class name; if no corresponding class information is found, determine that the class encountered this time is not a subclass of the second target class; if the parent class name in the queried class information is the same as the class name of the second target class, determine that the class encountered this time is a subclass of the second target class, and add the queried class information to the second set; if the parent class name in the queried class information is different from the class name of the second target class, set the parent class name as the second target class name, and return to the step of querying the corresponding class information in the hash table based on the second target class name.

[0138] In one implementation, when a computer program is executed by a processor to determine, based on all subclasses of a first target class and all subclasses of a second target class, all subclasses of the first target class and all subclasses of the second target class are considered, the following steps are also performed:

[0139] Compare the class information in the first set with the class information in the second set; based on the comparison result, determine all subclasses that belong only to the first target class.

[0140] In one implementation, when a computer program is executed by a processor to store the class name and class information of each class in the target project into a hash table as key-value pairs, the following steps are also performed:

[0141] The bytecode manipulation framework scans each class file in the target project; the class name and class information of each scanned class are stored in a hash table as key-value pairs.

[0142] Those skilled in the art will understand that implementing all or part of the processes in the above method embodiments can be accomplished by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0143] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0144] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A method for analyzing class inheritance relationships, characterized in that, The method is used to determine all subclasses that belong only to a first target class; the method includes: Store the class name and class information of each class in the target project in a hash table as key-value pairs; wherein the key and value in the key-value pair are the class name and class information of each class, respectively. Traverse the hash table to obtain all subclasses of the first target class and all subclasses of the second target class, where the first target class is the Activity class and the second target class is the BaseActivity class. Based on all subclasses of the first target class and all subclasses of the second target class, determine all subclasses that belong only to the first target class; The step of traversing the hash table to obtain all subclasses of the first target class and all subclasses of the second target class includes: The hash table is traversed based on the class name of the first target class to obtain all subclasses of the first target class; The hash table is traversed based on the class name of the second target class to obtain all subclasses of the second target class; The step of traversing the hash table according to the class name of the first target class to obtain all subclasses of the first target class includes: Iterate through the class name of each class in the hash table; For each class name encountered during iteration, perform the following operations: Set the class name of the class encountered in this iteration as the first target class name; Query the corresponding class information in the hash table based on the first target class name; If no corresponding class information is found, it is determined that the class traversed in this iteration is not a subclass of the first target class; When the parent class name in the queried class information is the same as the class name of the first target class, the class traversed this time is determined to be a subclass of the first target class, and the queried class information is added to the first set; When the parent class name in the retrieved class information is different from the class name of the first target class, the parent class name is set as the first target class name, and the step of querying the corresponding class information in the hash table based on the first target class name is returned.

2. The method as described in claim 1, characterized in that, Traverse the hash table based on the class name of the second target class to obtain all subclasses of the second target class, including: Iterate through the class name of each class in the hash table; For each class name encountered during iteration, perform the following operations: Set the class name of the class encountered in this iteration as the second target class name; Query the corresponding class information in the hash table based on the second target class name; If no corresponding class information is found, it is determined that the class traversed in this iteration is not a subclass of the second target class; When the parent class name in the queried class information is the same as the class name of the second target class, the class traversed this time is determined to be a subclass of the second target class, and the queried class information is added to the second set; When the parent class name in the retrieved class information is different from the class name of the second target class, the parent class name is set as the second target class name, and the step of retrieving the corresponding class information in the hash table based on the second target class name is returned.

3. The method as described in claim 2, characterized in that, Based on all subclasses of the first target class and all subclasses of the second target class, determine all subclasses that belong exclusively to the first target class, including: Compare the class information in the first set with the class information in the second set; Based on the comparison results, all subclasses belonging only to the first target class are determined.

4. The method as described in claim 1, characterized in that, Store the class name and class information of each class in the target project in a hash table as key-value pairs, including: Use a bytecode manipulation framework to scan each class file in the target project; The class name and class information of each scanned class are stored in a hash table as key-value pairs.

5. A class inheritance relationship analysis device, characterized in that, The apparatus is used to determine all subclasses that belong only to a first target class; the apparatus includes: Store the class name and class information of each class in the target project in a hash table as key-value pairs; wherein the key and value in the key-value pair are the class name and class information of each class, respectively. Traverse the hash table to obtain all subclasses of the first target class and all subclasses of the second target class, where the first target class is the Activity class and the second target class is the BaseActivity class. Based on all subclasses of the first target class and all subclasses of the second target class, determine all subclasses that belong only to the first target class; The step of traversing the hash table to obtain all subclasses of the first target class and all subclasses of the second target class includes: The hash table is traversed based on the class name of the first target class to obtain all subclasses of the first target class; The hash table is traversed based on the class name of the second target class to obtain all subclasses of the second target class; The step of traversing the hash table according to the class name of the first target class to obtain all subclasses of the first target class includes: Iterate through the class name of each class in the hash table; For each class name encountered during iteration, perform the following operations: Set the class name of the class encountered in this iteration as the first target class name; Query the corresponding class information in the hash table based on the first target class name; If no corresponding class information is found, it is determined that the class traversed in this iteration is not a subclass of the first target class; When the parent class name in the queried class information is the same as the class name of the first target class, the class traversed this time is determined to be a subclass of the first target class, and the queried class information is added to the first set; When the parent class name in the retrieved class information is different from the class name of the first target class, the parent class name is set as the first target class name, and the step of querying the corresponding class information in the hash table based on the first target class name is returned.

6. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 4.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Embedded hash table and operation method, traversal method and device thereof

    CN112948642A

  • Program execution device

    JP2003256209A