为 Android Studio 中的方法生成 KDoc [英] Generate KDoc for methods in Android Studio

查看:42
本文介绍了为 Android Studio 中的方法生成 KDoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android Studio 中注释Java 方法时,我可以输入/**,AS 会为我生成带有方法参数和返回类型的javadoc.但它似乎不适用于 Kotlin.

有没有什么方法可以教AS自动生成Kotlin KDoc格式的方法文档?

是的,这个问题与可能的重复问题大致相同,但我的问题不是为什么?",我知道 KDoc 有不同的格式.我的问题是是否有办法在 AS 中为 Kotlin 做同样的事情?也许有一种方法可以添加/编辑此模板或类似的东西?

解决方案

自 2019 年 1 月起,Jetbrains 网站上就有了一个名为 kdoc-generator 的插件.

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

<块引用>

用于生成类和方法 KDoc 的插件.

这个生成器的功能与 JavaDoc 完全一样.这意味着当您使用/**"创建注释并按 Enter 键时,kdoc 生成器会自动为参数和方法的返回值创建@param"或​​@return"标签,并直接位于此创建的注释下方.

当你输入/**在您编写的方法上方的文件中,然后按 Enter 键,您会得到类似于以下内容的内容:

/**** @param str* @param 年龄*/有趣的 foo(str: String, age: Int) {}

要直接在 Android Studio 中安装此插件:

  1. 打开文件/设置(Mac:AndroidStudio/首选项)
  2. 选择插件
  3. 点击浏览存储库...
  4. 在搜索栏中输入kdoc-generator"
  5. 点击安装
  6. 重启 Android Studio现在kdoc-generator已经安装好了,可以直接使用了.

此外,Jetbrains 为 Kotlin 开发了一个文档引擎,您可以使用它来将 Kotlin 文件中的文档转换为一些标准格式,例如HTML

https://github.com/Kotlin/dokka

<块引用>

Dokka 是 Kotlin 的文档引擎,执行与 Java 的 javadoc 相同的功能.就像 Kotlin 本身一样,Dokka 完全支持混合语言的 Java/Kotlin 项目.理解Java文件中的标准Javadoc注释和Kotlin文件中的KDoc注释,可以生成标准Javadoc、HTML、Markdown等多种格式的文档.

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?

解决方案

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.

这篇关于为 Android Studio 中的方法生成 KDoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