Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use @link and @code in kotlin kDoc

I'm trying to document a method and trying to use @link and @code as in JavaDoc.

I know in kotlin there is a kDoc but I can't find them or at least something similar.

like image 659
humazed Avatar asked Jul 19 '17 15:07

humazed


People also ask

What is KDoc in Kotlin?

The language used to document Kotlin code (the equivalent of Java's Javadoc) is called KDoc. In its essence, KDoc combines Javadoc's syntax for block tags (extended to support Kotlin's specific constructs) and Markdown for inline markup.

How do I comment with Kotlin code?

Single-line comments starts with two forward slashes ( // ). Any text between // and the end of the line is ignored by Kotlin (will not be executed).


1 Answers

@link and @code doesn't exist in kDoc but can easily be replaced by Inline Markup.

from KotlinDoc Linking to Elements

Inline Markup

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

Linking to Elements

To link to another element (class, method, property or parameter), simply put its name in square brackets:

Use the method [foo] for this purpose.

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

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

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

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

like image 107
humazed Avatar answered Oct 16 '22 13:10

humazed