更新时间:2022-12-28 12:55:59
Preferences -> Java -> Editors -> Save Actions -> 勾选 Perform the保存时的选定操作 -> 检查 附加操作 -> 单击 Configure.. -> 转到 代码组织 选项卡 -> 检查删除尾随空格 -> 选择所有行.
Preferences -> Java -> Editors -> Save Actions -> check Perform the selected actions on save -> check Additional actions -> click Configure.. -> go to Code organizing tab -> check Remove trailing whitespace -> select All lines.
Preferences -> Java -> Editor -> Save Actions -> 勾选Perform保存时选择的动作 -> 勾选Format source code -> 选择Format编辑行.
Preferences -> Java -> Editor -> Save Actions -> check "Perform the selected actions on save -> check Format source code -> select Format edited lines.
请注意,不必单击在格式化程序页面上配置格式化程序设置 - 所有代码样式都会自动包括删除尾随空格.至少我在 Formatter 配置中找不到这个设置,而且它对于内置的 Java 约定、Eclipse、Eclipse 2.1 样式以及 GoogleStyle.
Note it is not necessary to click Configure the formatter settings on the Formatter page - all the code styles automatically include removing trailing whitespace. At least I couldn't find a setting for this in Formatter configuration, and it worked out of the box for built-in Java Conventions, Eclipse, Eclipse 2.1 styles, as well as GoogleStyle.
使用此设置时,您显然还需要关闭问题第 1 部分的解决方案.
When using this set-up, you obviously need to also turn off the solution to part 1 of the question.
Eclipse version checked: 4.5.2, 4.11