Adding Javadoc Links in IntelliJ Idea with Live Templates

In Eclipse there is this wonderful little helper for adding Javadoc links while you’re typing a class name. It looks like this:

auto completion for Javadoc links in Eclipse

It suggests not just to put the classes name there but also use a @link tag so one can navigate the Javadoc sources later on. The finished comment:

auto completion for Javadoc links in Eclipse

Unfortunately this functionality is not available in JetBrains’ IntelliJ Idea. There is (of course) auto completion for classnames in Idea but it simply doesn’t put them in a @link tag. A simple trick saves the day: simply create a live template with context ‘Java comment’ like here:

creating a live template for the javadoc link

EDIT: The screenshot is missing the word ‘link’. The complete template should be: ‘{@link $LINK$} ‘.

Don’t forget to click on ‘Edit variables’ and fill in ‘complete()’ as Expression. This activates the auto completion for classnames.

Now everytime a @link in the Javadocs is needed we invoke the Live Templates with Alt + J and enter a classname. The @link tag will be build around that name. It’s not as simple as with Eclipse, but works pretty well.

live template for the javadoc @link

live template for the javadoc @link tag