androidandroid-studiokotlinkdoc

Document template generation kotlin


Working before in Android Studio if before the function I put / ** and hit enter, then I automatically generated the next document with annotations for describing the parameters, the return value, etc.

/**
* @params a
* @return
*/
int f(int a)
{
    return a;
}

When I started working with Kotlin in Android Studio, I tried to generate a similar template, it produces blank template without returns, params, etc.

   /**
    *
    */
    fun f(a: Int)
    {
       return a
    }

I installed Dokka and tried to set it up in Android Stuio, but it did not work. How can I configure the generation of a similar template for Kotlin in Android Studio?


Solution

  • Kotlin and especially KDoc encourage a different documentation style. As stated in this discussion:

    The reason is that we found that referring to parameter names from the documentation text allows to write documentation that is more concise and easier to read compared to the traditional javadoc style where every parameter is documented in a separate tag. Therefore, we do not generate the template with parameter names by default. (D. Jemerov, Kotlin in Action Author)

    Here’s an example of let, which is part of the standard library:

    /**
     * Calls the specified function [block] with `this` value as its argument and returns its result.
     */
    @kotlin.internal.InlineOnly
    public inline fun <T, R> T.let(block: (T) -> R): R