How should a function like Kotlin be documented?

In Kotlin v1.1 +, it is possible to declare type aliases that provide alternative names for existing types. This is especially useful for function types - for example:

typealias OnItemClick = (view: View, position: Int) -> Boolean 

And they can be documented with KDoc comments, like the other participants:

 /** * Type definition for an action to be preformed when a view in the list has been clicked. */ typealias OnItemClick = (view: View, position: Int) -> Boolean 

But is there a specific way to document parameters and the type of the return type of a function?

The Kotlin website contains information on documenting the Kotlin code , but does not mention types.

Like the functions themselves, it would be nice if the types of functions could be documented as follows:

 /** * @param view the view that was clicked * @param position the layout position from the ViewHolder (see [ViewHolder.getLayoutPosition]) * @return whether the click was successful */ typealias OnItemClick = (view: View, position: Int) -> Boolean 

But tags are not recognized in KDoc.

So, how should parameters and return types be documented?

+5
source share
1 answer

Unfortunately, there is currently no special support in KDoc for documenting parameters and return values ​​for type types for function types, so you just need to describe them as part of the documentation. I added a feature request to add support.

+4
source

Source: https://habr.com/ru/post/1275820/


All Articles