I'm creating an after save action for the java editor following this guide. So far my code for the cleanup looks like this:
public class CheckFileCleanUp implements ICleanUp {
@Override
public ICleanUpFix createFix(final CleanUpContext cleanUpContext) throws CoreException {
final ICompilationUnit compilationUnit = cleanUpContext.getCompilationUnit();
IPath path = compilationUnit.getPath();
IFile[] files = compilationUnit.getJavaProject().getProject().getWorkspace().getRoot().findFilesForLocation(path);
RunCheckstyleOnFilesJob job = new RunCheckstyleOnFilesJob(Arrays.asList(files));
job.setRule(job);
job.schedule();
return new ICleanUpFix() {
@Override
public CompilationUnitChange createChange(final IProgressMonitor progressMonitor) throws CoreException {
return new CompilationUnitChange("", compilationUnit);
}
};
}
@Override
public CleanUpRequirements getRequirements() {
return new CleanUpRequirements(false, false, true, Collections.<String, String> emptyMap());
}
@Override
public String[] getStepDescriptions() {
return new String[] { "Run checkstyle" };
}
@Override
public void setOptions(final CleanUpOptions cleanUpOptions) {
}
public RefactoringStatus checkPreConditions(final IJavaProject paramIJavaProject, final ICompilationUnit[] paramArrayOfICompilationUnit,
final IProgressMonitor paramIProgressMonitor) throws CoreException {
return new RefactoringStatus();
}
public RefactoringStatus checkPostConditions(final IProgressMonitor paramIProgressMonitor) throws CoreException {
return new RefactoringStatus();
}
}
and the extension config is:
<extension point="org.eclipse.jdt.ui.cleanUps">
<cleanUp id="eclipsecs.saveaction" class="eclipsecs.saveaction.CheckFileCleanUp" />
</extension>
The cleanup doesn't need any other options so I skipped those sections of the guide.
However the first time I simply edit a java source file and save it, I get the following message in the error log:
The clean up 'eclipsecs.saveaction' contributed by 'eclipse-cs-save-action' has been disabled because it does not honor any options.
How can I make my clean up honor the required options and what options are those required options?
You get this message because you are not honoring the enabled option for your cleanup.
You must remember the CleanUpOptions
given to you by setOption
and test isEnabled("your id")
in getStepDescriptions
, createFix
, ... and not do anything if your cleanup is not enabled.