You will have the opportunity to read the source code written by other members of the project, read the source code to investigate the framework you are using, and read the source code in various situations.
In such a case, there are several approaches to use the IDE's functions, improve the sense of hitting, train the keyboard operation to be faster, and so on.
In this article, we will focus on using the functions of the IDE from among those approaches, and introduce the functions that are useful for reading the source code when the language is Java and the IDE uses Eclipse.
For the sake of clarity, some screenshots are posted, but the source code shown there is from a database access library called Doma. (Completely my hobby)
Also, since my body is cursed by Eclipse, I will write about the features of Eclipse, but I think there are similar ones in other IDEs. So, if you are using another IDE, I would be grateful if you could write an article saying "This IDE should do this".
First of all, from the basics. If you are reading the source code and want to jump from the code calling the method to the point where the method is defined, place the cursor on the code calling the method and press
If you read a specific process from the beginning, you will often jump to the method definition, so I think it is a function that you often use.
If you jump to the method definition with
F3, there may be no implementation in the interface beyond that.
In that case, place the cursor on the method call code and press
Command + T. Then, a list of classes that implement the method will be displayed, so this is it! Select the class you think you want and jump to the method definition.
Command + T
In this example, only one class is shown, but in some cases many implementation classes are shown. Among them, this is it! Choosing a class that seems like it requires knowledge and sense, but training them is another story, so I will omit it.
You may want to know where a method is called from, such as when investigating the impact of specification changes. In that case, hover over the method definition you want to investigate and press
Control + alt + H. Then you will see a list of places that are calling that method.
If you press the triangle mark to the left of each item in the list of call points, the call points of that method will be displayed in a list.
That way you can go back and forth in the calling hierarchy.
Place the cursor on the class and press
Command + Shift + G. Then, the places that refer to that class will be listed.
If the class is referenced as a field, the field name will be displayed, and if it is referenced as an argument / local variable, the constructor name or method name will be displayed in the search results.
This feature was needed when I read a framework of a reasonable size, such as Spring Boot.
Other than these, I often use type search and resource search.
Command + Shift + T(searches into JAR)
Command + Shift + R(doesn't search inside the JAR)
In my case, I think these are used more often when writing the source code than when reading the source code.
Other than Eclipse, there are other tools that can help you read the source code. Here, I will only give a brief introduction as a bonus.
I often use
git grep and
git grep often uses the
-i option and the
--name-only option together.
Large projects, such as the Spring Framework, are often
git grep to import into Eclipse for search.
unite.vim is a Vim plugin that allows you to search various things such as files and buffers as data sources. It's extremely convenient, but I'm having a little trouble because it doesn't work on my company's PC. I have to do something ...
By the way, unite.vim is in maintenance mode, and the successor is denite.nvim. I have to change ...
I introduced the functions that are useful for reading the source code using Java and Eclipse as the subject, but how was it? As mentioned earlier, I think that other IDEs have similar functions (or more convenient functions), so please check the manual of your IDE or ask the experts around you.
This time I wrote the features of Eclipse specifically, but I hope I can announce at another time the mindset of reading the source code and other approaches that can be taken to read the source code quickly. I am.
Then everyone, have a good source code reading life!