Community
Participate
Working Groups
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.
Created attachment 14959 [details] Patch for JDT Core
Created attachment 14960 [details] Patch for JDT UI, formatting
Created attachment 14961 [details] Patch for JDT UI, preferences for formatting
Created attachment 14967 [details] Patch for JDT UI, preference constants for formatting
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
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.?
sounds good
Created attachment 15031 [details] Patch for JDT Core
Created attachment 15032 [details] Patch for JDT UI, formatting
Created attachment 15033 [details] Patch for JDT UI, preferences for formatting
Done, now it has only one option on Comments tab.
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.
Christof, please annotate this PR when you start moving things down to J Core.
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. :-(
I still think it would be a worthwhile addition. Please post updated patches if you can spend the additional time.
Konstantin, do you plan on providing the patch?
Sorry, I am very busy now on my main job. So, I will, but not in next 3-4 weeks, sorry. :-(
*** Bug 79264 has been marked as a duplicate of this bug. ***
Comment formatter is now in JDT Core.
Closing, separate settings for enabling the formatting of Javadoc, block comments and line comments are there since I remember.
Verified for 4.8 M6 using I20180306-2000 build