Use IntelliJ IDEA to view the class inheritance graph

I haven't had much to do recently, so I went back and fiddled with the past knowledge points. When it came to the Servlet part, when I was studying before, I just remembered the inheritance relationship and interface implementation from top to bottom in a mess.

 

This time, I used IDEA's diagram, and the result is clear at a glance, and it is also easy to use for bursting, so I will share it here.

 

1. View the inheritance chain in graphical form

In the tab of the class you want to view, right-click and select Diagrams, there are show and show... Popup, but the former is newly created in the tab, and the latter is displayed in the form of a floating window:

 

In fact, you can also right-click the class you want to view from the project directory tree on the left, and also select Diagrams, the effect is the same:

 

Then you will get the inheritance relationship graph as shown below, taking a custom servlet as an example:

The obvious ones are:

  • Solid blue arrows refer to inheritance relationships
  • The green dashed arrow refers to the interface implementation relationship

 

2. Optimize inheritance chain graphics, think what I think

2.1 Get rid of the classes you don't care about

Some of the obtained inheritance relationship graphs are not what we want to know, such as Object and Serializable in the above figure. We only want to care about the important inheritance relationships of Servlet. What should we do?

 

Simple, delete. Click to select the class you want to delete, and then just use the delete key on the keyboard. After cleaning up the relationships of other classes, the graph is as follows:

 

2.2 Display class details

Some people say, eh, how can this be enough? I also want to see the inherited methods? Simple, IDEA can satisfy you.

 

Right-click on the page, select show categories, and expand the properties, methods, constructors, etc. in the class as needed. Of course, the second method can also directly use the above toolbar:

 

Then you get:

 

 

What, do you still want to filter in the method, for example, you want to see protected permissions and above? Simple, right-click to select Change Visibility Level, and adjust as needed.

 

 

 

What, you think the graphics are too small and you can't see clearly? IDEA can also satisfy you. Press and hold Alt on the keyboard, and a magnifying glass appears. Is it surprising or unexpected?

 

2.3 Adding 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:

 

For example, we added a Student class as shown in the following figure. Well, there is no arrow, it seems that it has no indescribable relationship with the current classes and interfaces:

 

 

2.4 View specific code

If you want to view the specific source code of a certain class, such as a certain method, of course, it is impossible to display it on the graph, otherwise the screen will not be able to explode?

 

But you can use graphics, or cooperate with IDEA's structure to easily and quickly enter the source code of a class for viewing.

 

After double-clicking a class, you can walk in the method list under it. For the method you want to view, right-click and select Jump to Source:

 

After entering a class, if you want to quickly view other methods of the class, you can also use the structure function provided by IDEA:

 

After selecting the structure in the left column, all the methods in the class will be displayed on the left as shown in the figure above. Click which method, and the page content will jump to the method section.

 

3. Finally

Using the IDEA functions mentioned above, learning and viewing class relationships, and understanding things such as mainstream framework source code, can be said to be very comfortable. 

4. Reference link

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325070860&siteId=291194637