Bug 61110 - [formatting] Extra lines should not be added to multi-line comments when reformatting
Summary: [formatting] Extra lines should not be added to multi-line comments when refo...
Status: CLOSED DUPLICATE of bug 270209
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P5 normal with 1 vote (vote)
Target Milestone: 3.6 M6   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-05 15:30 EDT by Dirk Bergstrom CLA
Modified: 2016-01-14 16:48 EST (History)
2 users (show)

See Also:


Attachments
Patch for improving clear blank line behavior of formatter in multi-line comments (4.07 KB, patch)
2005-04-03 01:41 EST, Cagatay Kavukcuoglu CLA
no flags Details | Diff
Patch to test improved formatter behavior in multi-line comments (2.86 KB, patch)
2005-04-03 01:43 EST, Cagatay Kavukcuoglu CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Bergstrom CLA 2004-05-05 15:30:05 EDT
Currently, a comment like this:

                                          | <= margin
    /* this is a multi-line comment about nothing in
     * particular, blah blah. */

Gets reformatted to:

    /*
     * this is a multi-line comment about
     * nothing in particular, blah blah.
     */

A two-line comment is now four lines.  I think this is a waste of space.  I'd
prefer that it look like this after reformatting:

    /* this is a multi-line comment about
     * nothing in particular, blah blah. */
Comment 1 Cagatay Kavukcuoglu CLA 2005-03-03 13:08:30 EST
This is bugging me as well. The comments added to new methods after using the 
Override/Implement Methods action will get reformatted and expand to swallow 
four lines instead of two.
Comment 2 Cagatay Kavukcuoglu CLA 2005-04-03 01:41:59 EST
Created attachment 19489 [details]
Patch for improving clear blank line behavior of formatter in multi-line comments

This patch allows the code formatter to remove the initial blank line in
multi-line comments if the formatter preference
"org.eclipse.jdt.core.formatter.comment.clear_blank_lines" is true.
Comment 3 Cagatay Kavukcuoglu CLA 2005-04-03 01:43:00 EST
Created attachment 19490 [details]
Patch to test improved formatter behavior in multi-line comments
Comment 4 Cagatay Kavukcuoglu CLA 2005-04-03 01:53:05 EST
This set of patches is for 3.1M6. JDT UI might want to change the formatter
preference page for comments to include a multi-line comment. The initial blank
line in the default "Overriding Methods" code template should also be removed if
you want to stay consistent with the default formatter preferences.
Comment 5 Dani Megert CLA 2005-04-05 07:33:11 EDT
>The initial blank
>line in the default "Overriding Methods" code template should also be removed if
>you want to stay consistent with the default formatter preferences.

The template is:
/* (non-Javadoc)
 * ${see_to_overridden}
 */

I don't see an initial blank line.
Comment 6 Dani Megert CLA 2005-04-05 07:40:16 EDT
I would not expect that my comment:

/*
 * A
 *
 * B
 */

Would be formatted into

/* A
 * B
 */

or even
/* A
 * B */

if I selected to clear blank lines. Instead I'd expect to see:

/*
 * A
 * B
 */

It is common in Java to use an initial /* (see also Code Conventions for the
Java Programming Language, 5.5.1).
Comment 7 Cagatay Kavukcuoglu CLA 2005-04-05 09:24:02 EDT
Ah, I had previously changed my template to get rid of the "(non-javadoc)", I 
find it uselessly redundant. As for comment 6, I guess this is where my tastes 
differ from the code conventions, but I can understand why block comments are 
formatted the way they are. I would not expect

/*
 * A
 *
 * B
 */

to be formatted to 

/* A
 * B */

either, I don't think the patch does this. It does format the former to

/* A
 * B
 */

,though. 

How would you be willing to accept this patch? Is it too late to add a new 
(maybe only changed through preferences.ini) preference to control this 
behavior?
Comment 8 Dani Megert CLA 2005-04-05 09:29:56 EDT
I think the correct way to resolve this bug is to add a new option (e.g.
"Compact comments"). The question is whether we would also apply this to Javadoc:

/** This is a Javadoc
 * comment. */

Feature work is mostly done and all API changes have to be approved by the PMC.
Comment 9 Cagatay Kavukcuoglu CLA 2005-04-05 22:29:10 EDT
I like the sound of that, compact comments. On the other hand, my only intention
was to get rid of the initial blank line in block comments. I would not want my
Javadoc comments compacted this way. I'm also not fond of the closing comment
tag '*/' being moved to the end of the last line, I find that it makes the
comment less readable. Still, one could imagine a "Compact multi-line comments"
checkbox that enables these child checkboxes: "Compact Javadoc comments",
"Compact block comments", "Close block comments on last comment line". This may
be more than what PMC wants to approve though, and I'm not sure about the
usefulness of compacting a Javadoc comment at all. I can also see how closing
comments on the last line could be useful, though only when the original is not
using any content prefix.

In any case, I'd like to help out if I can in implementing what you think is
acceptable at this point in the project plan if you don't have any cycles.
Comment 10 Dani Megert CLA 2005-04-06 04:19:23 EDT
>usefulness of compacting a Javadoc comment at all
The problem is that it might also depend on what code you write:

E.g. a simple field comment could look like:
/** x coordinate. */

But if more is added it turns into:
/**
 * X coordinate.
 * @since 3.1
 */

This will not make it into 3.1. The number of PMC requests should be kept to a
minimum and for critical / must-have API changes.
Comment 11 Dani Megert CLA 2005-10-10 12:43:25 EDT
Ownership changed.
Comment 12 Olivier Thomann CLA 2007-06-21 11:03:38 EDT
Block comment formatting can be disabled in 3.3.
Is this good enough?
Comment 13 Cagatay Kavukcuoglu CLA 2007-06-21 11:35:29 EDT
It's not ideal, though still better than past behavior. Thanks.
Comment 14 Frederic Fusier CLA 2008-08-18 08:01:33 EDT
Ownership has changed for the formatter, but I surely will not have enough time to fix your bug during the 3.5 development process, hence set its priority to P5.
Please finalize the posted patch if you definitely need the bug to be fixed in this version and I'll have a look at it...
TIA
Comment 15 Mateusz Matela CLA 2014-08-14 19:05:25 EDT
Looks like bug 270209 was a duplicate of this. It was fixed, so this one can be closed as well.
Comment 16 Mateusz Matela CLA 2016-01-14 16:48:51 EST

*** This bug has been marked as a duplicate of bug 270209 ***