Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 48950 - [formatting] Comment formatter: Header detection error prone
Summary: [formatting] Comment formatter: Header detection error prone
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 3.0 M9   Edit
Assignee: Christof Marti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 57161 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-12-17 04:10 EST by Dani Megert CLA
Modified: 2004-04-02 02:50 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2003-12-17 04:10:00 EST
I200312162000

Changing the "Format header comment" affects the interface's Javadoc in the
following code (taken from new code formatter comment preview): 

/**
 * An example for comment formatting. This example is meant to illustrate the
various possiblilities offered by <i>Eclipse</i> in order to format comments.
 */
interface Example {
    /**
     *
     * These possibilities include:
     * <ul><li>Formatting of header comments.</li><li>Formatting of Javadoc
tags</li></ul>
     */
    int bar();

    /**
     * The following is some sample code which illustrates source formatting
within javadoc comments:
     * <pre>public class Example {final int a= 1;final boolean b= true;}</pre>
     * @param a The first parameter. For an optimum result, this should be an
odd number
     * between 0 and 100.
     * @param b The second parameter.
     * @result The result of the foo operation, usually within 0 and 1000.
     */
    int foo(int a, int b);
}
Comment 1 Tom Hofmann CLA 2003-12-17 04:57:11 EST
the "format header comment" feature just checks for comments at position 0. A
solution would be to add an empty line before the javadoc comment, or a package
declaration or so.
Comment 2 Dani Megert CLA 2004-01-05 11:28:29 EST
I disagree and would say it is a bug that the file header comment can't start
with empty lines.

See also bug 49527
Comment 3 Tom Hofmann CLA 2004-01-14 05:13:03 EST
So the real problem is that the type comment of a type in the default package
that specifies no imports is not formatted when "format header comments" is
unchecked. 

Seems not like a very frequent problem - workaround for the preference page by
- adding an import statement
- adding a package declaration
- setting format header comment to "true" for the preview.
Comment 4 Dani Megert CLA 2004-01-14 05:41:42 EST
As discussed and decided with Tom, the current header detection scheme is quite
error prone and should be replaced by the following heuristic: treat everything
as header from 0 to beginning of first top level type's source range offset.

Adapted summary and increased priority.
Comment 5 Christof Marti CLA 2004-03-23 10:27:58 EST
How should we handle the case where we don't have an editor? E.g., in previewers
we do not have a Java model. Right?
Comment 6 Dani Megert CLA 2004-03-23 11:27:47 EST
you could make temporary working copy using the preview source
Comment 7 Christof Marti CLA 2004-03-29 02:55:33 EST
There is a problem with the proposal from comment 4: Given a CU with a header
comment and a top-level type's comment with nothing but whitespace in-between,
the source range of the top-level type starts at the offset of the header
comment, not the type's comment.
Comment 8 Dani Megert CLA 2004-03-29 03:34:25 EST
See bug 56532.
As a workaround you could use a Java code scanner and do it yourself (see
JavaDocAccess as a hint).

Comment 9 Dani Megert CLA 2004-03-30 07:49:58 EST
Fixed (released modified patch by Christof)
Available in builds > 20040330
Comment 10 Dani Megert CLA 2004-04-02 02:50:19 EST
*** Bug 57161 has been marked as a duplicate of this bug. ***