diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2020-03-25 15:51:51 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-03-25 15:58:37 +0100 |
commit | 40c3650b2e51d06a10ba204c79ca5c94d390a513 (patch) | |
tree | c834da7008e3dfdb5cea43a5765ccf80f5774c65 /plugins/base/src/main/kotlin | |
parent | af9d525d75a517a5a7cb39d30fd4b2c9e8b93837 (diff) | |
download | dokka-40c3650b2e51d06a10ba204c79ca5c94d390a513.tar.gz dokka-40c3650b2e51d06a10ba204c79ca5c94d390a513.tar.bz2 dokka-40c3650b2e51d06a10ba204c79ca5c94d390a513.zip |
Introduce VoidObject and JavaObject
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r-- | plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt | 15 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt | 18 |
2 files changed, 20 insertions, 13 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index b93be352..c40c5b7c 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.base.signatures import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.links.DriOfAny import org.jetbrains.dokka.links.DriOfUnit import org.jetbrains.dokka.links.sureClassNames import org.jetbrains.dokka.model.* @@ -89,13 +90,19 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog signatureForProjection(it.type) } text(")") - val returnType = f.type - if (!f.isConstructor && returnType is TypeConstructor && returnType.dri != DriOfUnit) { + if (f.documentReturnType()) { text(": ") - signatureForProjection(returnType) + signatureForProjection(f.type) } } + private fun DFunction.documentReturnType() = when { + this.isConstructor -> false + this.type is TypeConstructor && (this.type as TypeConstructor).dri == DriOfUnit -> false + this.type is Void -> false + else -> true + } + private fun signature(t: DTypeParameter) = contentBuilder.contentFor(t) { link(t.name, t.dri) list(t.bounds, prefix = " : ") { @@ -128,6 +135,8 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog text("?") } + is JavaObject -> link("Any", DriOfAny) + is Void -> link("Unit", DriOfUnit) is PrimitiveJavaType -> signatureForProjection(p.translateToKotlin()) } diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 74a6a7ea..218f8c82 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -223,7 +223,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { javadocParser.parseDocumentation(psi).toPlatformDependant(), PsiDocumentableSource(psi).toPlatformDependant(), psi.getVisibility().toPlatformDependant(), - psi.returnType?.let { getBound(type = it) } ?: VoidBound, + psi.returnType?.let { getBound(type = it) } ?: Void, psi.mapTypeParameters(dri), null, psi.getModifier(), @@ -254,14 +254,17 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { is PsiClassReferenceType -> { val resolved: PsiClass = type.resolve() ?: throw IllegalStateException("${type.presentableText} cannot be resolved") - val arguments = type.parameters.map { getProjection(it) } - TypeConstructor(DRI.from(resolved), arguments) + if (resolved.qualifiedName == "java.lang.Object") { + JavaObject + } else { + TypeConstructor(DRI.from(resolved), type.parameters.map { getProjection(it) }) + } } is PsiArrayType -> TypeConstructor( DRI("kotlin", "Array"), listOf(getProjection(type.componentType)) ) - is PsiPrimitiveType -> PrimitiveJavaType(type.name) + is PsiPrimitiveType -> if(type.name == "void") Void else PrimitiveJavaType(type.name) else -> throw IllegalStateException("${type.presentableText} is not supported by PSI parser") } } @@ -287,12 +290,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { private fun PsiTypeParameterListOwner.mapTypeParameters(dri: DRI): List<DTypeParameter> { fun mapBounds(bounds: Array<JvmReferenceType>): List<Bound> = if (bounds.isEmpty()) emptyList() else bounds.mapNotNull { - (it as? PsiClassType)?.let { classType -> - val resolved = classType.resolve()!! - val dri = if (resolved.qualifiedName == "java.lang.Object") DriOfAny - else DRI.from(resolved) - Nullable(TypeConstructor(dri, emptyList())) - } + (it as? PsiClassType)?.let { classType -> Nullable(getBound(classType)) } } return typeParameters.mapIndexed { index, type -> DTypeParameter( |