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.

Bug 217904

Summary: Add OnSaveTask SPI
Product: editor Reporter: Miloslav Metelka <mmetelka>
Component: Formatting & IndentationAssignee: apireviews <apireviews>
Status: RESOLVED FIXED    
Severity: normal CC: abien
Priority: P1 Keywords: API, API_REVIEW_FAST
Version: 7.3   
Hardware: PC   
OS: Linux   
Issue Type: TASK Exception Reporter:
Attachments: Patch containing OnSaveTask
Corrected API patch.
A possible java.hints implementation.
Corrected java.hints implementation.
Patch with JL01, 02, 03 implemented

Description Miloslav Metelka 2012-09-05 14:10:55 UTC
Attached patch adds an SPI class OnSaveTask which allows modules to register (into MimeLookup) custom tasks that will be performed right before document saving.
Comment 1 Miloslav Metelka 2012-09-05 14:14:19 UTC
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.
Comment 2 Miloslav Metelka 2012-09-05 14:15:02 UTC
Created attachment 123958 [details]
Patch containing OnSaveTask
Comment 3 Jan Lahoda 2012-09-06 15:48:24 UTC
Created attachment 123991 [details]
Corrected API patch.

A patch corrected to always call the given Runnable in runLocked.
Comment 4 Jan Lahoda 2012-09-06 15:49:19 UTC
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.
Comment 5 Jan Lahoda 2012-09-06 15:56:05 UTC
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.
Comment 6 Jan Lahoda 2012-09-06 15:56:31 UTC
Created attachment 123993 [details]
Corrected java.hints implementation.
Comment 7 Miloslav Metelka 2012-09-06 22:26:03 UTC
Created attachment 124003 [details]
Patch with JL01, 02, 03 implemented
Comment 8 Miloslav Metelka 2012-09-06 22:26:28 UTC
Honzo, could you check the patch and possibly update java.hints as necessary? Thanks.
Comment 9 Jaroslav Tulach 2012-09-07 09:44:51 UTC
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.
Comment 10 Miloslav Metelka 2012-09-17 11:30:35 UTC
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
Comment 11 Quality Engineering 2012-09-18 02:11:17 UTC
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.
Comment 12 Quality Engineering 2012-09-19 03:05:50 UTC
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.
Comment 13 Dusan Balek 2013-06-14 09:42:26 UTC
*** Bug 231224 has been marked as a duplicate of this bug. ***