diff options
Diffstat (limited to 'plugins/base')
4 files changed, 23 insertions, 14 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( diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index a0cb68d7..b448bf75 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -362,7 +362,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { """ ) { with((this / "java" / "Test" / "fn").cast<DFunction>()) { - type.name equals "Any" + assertTrue(type is JavaObject) } } } diff --git a/plugins/base/src/test/kotlin/utils/TestUtils.kt b/plugins/base/src/test/kotlin/utils/TestUtils.kt index 8a3053b3..41c245e6 100644 --- a/plugins/base/src/test/kotlin/utils/TestUtils.kt +++ b/plugins/base/src/test/kotlin/utils/TestUtils.kt @@ -74,4 +74,6 @@ val Bound.name: String? is OtherParameter -> name is PrimitiveJavaType -> name is TypeConstructor -> dri.classNames + is JavaObject -> "Object" + is Void -> "void" }
\ No newline at end of file |