Eclipse 保存操作与代码清理

cne*_*eff 7 eclipse

当我在 Java->Editor->Save Actions 中打开“保存时执行选择操作”时,有没有办法让 Eclipse 自动使用 Java->Code Style->Clean Up 中的配置设置?必须在两个地方完成所有配置似乎是多余的。

Mar*_*ich 2

这似乎是一个悬而未决的问题:https://bugs.eclipse.org/bugs/show_bug.cgi ?id=178429

可能的解决方法是将清理操作导出为 xml,然后从那里提取属性(通过替换<setting id="为空字符串、 value="by ="/>by 空字符串和cleanupby sp_cleanup):

<setting id="cleanup.use_autoboxing" value="false"/>
<setting id="cleanup.always_use_this_for_non_static_method_access" value="false"/>
<setting id="cleanup.qualify_static_method_accesses_with_declaring_class" value="false"/>
<setting id="cleanup.organize_imports" value="false"/>
<setting id="cleanup.remove_trailing_whitespaces_ignore_empty" value="false"/>
<setting id="cleanup.lazy_logical_operator" value="false"/>
Run Code Online (Sandbox Code Playgroud)

结果如下所示

sp_cleanup.use_autoboxing=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.organize_imports=false
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.lazy_logical_operator=false
Run Code Online (Sandbox Code Playgroud)

然后,您可以在工作区中打开文件.metadata.plugins\org.eclipse.core.runtime.settings\org.eclipse.jdt.ui.prefs并将所有sp_cleanup条目替换为提取的条目。我认为这适用于大多数属性。更改配置文件之前,请对其进行备份。