aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/model/Documentable.kt6
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt56
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt8
3 files changed, 44 insertions, 26 deletions
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt
index 22930bf2..5c08e47e 100644
--- a/core/src/main/kotlin/model/Documentable.kt
+++ b/core/src/main/kotlin/model/Documentable.kt
@@ -329,7 +329,7 @@ sealed class Projection
sealed class Bound : Projection()
data class OtherParameter(val name: String) : Bound()
object Star : Projection()
-data class TypeConstructor(val dri: DRI, val projections: List<Projection>) : Bound()
+data class TypeConstructor(val dri: DRI, val projections: List<Projection>, val modifier: FunctionModifiers = FunctionModifiers.NONE) : Bound()
data class Nullable(val inner: Bound) : Bound()
data class Variance(val kind: Kind, val inner: Bound) : Projection() {
enum class Kind { In, Out }
@@ -338,6 +338,10 @@ data class PrimitiveJavaType(val name: String): Bound()
val VoidBound = PrimitiveJavaType("void")
+enum class FunctionModifiers {
+ NONE, FUNCTION, EXTENSION
+}
+
enum class ExtraModifiers {
STATIC, INLINE, INFIX, SUSPEND, REIFIED, CROSSINLINE, NOINLINE,
OVERRIDE, DATA, CONST, DYNAMIC, EXTERNAL, INNER, LATEINIT, OPERATOR, TAILREC, VARARG
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index dd99d0cd..6eeedb88 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -11,6 +11,7 @@ import org.jetbrains.dokka.model.DEnum
import org.jetbrains.dokka.model.DFunction
import org.jetbrains.dokka.pages.ContentKind
import org.jetbrains.dokka.pages.ContentNode
+import org.jetbrains.dokka.pages.PlatformData
import org.jetbrains.dokka.pages.TextStyle
import org.jetbrains.dokka.utilities.DokkaLogger
@@ -73,9 +74,6 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
text(": ")
signatureForProjection(it.type)
-// val type = it.type
-// if (type is KotlinTypeWrapper && type.isFunctionType) funType(type)
-// else type(type)
}
text(")")
val returnType = f.type
@@ -95,12 +93,15 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
private fun PageContentBuilder.DocumentableContentBuilder.signatureForProjection(p: Projection): Unit = when (p) {
is OtherParameter -> text(p.name)
- is TypeConstructor -> group {
- link(p.dri.classNames.orEmpty(), p.dri)
- list(p.projections, prefix = "<", suffix = ">") {
- signatureForProjection(it)
+ is TypeConstructor -> if (p.function)
+ +funType(this.mainDRI, this.mainPlatformData, p)
+ else
+ group {
+ link(p.dri.classNames.orEmpty(), p.dri)
+ list(p.projections, prefix = "<", suffix = ">") {
+ signatureForProjection(it)
+ }
}
- }
is Variance -> group {
text(p.kind.toString() + " ")
@@ -117,28 +118,35 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
is PrimitiveJavaType -> signatureForProjection(p.translateToKotlin())
}
- fun PageContentBuilder.DocumentableContentBuilder.funType(type: KotlinTypeWrapper) {
- if (type.isExtension) {
- type(type.arguments.first())
- text(".")
- }
+ fun funType(dri: DRI, platformData: Set<PlatformData>, type: TypeConstructor) =
+ contentBuilder.contentFor(dri, platformData, ContentKind.Symbol, setOf(TextStyle.Monospace)) {
+ if (type.extension) {
+ signatureForProjection(type.projections.first())
+ text(".")
+ }
- val args = if (type.isExtension) {
- type.arguments.drop(1)
- } else
- type.arguments
+ val args = if (type.extension)
+ type.projections.drop(1)
+ else
+ type.projections
- text("(")
- args.subList(0, args.size - 1).forEachIndexed { i, arg ->
- type(arg)
- if (i < args.size - 2) text(", ")
+ text("(")
+ args.subList(0, args.size - 1).forEachIndexed { i, arg ->
+ signatureForProjection(arg)
+ if (i < args.size - 2) text(", ")
+ }
+ text(") -> ")
+ signatureForProjection(args.last())
}
- text(") -> ")
- type(args.last())
- }
}
private fun PrimitiveJavaType.translateToKotlin() = TypeConstructor(
dri = DRI("kotlin", name.capitalize()),
projections = emptyList()
)
+
+val TypeConstructor.function
+ get() = modifier == FunctionModifiers.FUNCTION || modifier == FunctionModifiers.EXTENSION
+
+val TypeConstructor.extension
+ get() = modifier == FunctionModifiers.EXTENSION
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index e2afefe5..8e0f1231 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -11,11 +11,14 @@ import org.jetbrains.dokka.pages.PlatformData
import org.jetbrains.dokka.parsers.MarkdownParser
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.descriptors.DescriptorToDocumentableTranslator
+import org.jetbrains.kotlin.builtins.isExtensionFunctionType
+import org.jetbrains.kotlin.builtins.isFunctionType
import org.jetbrains.kotlin.codegen.isJvmStaticInObjectOrClassOrInterface
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies
+import org.jetbrains.kotlin.idea.kdoc.findKDoc
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.components.isVararg
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
@@ -421,7 +424,10 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv
}
else -> TypeConstructor(
DRI.from(constructor.declarationDescriptor!!), // TODO: remove '!!'
- arguments.map { it.toProjection() }
+ arguments.map { it.toProjection() },
+ if (isExtensionFunctionType) FunctionModifiers.EXTENSION
+ else if (isFunctionType) FunctionModifiers.FUNCTION
+ else FunctionModifiers.NONE
)
}