开发者

How do I turn off '*' in multi-line comments in Eclipse?

When coding with Eclipse, how do you turn off the "*" comments that come up when you start a multi-line comment?

Instead of se开发者_C百科eing this,

/**
* Here is a comment
* some more 
*/

Can I get this?

/**
  Here is a comment
  some more
*/

If you are wondering the "/**" is because I use doxygen.


As mentioned in this thread, you can only do that (meaning "disabling the leading asterisks") by going to

 Preferences > Java > Code Style > Code Templates

So for example, if you modify the template for comments of a field into:

/**

 */

It will come that way (without any asterisk in the middle) when you will comment a Field.

However, it does go against the Sun convention for Java comment formatting up to jdk1.3 (update: current oracle link) (as seen also here)...
However, as noted in the comments by Amedee Van Gasse:

Starting with Javadoc 1.4, the leading asterisks are optional.


An even simpler way (if you only need to do that for certain comments of your codes, while keeping the other one with the standard style) is, when a multi-line comment appear like this one:

/**
 *
 */

, you can first remove the one leading asterisk, the enter your comments.
You will see no other leading asterisks are showing up at the beginning of each new line of comments.

 /**

  */

 /**
    My first line of comment
    My second line of comment
    My third line of comment
  */


With eclipse 4.2.1 I used the formatter off / on feature, be sure to not have the formatter on tag on the same line as the comments tag other wise the stars nightmare will be back.

// @formatter:off
/*
Eclipse your * are messing up my comments big time and If I used you
more often I'd put a patch together to add back in the "Add Leading Star" option 
*/
// @formatter:on

The on/off features have to be turned "on" in Eclipse preferences: Java > Code Style > Formatter. Click on "Edit" button, "Off/On Tags", check off "Enable Off/On tags".

From

How to turn off the Eclipse code formatter for certain sections of Java code?

Also. I change the tags to //off //on for ease of use

A similar post is How to disable the automatic asterisk (inserting stars) in Eclipse when adding a multi-line comment?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