Bug 260381

Summary: [formatter] Javadoc formatter breaks {@code ...} tags.
Product: [Eclipse Project] JDT Reporter: Philippe Maseres <p.maseres>
Component: CoreAssignee: Frederic Fusier <frederic_fusier>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann, srikanth_sankaran
Version: 3.4.1   
Target Milestone: 3.6 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed patch
none
New complete patch
none
Final patch
none
Final patch (without whitespaces noise...)
none
Released patch
none
Additional patch none

Description Philippe Maseres CLA 2009-01-08 07:38:57 EST
Build ID: M20080911-1700

Steps To Reproduce:
1. Edit a javadoc comment with tags that contain {@code ...} elements. Example :

/**
 * Comments that can be formated in several lines...
 *
 *  @author Myself
 *
 *  @version {@code $Revision: 1.2 $ $Date: 2009/01/07 12:27:50 $ $Author: myself $ $Source: /projects/cvs/module/project/src/com/foo/Main.java,v $}
 */

2. Format the code.

3. The version tag value is broken, since the formatter splits the line :

/**
 * Comments that can be formated in several lines...
 * 
 * @author Myself
 * 
 * @version {@code $Revision: 1.2 $ $Date: 2009/01/07 12:27:50 $ $Author: myself
 *          $ $Source: /projects/cvs/module/project/src/com/foo/Main.java,v $}
 */



More information:
Older versions (3.3 Europa, for example) handles the special {@code ...} sequence without splitting the value into multiple lines...
Comment 1 Frederic Fusier CLA 2009-01-08 09:29:07 EST
There's no specification saying that the @version tag should be kept on one line and splitting the @code text in two lines does not really break it.

But I agree that, since 3.3, there's an inconsistency between in-line @code tag and <code>...</code> HTML tags formatting although it is specified that {@code} is equivalent to <code>{@literal}</code>...

However, replacing @code in-line tag by <code> HTML tag is not a possible workaround as this produces the following output:
/**
 * Comments that can be formated in several lines...
 * 
 * @author Myself
 * 
 * @version
 * 
 *          <code>$Revision: 1.2 $ $Date: 2009/01/07 12:27:50 $ $Author:myself $ $Source: /projects/cvs/module/project/src/com/foo/Main.java,v $</code>
 */
public class X02 {

}

The formatter should not split the line in this case...
Comment 2 Frederic Fusier CLA 2009-06-23 04:25:27 EDT
Created attachment 139842 [details]
Proposed patch

Add the notion of immutable block based on the tag value (currently only @code).
Comment 3 Olivier Thomann CLA 2010-02-08 15:10:08 EST
You might want to add the same support for @literal.
See http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html#{@code}
Comment 4 Frederic Fusier CLA 2010-02-09 17:14:24 EST
Created attachment 158645 [details]
New complete patch

This patch addresses the initial issue but also remove all differences with 3.3 behavior in this area... :-)

It also considers @literal inline tag as immutable.
Comment 5 Frederic Fusier CLA 2010-02-11 07:03:48 EST
Created attachment 158835 [details]
Final patch

Final patch fixing one minor issue when the inline tag closing brace is at max column + 1...
Comment 6 Frederic Fusier CLA 2010-02-11 07:16:06 EST
Created attachment 158838 [details]
Final patch (without whitespaces noise...)

Previous patch wrongly included white spaces cleaning although I didn't want to do it... It seems that something went wrong with the Save Actions...
Comment 7 Frederic Fusier CLA 2010-02-11 07:21:08 EST
Created attachment 158839 [details]
Released patch

One more additional change in a Javadoc comment...
Comment 8 Frederic Fusier CLA 2010-02-11 07:21:45 EST
Released for 3.6M6 in HEAD stream.
Comment 9 Frederic Fusier CLA 2010-02-14 10:57:00 EST
Created attachment 159072 [details]
Additional patch

This additional patch fixes some minor issues with the line length computation while formatting an immutable block.

It also changes the initial tests as the $Revision,  $Date, etc. were meaningful for CVS and was changed at each check-out!
Comment 10 Frederic Fusier CLA 2010-02-14 10:58:37 EST
(In reply to comment #9)
> Created an attachment (id=159072) [details]
> Additional patch
> 
Released for 3.6M6
Comment 11 Srikanth Sankaran CLA 2010-03-09 03:54:16 EST
Verified for 3.6M6 using build I20100305-1011