32

In Java's Javadoc, there is a way to inherit a method's documentation in a subclass using {@inheritDoc} tag.

Is there a way to do the same in Kotlin's KDoc?

Basically, what I'd like to do is the following:

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() { /* ... */ }
}
hotkey
  • 140,743
  • 39
  • 371
  • 326
  • Does `{@inheritDoc}` not work? Did you try it? – CaseyB Mar 03 '16 at 16:04
  • 1
    @CaseyB, yes, I did, and neither IntelliJ nor dokka understands it, they just show it as text. – hotkey Mar 03 '16 at 16:09
  • 2
    I can't find anything documenting my finding but from what I can tell Kotlin Doc inherits the documentation when overriding a function if no documentation is specified on the override. Now what I'm wondering is how to "extend"/"include" the base documentation... – mfulton26 Mar 03 '16 at 16:11
  • @mfulton26, OK, now I see that dokka inserts the parent's docs by default. It will be great if you find a way to customize them, but just inheriting them would suffice for me. – hotkey Mar 03 '16 at 16:51
  • @hotkey I did look through https://github.com/Kotlin/dokka but didn't find anything useful. You might create a GitHub issue or a Kotlin YouTrack issue to inquire about such. – mfulton26 Mar 03 '16 at 17:04

1 Answers1

34

Dokka always copies the documentation from a base member to an inherited one if the inherited member does not have its own documentation. There is no way to combine the base member documentation with additional text provided in the inherited member.

(Dokka doesn't support the @inheritdoc Javadoc tag because this inevitably leads to the proliferation of comments consisting of only /** @inheritdoc */ which I find super useless and redundant.)

yole
  • 92,896
  • 20
  • 260
  • 197
  • 12
    Yet for some reason when I hit `Ctrl + Q` on an inherited function with no documentation, it doesn't show any, however the base function does have it specified and when I `Ctrl + B` to it and hit `Ctrl + Q` on a base function, documentation is shown. Maybe this is some ide-plugin bug. – dimsuz Jun 04 '16 at 22:29
  • 7
    @yole When I hit the quick documentation shortcut on an overridden method from a java class/interface, I see no documentation while the base class/interface has some documentation. This is really inconvenient. Is there an open issue on that? – Louis CAD Feb 16 '17 at 08:05
  • 3
    @LouisCAD It looks like there is. See https://youtrack.jetbrains.com/issue/KT-25035 – MariusVolkhart Jun 24 '20 at 09:39
  • Just FYI, on android studio when I hover over an inherited property, it does show the documentation from the base property. – Dhunju_likes_to_Learn Apr 19 '22 at 22:33