鍍金池/ 問答/Android  網(wǎng)絡(luò)安全/ AndroidStudio Kotlin注釋生成問題

AndroidStudio Kotlin注釋生成問題

當(dāng)我使用AndroidStudio 3.0Kotlin代碼的時候,在方法上面添加注釋,為什么不會自動生成一些參數(shù)例如:

正常的Java方法注釋:

    /**
     * 顯示吐司
     *
     * @param text     文本
     * @param duration 顯示時長
     */
    private static void showToast(CharSequence text, int duration) {
         ···
         ···
    }

Kotlin的注釋,不會自動生成 @param 這些參數(shù)

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

請問怎么辦?

回答
編輯回答
何蘇葉

簡單的使用方法沒有
java doc是 setting -> editor -> general -> smart keys -> insert documentation comment stub 帶來的 是android studio(intellij idea)自帶的功能
kotlin是通過plugin支持的,原則上是第三方插件 所以需要這種功能的話只能是自己開發(fā),或者找github有沒有開源項目支持了


補(bǔ)充:
剛剛在官網(wǎng) 文檔中看到這么一段 https://kotlinlang.org/docs/r...
可以用于解釋為什么沒有自動生成params 和 return

官網(wǎng)的說明是:

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) = ...

大概意思是:應(yīng)該將參數(shù)結(jié)合到文檔的過程中結(jié)合上下文描述來說明參數(shù)的作用

類似于 這樣 Returns the absolute value of the given [number].
使用中括號包裹參數(shù)名稱的語法

2017年4月1日 13:30