How to use @link and @code in kotlin kDoc Ask Question

How to use @link and @code in kotlin kDoc Ask Question

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.

ベストアンサー1

@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:

この目的に使用します[this method][foo]。リンクでは修飾名を使用することもできます。JavaDoc とは異なり、修飾名では、メソッド名の前でも、常にドット文字を使用してコンポーネントを区切ることに注意してください。

[kotlin.reflect.KClass.properties]クラスのプロパティを列挙するために使用します。リンク内の名前は、ドキュメント化されている要素内で名前が使用されている場合と同じルールを使用して解決されます。特に、これは、現在のファイルに名前をインポートした場合、KDoc コメントで使用するときに名前を完全に修飾する必要がないことを意味します。

KDoc には、リンク内のオーバーロードされたメンバーを解決するための構文がないことに注意してください。Kotlin ドキュメント生成ツールは、関数のすべてのオーバーロードのドキュメントを同じページに配置するため、リンクが機能するために特定のオーバーロードされた関数を識別する必要はありません。

おすすめ記事