Bug 239719 - [formatter] Code formatter destroys pre formatted javadoc comments
Summary: [formatter] Code formatter destroys pre formatted javadoc comments
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.4.1   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-06 12:28 EDT by Hansgeorg Schwibbe CLA
Modified: 2008-08-28 12:43 EDT (History)
4 users (show)

See Also:
philippe_mulet: pmc_approved+


Attachments
Proposed patch (4.76 KB, patch)
2008-07-08 06:51 EDT, Frederic Fusier CLA
no flags Details | Diff
Proposed patch for R3_4_maintenance stream (4.79 KB, patch)
2008-07-08 12:41 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hansgeorg Schwibbe CLA 2008-07-06 12:28:39 EDT
When I try to format the following code with Shift+Ctrl+F, the <pre> formatted code will be damaged:
/**
 * <pre>
 *  public class Test implements Runnable
 *  {
 *    @Override
 *    public void run()
 *    { 
 *      // Hello really bad Ganymede formatter !!!
 *      // Shit happens when somebody tries to change a running system
 *      System.out.println("Press Shift+Ctrl+F to format");
 *    }
 *  }</pre>
 */
 public class Test 
 {
 }

The result is the following:
/**
 * <pre>
 *  public class Test implements Runnable
 * {
 * 
 * @Override public void run() { // Hello really bad Ganymede formatter !!! //
 *           Shit happens when somebody tries to change a running system
 *           System.out.println("Press Shift+Ctrl+F to format"); } }
 * 
 *           </pre>
 */
public class Test {
}
Comment 1 Frederic Fusier CLA 2008-07-07 06:54:51 EDT
I'll investigate...
Comment 2 Frederic Fusier CLA 2008-07-07 08:01:55 EDT
The problem comes from the @Override tag inside the code snippet... The FormatterCommentParser read it as a javadoc tag and stops the HTML tag <pre> just before!

Until a fix is released for this issue, the simple workaround is either to remove this tag or use the HTML character value for the '@' (&#064;):
/**
 * <pre>
 *  public class Test implements Runnable
 *  {
 *    &#064;Override
 *    public void run()
 *    { 
 *      // Hello really bad Ganymede formatter !!!
 *      // Shit happens when somebody tries to change a running system
 *      System.out.println("Press Shift+Ctrl+F to format");
 *    }
 *  }</pre>
 */
 public class Test 
 {
 }
will be then correctly formatted as:
/**
 * <pre>
 * public class Test implements Runnable {
 * 	&#064;Override
 * 	public void run() {
 * 		// Hello really bad Ganymede formatter !!!
 * 		// Shit happens when somebody tries to change a running system
 * 		System.out.println(&quot;Press Shift+Ctrl+F to format&quot;);
 * 	}
 * }
 * </pre>
 */
public class Test {
}

Comment 3 Hansgeorg Schwibbe CLA 2008-07-08 05:17:24 EDT
Editing all @override tags in all projects is too much work for me,
I jump back to Europa and wait for a stable Ganymede.
Comment 4 Frederic Fusier CLA 2008-07-08 06:51:13 EDT
Created attachment 106803 [details]
Proposed patch

The FormatterCommentParser now does not create tag when an html <pre> tag is currently opened...
Comment 5 Frederic Fusier CLA 2008-07-08 06:55:16 EDT
Released for 3.5M1
Comment 6 Frederic Fusier CLA 2008-07-08 07:23:18 EDT
(In reply to comment #3)
> Editing all @override tags in all projects is too much work for me,
> I jump back to Europa and wait for a stable Ganymede.
> 
Have you so many @Override tags inside <pre>...</pre> in javadoc comments?
Comment 7 Frederic Fusier CLA 2008-07-08 12:04:02 EDT
Philippe, would it be OK to backport the fix for this bug to 3.4.1?
Comment 8 Philipe Mulet CLA 2008-07-08 12:08:23 EDT
+1 for 3.4.1
Comment 9 Frederic Fusier CLA 2008-07-08 12:41:52 EDT
Created attachment 106845 [details]
Proposed patch for R3_4_maintenance stream
Comment 10 Frederic Fusier CLA 2008-07-09 04:26:04 EDT
Released for 3.4.1
Comment 11 Hansgeorg Schwibbe CLA 2008-07-10 02:41:11 EDT
> Have you so many @Override tags inside <pre>...</pre> in javadoc comments?
Yes, I build my javadoc with many code examples.
Comment 12 Frederic Fusier CLA 2008-07-10 03:07:27 EDT
(In reply to comment #11)
> > Have you so many @Override tags inside <pre>...</pre> in javadoc comments?
> Yes, I build my javadoc with many code examples.
> 
OK, so as the fix has been released in maintenance build M20080709-0800, you can install it + Ganymede on top of it. This should give you the opportunity to see that the formatter is now 25% faster than the Europa one and also may be report other issues we are not currently aware of...
Comment 13 Olivier Thomann CLA 2008-08-06 12:28:09 EDT
Verified for 3.5M1 using I20080805-1307
Comment 14 Olivier Thomann CLA 2008-08-06 13:29:40 EDT
Reopen to close as RESOLVED/FIXED. Will be closed as VERIFIED during 3.4.1
verification pass.
Comment 15 Olivier Thomann CLA 2008-08-06 13:30:07 EDT
Fixed.
Comment 16 Olivier Thomann CLA 2008-08-28 12:43:52 EDT
In fact @Override is replaced with &#064;Override if code snippet is formatted.
Verified for 3.4.1 using M20080827-2000.