java中怎么设置注释格式化,使Eclipse的Java代码格式化程序忽略块注释

Is there a way to make Eclipse's built-in Java code formatter ignore comments? Whenever I run it, it turns this:

/*

* PSEUDOCODE

* Read in user's string/paragraph

*

* Three cases are possible

* Case 1: foobar

* do case 1 things

* Case 2: fred hacker

* do case 2 things

* Case 3: cowboyneal

* do case 3 things

*

* In all cases, do some other thing

*/

into this:

/*

* PSEUDOCODE Read in user's string/paragraph

*

* Three cases are possible Case 1: foobar do case 1 things Case 2: fred

* hacker do case 2 things Case 3: cowboyneal do case 3 things

*

* In all cases, do some other thing

*/

I have already played around with the Windows > Preferences > Java > Code Style > Formatter settings but can't find one for keeping comment formatting. I'm using Eclipse 3.4.0.

解决方案

Update 2010, as pointed by the OP and in this answer, the special string // @formatter:off in Eclipse 3.6 is enough.

It was not available at the time of the question.

Original answer: June 2009, Eclipse 3.4/3.5

With the Java Formatter (Windows > Preferences > Java > Code Style > Formatter), you can create a new Formatter profile.

In the Comments tab (in eclipse3.5), you can make sure, in the "Javadoc comment settings", to uncheck "Format HTML tags".

Check also the "Never join lines" in the "General settings" section.

Then your comment should be written as:

/**

* PSEUDOCODE

* Read in user's string/paragraph

*

* Three cases are possible:

*

*

Case 1: foobar

*

do case 1 things

*

Case 2: fred hacker

*

do case 2 things

*

Case 3: cowboyneal

*

do case 3 things

*

* In all cases, do some other thing

*/

Note: I have made a Javadoc comment, and not a simple comment, as I believe a comment with that much text in it may be better placed in front of a method. Plus, Javadoc sections have more formatting parameters to play with.

If it is in front of a method (true Javadoc), the HTML tags

and
will help to present it properly within the Javadoc view.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值