Bug 75516 - [formatting] Proposed comments formatting changes
Summary: [formatting] Proposed comments formatting changes
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P5 enhancement with 5 votes (vote)
Target Milestone: 4.8 M6   Edit
Assignee: Mateusz Matela CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 79264 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-10-02 08:55 EDT by Konstantin Scheglov CLA
Modified: 2018-03-07 01:49 EST (History)
6 users (show)

See Also:


Attachments
Patch for JDT Core (5.32 KB, patch)
2004-10-02 08:56 EDT, Konstantin Scheglov CLA
no flags Details | Diff
Patch for JDT UI, formatting (1.55 KB, patch)
2004-10-02 08:57 EDT, Konstantin Scheglov CLA
no flags Details | Diff
Patch for JDT UI, preferences for formatting (4.48 KB, patch)
2004-10-02 08:58 EDT, Konstantin Scheglov CLA
no flags Details | Diff
Patch for JDT UI, preference constants for formatting (1.41 KB, patch)
2004-10-03 09:17 EDT, Konstantin Scheglov CLA
no flags Details | Diff
Patch for JDT Core (4.93 KB, patch)
2004-10-06 22:43 EDT, Konstantin Scheglov CLA
no flags Details | Diff
Patch for JDT UI, formatting (1.09 KB, patch)
2004-10-06 22:44 EDT, Konstantin Scheglov CLA
no flags Details | Diff
Patch for JDT UI, preferences for formatting (2.84 KB, patch)
2004-10-06 22:45 EDT, Konstantin Scheglov 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 2004-10-02 08:55:05 EDT
In Eclipse 3.0 we received very configurable formatter with ability to format
even JavaDoc comments. This is very good, but comments formatting is too
intrusive. It formats all what is comment, breaks current comments format.

  For example, even if we have comments formatting disabled and format file
using Ctrl+Shift+F, following comment:

		/*shell.open();
   		while (!shell.isDisposed()) {
   			if (!display.readAndDispatch())
   				display.sleep();
   		 }*/

  will be converted into:

		/*shell.open();
		 while (!shell.isDisposed()) {
		 if (!display.readAndDispatch())
		 display.sleep();
		 }*/

  This is not what I expect. I comment blocks of code to temporary remove them,
or just comment part of method to rewrite it better, but I still want to look on
old code for references. But if code becomes unindented, it is hard to
understand it. So, I propose to add option "Keep comments indetntation" in
formating profile, page "Indentation".

  Then, if comments formatting is enable, attempt to format simple /* */ comment
gives disaster in result. Here is result for previous sample:
		/*
		 * shell.open(); while (!shell.isDisposed()) { if
		 * (!display.readAndDispatch()) display.sleep(); }
		 */

  Now it is impossible at all to understand this. Moreover, it is hard now to
turn this text back into "live" code. If there were strings, it is possible that
they now broken in random places, so code will not even compile.
  So, I propose to add option "Format only JavaDoc comments" in formating
profile, page "Comments".

  Understand me right, JavaDoc formatting is great, but only when it works on
JavaDoc comments. If it breaks my comments inside of code, I just turn comments
formating at all and can not use JavaDoc formatting.

  I will attach patches for proposed changes.
Comment 1 Konstantin Scheglov CLA 2004-10-02 08:56:29 EDT
Created attachment 14959 [details]
Patch for JDT Core
Comment 2 Konstantin Scheglov CLA 2004-10-02 08:57:25 EDT
Created attachment 14960 [details]
Patch for JDT UI, formatting
Comment 3 Konstantin Scheglov CLA 2004-10-02 08:58:03 EDT
Created attachment 14961 [details]
Patch for JDT UI, preferences for formatting
Comment 4 Konstantin Scheglov CLA 2004-10-03 09:17:49 EDT
Created attachment 14967 [details]
Patch for JDT UI, preference constants for formatting
Comment 5 Dani Megert CLA 2004-10-04 10:56:03 EDT
Having separate options for each comment type is an improvement (see also bug
49412).

Formatting is currently split between JDT UI (comment formatting) and JDT Core
(code formatter). There are plans in 3.1 to push down comment formatting to J
Core. I think it's confusing to have a comment option (Keep comments
indentation) which is not on the Comment tab. What would be the difference
between this option and not formatting the block comment?

