在Java的Javadoc中,有一种方法可以使用{@inheritDoc}
标记在子类中继承方法的文档.
有没有办法在Kotlin的KDoc中做同样的事情?
基本上,我想做的是以下内容:
abstract class Base {
/**
* Some KDoc documentation here.
*/
abstract fun foo()
}
class Derived: Base() {
/**
* Here is all the documentation from Base#foo's KDoc inherited.
*
* And here goes something more in addition.
*/
override fun foo() { /* ... */ }
}
Run Code Online (Sandbox Code Playgroud) 对于两种给定的方法:
/**
* Adds a [DataItem] to the Android Wear network. The updated item is synchronized across all devices.
*/
fun putItem(){ .... }
/**
* "same KDOC here with above"
*/
fun putItem(putRequest: PutDataRequest){ .... }
Run Code Online (Sandbox Code Playgroud)
有没有可能复制/链接第二种方法的文档与第一种方法相同?
手动复制粘贴KDOC并不是那么好,因为如果你更新其中一个,很有可能第二个意外地过时.
我正在尝试使用Dokka插件为Android Kotlin应用程序生成Javadoc.我将插件添加到我的gradle中:
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.15"
Run Code Online (Sandbox Code Playgroud)
然后我按照项目说明进行了基本配置:
dokka {
outputFormat = 'javadoc'
outputDirectory = "$rootDir/docs"
skipEmptyPackages = true
noStdlibLink = true
}
Run Code Online (Sandbox Code Playgroud)
我使用基本的gradle命令生成文档:
[user@linux AppDir]$ bash gradlew dokka
Run Code Online (Sandbox Code Playgroud)
输出很好,但它包括我添加到项目中的android或插件的多个目录,例如:
android.R
android.support
com.google
com.crashlytics
.
.
.
etc.
Run Code Online (Sandbox Code Playgroud)
我如何跳过这些包裹?有没有办法只为我的/ app/scr/java文件夹和我创建的文件生成dock?任何帮助表示赞赏.
我如何将(经过测试的、非陈旧的)代码示例包含到 Dokka 包文档中?
更具体地说,假设我的以下配置中有此配置build.gradle.kts
:
withType<DokkaTask> {
outputFormat = "html"
outputDirectory = "$buildDir/documentation"
includes = listOf("packageDocumentation.md")
samples = listOf("$rootDir/src/test/kotlin/some/project/TheSamples.kt")
}
Run Code Online (Sandbox Code Playgroud)
然后是一些测试代码:
package some.project
import org.junit.jupiter.api.Test
class TheSamples {
@Test
fun helloWorldSample() {
println("hello, world")
}
}
Run Code Online (Sandbox Code Playgroud)
还有一个包文档 Markdown 文件:
# Package some.project
This is the documentation for some package.
@sample some.project.TheSamples#helloWorldSample
Run Code Online (Sandbox Code Playgroud)
,如何将println(...)
-part包含到文档中?当前版本的 Dokka 是否完全支持它?
交换#
的.
或更换@sample
由@includeFunction
什么也没做。
此外:
假设有一个类主要构造函数具有param
我想要在类的doc块中解析(链接到实际参数)的参数.
/** Class A does something using [param].
@constructor constructs A with [param].
*/
class A (param: Int)
Run Code Online (Sandbox Code Playgroud)
但是,param
IDE会突出显示题词,表示无法解析符号param
.
在Java中,如果要记录包,则必须将其放入package-info.class文件中.对于Kotlin和KDoc来说,这仍然是一回事吗?我查看了一些Kotlin源代码,无法找到编写包文档的位置.
我正在尝试生成我的项目的Doka文档。在生成时,出现了上述错误。我搜索了很多,但无法获得解决方案。我也通过这个链接。在这里说这可能是与匕首有关的问题。我也尝试了所有这些解决方案,但不适用于我。我将所有Gradle文件发布在此处,以进行进一步说明。如果有人遇到此问题或知道解决方法,请发表评论。
项目摇篮:
buildscript {
ext.kotlin_version = '1.3.20'
ext.dokkaVersion = '0.9.17'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokkaVersion"
classpath "org.jetbrains.kotlin:kotlin-allopen:1.3.20"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
应用程式摇篮:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'org.jetbrains.dokka-android'
android { …
Run Code Online (Sandbox Code Playgroud) object
我的项目中有类似以下内容
object UrlUtils {
private const val PARAM = "whatever"
/**
* Method that appends the [PARAM] parameter to the url
*/
fun appendParameter(url: String) {
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我想PARAM
在方法的 KDoc 注释中引用字段的值appendParameter
,但是在查看注释时,我看不到实际值,而只看到字段的名称。
将 PARAM 参数附加到 url 的方法
我想要的是:
将whatever参数附加到url的方法
在 Javadoc 中,这是通过使用来实现的{@value PARAM}
,但在 KDoc 中似乎没有类似的东西。甚至自动代码转换器也保留旧的 Javadoc。
所以我的问题是:我是否遗漏了什么,或者 KDoc/Dokka 是否缺少此功能?
我正在编写一个以 lambda 作为参数的 Kotlin 函数,例如
fun someFunction( param1: (value1: Boolean, value2: Boolean) -> Unit )
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法将函数记录为输入,以便我可以参考value1
或value2
在文档中?
到目前为止做
/**
* Documentation for someFunction
* @param param1 Takes a function where [value1] is some value
*/
fun someFunction( param1: (value1: Boolean, value2: Boolean) -> Unit )
Run Code Online (Sandbox Code Playgroud)
没有奏效,dokka 将无法构建文档。