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

5 thoughts on “Adding Javadoc Links in IntelliJ Idea with Live Templates

  1. Pingback: Comparison of Eclipse 3.6 and IntelliJ IDEA 10.5: Pros and Cons « The Holy Java

  2. Nice tip. You can also make a live template if you want to @link to a method:

    {@link #$METHOD$}

    For the $METHOD$ variable, pick “methodName()”.

  3. Thanks for the comment! I haven’t thought about methods yet, but this sounds good!

  4. Thanks! This was the last thing I was missing after migrating to IntelliJ from eclipse. The live template mechanism has changed a bit since (I am using Intellij 12), e.g. expanding a live template now simply works with pressing tab by default.

Leave a Reply