Eclipse formatter adds space in empty comment lines

久未见 提交于 2019-12-03 06:30:17

问题


The eclipse code formatter adds a trailing space in each empty Javadoc comment line (see screenshot).

The formatter of a colleague is always removing those spaces (and thus producing annoying SVN diffs). He is claiming to use the same formatter settings (XML file). Nevertheless, I tried all the options in the comments tab of the formatter settings page - without success.

Can it be a difference between eclipse versions? (I am using Springsource Tool Suite 2.7.1, which is based on Helios, I believe)


回答1:


Go to Preferences -> Java -> Editor -> Save actions and select Format edited lines.

After applying changes all trailing whitespaces in Javadoc will be removed

Note: "Additional actions"->"Remove trailing white space on all lines" must also be enabled.




回答2:


I found that if you go to Preferences → Java → Editor → Content Assist → Save Actions the following configuration works most of the time:

  • ☑ Perform the selected actions on save
    • ☐ Format source code
  • ☑ Additional actions
    • Remove trailing white spaces on all lines

(That is to say, turn off the Format source code option in Save Actions, but keep the Remove trailing white spaces on all lines in Additional actions on.)

The formatter and save actions duke it out, but save actions seems to win most of the time. The downside of this is that you need to periodically manually format the code.

This is using Eclipse Juno.




回答3:


I've also had this issue and solved it by doing a Search/Replace in Eclipse.

  1. Go to Search > File and be sure Regular Expression is checked.
  2. Enter the string ^([\s]+\*)([\s]+)$ into the Containing text field.
  3. Constrain your search to *.java File name patterns
  4. Press the Replace (not Search) button
  5. Make sure regular expression is checked in the Replace box and use the string $1 as a replacement. Replace at will.

What this is doing is searching for lines that start with blank space characters that contain a * and then further blank space and no other content. It then replaces the whole line with the first matched part of the regex, which is just the initial spacing and * of the comment line.




回答4:


see https://bugs.eclipse.org/bugs/show_bug.cgi?id=360523 for a possible workaround.



来源:https://stackoverflow.com/questions/7008340/eclipse-formatter-adds-space-in-empty-comment-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!