Eclipse 保存操作与代码清理

标签 eclipse

当我在 Java->Editor->Save Actions 中打开“Perform the selection actions on save”时,有没有办法让 Eclipse 自动使用 Java->Code Style->Clean Up 中的配置设置?必须在两个地方进行所有这些配置似乎是多余的。

最佳答案

这接缝是一个悬而未决的问题:https://bugs.eclipse.org/bugs/show_bug.cgi?id=178429
可能的解决方法是将清理操作导出为 xml,然后从中提取属性(通过将 <setting id=" 替换为空字符串,将 value=" 替换为 = ,将 "/> 替换为空字符串和 cleanup来自 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"/>
结果将类似于以下内容
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
在您的工作区中,您可以打开文件 .metadata.plugins\org.eclipse.core.runtime.settings\org.eclipse.jdt.ui.prefs 并替换所有 sp_cleanup 提取的条目。我认为这将适用于大多数属性。在更改配置文件之前备份它。

关于Eclipse 保存操作与代码清理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51824250/

相关文章:

android - 是否可以在我的设备上稳定构建和每晚构建应用程序?

eclipse - 如何在Eclipse中配置EOL

java - 在 Eclipse 中自定义搜索(文件)功能

java - 如何在 Android 中动态创建按钮?

java - 配置 appengine-web.xml

java - 如何根据 Eclipse 中的使用情况对 Java 类的方法/成员进行排序?

java - 用点符号命名的 JPA 实体

java - Maven 多模块 : error assembling WAR: webxml attribute is required

java - 在 Eclipse RCP 应用程序中读取输入

eclipse - 插件中何时需要 Activator 类/"Bundle-Activator",何时不需要?