Bug 475823 - "Eclipse" default formatter should not add line breaks to @params in Javadoc
Summary: "Eclipse" default formatter should not add line breaks to @params in Javadoc
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.8 M6   Edit
Assignee: Lars Vogel CLA
QA Contact: Manoj N Palat CLA
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks: 531826
  Show dependency tree
 
Reported: 2015-08-25 10:42 EDT by Lars Vogel CLA
Modified: 2018-03-30 14:12 EDT (History)
8 users (show)

See Also:
mateusz.matela: review+


Attachments
Javadoc params formatter setting (137.42 KB, image/png)
2015-08-25 10:42 EDT, Lars Vogel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2015-08-25 10:42:03 EDT
Created attachment 256100 [details]
Javadoc params formatter setting

AFAIK we in Eclipse try to follow the official Oracle code conventions as much as possible, and AFAICS Oracle and Google code conversions suggest to not add line breaks after @param tags

Links:

http://www.oracle.com/technetwork/articles/java/index-137868.html
https://google.github.io/styleguide/javaguide.html#s7.1.2-javadoc-paragraphs
Comment 1 Lars Vogel CLA 2016-11-28 14:52:30 EST
Jay, Manoj whats your option here?
Comment 2 Jay Arthanareeswaran CLA 2016-11-28 23:36:09 EST
Just tried out on my workspace and interestingly, I always see the @param tag and summary in a single line no matter what the option is set to. Am I missing something here?
Comment 3 Lars Vogel CLA 2016-11-29 04:33:59 EST
I tested with JavaResolutionFactory from pde.ui

With lines breaks:

