Is javadoc {@Code {@link}} tag nesting allowed?

I am trying to put a link inside a code tag in javadoc. Below is my attempt.

/** * This method builds XML. * <pre> * {@code * <Person {@link #companyId}='1234'/> * } * </pre> **/ 

But there is no link in the generated Javadoc. The string {@link #companyId}='1234' matches as is.

  • Is javadoc tag nesting allowed?
  • Is there a way to add links to the code?
+4
source share
2 answers

It depends on the tag. The tag {@code ...} interprets its contents as is, i.e. Avoids any interpretation of content like Javadoc or HTML. This is similar to the contents of the {@link ... } tag.

Here is a workaround:

 /** * This method builds XML. * <pre> * {@code <Person }{@link #companyId}{@code ='1234'/>} * </pre> **/ 
+4
source

In eclipse, at least it works to use any of the following, depending on whether you want additionally encoded text before or after the link.

 {@code {@link foo} {@code {@link foo} {@code bar} {@code baz}{@code {@link foo} {@code baz}{@code {@link foo} {@code bar} 

For this to work, you need unsurpassed braces and separate @code annotations. If you don't want a space between foo and bar in javadoc, you can remove the space before the last @code , although this cannot be done for the space between baz and foo .

The JavaDoc parser, which eclipse successfully uses, converts it into a link with code formatting, so it is good, at least for temporary use. However, this is not entirely best practice and may be changed in the future, so you should probably use the Paulo solution if you write code that will continue in a year.

0
source

Source: https://habr.com/ru/post/1382221/


All Articles