I'm trying to document a method and trying to use @link
and @code
as in JavaDoc.
I know in kotlin there is a kDoc but I can't find them or at least something similar.
Sample how to leave links for classes:
/**
* [YourClass] Methods
* */
also with method calls
/**
* [YourClass.someMothod] Methods
* */
Real example:
/**
* [BaseActivity] Methods
* */
override fun initVars() {
//Just Sample
}
/**
* [MainContract.View] - Overrides
* */
override fun handleConnectionMassage(isShow: Boolean) {
//Just Sample
}
The answer that Artur gave is a good hint in general, but the result is wrong. At least IntelliJ IDEA does not grok the result. The markdown link format using []()
is fine in the main comment text, but not for external links in the @see
tag. For those, you need the same syntax as in Java:
/**
* Do something.
*
* @see <a href="https://stackoverflow.com/q/45195370/2621917">External links in kdoc</a>
*/
I struggled with this for a bit with Android Studio 3.5.2 on Mac. This worked for me:
/**
* [Your fully-qualified class name.function name]
*/
If I didn't use the fully-qualified name Kdoc would complain that it was a unresolved reference. What I couldn't figure out is how to actually use the link itself. For that you need to press and hold the COMMAND key (on Mac) and then the links would be active.
As for the @code
you should use Markdown syntax (cause KDoc is an extended version of Markdown):
To produce a code block in Markdown, simply indent every line of the block by at least 4 spaces or 1 tab.
/**
* Some code sample:
*
* Set<String> s;
* System.out.println(s);
*/
class Scratch
You can write your code with java and convert class into Kotlin.
/**
* @see <a href="http://somelink.com">link</a>
*/
public class Some {
}
will be converted to
/**
* @see [link](http://somelink.com)
*/
class Some
To reference a method use the class:
/**
* When the configuration succeeds **[MyCallback.onConfigured]** is called.
*/
class MyClass(myCallback: MyCallback) {
Using a variable/parameter does not work:
/**
* When the configuration succeeds **[myCallback.onConfigured]** is called.
*/
class MyClass(myCallback: MyCallback) {
@link
and@code
doesn't exist in kDoc but can easily be replaced by Inline Markup.from KotlinDoc Linking to Elements