diff options
author | Marcin Aman <maman@virtuslab.com> | 2020-05-05 12:09:39 +0200 |
---|---|---|
committer | BarkingBad <32793002+BarkingBad@users.noreply.github.com> | 2020-05-06 12:14:18 +0200 |
commit | 17ef3207c536a9bd5357336977a0c59efcc8daba (patch) | |
tree | 7dfcd4e3f524de1ce673d79fab2afacaa007e25c /plugins/base | |
parent | a09cdf52571c9c93ca3244d2fc92577dee3fae24 (diff) | |
download | dokka-17ef3207c536a9bd5357336977a0c59efcc8daba.tar.gz dokka-17ef3207c536a9bd5357336977a0c59efcc8daba.tar.bz2 dokka-17ef3207c536a9bd5357336977a0c59efcc8daba.zip |
Receiver for extension property #809
Diffstat (limited to 'plugins/base')
7 files changed, 71 insertions, 2 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 7b35c455..30ec38bb 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -89,6 +89,18 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun propertySignature(p: DProperty, platformData: Set<PlatformData> = p.platformData.toSet()) = contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace), platformData = platformData) { + platformText(p.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } + platformText(p.modifier){ it.name + " "} + p.setter?.let { text("var ") } ?: text("val ") + list(p.generics, prefix = "<", suffix = "> ") { + +buildSignature(it) + } + p.receiver?.also { + signatureForProjection(it.type) + text(".") + } + link(p.name, p.dri) + text(": ") signatureForProjection(p.type) } diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt index 4daa4a50..f871cdec 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt @@ -132,7 +132,8 @@ fun DProperty.mergeWith(other: DProperty): DProperty = copy( modifier = modifier.mergeWith(other.modifier), platformData = (platformData + other.platformData).distinct(), getter = getter?.let { g -> other.getter?.let { g.mergeWith(it) } ?: g } ?: other.getter, - setter = setter?.let { s -> other.setter?.let { s.mergeWith(it) } ?: s } ?: other.setter + setter = setter?.let { s -> other.setter?.let { s.mergeWith(it) } ?: s } ?: other.setter, + generics = merge(generics + other.generics, DTypeParameter::mergeWith) ).mergeExtras(this, other) fun DClasslike.setPlatformData(platformData: List<PlatformData>): DClasslike = when (this) { diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt index 36441426..c261d2dc 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilter.kt @@ -163,6 +163,7 @@ internal object DocumentableVisibilityFilter : PreMergeDocumentableTransformer { getter, modifier, filteredPlatforms, + generics.mapNotNull { it.filter(filteredPlatforms) }, extra ) } diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 757a84e1..be18c592 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -275,6 +275,7 @@ private class DokkaDescriptorVisitor( else PlatformDependent.from(platformData, descriptor.modifier()), type = descriptor.returnType!!.toBound(), platformData = listOf(platformData), + generics = descriptor.typeParameters.map { it.toTypeParameter() }, extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) ) } diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index c0e1b4af..e5fa4bfc 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -357,6 +357,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { accessors.firstOrNull { it.returnType == psi.type }?.let { parseFunction(it) }, psi.getModifier().toPlatformDependant(), listOf(platformData), + emptyList(), PropertyContainer.empty<DProperty>() + psi.annotations.toList().toExtra() ) } diff --git a/plugins/base/src/test/kotlin/model/PropertyTest.kt b/plugins/base/src/test/kotlin/model/PropertyTest.kt index 14f7b402..ac055c69 100644 --- a/plugins/base/src/test/kotlin/model/PropertyTest.kt +++ b/plugins/base/src/test/kotlin/model/PropertyTest.kt @@ -188,6 +188,59 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro } } } + + @Test fun genericTopLevelExtensionProperty(){ + inlineModelTest( + """ | val <T : Number> List<T>.sampleProperty: T + | get() { TODO() } + """.trimIndent() + ){ + with((this / "property" / "sampleProperty").cast<DProperty>()) { + name equals "sampleProperty" + with(receiver.assertNotNull("Property receiver")) { + type.name equals "List" + } + with(getter.assertNotNull("Getter")) { + type.name equals "T" + } + setter equals null + generics counts 1 + generics.forEach { + it.name equals "T" + it.bounds.first().name equals "Number" + } + visibility.values allEquals KotlinVisibility.Public + } + } + } + + @Test fun genericExtensionPropertyInClass(){ + inlineModelTest( + """ | package test + | class XD<T> { + | var List<T>.sampleProperty: T + | get() { TODO() } + | set(value) { TODO() } + | } + """.trimIndent() + ){ + with((this / "property" / "XD" / "sampleProperty").cast<DProperty>()) { + name equals "sampleProperty" + children counts 0 + with(receiver.assertNotNull("Property receiver")) { + type.name equals "List" + } + with(getter.assertNotNull("Getter")) { + type.name equals "T" + } + with(setter.assertNotNull("Setter")){ + type.name equals "Unit" + } + generics counts 0 + visibility.values allEquals KotlinVisibility.Public + } + } + } // @Test // fun annotatedProperty() { // checkSourceExistsAndVerifyModel( diff --git a/plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/index.html b/plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/index.html index 1a32310b..de6b4b3b 100644 --- a/plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/index.html +++ b/plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/index.html @@ -67,7 +67,7 @@ <tr class="platform-tagged"> <td class="content"><a href="">size</a></td> <td class="content"> - <div class="platform-hinted" data-platform-hinted="data-platform-hinted"><div class="content" data-active="" data-togglable="jvm"><div class="symbol monospace"><a href="">Int</a></div></div></div> + <div class="platform-hinted" data-platform-hinted="data-platform-hinted"><div class="content" data-active="" data-togglable="jvm"><div class="symbol monospace">final val <a href="">size</a>: <a href="">Int</a></div></div></div> <div class="brief "> </div> </td> <td class="platform-tagged"> |