Eclipse: How to have the code formatter insert tabs after javadoc tags

10,352

Solution 1

Sure, in eclipse, go to Windows, preferences, Java>Code Style>Formatter, and click on edit. Then look for the comments you want to modify and add a tab.

That said, are you sure you want to do this? Please consider the guidelines, not to mention that now or in the future, some parsers might fail to find your javadoc, and some programmers might be very annoyed with you ;)

Edit: Oh :/ I'm afraid you're right; I was thinking of Java>CodeStyle>CodeTemplates, which will put whatever you want when a method/class is created. This, however, will not be respected by the autoformatter :(

Solution 2

Add <br>

   
    /**
    * @param from
    *            a point belonging to the map
    * @param to
    *            a point belonging to the map
    * @return a list of weighted edges on the shortest path from<br>
    *         {@code from} to {@code to}
    */

Eclipse will include a line-break for each <br>. In Addition, when you generate your JavaDocs with Eclipse it also includes a forced line-break.

Another way to have a fix format is the <pre> </pre> tag.

/**
* Some Comments
* 
* <pre>
* Hello
* World
* </pre>
* 
* @param toTest
* @return ...
*/

One Problem with <pre> is that you have a forced line-break before the opening <pre> and after the closing </pre> tag, wich means it cannot be used with @return, @param,...

Note: <pre> and <br> are only usable with JavaDoc-Comments /**. In a normal block-comment /* these two are ignored by eclipse.

Share:
10,352
Norswap
Author by

Norswap

Updated on June 04, 2022

Comments

  • Norswap
    Norswap almost 2 years

    I'd like to have:

        /**
     * @param from  a point belonging to the map
     * @param to    a point belonging to the map
     * @return      a list of weighted edges on the shortest path from
     *                  {@code from} to {@code to}
     */
    

    But eclipse gives me:

    /**
     * @param from a point belonging to the map
     * @param to a point belonging to the map
     * @return a list of weighted edges on the shortest path from {@code from}
     *         to {@code to}
     */
    

    Is there a way to change this ?

  • Gray
    Gray over 12 years
    +1. Also other developers are going to reformat your code using their standard settings and change the formatting anyway.
  • Norswap
    Norswap over 12 years
    When I click on "Edit" I get to a window with a few window tabs and settings to configure in the form of checkboxes etc... But I can't find the particular setting to change to achieve the intended result. The closest thing is "indent description of \@param tag" but it doesn't seem to work when \@param and its description are on different lines. Neither does it work with other tags. As for the guidelines, I am actually getting my cues form them. If you look them trough you'll see they align what follows their tags.
  • Norswap
    Norswap over 12 years
    I should have mentionned I was using Helios. I will download the latest version and see what's up.
  • Norswap
    Norswap over 12 years
    I haven't got more success with Indigo.
  • Miquel
    Miquel over 12 years
    Oh :/ I'm afraid you're right; I was thinking of Java>CodeStyle>CodeTemplates, which will put whatever you want when a method/class is created. This, however, will not be respected by the autoformatter :(
  • Norswap
    Norswap over 12 years
    Since what I asked doesn't seem to be possible, I will accept this answer.