Bug 197169 - Formatter expands @ in annotation in javadoc, creating invalid tag
Summary: Formatter expands @ in annotation in javadoc, creating invalid tag
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.3.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on: 198153
Blocks:
  Show dependency tree
 
Reported: 2007-07-19 12:36 EDT by Matt McCutchen CLA
Modified: 2008-09-16 09:46 EDT (History)
2 users (show)

See Also:


Attachments
Fix (1.81 KB, patch)
2007-07-27 15:11 EDT, Matt McCutchen CLA
no flags Details | Diff
Add regression test (1.36 KB, patch)
2007-07-30 13:55 EDT, Matt McCutchen CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt McCutchen CLA 2007-07-19 12:36:49 EDT
Build ID: HEAD as of 7/19/2007

I am writing the javadoc comment for an annotation class, and I want to give an example of how to use the annotation.  If I just write it out as-is with the @ sign, both javadoc and JDT think it's a Javadoc tag; javadoc(1) complains that it's unknown and JDT that it's invalid.  Thus, I replaced the @ with @ as suggested by Sun's javadoc(1) man page.  The entity works fine in the generated javadoc and in hovers, but the source formatter expands it back to @, causing the problem again.

I can understand wanting to expand entities as a cleanup, but as a special case, the source formatter needs to be taught never to expand @ in javadoc because that could cause something to be misinterpreted as a javadoc tag.

Steps To Reproduce:
1. Activate the Package Explorer, deselect everything, and paste the following code:

/**
 * Here's an example of how to use this annotation:
 *
 * <pre>
 * &#064;Coolness("extreme") class Foo {}
 * </pre>
 */
public @interface Coolness {
    String value();
}

2. Format the source file that opens (Source -> Format).  A warning appears on the annotation inside the <pre>.
Comment 1 Matt McCutchen CLA 2007-07-19 12:39:22 EDT
Oops, I forgot a step:

1/2. Go to Window -> Preferences -> Java -> Compiler -> Javadoc and ensure that "Malformed Javadoc comments" is set to at least Warning.
Comment 2 Matt McCutchen CLA 2007-07-27 15:11:09 EDT
Created attachment 74826 [details]
Fix

This patch fixes the bug by changing Java2HTMLEntityReader to translate a @ back to a &#064; when it is the first thing on a line.
Comment 3 Matt McCutchen CLA 2007-07-27 15:42:00 EDT
I can't recommend the use of &#064; until bug 198153 is also fixed because the formatter adds another space before the &#064; each time you format the code.
Comment 4 Matt McCutchen CLA 2007-07-30 13:55:50 EDT
Created attachment 74955 [details]
Add regression test

This patch applies on top of my regression test for bug 198153.
Comment 5 Olivier Thomann CLA 2007-07-30 16:18:18 EDT
Released for 3.4M1.
Added regression test in org.eclipse.jdt.core.tests.formatter.comment.JavaDocTestCase#test197169

Thanks for the contribution.
Comment 6 Frederic Fusier CLA 2007-08-07 07:15:25 EDT
Verified for 3.4M1 using build I20070806-1800.
Comment 7 Olivier Thomann CLA 2007-08-13 13:01:58 EDT
Jérôme,

The fix for this bug is also required to be backported for 3.3.1 in order to properly backport bug 109636.
+1 for 3.3.1 ?
Comment 8 Jerome Lanneluc CLA 2007-08-14 07:13:24 EDT
+1 for backporting to 3.3.1
Comment 9 Olivier Thomann CLA 2007-08-14 10:54:24 EDT
Reopen for 3.3.1.
Comment 10 Olivier Thomann CLA 2007-08-14 11:05:28 EDT
Released for 3.3.1.
Added regression test in
org.eclipse.jdt.core.tests.formatter.comment.JavaDocTestCase#test197169
Comment 11 David Audel CLA 2007-09-03 08:57:49 EDT
Verified for 3.3.1 using build M20070831-2000.