Bug 49412 - [formatting] Offer comment formatting options per comment type
Summary: [formatting] Offer comment formatting options per comment type
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 52115 88570 94024 (view as bug list)
Depends on:
Blocks: 163347
  Show dependency tree
 
Reported: 2003-12-30 00:27 EST by Konstantin Scheglov CLA
Modified: 2007-03-12 06:01 EDT (History)
4 users (show)

See Also:


Attachments
Proposed fix (235.49 KB, patch)
2007-02-01 20:29 EST, Olivier Thomann CLA
no flags Details | Diff
Proposed fix for the JDT/UI side (18.12 KB, patch)
2007-02-01 20:30 EST, Olivier Thomann CLA
no flags Details | Diff
Regression tests updated (8.19 KB, patch)
2007-02-01 20:31 EST, Olivier Thomann CLA
no flags Details | Diff
New patch (242.10 KB, patch)
2007-02-02 09:40 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Scheglov CLA 2003-12-30 00:27:17 EST
Is it possible to avoid formating simple comments, not JavaDoc?
  I often comment big pieces of code using /* */ pair, but when
I format code, it breaks structure of code inside of comments. :-(
  In same time, I would like to have JavaDoc comments formated, because
they start with /**. Is it possible to have additional switch for this?
Or, if it is already exists, please point on it. ;-)
Comment 1 Olivier Thomann CLA 2004-01-02 11:21:09 EST
Move to JDT/UI.
This is related to formatting comments.
Comment 2 Dani Megert CLA 2004-01-05 05:02:48 EST
Note: Comment formatting does not depend on old/new Java code formatter.
Comment 3 Dani Megert CLA 2005-10-10 12:56:09 EDT
Ownership changed.
Comment 4 Olivier Thomann CLA 2007-02-01 20:29:06 EST
Created attachment 58077 [details]
Proposed fix

This fix also cleans up some code in the code formatter.
Comment 5 Olivier Thomann CLA 2007-02-01 20:30:54 EST
Created attachment 58078 [details]
Proposed fix for the JDT/UI side

Benno,

This patch contains all the changes on the UI side. Please review them and tell me if this is fine for you. I reorganize a bit the comment formatting preference page.
If everything is fine, I would release it tomorrow. Then you could work on the Cleanup wizard related issue.
Comment 6 Olivier Thomann CLA 2007-02-01 20:31:54 EST
Created attachment 58079 [details]
Regression tests updated
Comment 7 Benno Baumgartner CLA 2007-02-02 04:46:12 EST
This does not seam to work:
1. Enable formatting all comment styles
2. Uncheck 'Enable Line Comment Formatting'
Is:
!ENTRY org.eclipse.jdt.ui 4 10001 2007-02-02 10:32:24.864
!MESSAGE Internal Error
!STACK 0
org.eclipse.text.edits.MalformedTreeException: End position lies outside document range
	at org.eclipse.text.edits.TextEditProcessor.checkIntegrityDo(TextEditProcessor.java:170)
	at org.eclipse.text.edits.TextEdit.dispatchCheckIntegrity(TextEdit.java:740)
	at org.eclipse.text.edits.TextEditProcessor.performEdits(TextEditProcessor.java:149)
	at org.eclipse.text.edits.TextEdit.apply(TextEdit.java:708)
	at org.eclipse.text.edits.TextEdit.apply(TextEdit.java:732)
	at org.eclipse.jdt.internal.ui.text.comment.CommentFormattingStrategy.format(CommentFormattingStrategy.java:78)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.formatSlave(MultiPassContentFormatter.java:221)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.formatSlaves(MultiPassContentFormatter.java:268)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.format(MultiPassContentFormatter.java:144)
	at org.eclipse.jdt.internal.ui.preferences.formatter.CompilationUnitPreview.doFormatPreview(CompilationUnitPreview.java:60)
	at org.eclipse.jdt.internal.ui.preferences.formatter.JavaPreview.update(JavaPreview.java:164)
	at org.eclipse.jdt.internal.ui.preferences.formatter.CommentsTabPage.doUpdatePreview(CommentsTabPage.java:233)
	at org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialogTabPage$1.update(ModifyDialogTabPage.java:70)
	at java.util.Observable.notifyObservers(Observable.java:142)
	at java.util.Observable.notifyObservers(Observable.java:98)
	at org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialogTabPage$ButtonPreference.checkboxChecked(ModifyDialogTabPage.java:193)
	at org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialogTabPage$2.widgetSelected(ModifyDialogTabPage.java:185)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:215)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3465)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3079)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:820)
	at org.eclipse.jface.window.Window.open(Window.java:796)
	at org.eclipse.jdt.internal.ui.preferences.formatter.ProfileConfigurationBlock$ButtonController.modifyButtonPressed(ProfileConfigurationBlock.java:174)
	at org.eclipse.jdt.internal.ui.preferences.formatter.ProfileConfigurationBlock$ButtonController.widgetSelected(ProfileConfigurationBlock.java:160)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:215)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3465)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3079)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:820)
	at org.eclipse.jface.window.Window.open(Window.java:796)
	at org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:65)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:499)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:545)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:490)
	at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:402)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3465)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3079)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2099)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2063)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:1969)
	at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:456)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:228)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:451)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:101)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:146)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:169)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:476)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:416)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1124)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1099)
Comment 8 Benno Baumgartner CLA 2007-02-02 05:03:28 EST
Also:
1. Enable only line comment formatting
Is:
 Line width group is not enabled.

But it looks like in the preview that the line width setting is has also an effect on the single line formatting? Same for block comment formatting.
The line width setting must either be part of javadoc group if it is only affecting javadoc formatting or be enabled if any comment style is enabled.

Also:
Disable all comment formatting styles does result in painting the javadoc group text gray, but not the 'javadoc and block' and line width. This groups must be disabled as well.

Also:
If possible I would like to have two 'Clear blank lines in comments' check boxes, one for javadoc and one for block comments:

-- Javadoc comment settings -------
[ ] Format header comment
[ ] ...
...
[ ] New line after @param tags
[ ] Remove blank lines

-- Block comment settings ----------
[ ] Remove blank lines

-- Line width ----------------------
....

This would make the ui code easier and IMHO make the ui easier to understand. Plus it would allow to add new block comment settings in the future without problems.
Comment 9 Benno Baumgartner CLA 2007-02-02 05:13:44 EST
Btw, if you want too I can take care of the first two UI issues.
Comment 10 Olivier Thomann CLA 2007-02-02 08:13:24 EST
(In reply to comment #8)
> If possible I would like to have two 'Clear blank lines in comments' check
> boxes, one for javadoc and one for block comments:
This means that we need to split the existing option for clearing blank lines in comment in two different options.
- one for the javadoc comment
- one for the block comment

I'll take care of this. I'll add a new patch for the UI side as well that you could modify.
Comment 11 Olivier Thomann CLA 2007-02-02 09:40:38 EST
Created attachment 58113 [details]
New patch

new patch that also splits the option for clearing blank lines inside comments.
Comment 12 Olivier Thomann CLA 2007-02-02 09:49:26 EST
Released for 3.3M5
Comment 13 Olivier Thomann CLA 2007-02-02 14:34:05 EST
I missed some backward compatibility changes on the core side.
Old preferences also need to be support at the code level in order not to break existing code formatter profile.
This is for users that target directly the code formatter without going through the compatibility layer in the UI.
Comment 14 Eric Jodet CLA 2007-02-06 06:21:17 EST
Verified for 3.3 M5 using build I20070205-0009
Comment 15 Olivier Thomann CLA 2007-02-08 10:41:29 EST
*** Bug 88570 has been marked as a duplicate of this bug. ***
Comment 16 Olivier Thomann CLA 2007-02-13 15:18:02 EST
*** Bug 94024 has been marked as a duplicate of this bug. ***
Comment 17 Dani Megert CLA 2007-03-12 06:01:21 EDT
*** Bug 52115 has been marked as a duplicate of this bug. ***