为什么ICleanUp运行的选项与ICleanUpOptionsInitializer初始化的选项不同?

时间:2015-07-21 09:04:18

标签: java eclipse eclipse-jdt

我的清理有以下插件配置:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
  <extension point="org.eclipse.jdt.ui.cleanUps">
      <cleanUp id="eclipsecs.saveaction" class="eclipsecs.saveaction.CheckFileCleanUp">
      </cleanUp>
      <cleanUpOptionsInitializer
            class="eclipsecs.saveaction.CheckFileCleanUpOptionsInitializer" cleanUpKind="saveAction">
      </cleanUpOptionsInitializer>
  </extension>
</plugin>

ICleanUp和ICleanUpOptionsInitializer的实现只记录它们传递的ICleanupOptions实例。

public class CheckFileCleanUp implements ICleanUp {

    public static final String CLEANUP_ID = "com.mgmtp.eclipsecs.saveaction";

    private final ILog log;

    public CheckFileCleanUp() {
        this .log = Activator.getDefault().getLog();
    }

    @Override
    public void setOptions(final CleanUpOptions cleanUpOptions) {
        log.log(new Status(IStatus.INFO, Activator.PLUGIN_ID, "setting options " + cleanUpOptions));
    }

    // other code ommited
}


public class CheckFileCleanUpOptionsInitializer implements ICleanUpOptionsInitializer  {

    private ILog log;

    public CheckFileCleanUpOptionsInitializer() {
        this.log = Activator.getDefault().getLog();
    }

    @Override
    public void setDefaultOptions(final CleanUpOptions options) {
        log.log(new  Status(IStatus.INFO, Activator.PLUGIN_ID, "initializing default options for checking file with checkstyle with options instance " + options));
        options.setOption(CheckFileCleanUp.CLEANUP_ID, CleanUpOptions.TRUE);
    }
}

在eclipse日志中,我看到为每个清理选项编写的不同哈希码,它们被传递给清理本身和选项初始化器。

即使选项初始化程序确实启用了CheckFile清理,传递给CheckFile清理的选项也表示它未启用。

默认情况下,如果使用选项初始值设定项启用CleanUp,我需要做什么?

我用日食火星测试了这个。

1 个答案:

答案 0 :(得分:0)

正在使用的清理选项从文件.settings/org.eclipse.jdt.ui.prefs加载。对于已存在的项目,该文件没有存储新创建的清理的值。因此,默认情况下禁用清理。

可以在文件中修改该选项,也可以the tutorial中指定的方式提供ICleanUpConfigurationUI