Bug 147284 - [typing] Character "@" can't be used in code snippets within javadoc
Summary: [typing] Character "@" can't be used in code snippets within javadoc
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-15 09:29 EDT by Bogdan Butnaru CLA
Modified: 2023-04-10 18:01 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bogdan Butnaru CLA 2006-06-15 09:29:29 EDT
I tried adding as the Javadoc for a method something like:

/** 
    Method usage:

    <pre>
    class ClassName {
        [...]
        @Override
        public int toString(){
            return Class.staticMethod(this, ClassName.class);
        }
        [...]
    }
    </pre>

    @param object an object.
    @param objClass the object's compile-time class.
*/

The problem is that apparently the Javadoc extractor considers the @Override annotation as a Javadoc tag, can't recognize it, and stops working with a warning at that point.

I tried using the &#x40; (that should have been [ampersand, hash, lower-case x, four, zero, semicolon], not sure if it will show up right), the HTML-entity for the "@" sign (at?). Unfortunately, when auto-formatting the file Eclipse converts the entity in a plain "@" character. While perhaps not really a bug (as far as HTML is concerned the change should be invisible), I think that it may help changing this. 

(I'm not sure though, and anyway I wouldn't be surprised if the Javadoc extractor wouldn't see it as a "@" anyway. Any suggestions for including code snippets with annotations in Javadoc are welcome.)
Comment 1 Bogdan Butnaru CLA 2006-06-15 09:40:40 EDT
I discovered that using <code>@Override [...]</code> works. However I can't seem to convince the <code/> tag to behave as anything other than an inline element (which it is in HTML, AFAIK), meaning it doesn't work with multi-line code snippets. I was able to get the thing above work using 

<pre>
    class ClassName {
        [...]
        <code>@Override</code>
        public int toString(){
            return Class.staticMethod(this, ClassName.class);
        }
        [...]
    }
</pre>

that is, wraping the annotation in a <code/> tag (on top, or rather inside of the <pre/> tag). This is not at all elegant, but works.

If anyone knows a better solution, please drop me a note.

Since this is not really an Eclipse bug, rather a deficiency of Javascript (I think), I resolved the bug to "fixed". Not sure if this is right, but "wontfix" seems to suggest it really is a bug.
Comment 2 Bogdan Butnaru CLA 2006-06-15 09:49:05 EDT
Of course, now I noticed this still doesn't work right. The snippet in my last comment works, presumably meaning it's valid Javascript.

However, when auto-formatting Eclipse turns it into

<pre>
    class ClassName {
        [...]
	             		
<code>
@Override
</code>
	public int toString(){
            return Class.staticMethod(this, ClassName.class);
        }
        [...]
    }
</pre>

(moves the <code/> markers on separate lines, and slides everything at line beginning) which is not only very ugly, but changes the semantic--meaning that the Javadoc extractor chokes on it. I presume this is because the <code/> tag is supposed to be one line only, but I'm not sure.

Anyway, this means that Eclipse turns something that works in something that doesn't when auto-formatting, which is probably bad.
Comment 3 Bogdan Butnaru CLA 2006-06-15 09:54:52 EDT
Probably a separate issue, but maybe related: while using <code>@Annotation</code>, in a single line, outside of a <pre/> tag, works as far as the Javadoc extractor is concerned, Eclipse autoformats everything after the occurence incorrectly. Apparently it assumes it is a Javadoc tag.

I'm sure most of this is because "@" was not expected to appear in code when Javadoc was initially designed, so it's probably unclear yet how to deal with it, but we probably want to look at the problem.
Comment 4 Dani Megert CLA 2006-06-15 11:50:00 EDT
Can be reproduced in 3.2 RC7
Comment 5 Eclipse Genie CLA 2019-04-11 11:00:41 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 6 Dani Megert CLA 2019-04-12 04:18:08 EDT
Still an issue in 4.11 M1.
Comment 7 Dani Megert CLA 2019-04-12 04:19:09 EDT
One can use &#64; instead of @ as a workaround.

Also, the formatter does this for you.
Comment 8 Mateusz Matela CLA 2019-04-28 08:54:16 EDT
(In reply to Dani Megert from comment #7)
> One can use &#64; instead of @ as a workaround.
> 
> Also, the formatter does this for you.

So what should be the fix for this bug?
When you type @ inside <pre> it automatically inserts &#64; instead?
Comment 9 Dani Megert CLA 2019-04-28 10:04:32 EDT
(In reply to Mateusz Matela from comment #8)
> (In reply to Dani Megert from comment #7)
> > One can use &#64; instead of @ as a workaround.
> > 
> > Also, the formatter does this for you.
> 
> So what should be the fix for this bug?
> When you type @ inside <pre> it automatically inserts &#64; instead?
Probably.
Comment 10 Eclipse Genie CLA 2021-04-18 17:18:03 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 11 Eclipse Genie CLA 2021-04-19 07:22:18 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 12 Eclipse Genie CLA 2023-04-10 18:01:25 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.