This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Attached patch adds an SPI class OnSaveTask which allows modules to register (into MimeLookup) custom tasks that will be performed right before document saving.
Requesting a fasttrack review. It's only one class OnSaveTask with two inner classes Factory and Context. A test is there and two implementations TrailingWhitespaceRemove and ReformatBeforeSave.
Created attachment 123958 [details] Patch containing OnSaveTask
Created attachment 123991 [details] Corrected API patch. A patch corrected to always call the given Runnable in runLocked.
Created attachment 123992 [details] A possible java.hints implementation. An implementation for Java that allows to select Remove Unused Imports or Organize Imports as the post-save actions.
A few comments: JL01: would it be possible not to pass the UndoableEdit to the run method, but rather add something like "addEdit(UndoableEdit edit)" to the Context? JL02: I would suggest to make the OnSaveTask Cancelable. JL03: how about modified lines, could the Context be extended to return them. I know I can get them from the Document, but having them in the Context would be more convenient.
Created attachment 123993 [details] Corrected java.hints implementation.
Created attachment 124003 [details] Patch with JL01, 02, 03 implemented
Honzo, could you check the patch and possibly update java.hints as necessary? Thanks.
Y01 Right now the public javadoc advocates to register the task in layer - I'd rather stress that the proper registration is via @MimeRegistration annotation in include an example of such registration in the javadoc.
Implemented Y01 and integrated: http://hg.netbeans.org/jet-main/rev/4ba15f1c615e Also integrated jlahoda's java related tasks and customizer: http://hg.netbeans.org/jet-main/rev/3ca98f3ad60f
Integrated into 'main-golden', will be available in build *201209180001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/4ba15f1c615e User: Miloslav Metelka <mmetelka@netbeans.org> Log: #217904 - Add OnSaveTask SPI.
Integrated into 'main-golden', will be available in build *201209190001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/3ca98f3ad60f User: Miloslav Metelka <mmetelka@netbeans.org> Log: #217904 - Add OnSaveTask SPI - integrated jlahoda's java OnSave tasks and customizer.
*** Bug 231224 has been marked as a duplicate of this bug. ***