/**
	 * Creates and returns an IJavaCompletionProposal for the given
	 * AbstractManifestChange with the given relevance.
	 * 
	 * @param change
	 *            the modification which should be performed by the proposal
	 * @param relevance
	 *            the relevance of the IJavaCompletionProposal
	 * @since 3.4
	 * @see AbstractManifestChange
	 */
	public final static IJavaCompletionProposal createJavaCompletionProposal(final AbstractManifestChange change, final int relevance) {
	

If I remove the "New line after @param tags" setting in the formatter:

/**
	 * Creates and returns an IJavaCompletionProposal for the given
	 * AbstractManifestChange with the given relevance.
	 *
	 * @param change the modification which should be performed by the proposal
	 * @param relevance the relevance of the IJavaCompletionProposal
	 * @since 3.4
	 * @see AbstractManifestChange
	 */
	public final static IJavaCompletionProposal createJavaCompletionProposal(final AbstractManifestChange change,
Comment 4 Mateusz Matela CLA 2016-11-29 13:14:15 EST
Looking at the preview window, the "New line after @param" option seems to be working correctly in both master and maintenance branch. I don't know what could go wrong in your case, Jay.
Comment 5 Jay Arthanareeswaran CLA 2016-12-04 23:44:32 EST
(In reply to Mateusz Matela from comment #4)
> Looking at the preview window, the "New line after @param" option seems to
> be working correctly in both master and maintenance branch. I don't know
> what could go wrong in your case, Jay.

The problem could have been my eyes. I no longer see this problem, but was certain the sample code wouldn't change when I played around with the relevant options.

Anyway, coming back to Lar's request: Lars, I agree with your point, but do we really want to break the existing users? People may not like it if the code changes without them making any change.
Comment 6 Mateusz Matela CLA 2016-12-11 16:53:09 EST
Maybe we could come up with a solution that wouldn't change the behavior for workspaces migrating from previous versions? For example, if a workspace has the active profile "Eclipse [built-in]", it would save all settings as a new profile, "Eclipse 4.6" or something like that.
Comment 7 Lars Vogel CLA 2016-12-20 12:36:34 EST
(In reply to Jay Arthanareeswaran from comment #5)
> Anyway, coming back to Lar's request: Lars, I agree with your point, but do
> we really want to break the existing users? People may not like it if the
> code changes without them making any change.

We have adjusted the Eclipse profile over the last years. I think we should be open to improve our "Eclipse" profile.

If the customer wants a stable profile he should create his own profile, for example by copying one of the existing profiles.
Comment 8 Mateusz Matela CLA 2017-05-02 14:51:42 EDT
+1 for this change.
As long as only the built-in profiles change and pre-existing custom profiles stay the same after migration, it shouldn't be a problem. If someone didn't bother to create their own profile, they probably don't care that much.

We've already introduced such a change in bug 514017.
Comment 9 Lars Vogel CLA 2017-11-17 03:59:19 EST
(In reply to Mateusz Matela from comment #8)
> +1 for this change.
> As long as only the built-in profiles change and pre-existing custom
> profiles stay the same after migration, it shouldn't be a problem. If
> someone didn't bother to create their own profile, they probably don't care
> that much.
> 
> We've already introduced such a change in bug 514017.

Can we proceed with this change? Do you need a Gerrit?
Comment 10 Mateusz Matela CLA 2017-11-21 05:04:48 EST
(In reply to Lars Vogel from comment #9)
> Can we proceed with this change? Do you need a Gerrit?

Without further objections from Jay, I assume we can :)
Yes please, a Gerrit wyould be helpful.
Comment 11 Eclipse Genie CLA 2017-11-22 04:32:38 EST
New Gerrit change created: https://git.eclipse.org/r/112049
Comment 12 Mateusz Matela CLA 2017-11-23 18:03:00 EST
Of course, changing just one line is not enough :)
Are you up for updating the failing tests? (probably best to change the setting to true in each one)
Comment 13 Dani Megert CLA 2017-11-24 03:47:05 EST
(In reply to Mateusz Matela from comment #12)
> Of course, changing just one line is not enough :)
> Are you up for updating the failing tests? (probably best to change the
> setting to true in each one)

Please also run the JDT UI tests and make sure they don't fail.
Comment 14 Lars Vogel CLA 2017-11-24 03:55:03 EST
(In reply to Mateusz Matela from comment #12)
> Of course, changing just one line is not enough :)

That is why the patch has the commit message: ;-)
---------
[WIP] Bug 475823 - "Eclipse" default formatter should not add line breaks to @params in Javadoc 

WIP, as I also need to adjust the tests
-------
> Are you up for updating the failing tests? (probably best to change the
> setting to true in each one)

Thanks for the pointer, I was unsure if I should adjust the test or override the setting for the test. I will try to update the test. We have an Eclipse hackathon planned for 11.12 and I will try to pick this for the hackathon.
Comment 15 Lars Vogel CLA 2017-12-21 04:55:18 EST
(In reply to Mateusz Matela from comment #12)
> (probably best to change the setting to true in each one)

I did this for one test, can you check if the change is in line with your suggestion? https://git.eclipse.org/r/#/c/112049/3/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java

Once I get your OK, I will adjust the other 146 tests.
Comment 16 Dani Megert CLA 2017-12-21 10:20:32 EST
Note that such changes can be a big pain for our users as they will get unexpected changes when saving a file with auto-format enabled.

I'm -1 for that unless there are many other +1 votes.
Comment 17 Mateusz Matela CLA 2017-12-25 17:11:52 EST
(In reply to Lars Vogel from comment #15)
> (In reply to Mateusz Matela from comment #12)
> > (probably best to change the setting to true in each one)
> 
> I did this for one test, can you check if the change is in line with your
> suggestion?
> https://git.eclipse.org/r/#/c/112049/3/org.eclipse.jdt.core.tests.model/src/
> org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java
> 
> Once I get your OK, I will adjust the other 146 tests.

I was thinking about something similar to the setPageWidth80() method in FormatterRegressionTesets - a separate method makes it more clear that the preference change is related to modified defaults, not an essential part of what given test is checking.


(In reply to Dani Megert from comment #16)
> Note that such changes can be a big pain for our users as they will get
> unexpected changes when saving a file with auto-format enabled.
> 
> I'm -1 for that unless there are many other +1 votes.

You do remember it will only affect people who don't use their own formatter profile, right? Can you explain how this case is different from e.g. bug 514017, where you gave +1?
Comment 18 Gautier de SAINT MARTIN LACAZE CLA 2017-12-25 17:32:25 EST
+1 for changing this default behaviour.
Comment 19 Mateusz Matela CLA 2018-01-16 18:10:56 EST
Here's a thought: bug 128653 is about aligning @param descriptions, a feature which would bring the format even closer to Oracle conventions. So we may want to add that feature first and turn it on by default too. This way there will be more good reasons to change the default profile and we'll make sure the javadoc formatting is affected only once.

Bug 128653 shouldn't be hard to fix, but I prefer to wait until bug 462940 is closed before adding new features.
Comment 20 Florian Gruner CLA 2018-01-18 10:56:03 EST
+1 for the default behaviour
Comment 21 Florian Gruner CLA 2018-01-18 10:58:53 EST
(In reply to Florian Gruner from comment #20)
> +1 for the default behaviour

Sorry, this was unclear. +1  for not adding line breaks.
Comment 22 Simon Scholz CLA 2018-01-19 06:21:31 EST
I'd say +1 for this change in order spare unnecessary lines of code.
Comment 23 Gautier de SAINT MARTIN LACAZE CLA 2018-02-10 02:18:49 EST
+1 for removing the line breaks
Comment 24 Lars Vogel CLA 2018-02-13 06:28:44 EST
IMHO this improves our default formatting and we should always try to deliver the best out-of-box experience for our customers.

As it is easy for customers to adjust their profile I suggest to merge this for M6.

Manoj, please review the Gerrit change.
Comment 25 Manoj N Palat CLA 2018-02-13 09:51:13 EST
(In reply to Lars Vogel from comment #24)
> 
> Manoj, please review the Gerrit change.
@Lars: Matuesz will be the better person to review the change.
@Mateusz: Can you please review? TIA
Comment 26 Mateusz Matela CLA 2018-02-20 17:18:12 EST
I did the review in Gerrit.

What do you think about comment 19? If we want to change the default alignment style, it would be good to change these defaults together. Bug 128653 is on the top of my list and I should manage to finish it next weekend, but if I don't, maybe it would be better to wait another year with this change rather than make two changes year after year that could cause reformatting of all files.
Comment 27 Lars Vogel CLA 2018-02-21 09:28:13 EST
(In reply to Mateusz Matela from comment #26)
> I did the review in Gerrit.

Thanks, I adjust the Gerrit as soon as I can.

> but if I don't, maybe it would be better to wait another year

I would prefer not to wait another year.
Comment 28 Eclipse Genie CLA 2018-02-21 09:42:34 EST
New Gerrit change created: https://git.eclipse.org/r/117871
Comment 29 Lars Vogel CLA 2018-02-21 09:43:35 EST
(In reply to Eclipse Genie from comment #28)
> New Gerrit change created: https://git.eclipse.org/r/117871

This is for JDT UI CleanUpStressTest
Comment 30 Lars Vogel CLA 2018-02-22 03:18:46 EST
(In reply to Manoj Palat from comment #25)
> @Mateusz: Can you please review? TIA

Mateusz gave his +1 on the changes. 
Manoj, can we merge the changes? I'm waiting since 2015 for this.
Comment 31 Lars Vogel CLA 2018-02-26 11:18:16 EST
(In reply to Lars Vogel from comment #30)
Manoj or Mateusz can we merge this, so that we can test it in M6?
Comment 32 Mateusz Matela CLA 2018-02-26 14:04:24 EST
If I read https://wiki.eclipse.org/Photon/Simultaneous_Release_Plan correctly, we still have almost 2 weeks left.
I'm pretty close to completing the Javadoc align feature and I think we could turn it on by default in this bug.
Comment 33 Lars Vogel CLA 2018-02-27 03:00:42 EST
(In reply to Mateusz Matela from comment #32)
> If I read https://wiki.eclipse.org/Photon/Simultaneous_Release_Plan
> correctly, we still have almost 2 weeks left.

According to Danis email, we only have this week left, next week is testing week. https://dev.eclipse.org/mhonarc/lists/eclipse-dev/msg10624.html

> I'm pretty close to completing the Javadoc align feature and I think we
> could turn it on by default in this bug.

Would be great to see this also in. I hope you manage to finish it this week.
Comment 34 Mateusz Matela CLA 2018-02-28 19:02:38 EST
OK, done. See bug 531821 for UI changes needed to see the new preferences.

Now we have to choose the best default Javadoc alignment. I think "Align descriptions, group by type" is a good balance between cleanness and saving space.
We should also disable the "Indent wrapped @param/@throws descriptions" setting (AKA "Ident description after @param").

@Lars can you take care of changing these defaults and updating the affected tests?
Comment 35 Lars Vogel CLA 2018-03-01 01:21:44 EST
(In reply to Mateusz Matela from comment #34)
> OK, done. See bug 531821 for UI changes needed to see the new preferences.
> 
> Now we have to choose the best default Javadoc alignment. I think "Align
> descriptions, group by type" is a good balance between cleanness and saving
> space.
> We should also disable the "Indent wrapped @param/@throws descriptions"
> setting (AKA "Ident description after @param").
> 
> @Lars can you take care of changing these defaults and updating the affected
> tests?

Could you please do it? I'm currently working for a customer and I'm not familiar with the new settings.
Comment 38 Lars Vogel CLA 2018-03-02 02:30:07 EST
Awesome Mateusz, thanks a bunch. Shall I add it to the noteworthy?
Comment 39 Mateusz Matela CLA 2018-03-02 12:03:45 EST
Not sure, AFAIR we've never advertised it in N&N when the formatter defaults changed. I've mentioned the changed defaults for Javadoc tags in N&N note for bug 531821.
Comment 40 Lars Vogel CLA 2018-03-02 12:16:16 EST
(In reply to Mateusz Matela from comment #39)
> Not sure, AFAIR we've never advertised it in N&N when the formatter defaults
> changed. I've mentioned the changed defaults for Javadoc tags in N&N note
> for bug 531821.

Ok, thanks again for the merge.
Comment 41 Sasikanth Bharadwaj CLA 2018-03-07 06:10:39 EST
Verified for 4.8 M6 using I20180306-2000 build
Comment 42 Lars Vogel CLA 2018-03-23 03:58:47 EDT
Mateusz, is there a way to mass update "only" the formatter settings in all eclipse.platform projects? 

The changes in the default profile are only applied to a project, if I go to the project properties -> Formatter and press the Edit... button. Unfortunately this cannot be done for multiple projects AFAIK and copied in the jdt ui and jdt core .settings files around would override other settings.
Comment 43 Mateusz Matela CLA 2018-03-23 17:31:24 EDT
(In reply to Lars Vogel from comment #42)
> Mateusz, is there a way to mass update "only" the formatter settings in all
> eclipse.platform projects?

I've never done this, but it should be enough to use find/replace on .settings/org.eclipse.jdt.core.prefs files. The relevant prefs are:
-org.eclipse.jdt.core.formatter.comment.indent_parameter_description
-org.eclipse.jdt.core.formatter.comment.indent_root_tags
-org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter
-org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped (new one to set to true)

Compare with the change to DefaultCodeFormatterOptions in this commit.
Comment 44 Mateusz Matela CLA 2018-03-27 19:52:49 EDT
Actually there's a bug related to upgrading with unmanaged profiles, see bug 532964. Not sure if this is what affected you, Lars.
Comment 45 Lars Vogel CLA 2018-03-28 06:07:29 EDT
Thanks for the info but I don't think we are affected as we do not use unmanaged profile. As for the adjustment of settings, I plan to do it manually