生成Kotlin方法/类注释

Den*_*out 21 comments intellij-idea kotlin

如何为您的方法/类生成注释?只需输入:

/**
Run Code Online (Sandbox Code Playgroud)

并且推入输入似乎在IntelliJ IDEA 2016.1.3中不起作用

似乎Dokka取代了KDoc,但为什么IntelliJ没有支持?或者我错过了什么?

澄清:当输入/**+输入时,会生成:

/**
 *
 */
Run Code Online (Sandbox Code Playgroud)

但我想知道为什么没有添加@param和其他的代(就像IntelliJ对Java一样).这些注释也用于记录Kotlin代码(https://kotlinlang.org/docs/reference/kotlin-doc.html)

yol*_*ole 16

@param和其他标记也不会产生因为科特林推荐文档风格是使用引用参数名称从文档注释文本[foo]语法,而不是使用显式记录他们@param的标签.您可以查看Kotlin标准库文档以了解如何使用此样式.

  • @Daksh为了它的价值,我发现那些文件正在引用[这里](https://kotlinlang.org/docs/reference/coding-conventions.html#documentation-comments). (5认同)
  • 那么为什么 [Documenting Kotlin Code](https://kotlinlang.org/docs/reference/kotlin-doc.html) 页面会有所有可用标签的列表?我真的在这里错过了什么吗? (2认同)

Sea*_*eau 11

要扩展@ yole的答案和@Charles A.的评论,这里是创建KDocs时首选格式的完整解释,以及它与JavaDocs的区别.

这里的Kotlin文档:

https://kotlinlang.org/docs/reference/coding-conventions.html#documentation-comments

...说:

通常,请避免使用@param和@return标记.相反,将参数描述和返回值直接合并到文档注释中,并在参数的任何位置添加链接.仅当需要冗长的描述且不适合主文本流时才使用@param和@return.

避免这样做:

/**
 * Returns the absolute value of the given number.
 * @param number The number to return the absolute value for.
 * @return The absolute value.
 */
fun abs(number: Int) = ...
Run Code Online (Sandbox Code Playgroud)

改为:

/**
 * Returns the absolute value of the given [number].
 */
fun abs(number: Int) = ...
Run Code Online (Sandbox Code Playgroud)