Code Navigation


I have an annoying problem.
Whenever I Ctrl + click on a class name it takes me to the .class file instead of the source file

How can I change it?


1 comment

That's an indication that IDEA does not have the source for that particular class "registered". The solution will vary depending on where that class exists.

1. If the class is from a library, go to the library definition and attach the source directory or jar for the library -- One gotcha to watch out for here is the danger of the dependency existing in two library definitions, only one of which has the sources attached. For example, say I have a library definition for Spring; and as part of that definition I have some needed Spring transitive dependencies defined. Say one of those transitive dependencies is the commons-io API. But I do not have the commons-io source attached to the Spring library definition. And lastly, the Spring definition is using the commons-io jar from the spring\lib directory. Now I also have have a commons-io library defined, which has the sources attached. That commons-io library is using the jars in a commons-io directory. If in my dependencies list for my module I have the spring library dependency listed before the commons-io dependency, IDEA will find the commons-io classes, say FileUtils for example, in the spring library first. There's no sources for it there, so when I click it with a ctrlclick, I get the .class file and not the source. If however, I have the commons-io library listed first, it is found there, which has the sources attached, and when I ctrl click it, I go to the sources. An easy way to determine where IDEA is finding a particular class is to put your cursor over it and click ctrl+Q to pull up the Quick Javadoc. In the upper right corner of that javadoc popup window will be the name the library where IDEA is finding the file (this is the name you gave it in the library definition). So in the above example, if I saw my spring library definition's name and not my commons-io definition name, I would know that IDEA is picking it up from the Spring definition and would then know why I could not view the source.

2. If the class if from the JDK, make sure that under the JDK definition, on the sourcepath tab, the file is attached (that zip file is in the root directory of the JDK)

3. If the class is one of your own, make sure you have all your source directories identified for each module on the Sources tab, and inner module dependencies correctly identified on the dependency tab.

BTW, once you have the sources figured out, be sure to check out the "Quick Definition Lookup" via CtrlShiftI which will show you the source for the symbol at the cursor point in a popup window. This is sometimes much more convenient that going to the source in a new editor tab.


Please sign in to leave a comment.