Note you can use end of line comments to comment out the code. They are better
preserved
Comment 6 Konstantin Scheglov CLA 2004-10-06 07:05:09 EDT
I know about 49412, this is my request. :-)

End of line comments are not preserved good enough, if I have:

  System.out.println("long string with spaces");

it try to comment and format it, it will be separated on several lines by spaces
in strings. So, after uncommentaing, it will be not compilable.

I specially tried to place "keep indentation" on indentation tab, because they
are related IMHO. But I agree, that if comments formatting is enabled only for
/**, this option is not useful. I was not sure how to access JDT Core option
from JDT UI, but now I this I can use JavaCore.getOption() method for this.

This is good that comments formatting will go to Core, at least rest formatting
in Core is very comfigurable, so there is chance that comments formatting will
too. :-) But for now I would like to have at least option to select, format only
/** or all comments. In JDT UI I will just check same option to decide, keep
indentation or not.

How this sounds for you.?
Comment 7 Dani Megert CLA 2004-10-06 08:27:51 EDT
sounds good
Comment 8 Konstantin Scheglov CLA 2004-10-06 22:43:58 EDT
Created attachment 15031 [details]
Patch for JDT Core
Comment 9 Konstantin Scheglov CLA 2004-10-06 22:44:50 EDT
Created attachment 15032 [details]
Patch for JDT UI, formatting
Comment 10 Konstantin Scheglov CLA 2004-10-06 22:45:27 EDT
Created attachment 15033 [details]
Patch for JDT UI, preferences for formatting
Comment 11 Konstantin Scheglov CLA 2004-10-06 22:46:35 EDT
Done, now it has only one option on Comments tab.
Comment 12 Dani Megert CLA 2004-10-21 12:22:43 EDT
Thanks for the patch and sorry for taking so long, I was quite busy. I did not
yet release the patch for the following reasons:
- the preference preview does not update if the new option is toggled
- the preference constant should be defined in JDT UI's PreferenceConstants like
  all other comment formatter preferences
- a J Core patch should not be needed since fully disabling comment formatting 
  and disabling Javadoc formatting should give same result. If this result is 
  not OK then we should report this in a separate PR against J Core

An additional improvement would be to offer separate preferences for
EndOfLineComment and  TraditionalComment (= block comment) as well.

IMPORTANT: We are currently in the process of moving the formatter down to J
Core. In a first step we moved (or copied) the corresponding types into
org.eclipse.jdt.internal.corext.text.comment inside JDT UI. We don't know the
exact date yet when J Core will adopt it. Making the patch against this is OK
for now.

Note: I will be away next week. If you have a question, simply post it in here,
Christof will take care of it.
Comment 13 Dani Megert CLA 2004-10-21 12:24:10 EDT
Christof, please annotate this PR when you start moving things down to J Core.
Comment 14 Konstantin Scheglov CLA 2004-10-28 05:44:29 EDT
It looks now that this patch is just one option and check in one place, so I
don't think that it is worthy consideration. Sorry that I've used your time. :-(
Comment 15 Christof Marti CLA 2004-10-28 06:35:41 EDT
I still think it would be a worthwhile addition. Please post updated patches if
you can spend the additional time.
Comment 16 Dani Megert CLA 2004-11-01 10:54:31 EST
Konstantin, do you plan on providing the patch?
Comment 17 Konstantin Scheglov CLA 2004-11-02 00:21:47 EST
Sorry, I am very busy now on my main job.
So, I will, but not in next 3-4 weeks, sorry. :-(
Comment 18 Dani Megert CLA 2004-11-23 05:34:38 EST
*** Bug 79264 has been marked as a duplicate of this bug. ***
Comment 19 Dani Megert CLA 2006-01-31 05:28:37 EST
Comment formatter is now in JDT Core.
Comment 20 Mateusz Matela CLA 2018-03-02 15:58:15 EST
Closing, separate settings for enabling the formatting of Javadoc, block comments and line comments are there since I remember.
Comment 21 Sasikanth Bharadwaj CLA 2018-03-07 01:49:39 EST
Verified for 4.8 M6 using I20180306-2000 build