From 17ef3207c536a9bd5357336977a0c59efcc8daba Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Tue, 5 May 2020 12:09:39 +0200 Subject: Receiver for extension property #809 --- .../kotlin/signatures/KotlinSignatureProvider.kt | 12 +++++ .../documentables/DefaultDocumentableMerger.kt | 3 +- .../documentables/DocumentableVisibilityFilter.kt | 1 + .../DefaultDescriptorToDocumentableTranslator.kt | 1 + .../psi/DefaultPsiToDocumentableTranslator.kt | 1 + plugins/base/src/test/kotlin/model/PropertyTest.kt | 53 ++++++++++++++++++++++ .../out/html/root/[jvm root]/-fancy/index.html | 2 +- 7 files changed, 71 insertions(+), 2 deletions(-) (limited to 'plugins/base') 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 = 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): 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() + 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 List.sampleProperty: T + | get() { TODO() } + """.trimIndent() + ){ + with((this / "property" / "sampleProperty").cast()) { + 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 { + | var List.sampleProperty: T + | get() { TODO() } + | set(value) { TODO() } + | } + """.trimIndent() + ){ + with((this / "property" / "XD" / "sampleProperty").cast()) { + 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 @@ size - +
final val size: Int
-- cgit