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

查看:504
本文介绍了为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-generator会自动为参数创建"@param"或​​"@return"标签,并在此创建的注释下方直接返回方法的值.

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

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

}

要直接在Android Studio中安装此插件,请执行以下操作:

  1. 打开文件/设置(Mac:AndroidStudio/首选项)
  2. 选择插件
  3. 点击浏览存储库...
  4. 在搜索栏中输入"kdoc-generator"
  5. klick安装
  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天全站免登陆