Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate KDoc for methods in Android Studio [closed]

When commenting methods for Java in Android Studio, I can type /** and AS generates javadoc with method parameters and return type for me. But it seems it doesn't work for Kotlin.

Is there some way to teach AS to generate method docs in Kotlin KDoc format automatically?

Edit: yes, this question is about the same thing as the possible duplicate, but my question isn't "why?", I understand that KDoc has different format. My question is if there is a way to do the same for Kotlin in AS? Maybe there is a way to add/edit this template or something like this?

like image 456
Georgiy Shur Avatar asked Nov 13 '16 13:11

Georgiy Shur


People also ask

What is Dokka in Android?

Dokka is a documentation engine for Kotlin, performing the same function as javadoc for Java. Just like Kotlin itself, Dokka fully supports mixed-language Java/Kotlin projects.

What is KDoc 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 I add documents to Kotlin?

Documenting Modules and Packages KDoc also supports documenting a package or a module using a custom markdown file. Open module.md in the app module. Replace the contents of the file (the TODO:4 line) with the following: # Module notktx-app ## Description This adds a custom module-level description for the app module.

How do you comment a function on Kotlin?

Kotlin Multi-line Comments A multi-line comment in Kotlin starts with /* and end with */. So any text written in between /* and */ will be treated as a comment and will be ignored by Kotlin compiler. Multi-line comments also called Block comments in Kotlin.


2 Answers

Since January 2019, there is a plugin on the Jetbrains website called kdoc-generator.

https://plugins.jetbrains.com/plugin/10389-kdoc-generator

Plugin to generate class and method KDoc.

This generator functions exactly like JavaDoc. That means when you create a commentary with "/**" and press enter, the kdoc-generator creates automatically "@param" or "@return" tags for the parameter and return values of the method directly below this created commentary.

When you type /** in your file above a method you wrote and then press enter you get something similar to this:

/**  *  * @param str   * @param age  */ fun foo(str: String, age: Int) {  } 

To install this Plugin directly in Android Studio:

  1. open File/Settings (Mac: AndroidStudio/Preferences)
  2. choose Plugins
  3. click Browse repositories...
  4. enter "kdoc-generator" in searchbar
  5. klick Install
  6. restart Android Studio Now the kdoc-generator is installed and you can use it directly.

Additionally Jetbrains developed a documentation engine for Kotlin, that you can use to convert your documentation in Kotlin files to some standard formats, e.g. HTML

https://github.com/Kotlin/dokka

Dokka is a documentation engine for Kotlin, performing the same function as javadoc for Java. Just like Kotlin itself, Dokka fully supports mixed-language Java/Kotlin projects. It understands standard Javadoc comments in Java files and KDoc comments in Kotlin files, and can generate documentation in multiple formats including standard Javadoc, HTML and Markdown.

like image 100
Shorxy Avatar answered Nov 13 '22 18:11

Shorxy


As this is most likely a bug with IntelliJ, I've taken the liberty of filing a bug report here. You can choose to watch this issue to get notified of any updates.

like image 43
Andrew Orobator Avatar answered Nov 13 '22 20:11

Andrew Orobator