Foreword: Recently, I happened to have nothing to do, so I went back to the past knowledge. When I came to the Servlet part, I just remembered the inheritance relationship and interface implementation from top to bottom.
The diagram of IDEA is used this time, and the result is clear at a glance.
1. Look at inheritance chains in graphical form
In the TAB of the class you want to view, right click and choose Diagrams. There are show and Show… Popup, except that the former is newly created in the TAB, and the latter is displayed in the form of floating window:
In fact, you can also right click on the class you want to view from the project tree on the left, again, Diagrams, and it looks the same:
You should then get an inheritance diagram like the following, using a custom Servlet as an example:
The obvious:
- The solid blue arrows indicate inheritance relationships
- The dotted green arrow indicates the interface implementation relationship
2, optimize the inheritance chain graph, like I think
2.1 Remove unconcerned classes
For example, Object and Serializable in the figure above, we only care about the most important inheritance relationships for servlets.
Easy, delete it. Select the class you want to delete and use the Delete key on your keyboard.
After cleaning the relationships of other classes, the graph is as follows:
2.2 Display class details
Some people say, ah, how is this enough, that inherited those methods I also want to see ah? Simple, IDEA all meet you. Follow wechat official number: Internet architect, reply: 2T in the background, you can get the tutorials I organized, they are dry goods.
Right-click on the page and select Show Categories to expand properties, methods, constructors, and so on in the class as needed. Of course, the second method can also be used directly from the toolbar above:
Then you get:
What, in the method you want to filter, like, you want to see protected and above? Simply right-click and choose Change Visibility Level to adjust as required.
What, you think it’s too small for you to see? IDEA can also satisfy you, press Alt on the keyboard, there is a magnifying glass, surprise, surprise? IDEA shortcut keys ultimate complete, recommended collection.
2.3 Add other classes to the relationship
When we need to see if other classes have an inheritance relationship with the current class, we can choose to add it to the current inheritance relationship graph. Follow wechat official account: Internet Architect, reply: 2T in the background, you can get 2T full set of architect series tutorials, are dry goods.
Right click on the page, select Add Class to Diagram, and type the Class you want to Add:
For example, we add a Student class, as shown in the figure below. Well, there are no arrows, so it doesn’t seem to have any indescribable relationships with the current classes and interfaces:
2.4 View specific codes
If you want to view the specific source code of a class, such as a method, of course, it is not possible to show you on the graph, otherwise the screen would not be exploded? Intellij IDEA read the source code of 4 stunts, this article must see.
But you can use graphics, or with the structure of IDEA to easily and quickly enter the source code of a class to view.
Double-click a class to navigate through the list of methods 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 this class will be displayed on the left as shown in the figure above. Click the method, and the page content will jump to the part of this method.
3, the last
Using the IDEA features mentioned above, learning and viewing class relationships, understanding such things as mainstream framework source code, can be said to be very comfortable. This article is over here, like friends can click attention + forwarding collection yo, will continue to update the dry goods