Community
Participate
Working Groups
This bug was found on JDT 3.15.0 (I cannot upgrade due to the unrelated 560434) but seems to be present on newer versions still. Nested Javadoc `@code` taglets are not parsed correctly: ``` public class Test { /**{@code {@code null}}*/ public void test() {} } ``` This code yields the HTML `<code>{@code null}</code>` when processed using the OpenJDK `javadoc` tool. When parsing the comment with JDT however, The @code TagElement is empty (`.fragments()` is empty) and the text (` {@code null}}`) comes *after* the TagElement as a separate TextElement. While nested tag parsing appears to be implemented – there is a `openingBraces` variable in AbstractCommentParser – this handling does not appear to work (anymore?). In particular, the parser falsely sets `inlineTagStarted = false` at the first closing brace and never ends up pushing the text to the TagElement produced for the outer `@code`. Unfortunately I am too unfamiliar with the JDT project structure to produce a test case for this that would accompany a PR. In local testing, the following patch, backported to JDT 3.15.0, appears to fix the issue: ``` Index: org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java (revision d5c188d78ee37a5a78869313b94fa62ff542cea6) +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java (date 1609950685782) @@ -340,7 +340,8 @@ } if (!isFormatterParser && !considerTagAsPlainText) this.textStart = this.index; - setInlineTagStarted(false); + if (!considerTagAsPlainText) + setInlineTagStarted(false); } else { if (!this.lineStarted) { this.textStart = previousPosition; ```
Just bumped into this while working on bug 552012. The patch from Jonas works for one-line examples, but it doesn't fix the problem when opening and closing braces are in separate lines, for example: /** * <pre>{@code * public class X { * int a; * } * }</pre> */ public class MyTest {} In this case the resulting tags structure is this: [0] (TextElement) <pre> [1] (TagElement) {@code public class X int a;} [1.0] (TextElement) public class X [1.1] (TextElement) int a; [2] (TextElement) </pre> The TagElement [1] should have only one TextElement with full text of the @code tag An even more complex case: when one of the lines starts with @ (in Java 11 Javadoc reported errors for this, but not since at least Java 15). /** * <pre>{@code * public class X { * @Deprecated * int a; * } * }</pre> */ Here the structure is wrong at the top level: [0] (TextElement) <pre> [1] (TagElement) {@code public class X } [2] (TextElement) Deprecated [2] (TextElement) int a; [2] (TextElement) } [2] (TextElement) }</pre>
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.