Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Javadoc have an equivalent to <![CDATA[ ... ]]>?

Unfortunately, there is no CDATA in HTML.

This is a pity, because it would be perfect for adding javadoc comments that include XML, so you don't have to escape the < and >, for example:

/**<![CDATA[ This parses <complexType name=""> ]]>*/

However, it would be possible for javadoc to recognize the CDATA section, and convert it to HTML for you. For example:

This parses &lt;complexType name=""&gt;

Or it could use some simpler syntax than CDATA. Because javadoc is extensible, it's possible someone has added this functionality; or maybe javadoc already has it buried somewhere inside... Does anybody know?

like image 959
13ren Avatar asked Nov 23 '09 09:11

13ren


3 Answers

You can use JavaDoc's @code tag: /** This parses {@code <complexType name="">} */

like image 196
Fabian Steeg Avatar answered Oct 20 '22 10:10

Fabian Steeg


Extending @Fabian's answer, I use both <pre> and {@code ...}. Here an example with XML as source code:

/*Outputs data from a result set to an XML
 * with following structure:
 * <pre>
 * {@code
 * <row>
 *  <FIELD1>gregh</FIELD1>
 *  <FIELD2>487</FIELD2>
 *  <!-- etc. -->
 * </row>
 * <!-- more rows-->
 * }
 * </pre>
 */

<pre> allows you to write code on multiple lines and preserve its structure.

Tested with Eclipse 3.6.1.

like image 33
bluish Avatar answered Oct 20 '22 09:10

bluish


Close and reopen the {@code} tag around the braces to get ${dollar_sign_variables} to render correctly in eclipse despite bug 206319 and bug 206345 and without resorting to full HTML escaping:

/*
 * <pre>
 * {@code
 * <outer>
 *   <inner1>Text</inner1>
 *   <inner2>$}{ "script" }{@code </inner2>
 * </outer>
 * }
 * </pre>
 */

which renders in Eclipse Indigo SR2 (3.7.2) as

<outer>
  <inner1>Text</inner1>
  <inner2>${ "script" }</inner2>
</outer>
like image 8
willkil Avatar answered Oct 20 '22 08:10

willkil