diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-08-18 13:18:22 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-08-20 15:36:07 +0200 |
commit | 54df62709a37fc8f55bded26fd5db15f9eb0fd25 (patch) | |
tree | 347eb9eff50fdcc2a260f00c42989e0c7e4d1aff /plugins | |
parent | a9be511b052755258bc92225c4f5a8977f174b89 (diff) | |
download | dokka-54df62709a37fc8f55bded26fd5db15f9eb0fd25.tar.gz dokka-54df62709a37fc8f55bded26fd5db15f9eb0fd25.tar.bz2 dokka-54df62709a37fc8f55bded26fd5db15f9eb0fd25.zip |
Hide unused generic type variables in constructor
Diffstat (limited to 'plugins')
9 files changed, 36 insertions, 14 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt index 689f6db5..0defc69e 100644 --- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -6,6 +6,8 @@ import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet +import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.driOrNull +import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.drisOfAllNestedBounds interface JvmSignatureUtils { @@ -133,6 +135,10 @@ interface JvmSignatureUtils { it.dri == DRI("kotlin", "Deprecated") || it.dri == DRI("java.lang", "Deprecated") } == true) setOf(TextStyle.Strikethrough) else emptySet() + + infix fun DFunction.uses(t: DTypeParameter): Boolean = + t.dri in (listOfNotNull(receiver?.type?.drisOfAllNestedBounds, receiver?.dri) + + parameters.flatMap { listOf(it.dri) + it.type.drisOfAllNestedBounds }) } sealed class AtStrategy diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 16598acd..823e1e8f 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -15,7 +15,6 @@ import org.jetbrains.dokka.pages.ContentKind import org.jetbrains.dokka.pages.ContentNode import org.jetbrains.dokka.pages.TextStyle import org.jetbrains.dokka.utilities.DokkaLogger -import java.lang.IllegalStateException import kotlin.text.Typography.nbsp class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider, @@ -240,7 +239,8 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog ) text(f.modifiers()[it]?.toSignatureString() ?: "") text("fun ") - list(f.generics, prefix = "<", suffix = "> ") { + val usedGenerics = f.generics.filter { f uses it } + list(usedGenerics, prefix = "<", suffix = "> ") { +buildSignature(it) } f.receiver?.also { @@ -317,7 +317,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog p: Projection, showFullyQualifiedName: Boolean = false ): Unit = when (p) { - is TypeParameter -> link(p.name, p.declarationDRI) + is TypeParameter -> link(p.name, p.dri) is TypeConstructor -> if (p.function) +funType(mainDRI.single(), mainSourcesetData, p) diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt index 193b41e1..e8107177 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt @@ -35,7 +35,7 @@ object KotlinSignatureUtils : JvmSignatureUtils { val Bound.driOrNull: DRI? get() { return when (this) { - is TypeParameter -> this.declarationDRI + is TypeParameter -> this.dri is TypeConstructor -> this.dri is Nullable -> this.inner.driOrNull is PrimitiveJavaType -> this.dri @@ -45,4 +45,18 @@ object KotlinSignatureUtils : JvmSignatureUtils { is UnresolvedBound -> null } } + + val Projection.drisOfAllNestedBounds: List<DRI> get() = when (this) { + is TypeParameter -> listOf(dri) + is TypeConstructor -> listOf(dri) + projections.flatMap { it.drisOfAllNestedBounds } + is Nullable -> inner.drisOfAllNestedBounds + is PrimitiveJavaType -> listOf(dri) + is Void -> listOf(DriOfUnit) + is JavaObject -> listOf(DriOfAny) + is Dynamic -> emptyList() + is UnresolvedBound -> emptyList() + is Variance -> inner.drisOfAllNestedBounds + is Star -> emptyList() + } + } diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ExtensionExtractorTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ExtensionExtractorTransformer.kt index 6ce6e396..af65c205 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/ExtensionExtractorTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/ExtensionExtractorTransformer.kt @@ -91,7 +91,7 @@ private fun Callable.asPairsWithReceiverDRIs(): Sequence<Pair<DRI, Callable>> = private fun Callable.findReceiverDRIs(bound: Bound): Sequence<DRI> = when (bound) { is Nullable -> findReceiverDRIs(bound.inner) is TypeParameter -> - if (this is DFunction && bound.declarationDRI == this.dri) + if (this is DFunction && bound.dri == this.dri) generics.find { it.name == bound.name }?.bounds?.asSequence()?.flatMap(::findReceiverDRIs).orEmpty() else emptySequence() diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 9584d35a..b172cebc 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -603,11 +603,11 @@ private class DokkaDescriptorVisitor( is DynamicType -> Dynamic else -> when (val ctor = constructor.declarationDescriptor) { is TypeParameterDescriptor -> TypeParameter( - declarationDRI = DRI.from(ctor.containingDeclaration).withPackageFallbackTo(fallbackPackageName()), + dri = DRI.from(ctor).withPackageFallbackTo(fallbackPackageName()), name = ctor.name.asString() ) else -> TypeConstructor( - DRI.from(constructor.declarationDescriptor!!), // TODO: remove '!!' + DRI.from(ctor!!), // TODO: remove '!!' arguments.map { it.toProjection() }, if (isExtensionFunctionType) FunctionModifiers.EXTENSION else if (isFunctionType) FunctionModifiers.FUNCTION diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 8dee2478..c9118920 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -360,9 +360,9 @@ class DefaultPsiToDocumentableTranslator( ?: return UnresolvedBound(type.presentableText) when { resolved.qualifiedName == "java.lang.Object" -> JavaObject - resolved is PsiTypeParameter && resolved.owner != null -> + resolved is PsiTypeParameter -> TypeParameter( - declarationDRI = DRI.from(resolved.owner!!), + dri = DRI.from(resolved), name = resolved.name.orEmpty() ) else -> diff --git a/plugins/base/src/test/kotlin/basic/DRITest.kt b/plugins/base/src/test/kotlin/basic/DRITest.kt index 353991ba..ba40a200 100644 --- a/plugins/base/src/test/kotlin/basic/DRITest.kt +++ b/plugins/base/src/test/kotlin/basic/DRITest.kt @@ -271,7 +271,7 @@ class DRITest : AbstractCoreTest() { val foo = sampleInner.children.first { it.name == "foo" } as MemberPageNode val documentable = foo.documentable as DFunction - assertEquals(sampleClass.dri.first().toString(), (documentable.type as TypeParameter).declarationDRI.toString()) + assertEquals(sampleClass.dri.first().toString(), (documentable.type as TypeParameter).dri.toString()) assertEquals(0, documentable.generics.size) } } diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/signatures/JavadocSignatureProvider.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/signatures/JavadocSignatureProvider.kt index cda7345a..96616794 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/signatures/JavadocSignatureProvider.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/signatures/JavadocSignatureProvider.kt @@ -95,7 +95,8 @@ class JavadocSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLo modifiers { text(f.modifier[it]?.takeIf { it !in ignoredModifiers }?.name?.plus(" ") ?: "") text(f.modifiers()[it]?.toSignatureString() ?: "") - list(f.generics, prefix = "<", suffix = "> ") { + val usedGenerics = f.generics.filter { f uses it } + list(usedGenerics, prefix = "<", suffix = "> ") { +buildSignature(it) } signatureForProjection(f.type) @@ -184,7 +185,7 @@ class JavadocSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLo } private fun PageContentBuilder.DocumentableContentBuilder.signatureForProjection(p: Projection): Unit = when (p) { - is TypeParameter -> link(p.name, p.declarationDRI) + is TypeParameter -> link(p.name, p.dri) is TypeConstructor -> group { link(p.dri.classNames.orEmpty(), p.dri) list(p.projections, prefix = "<", suffix = ">") { diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt index efb7b739..b15e1a0d 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -122,7 +122,8 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge signatureForProjection(returnType) text(nbsp.toString()) link(f.name, f.dri) - list(f.generics, prefix = "<", suffix = ">") { + val usedGenerics = f.generics.filter { f uses it } + list(usedGenerics, prefix = "<", suffix = ">") { +buildSignature(it) } text("(") @@ -149,7 +150,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge } private fun PageContentBuilder.DocumentableContentBuilder.signatureForProjection(p: Projection): Unit = when (p) { - is TypeParameter -> link(p.name, p.declarationDRI) + is TypeParameter -> link(p.name, p.dri) is TypeConstructor -> group(styles = emptySet()) { link(p.dri.classNames.orEmpty(), p.dri) |