How to use IDEA to view all inheritance relationships of a class

Use IDEA to view all inheritance relationships of a class

Recently I have been studying the inheritance relationship diagram of collections, but the ones I found online were not comprehensive, so I wondered if I could directly look at the inheritance relationship in the jar package. I checked the method online and summarized it as follows:

Tool: idea
Function: diagram

1. View the inheritance chain in graphical form

In the category you want to view, right-click and select Diagrams. There are show Diagrams and show Diagrams Popup. The former is created in the tab page and the latter is displayed in the form of a floating window:
Shortcut keys: Select the class Ctrl+Alt+Shift+U (displayed in a new window), Ctrl+Alt+U (displayed in a pop-up window)
gather
You can also select it from the project directory tree on the left , select the class you want to view, right-click, and select Diagrams, the effect is the same:
Insert image description here
Then you will get the inheritance relationship graph as shown below, taking the custom ArrayList as an example:
Insert image description here
The solid blue arrow refers to the inheritance relationship
The green dotted arrow refers to the interface implementation relationship

2. Optimize the inheritance chain graph

2.1 Remove classes you don’t care about

Some of the obtained inheritance relationship graphs are not what we want to understand, such as RandomAccess and Serializable in the picture above. We only want to care about the important inheritance relationships of ArrayList. What should we do?

Simple, delete it. Click to select the class you want to delete, then right-click and select delete. After cleaning up the relationships between other classes, the graph is as follows:
Insert image description here
Insert image description here

2.2 Display class details

If you want to see the inherited methods, right-click on the page and select show categories. You can expand the attributes, methods, constructors, etc. in the class as needed. Of course, the second method can also use the above toolbar directly:
Insert image description here
Then you will get:
Insert image description here
For example, if you want to see protected permissions and above, Right-click and select Change Visibility Level and adjust it as needed.
Insert image description here

If the graphic is too small or too small, you can right-click to adjust it or use the toolbar above.
Insert image description here

2.3 Add other classes to the relationship

When we also need to check whether other classes have an inheritance relationship with the current class, we can choose to add them to the current inheritance relationship graph.

Right-click on the page, select Add Class to Diagram, and then enter the class you want to add:
Insert image description here
For example, we added a Set class, as shown in the figure below. You can see that the solid arrow points to Collection, and Set inherits Collection:
Insert image description here

2.4 View specific code

If you want to view the specific source code of a certain method in a certain class, you can use graphics or use IDEA's structure to quickly and easily enter the source code of a certain class for viewing.
After double-clicking a class, you can browse the method list under it. For the method you want to view, select it, right-click, and select Jump to Source:
Insert image description here
Insert image description here
After entering a certain class, if you want to quickly view other methods of the class, you can also use the structure function provided by IDEA:
Insert image description here
After selecting structure in the left column, as shown above All methods in this class will be displayed on the left. Click on which method, and the page content will jump to that method part.

Reference article:View the inheritance diagram of a class

Guess you like

Origin blog.csdn.net/qq_42547733/article/details/133809273