Toggle Javadoc block comment in Eclipse

375 views Asked by At

I'm moving my API documentation from a flat text file in Github to Javadoc comments using apidoc.

So, I already have API output examples that I'd like to write in the javadoc syntax. I need to add the little * at the beginning of each line without typing them manually because there are a lot of them. Is it possible to do that in Eclipse ? I can't find it anywhere.

Example :

I want to turn

{
  "firstResult" : 1,
  "limit" : 30,
  "totalCount" : 2,
  "value" : [ 
    {
      "firstname" : "John",
      "name" : "Doe",
    }, 
    {
      "firstname" : "Johnny",
      "name" : "Doe"
    } 
  ]
}

into

/**
 * {
 * "firstResult" : 1,
 * "limit" : 30,
 * "totalCount" : 2,
 * "value" : [ 
 *   {
 *     "firstname" : "John",
 *     "name" : "Doe",
 *   }, 
 *   {
 *     "firstname" : "Johnny",
 *     "name" : "Doe"
 *   } 
 * ]
 * }
 */
1

There are 1 answers

1
Andy Thomas On BEST ANSWER

The leading asterisks are optional, in every version of Java since 1.4.

If you want them for appearance, here's one way. Unfortunately, it requires several steps.

First, paste in your text. For the purposes of this example, let's presume it's just these four lines:

{
  "firstResult" : 1,
  "limit" : 30
}

Now, at the top, add /** <pre>. At the bottom, add </pre> */. The <pre> tags prevents word wrap from destroying your indents and line breaks, both during javadoc creation and Source>Format. (If you're doing this a lot, consider pasting in all the headers first, then all the footers.)

/** <pre>
{
  "firstResult" : 1,
  "limit" : 30
}
</pre> */

Now, format the text with Source>Format or its shortcut Shift-Control-F. (If you don't want to format the whole file, select your comment first.)

/**
 * <pre>
 *  {
 *    "firstResult" : 1,
 *    "limit" : 30
 *  }
 * </pre>
 */