Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document a primary constructor parameter with Kotlin Dokka

Let's say there's a class which primary constructor has the parameter param that I'd like to be resolved (linked to the actual parameter) within the doc block of the class.

/** Class A does something using [param]. 
@constructor constructs A with [param].
*/
class A (param: Int)

However, the inscription param is highlighted by the IDE saying that it cannot resolve symbol param.

like image 1000
Markus Marvell Avatar asked Sep 19 '17 09:09

Markus Marvell


People also ask

Does Javadoc work with Kotlin?

The language used to document Kotlin code (the equivalent of Java's Javadoc) is called KDoc. In its essence, KDoc combines Javadoc's syntax for block tags (extended to support Kotlin's specific constructs) and Markdown for inline markup.

How do you use a constructor parameter in Kotlin?

The primary constructor is initialized in the class header, goes after the class name, using the constructor keyword. The parameters are optional in the primary constructor. The constructor keyword can be omitted if there is no annotations or access modifiers specified.

How do you pass a context in a constructor in Kotlin?

Define an interface with the same factory function and two objects for the scopes. Define a function that takes the scope and the initializer block. Now you can use the useScope -Function and within the block the right factory function is invoked. Save this answer.


1 Answers

Actually, dokka correctly finds the parameter if you reference it with [param] in the @constructor paragraph, you can check that by inspecting the URL that appears in the assembled docs, which looks like:

file:///.../some.package/-a/-init-.html#some.package.A$<init>(kotlin.Int)/param

Seemingly, the warning about an unresolved reference is an issue with the IDE support for KDoc. Please report it at kotl.in/issue.

Another option is to use @param in the class KDoc:

/** 
 * Class A does something using [param]. 
 * @param param means something special.
*/
class A (param: Int)
like image 133
hotkey Avatar answered Oct 21 '22 19:10

hotkey