Search code examples
javaeclipseeclipse-jdt

Why does an ICleanUp run with different options than what was initialized by the ICleanUpOptionsInitializer?


I have the following plugin configuration for my cleanup:

<?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>

The implementations of ICleanUp and ICleanUpOptionsInitializer just log the instance of ICleanupOptions that they get passed.

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);
    }
}

In the eclipse log I see different hash codes written for every cleanup option that is passed to the cleanup itself and the options initializer.

Even though the options initializer does enable the CheckFile cleanup, the options passed to the CheckFile cleanup say that it isn't enabled.

What do I need to do in order to enable the CleanUp by default with the options initializer?

I tested this with eclipse mars.


Solution

  • The clean up options that are in use are loaded from the file .settings/org.eclipse.jdt.ui.prefs. For already existing projects that file doesn't have a value for the newly created clean up stored. Therefore the cleanup is disabled by default.

    The option can be edited in the file or a ICleanUpConfigurationUI can be contributed as specified in the tutorial.