Trickzter
Trickzter

Reputation: 471

Kotlin static field value in method documentation?

I was wondering if there is a possibility to include the value of a static field of a class into the documentation of a class method.

We can link class members and parameters via square brackets:

/**
 * Sets the title of the notification dialog using [title]
 *
 * The maximum title length allowed is [MAX_TITLE_LENGTH]
 */
fun setTitle(title: String): NotificationDialog.Builder {
    if(title.length <= MAX_TITLE_LENGTH)
        mTitle = title
    else
        mTitle = title.substring(0, MAX_TITLE_LENGTH)

    return this
}

Goal

But I would like to have the value of MAX_TITLE_LENGTH in the method documentation and not a link to its name.

For the sake of completeness here is my class definition:

class Builder(val context: Context) {
    private var mTitle = ""

    /**
     * Sets the title of the notification dialog using [title]
     *
     * The maximum title length allowed is [MAX_TITLE_LENGTH]
     */
    fun setTitle(title: String): NotificationDialog.Builder {
        if(title.length <= MAX_TITLE_LENGTH)
            mTitle = title
        else
            mTitle = title.substring(0, MAX_TITLE_LENGTH)

        return this
    }

    fun build(): NotificationDialog {
        return NotificationDialog(context, mTitle)
    }

    companion object {
        private const val MAX_TITLE_LENGTH = 20
    }
}

Thanks in advance.

Upvotes: 5

Views: 732

Answers (1)

mregulski
mregulski

Reputation: 170

There is nothing like this, because KDoc is based on markup language. Instead of this, using brackets allows you to link between properties of class. See more here: https://kotlinlang.org/docs/reference/kotlin-doc.html#inline-markup

Upvotes: 0

Related Questions