Eclipse Plugin: ICleanUp.createFix not called

90 views Asked by At

Hi I'm working on an Eclipse plugin to add a custom Save Action. I've followd this tutorial: Contributing a clean up and a save action using the clean up extension point

Sadly on save my code in ICleanUp.createFix is not called.

I can see my plugin in the preferences (Java->Editor->Save Actions) in "Additional actions" so it appears to be enabled. screenshot

While debugging I get calls to ICleanUp.getStepDescriptions() and ICleanUp.setOptions(CleanUpOptions arg0) while editing my plugin options but as mentioned, no call to ICleanUp.createFix upon saving.

plugin.xml

<extension
     point="org.eclipse.jdt.ui.cleanUps">
     <cleanUp
        id="injection.cleanup"
        class="injection.cleanup.InjectionCleanupSaveAction">
  </cleanUp>
        <cleanUpOptionsInitializer
        class="injection.cleanup.OptionsInitializer"
        cleanUpKind="saveAction">
  </cleanUpOptionsInitializer>
  <cleanUpConfigurationUI
        class="injection.cleanup.ConfigUI"
        name="Injection Cleanup"
        cleanUpKind="saveAction">
  </cleanUpConfigurationUI>

InjectionCleanupSaveAction

public class InjectionCleanupSaveAction implements ICleanUp {

private static final String KEY = "injection.cleanup";
CleanUpOptions options;

@Override
public ICleanUpFix createFix(CleanUpContext arg0) throws CoreException {

    if (options.isEnabled(KEY)) {
        //return stuff..            
    }
}

@Override
public CleanUpRequirements getRequirements() {
    return new CleanUpRequirements(false, false, true, Collections.<String, String> emptyMap());
}

@Override
public String[] getStepDescriptions() {
    if (options.isEnabled(KEY)) {
        return new String[] { "Remove unused KiInjections" };
    }
    return new String[0];
}

@Override
public void setOptions(CleanUpOptions arg0) {
    options = arg0;
}

@Override
public RefactoringStatus checkPostConditions(IProgressMonitor arg0) throws CoreException {
    return new RefactoringStatus();
}

@Override
public RefactoringStatus checkPreConditions(IJavaProject arg0, ICompilationUnit[] arg1, IProgressMonitor arg2)
        throws CoreException {

    return new RefactoringStatus();
}

}

1

There are 1 answers

0
Rudi Wagner On

Apparently Java-Save Actions are only executed on Java-files within a Java-project. I was testing on a random java-File without a project therefore none of the save actions where executed.