Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggle Javadoc block comment in Eclipse

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"
 *   } 
 * ]
 * }
 */
like image 657
singe3 Avatar asked Apr 09 '26 10:04

singe3


1 Answers

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>
 */
like image 192
Andy Thomas Avatar answered Apr 11 '26 05:04

Andy Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!