Eclipse插件:未调用ICleanUp.createFix

时间:2017-01-05 14:55:15

标签: java eclipse eclipse-jdt

您好我正在使用Eclipse插件添加自定义保存操作。我已经按照本教程进行了操作:Contributing a clean up and a save action using the clean up extension point

遗憾的是,在保存时,我的ICleanUp.createFix中的代码未被调用。

我可以在首选项中看到我的插件(Java->编辑器 - >保存操作)"其他操作"所以它似乎已启用。 screenshot

在调试时,我在编辑插件选项时会调用ICleanUp.getStepDescriptions()和ICleanUp.setOptions(CleanUpOptions arg0),但如上所述,在保存时不会调用ICleanUp.createFix。

的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 个答案:

答案 0 :(得分:0)

显然,Java-Save Actions仅在Java项目中的Java文件上执行。我正在测试一个没有项目的随机java文件,因此没有执行任何保存操作。