How to use @link and @code in kotlin kDoc

I am trying to document a method and trying to use @link and @code , as in JavaDoc .

I know that kotlin has kDoc , but I can not find them or at least something like that.

+38
documentation kotlin kdoc
source share
3 answers

@link and @code do not exist in kDoc, but it can be easily replaced with Inline Markup .

from KotlinDoc Linking Items

Built-in markup

For inline markup, KDoc uses the regular Markdown syntax, extended to support shorthand syntax for binding to other code elements.

Link to items

To refer to another element (class, method, property or parameter) just put your name in square brackets:

Use the [foo] method for this.

If you want to specify a custom label for the link, use the Markdown link style syntax:

Use [this method][foo] for this purpose. You can also use names in links. Note that, unlike JavaDoc, qualified names always use the dot character to separate components, even before the Name method:

Use [kotlin.reflect.KClass.properties] to list the properties of a class. Names in links are resolved using the same rules as the name was used inside the documented element. In particular, this means that if you imported a name into the current file, you do not need to fully qualify it when you use it in a KDoc comment.

Note that KDoc does not have syntax to allow overloading members in links. Since the Kotlin documentation generation tool puts documentation for all function overloads on the same page, the definition of a specific overloaded function is not required to link to work.

+74
source share

You can write your code using Java and convert the class to Kotlin.

 /** * @see <a href="http://somelink.com">link</a> */ public class Some { } 

will be converted to

 /** * @see [link](http://somelink.com) */ class Some 
+5
source share

The answer Arthur gave is generally a good hint, but the result is incorrect. At least IntelliJ IDEA does not produce a result. The markdown link format using []() is suitable for the body of the comment, but not for external links in the @see tag. For them, you need the same syntax as in Java:

 /** * Do something. * * @see <a href="https://stackoverflow.com/q/45195370/2621917">External links in kdoc</a> */ 
+3
source share

All Articles