IDEA to view the inheritance relationship of classes

1. View the inheritance chain of the class

In the tab of the class you want to view, right-click, 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

You can also select the class from the project directory tree on the left, right-click, and also select Diagrams, the effect is the same,

Then you will get the inheritance relationship diagram, here is an example of SpringMVC's DispatcherServlet

  • Solid blue arrows represent inheritance relationships
  • Green dashed arrows represent interface implementation relationships

2. Remove 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:

3. Display class details

For example, if I want to see the methods or properties of a class, simply right-click on the page, select show categories, and expand the properties, methods, constructors, inner classes, etc. in the class as needed. Of course, the second method can also directly use the above toolbar.

You may get the following picture (because there are many methods, so there are only some methods of the class):

In the method, you also want to filter, for example, you want to see protected permissions and above? Simple, right-click to select Change Visibility Level, and adjust as needed

If you think the image font is too small, hold down the Alt key on the keyboard, and a magnifying glass will appear

4. 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.

Add the LoginController class, well, it doesn't seem to have anything to do with it

5. View the specific code

If you want to view the specific source code of a certain class, such as a certain method, after double-clicking a certain 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. Click which method , the page content will jump to the method section.

In short, if you learn this trick, it will be much more convenient to look at the source code in the future.

Guess you like

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