Hi, I am writing custom DokkaPlugin. And was wonde...
# dokka
j
Hi, I am writing custom DokkaPlugin. And was wondering, is there way to get default value of field from
DProperty
? For example:
Copy code
class Color{
 var r:Int = 250
}
How to get that
250
value?
m
AFAIK this should be a `org.jetbrains.dokka.model.DefaultValue`in extra properties Consider following tests: https://github.com/Kotlin/dokka/blob/d6c798e44381fd436a264229f94f19528382c136/plugins/base/src/test/kotlin/model/FunctionsTest.kt#L335
Also: if you would like to share your plugin with the community consider adding it here: https://kotlin.github.io/dokka/1.4.10.2/community/plugins-list/
j
@Marcin Aman Thanks so much
@Marcin Aman Looks like
DefaultValue
is using just as
extra
for
DParameter
. And for
DProperty
it's not used.
m
Hmm they should be gathered also for DProperty, i can do
val sample = 1
and in DProperty i get "1" as default value. Could you give me an example on which you are testing? Maybe something else is wrong
j
So there are two variants: 1)
Copy code
class Color (var r:Int = 250)
In this case from constructor I can get
DParameter
with
extra
where
defaultValue
will be 250. 2)
Copy code
class Color {var r:Int = 250}
In this case I have
DProperty
with
extra
but no
DefaultValue
there.
I also checked source code and found that
DefaultValue
instance is creating only for parameter:
Знімок екрана 2020-11-18 о 15.26.26.png
In the bottom you can see that there is no
defaultValue
in
extra
for code:
Copy code
class ColorTest {
    val r: Int = 1
}
Знімок екрана 2020-11-18 о 15.35.53.png
m
Not gonna lie i find it very strange that you don't have those values, which version of dokka are you using? Or maybe can you share your project so i'll try to help you on it? Imho they are gathered also for the `DParameter`: https://github.com/Kotlin/dokka/blob/1959b914c0838be814d45f617517ac73fa33cd47/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt#L442
j
Thank you so much for your reply. The problem is in version. I am using
1.4.0
😅. And for
DProperty
DefaultValue
was added in
1.4.10.2
. Thanks so much😊
❤️ 1