AndroidStudio Kotlin注释生成问题

发布于 2022-09-06 15:28:40 字数 566 浏览 15 评论 0

当我使用AndroidStudio 3.0Kotlin代码的时候,在方法上面添加注释,为什么不会自动生成一些参数例如:

正常的Java方法注释:

    /**
     * 显示吐司
     *
     * @param text     文本
     * @param duration 显示时长
     */
    private static void showToast(CharSequence text, int duration) {
         ···
         ···
    }

Kotlin的注释,不会自动生成 @param 这些参数

    /**
     * 
     */
    fun showToast(text : CharSequence, duration : Int) {
         ···
         ···
    }

请问怎么办?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫烠⑼条掵仅有一顆心 2022-09-13 15:28:40

简单的使用方法没有
java doc是 setting -> editor -> general -> smart keys -> insert documentation comment stub 带来的 是android studio(intellij idea)自带的功能
kotlin是通过plugin支持的,原则上是第三方插件 所以需要这种功能的话只能是自己开发,或者找github有没有开源项目支持了


补充:
刚刚在官网 文档中看到这么一段 https://kotlinlang.org/docs/r...
可以用于解释为什么没有自动生成params 和 return

官网的说明是:

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

// Avoid doing this:

/**
 * 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:

/**
 * Returns the absolute value of the given [number].
 */
fun abs(number: Int) = ...

大概意思是:应该将参数结合到文档的过程中结合上下文描述来说明参数的作用

类似于 这样 Returns the absolute value of the given [number].
使用中括号包裹参数名称的语法

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文