I don't understand the source code, I used this function of IDEA to understand it at a glance

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:

Edit switch to center

Add image comments, no more than 140 words (optional)

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:

Edit switch to center

Add image comments, no more than 140 words (optional)

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

Edit switch to center

Add image comments, no more than 140 words (optional)

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:

edit

Add image comments, no more than 140 words (optional)

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:

Edit switch to center

Add image comments, no more than 140 words (optional)

Then you get:

Edit switch to center

Add image comments, no more than 140 words (optional)

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.

Edit switch to center

Add image comments, no more than 140 words (optional)

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?

Edit switch to center

Add image comments, no more than 140 words (optional)

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:

Edit switch to center

Add image comments, no more than 140 words (optional)

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:

Edit switch to center

Add image comments, no more than 140 words (optional)

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:

Edit switch to center

Add image comments, no more than 140 words (optional)

Edit switch to center

Add image comments, no more than 140 words (optional)

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:

Edit switch to center

Add image comments, no more than 140 words (optional)

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.

Author: Official Account_IT Brother Link: https://juejin.cn/post/7029487729943511054 Source: Rare Earth Nuggets The copyright belongs to the author. For commercial reprints, please contact the author for authorization, and for non-commercial reprints, please indicate the source.

Guess you like

Origin blog.csdn.net/wdjnb/article/details/124428396