Intellij IDEA necessary skills to see the source code!

Recently, there was nothing to be busy with, so I went back and tinkered with the knowledge points of the past. When I came to the Servlet part, I used to remember the inheritance relationship and interface implementation from top to bottom when I was learning.

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

1. View the inheritance chain in graphical form

In the tab page 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 page, 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 tree on the left, and select Diagrams, the effect is the same:

Then you will get the inheritance relationship graph as shown in the following figure, taking a custom Servlet as an example:

The obvious is:

  • The solid blue arrow refers to the inheritance relationship

  • The green dotted arrow refers to the interface implementation relationship

2. Optimize the inheritance chain graphics, think what I think

2.1 Remove classes that don't care

Some of the inheritance relationship graphics obtained are not what we want to understand. For example, Object and Serializable in the above figure, we only want to care about the important inheritance relationships of Servlet, what should I do?

Simple, delete. Click to select the class you want to delete, and then just use the delete key on the keyboard.

After cleaning the relationship of other classes, the graph is as follows:

2.2 Display class details

Some people say, eh, how is this enough, I also want to see the inherited methods? Simple, IDEA meets you all.

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

Then you will get:

What, you still want to filter in the method, for example, you want to see protected permissions and above? Simple, right-click and 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 there is a magnifying glass. Surprise or surprise? IDEA shortcut keys are extremely large, and it is recommended to collect them.

2.3 Add other categories to the relationship

When we need to check whether other classes and the current class have an inheritance relationship, we can choose to add it to the current inheritance relationship graph. Pay attention to the WeChat public account: Java technology stack, reply in the background: idea, you can get my N idea tutorials, which are all dry goods.

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 below. Well, there is no arrow. It seems that there is 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 class, such as a method, of course, it is impossible to show you on the graphics, otherwise the screen must not be exploded Intellij IDEA 4 stunts to read the source code , this must-see.

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

After double-clicking a class, you can walk in the method list under it. For the method you want to view, right-click after selecting, 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 this class will be displayed on the left side of the figure above. Which method is clicked, the page content will jump to the method section.

3. Finally

It can be said that using the functions of IDEA mentioned above to learn and view class relationships and understand things such as the source code of mainstream frameworks is very comfortable.

Author: Dulk https://www.cnblogs.com/deng-cc/p/6927447.html

I recommend going to my blog to read more:

1. Java JVM, collection, multithreading, new features series tutorials

2. Spring MVC, Spring Boot, Spring Cloud series of tutorials

3. Maven, Git, Eclipse, Intellij IDEA series of tool tutorials

4. The latest interview questions for Java, backend, architecture, Alibaba and other major manufacturers

Life is beautiful, see you tomorrow ~

495 original articles have been published · 1032 thumbs up · 1.46 million views

Guess you like

Origin blog.csdn.net/youanyyou/article/details/105528638