Generating Kotlin method/class comments
您如何为您的方法/类生成注释? 只需输入:
1 | /** |
而且在IntelliJ IDEA 2016.1.3中似乎无法按回车键
似乎Dokka取代了KDoc,但是为什么IntelliJ中不提供支持? 还是我错过了什么?
说明:输入/ ** + enter时,将生成:
1 2 3 | /** * */ |
但是我想知道为什么没有添加@param和其他参数的生成(就像IntelliJ一样适用于Java)。 这些注释也用于记录Kotlin代码(https://kotlinlang.org/docs/reference/kotlin-doc.html)
为了扩展@yole的答案和@Charles A.的评论,这里是创建KDocs时首选格式的完整说明以及它与JavaDocs的区别。
Kotlin文档在这里:
https://kotlinlang.org/docs/reference/coding-conventions.html#documentation-comments
...说:
Generally, avoid using @param and @return tags. Instead, incorporate the description of parameters and return values directly into the documentation comment, and add links to parameters wherever they are mentioned. Use @param and @return only when a lengthy description is required which doesn't fit into the flow of the main text.
Avoid doing this:
1
2
3
4
5
6 /**
* 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) = ...Do this instead:
1
2
3
4 /**
* Returns the absolute value of the given [number].
*/
fun abs(number: Int) = ...