From e4044ec67ad90041b02bb84c4b966ffeac537617 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Sun, 1 Mar 2020 21:26:13 +0100 Subject: Add initial version of Kotlin as Java plugin --- .../kotlin/converters/KotlinToJavaConverter.kt | 246 +++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt new file mode 100644 index 00000000..19c4ef19 --- /dev/null +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -0,0 +1,246 @@ +package org.jetbrains.dokka.kotlinAsJava.converters + +import org.jetbrains.dokka.links.Callable +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.links.withClass +import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.Annotation +import org.jetbrains.dokka.model.Enum +import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.properties.PropertyContainer +import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType + +private fun List.groupedByLocation() = + map { it.sources to it } + .groupBy({ (location, _) -> + location.let { it.map.entries.first().value.path.split("/").last().split(".").first() + "Kt" } // TODO: first() does not look reasonable + }) { it.second } + +internal fun Package.asJava(): Package { + @Suppress("UNCHECKED_CAST") + val syntheticClasses = ((properties + functions) as List) + .groupedByLocation() + .map { (syntheticClassName, nodes) -> + Class( + dri = dri.withClass(syntheticClassName), + name = syntheticClassName, + properties = nodes.filterIsInstance().map { it.asJava() }, + constructors = emptyList(), + functions = ( + nodes.filterIsInstance().map { it.javaAccessors() } + + nodes.filterIsInstance().map { it.asJava(syntheticClassName) } + ) as List, // TODO: methods are static and receiver is a param + classlikes = emptyList(), + sources = PlatformDependent.empty(), + visibility = PlatformDependent.empty(), // TODO: fix this with the new visibility model -> public + companion = null, + generics = emptyList(), + supertypes = PlatformDependent.empty(), + documentation = PlatformDependent.empty(), + modifier = WithAbstraction.Modifier.Final, + platformData = platformData, + extra = PropertyContainer.empty() + ) + } + + return copy( + functions = emptyList(), + properties = emptyList(), + classlikes = classlikes.map { it.asJava() } + syntheticClasses, + packages = packages.map { it.asJava() } + ) +} + +internal fun Property.asJava(isTopLevel: Boolean = false, relocateToClass: String? = null) = + copy( + dri = if (relocateToClass.isNullOrBlank()) { + dri + } else { + dri.withClass(relocateToClass) + }, + modifier = if (setter == null) { + WithAbstraction.Modifier.Final + } else { + WithAbstraction.Modifier.Empty + }, + type = type.asJava(isTopLevel), // TODO: check, + setter = null, + getter = null // Removing getters and setters as they will be available as functions + ) // TODO: visibility -> always private; if (isTopLevel) -> static + +internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass: String? = null): List = + listOfNotNull( + getter?.copy( + dri = if (relocateToClass.isNullOrBlank()) { + dri + } else { + dri.withClass(relocateToClass) + }, + name = "get" + name.capitalize(), + modifier = if (setter == null) { + WithAbstraction.Modifier.Final + } else { + WithAbstraction.Modifier.Empty + }, + type = type.asJava(isTopLevel) // TODO: check, + ), + setter?.copy( + dri = if (relocateToClass.isNullOrBlank()) { + dri + } else { + dri.withClass(relocateToClass) + }, + name = "set" + name.capitalize(), + modifier = if (setter == null) { + WithAbstraction.Modifier.Final + } else { + WithAbstraction.Modifier.Empty + }, + type = type.asJava(isTopLevel) // TODO: check, + ) + ) // TODO: if (isTopLevel) -> static; visibility -> always? public + + +internal fun Function.asJava(containingClassName: String): Function { + val newName = when { + isConstructor -> containingClassName + else -> name + } + return copy( +// dri = dri.copy(callable = dri.callable?.asJava()), + name = newName, + type = type.asJava(), + parameters = parameters.map { it.asJava() } + ) // TODO: should receiver be the first param? +} + +internal fun Classlike.asJava(): Classlike = when (this) { + is Class -> asJava() + is Enum -> asJava() + is Annotation -> asJava() + is Object -> asJava() + is Interface -> asJava() + else -> throw IllegalArgumentException("$this shouldn't be here") +} + +internal fun Class.asJava(): Class = copy( + constructors = constructors.map { it.asJava(name) }, + functions = (functions + properties.map { it.getter } + properties.map { it.setter }).filterNotNull().map { + it.asJava( + name + ) + }, + properties = properties.map { it.asJava() }, + classlikes = classlikes.map { it.asJava() } +) // TODO: if modifier is from Kotlin, then Empty -> Final I think, Java ones stay the same + +internal fun Enum.asJava(): Enum = copy( + constructors = constructors.map { it.asJava(name) }, + functions = (functions + properties.map { it.getter } + properties.map { it.setter }).filterNotNull().map { + it.asJava( + name + ) + }, + properties = properties.map { it.asJava() }, + classlikes = classlikes.map { it.asJava() } +// , entries = entries.map { it.asJava() } +) // TODO: if modifier is from Kotlin, then Empty -> Final I think, Java ones stay the same + +internal fun Object.asJava(): Object = copy( + functions = (functions + properties.map { it.getter } + properties.map { it.setter }) + .filterNotNull() + .map { it.asJava(name.orEmpty()) }, + properties = properties.map { it.asJava() } + + Property( + name = "INSTANCE", + modifier = WithAbstraction.Modifier.Final, + dri = dri.copy(callable = Callable("INSTANCE", null, emptyList())), + documentation = PlatformDependent.empty(), + sources = PlatformDependent.empty(), + visibility = PlatformDependent.empty(), // TODO: public and static + type = JavaTypeWrapper( + dri.packageName?.split(".").orEmpty() + + dri.classNames?.split(".").orEmpty(), + emptyList(), + dri, + false + ), + setter = null, + getter = null, + platformData = platformData, + receiver = null + ), + classlikes = classlikes.map { it.asJava() } +) + +internal fun Interface.asJava(): Interface = copy( + functions = (functions + properties.map { it.getter } + properties.map { it.setter }) + .filterNotNull() + .map { it.asJava(name) }, + properties = emptyList(), + classlikes = classlikes.map { it.asJava() } // TODO: public static final class DefaultImpls with impls for methods (killme please) +) + +internal fun Annotation.asJava(): Annotation = copy( + properties = properties.map { it.asJava() }, + constructors = emptyList(), + classlikes = classlikes.map { it.asJava() } +) // TODO investigate if annotation class can have methods and properties not from constructor + +internal fun Parameter.asJava(): Parameter = copy( + type = type.asJava() +) + +internal fun String.getAsPrimitive(): JvmPrimitiveType? = org.jetbrains.kotlin.builtins.PrimitiveType.values() + .find { it.typeFqName.asString() == this } + ?.let { JvmPrimitiveType.get(it) } + +internal fun TypeWrapper.getAsType(classId: ClassId, fqName: String, top: Boolean): TypeWrapper { + val fqNameSplit = fqName + .takeIf { top } + ?.getAsPrimitive() + ?.name?.toLowerCase() + ?.let(::listOf) + ?: classId.asString().split("/") + + return JavaTypeWrapper( + fqNameSplit, + arguments.map { it.asJava(false) }, + classId.toDRI(dri), + fqNameSplit.last()[0].isLowerCase() + ) +} + +internal fun TypeWrapper.asJava(top: Boolean = true): TypeWrapper = constructorFqName + ?.takeUnless { it.endsWith(".Unit") } // TODO: ??? + ?.let { fqName -> fqName.mapToJava()?.let { getAsType(it, fqName, top) } } ?: this + + +private fun String.mapToJava(): ClassId? = + JavaToKotlinClassMap.mapKotlinToJava(FqName(this).toUnsafe()) + +internal fun ClassId.toDRI(dri: DRI?): DRI = DRI( + packageName = packageFqName.asString(), + classNames = classNames(), + callable = dri?.callable,//?.asJava(), TODO: ???? + extra = null, + target = null +) + +internal fun ClassId.classNames(): String = + shortClassName.identifier + (outerClassId?.classNames()?.let { ".$it" } ?: "") + +//fun TypeConstructor.asJava(): TypeReference = +// fullyQualifiedName.mapToJava() +// ?.let { tc.copy(fullyQualifiedName = it.asString(), params = tc.params.map { it.asJava() }) } ?: tc + +//fun TypeParam.asJava(): TypeReference = copy(bounds = bounds.map { it.asJava() }) + +//fun TypeReference.asJava(): TypeReference = when (this) { +// is TypeConstructor -> asJava() +// is TypeParam -> asJava() +// else -> this +//} \ No newline at end of file -- cgit From 8ea1e6752aadc7da2bd9e1fff7f4040d16e3d864 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Tue, 3 Mar 2020 19:56:07 +0100 Subject: Improve JavaSignatureProvider --- .../src/main/kotlin/JavaSignatureProvider.kt | 42 +++++++++++++--------- .../kotlin/converters/KotlinToJavaConverter.kt | 11 +++--- 2 files changed, 31 insertions(+), 22 deletions(-) (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt index 526546f2..6a6acf6d 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt @@ -15,7 +15,7 @@ import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.utilities.DokkaLogger class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider { - private val contentBuilder = PageContentBuilder(ctcc, logger) + private val contentBuilder = PageContentBuilder(ctcc, this, logger) override fun signature(documentable: Documentable): List = when (documentable) { is Function -> signature(documentable) @@ -30,9 +30,8 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge private fun signature(c: Classlike) = c.platformData.map { signature(c, it) }.distinct() private fun signature(c: Classlike, platform: PlatformData) = contentBuilder.contentFor(c, ContentKind.Symbol) { - text(c.visibility[platform]?.externalDisplayName ?: "") if (c is Class) { - text(c.modifier.toString()) + text(c.modifier.takeIf { it != WithAbstraction.Modifier.Empty }?.toString()?.toLowerCase().orEmpty()) } when (c) { is Class -> text(" class ") @@ -42,19 +41,27 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge is Annotation -> text(" @interface ") } text(c.name!!) - if (c is WithSupertypes) { - list(c.supertypes.getValue(platform), prefix = " : ") { + if (c is WithGenerics) { + val generics = c.generics.filterOnPlatform(platform) + if (generics.isNotEmpty()) { + text("<") + list(generics) { + +this@JavaSignatureProvider.signature(it) + } + text(">") + } + } + if (c is WithSupertypes && c.supertypes.containsKey(platform)) { + list(c.supertypes.getValue(platform), prefix = " extends ") { link(it.sureClassNames, it) } } } private fun signature(f: Function, platform: PlatformData) = contentBuilder.contentFor(f, ContentKind.Symbol) { - text(f.visibility[platform]?.externalDisplayName ?: "") - text(f.modifier.toString()) + text(f.modifier.takeIf { it != WithAbstraction.Modifier.Empty }?.toString()?.toLowerCase().orEmpty()) val returnType = f.type if (!f.isConstructor && returnType.constructorFqName != Unit::class.qualifiedName) { - text(": ") type(returnType) } text(" ") @@ -63,28 +70,26 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge if (generics.isNotEmpty()) { text("<") generics.forEach { - signature(it) + this@JavaSignatureProvider.signature(it) } text(">") } text("(") - list(listOfNotNull(f.receiver) + f.parameters.filterOnPlatform(platform)) { + list(f.parameters.filterOnPlatform(platform)) { type(it.type) text(" ") link(it.name!!, it.dri) - text(", ") } text(")") } private fun signature(t: TypeParameter) = contentBuilder.contentFor(t, ContentKind.Symbol) { - link(t.name, t.dri) + text(t.name.substringAfterLast(".")) if (t.bounds.isNotEmpty()) { - text("<") + text(" extends ") t.bounds.forEach { - signature(it, t.dri, t.platformData) + +signature(it, t.dri, t.platformData) } - text(">") } } @@ -93,13 +98,16 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge is TypeConstructor -> contentBuilder.contentFor(dri, platforms.toSet()) { link(p.dri.classNames.orEmpty(), p.dri) - }.children + p.projections.flatMap { signature(it, dri, platforms) } + list(p.projections, prefix = "<", suffix = ">") { + +signature(it, dri, platforms) + } + }.children is Variance -> contentBuilder.contentFor(dri, platforms.toSet()) { text(p.kind.toString() + " ") }.children + signature(p.inner, dri, platforms) - is Star -> contentBuilder.contentFor(dri, platforms.toSet()) { text("*") }.children + is Star -> contentBuilder.contentFor(dri, platforms.toSet()) { text("?") }.children is Nullable -> signature(p.inner, dri, platforms) + contentBuilder.contentFor( dri, diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index 19c4ef19..f7fc57ff 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -61,6 +61,7 @@ internal fun Property.asJava(isTopLevel: Boolean = false, relocateToClass: Strin } else { dri.withClass(relocateToClass) }, +// name = name.o, modifier = if (setter == null) { WithAbstraction.Modifier.Final } else { @@ -113,7 +114,8 @@ internal fun Function.asJava(containingClassName: String): Function { // dri = dri.copy(callable = dri.callable?.asJava()), name = newName, type = type.asJava(), - parameters = parameters.map { it.asJava() } + parameters = listOfNotNull(receiver?.asJava()) + parameters.map { it.asJava() }, + receiver = null ) // TODO: should receiver be the first param? } @@ -129,9 +131,7 @@ internal fun Classlike.asJava(): Classlike = when (this) { internal fun Class.asJava(): Class = copy( constructors = constructors.map { it.asJava(name) }, functions = (functions + properties.map { it.getter } + properties.map { it.setter }).filterNotNull().map { - it.asJava( - name - ) + it.asJava(name) }, properties = properties.map { it.asJava() }, classlikes = classlikes.map { it.asJava() } @@ -191,7 +191,8 @@ internal fun Annotation.asJava(): Annotation = copy( ) // TODO investigate if annotation class can have methods and properties not from constructor internal fun Parameter.asJava(): Parameter = copy( - type = type.asJava() + type = type.asJava(), + name = if (name.isNullOrBlank()) "\$self" else name ) internal fun String.getAsPrimitive(): JvmPrimitiveType? = org.jetbrains.kotlin.builtins.PrimitiveType.values() -- cgit From ea0945efe8c7b5dd9aabc4f049afaac612b70422 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 4 Mar 2020 16:50:40 +0100 Subject: Fix some DRI translations --- .../kotlin/signatures/KotlinSignatureProvider.kt | 7 -- .../documentables/PageContentBuilder.kt | 9 +++ .../src/main/kotlin/JavaSignatureProvider.kt | 88 ++++++++++------------ .../kotlin/converters/KotlinToJavaConverter.kt | 81 ++++++++++++++++---- 4 files changed, 114 insertions(+), 71 deletions(-) (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index cfca20b0..97445b2b 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -104,10 +104,3 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog } } } - -private fun PageContentBuilder.DocumentableContentBuilder.platformText( - value: PlatformDependent, - transform: (T) -> String -) = value.entries.forEach { (p, v) -> - transform(v).takeIf { it.isNotBlank() }?.also { text(it, platformData = setOf(p)) } -} \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index ef1b8ec1..b9e20919 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -4,6 +4,7 @@ import org.jetbrains.dokka.base.signatures.SignatureProvider import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Documentable +import org.jetbrains.dokka.model.PlatformDependent import org.jetbrains.dokka.model.TypeWrapper import org.jetbrains.dokka.model.doc.DocTag import org.jetbrains.dokka.model.properties.PropertyContainer @@ -264,5 +265,13 @@ open class PageContentBuilder( type(it) } } + + + fun platformText( + value: PlatformDependent, + transform: (T) -> String + ) = value.entries.forEach { (p, v) -> + transform(v).takeIf { it.isNotBlank() }?.also { text(it, platformData = setOf(p)) } + } } } \ No newline at end of file diff --git a/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt index 2e3ec152..8e2c783e 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt @@ -3,7 +3,6 @@ package org.jetbrains.dokka.kotlinAsJava import org.jetbrains.dokka.base.signatures.SignatureProvider 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.sureClassNames import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.Annotation @@ -17,48 +16,50 @@ import org.jetbrains.dokka.utilities.DokkaLogger class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider { private val contentBuilder = PageContentBuilder(ctcc, this, logger) - override fun signature(documentable: Documentable): List = when (documentable) { + private val ignoredVisibilities = setOf(JavaVisibility.Default, KotlinVisibility.Public) + private val ignoredModifiers = + setOf(WithAbstraction.Modifier.Open, WithAbstraction.Modifier.Empty, WithAbstraction.Modifier.Sealed) + + + override fun signature(documentable: Documentable): ContentNode = when (documentable) { is Function -> signature(documentable) is Classlike -> signature(documentable) + is TypeParameter -> signature(documentable) else -> throw NotImplementedError( "Cannot generate signature for ${documentable::class.qualifiedName} ${documentable.name}" ) } - private fun signature(f: Function) = f.platformData.map { signature(f, it) }.distinct() - - private fun signature(c: Classlike) = c.platformData.map { signature(c, it) }.distinct() + private fun signature(c: Classlike) = contentBuilder.contentFor(c, ContentKind.Symbol) { + platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } - private fun signature(c: Classlike, platform: PlatformData) = contentBuilder.contentFor(c, ContentKind.Symbol) { if (c is Class) { - text(c.modifier.takeIf { it != WithAbstraction.Modifier.Empty }?.toString()?.toLowerCase().orEmpty()) + text(c.modifier.takeIf { it !in ignoredModifiers }?.toString()?.toLowerCase().orEmpty() + " ") } + when (c) { - is Class -> text(" class ") - is Interface -> text(" interface ") - is Enum -> text(" enum ") - is Object -> text(" class ") - is Annotation -> text(" @interface ") + is Class -> text("class ") + is Interface -> text("interface ") + is Enum -> text("enum ") + is Object -> text("class ") + is Annotation -> text("@interface ") } text(c.name!!) if (c is WithGenerics) { - val generics = c.generics.filterOnPlatform(platform) - if (generics.isNotEmpty()) { - text("<") - list(generics) { - +this@JavaSignatureProvider.signature(it) - } - text(">") + list(c.generics, prefix = "<", suffix = ">") { + +buildSignature(it) } } - if (c is WithSupertypes && c.supertypes.containsKey(platform)) { - list(c.supertypes.getValue(platform), prefix = " extends ") { - link(it.sureClassNames, it) + if (c is WithSupertypes) { + c.supertypes.map { (p, dris) -> + list(dris, prefix = " extends ", platformData = setOf(p)) { + link(it.sureClassNames, it, platformData = setOf(p)) + } } } } - private fun signature(f: Function, platform: PlatformData) = contentBuilder.contentFor(f, ContentKind.Symbol) { + private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol) { text(f.modifier.takeIf { it != WithAbstraction.Modifier.Empty }?.toString()?.toLowerCase().orEmpty() + " ") val returnType = f.type if (!f.isConstructor && returnType.constructorFqName != Unit::class.qualifiedName) { @@ -66,16 +67,11 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge } text(" ") link(f.name, f.dri) - val generics = f.generics.filterOnPlatform(platform) - if (generics.isNotEmpty()) { - text("<") - generics.forEach { - this@JavaSignatureProvider.signature(it) - } - text(">") + list(f.generics, prefix = "<", suffix = ">") { + +buildSignature(it) } text("(") - list(f.parameters.filterOnPlatform(platform)) { + list(f.parameters) { type(it.type) text(" ") link(it.name!!, it.dri) @@ -85,34 +81,30 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge private fun signature(t: TypeParameter) = contentBuilder.contentFor(t, ContentKind.Symbol) { text(t.name.substringAfterLast(".")) - if (t.bounds.isNotEmpty()) { - text(" extends ") - t.bounds.forEach { - +signature(it, t.dri, t.platformData) - } + list(t.bounds, prefix = " extends ") { + signatureForProjection(it) } } - private fun signature(p: Projection, dri: DRI, platforms: List): List = when (p) { - is OtherParameter -> contentBuilder.contentFor(dri, platforms.toSet()) { text(p.name) }.children - is TypeConstructor -> contentBuilder.contentFor(dri, platforms.toSet()) { + 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 = ">") { - +signature(it, dri, platforms) + signatureForProjection(it) } - }.children + } - is Variance -> contentBuilder.contentFor(dri, platforms.toSet()) { + is Variance -> group { text(p.kind.toString() + " ") - }.children + signature(p.inner, dri, platforms) + signatureForProjection(p.inner) + } - is Star -> contentBuilder.contentFor(dri, platforms.toSet()) { text("?") }.children + is Star -> text("?") - is Nullable -> signature(p.inner, dri, platforms) + contentBuilder.contentFor( - dri, - platforms.toSet() - ) { text("?") }.children + is Nullable -> signatureForProjection(p.inner) } private fun Collection.filterOnPlatform(platformData: PlatformData) = diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index f7fc57ff..a8b45db0 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -16,7 +16,9 @@ import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType private fun List.groupedByLocation() = map { it.sources to it } .groupBy({ (location, _) -> - location.let { it.map.entries.first().value.path.split("/").last().split(".").first() + "Kt" } // TODO: first() does not look reasonable + location.let { + it.map.entries.first().value.path.split("/").last().split(".").first() + "Kt" + } // TODO: first() does not look reasonable }) { it.second } internal fun Package.asJava(): Package { @@ -61,16 +63,19 @@ internal fun Property.asJava(isTopLevel: Boolean = false, relocateToClass: Strin } else { dri.withClass(relocateToClass) }, -// name = name.o, modifier = if (setter == null) { WithAbstraction.Modifier.Final } else { WithAbstraction.Modifier.Empty }, - type = type.asJava(isTopLevel), // TODO: check, + visibility = visibility.copy( + map = visibility.mapValues { JavaVisibility.Private } + ), + type = type.asJava(isTopLevel), // TODO: check setter = null, - getter = null // Removing getters and setters as they will be available as functions - ) // TODO: visibility -> always private; if (isTopLevel) -> static + getter = null, // Removing getters and setters as they will be available as functions + extra = if (isTopLevel) extra.plus(extra.mergeAdditionalModifiers(listOf(ExtraModifiers.STATIC))) else extra + ) internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass: String? = null): List = listOfNotNull( @@ -86,7 +91,11 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass } else { WithAbstraction.Modifier.Empty }, - type = type.asJava(isTopLevel) // TODO: check, + visibility = visibility.copy( + map = visibility.mapValues { JavaVisibility.Public } + ), + type = type.asJava(isTopLevel), // TODO: check + extra = if (isTopLevel) getter!!.extra.plus(getter!!.extra.mergeAdditionalModifiers(listOf(ExtraModifiers.STATIC))) else getter!!.extra ), setter?.copy( dri = if (relocateToClass.isNullOrBlank()) { @@ -100,9 +109,13 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass } else { WithAbstraction.Modifier.Empty }, - type = type.asJava(isTopLevel) // TODO: check, + visibility = visibility.copy( + map = visibility.mapValues { JavaVisibility.Public } + ), + type = type.asJava(isTopLevel), // TODO: check + extra = if (isTopLevel) setter!!.extra.plus(setter!!.extra.mergeAdditionalModifiers(listOf(ExtraModifiers.STATIC))) else setter!!.extra ) - ) // TODO: if (isTopLevel) -> static; visibility -> always? public + ) internal fun Function.asJava(containingClassName: String): Function { @@ -134,18 +147,38 @@ internal fun Class.asJava(): Class = copy( it.asJava(name) }, properties = properties.map { it.asJava() }, - classlikes = classlikes.map { it.asJava() } + classlikes = classlikes.map { it.asJava() }, + generics = generics.map { it.asJava() }, + supertypes = supertypes.copy( + map = supertypes.mapValues { it.value.map { it.possiblyAsJava() } } + ) ) // TODO: if modifier is from Kotlin, then Empty -> Final I think, Java ones stay the same +private fun TypeParameter.asJava(): TypeParameter = copy( + dri = dri.possiblyAsJava(), + bounds = bounds.map { it.asJava() } +) + +private fun Bound.asJava(): Bound = when (this) { + is TypeConstructor -> copy( + dri = dri.possiblyAsJava() + ) + is Nullable -> copy( + inner = inner.asJava() + ) + else -> this +} + internal fun Enum.asJava(): Enum = copy( constructors = constructors.map { it.asJava(name) }, functions = (functions + properties.map { it.getter } + properties.map { it.setter }).filterNotNull().map { - it.asJava( - name - ) + it.asJava(name) }, properties = properties.map { it.asJava() }, - classlikes = classlikes.map { it.asJava() } + classlikes = classlikes.map { it.asJava() }, + supertypes = supertypes.copy( + map = supertypes.mapValues { it.value.map { it.possiblyAsJava() } } + ) // , entries = entries.map { it.asJava() } ) // TODO: if modifier is from Kotlin, then Empty -> Final I think, Java ones stay the same @@ -173,7 +206,10 @@ internal fun Object.asJava(): Object = copy( platformData = platformData, receiver = null ), - classlikes = classlikes.map { it.asJava() } + classlikes = classlikes.map { it.asJava() }, + supertypes = supertypes.copy( + map = supertypes.mapValues { it.value.map { it.possiblyAsJava() } } + ) ) internal fun Interface.asJava(): Interface = copy( @@ -181,7 +217,11 @@ internal fun Interface.asJava(): Interface = copy( .filterNotNull() .map { it.asJava(name) }, properties = emptyList(), - classlikes = classlikes.map { it.asJava() } // TODO: public static final class DefaultImpls with impls for methods (killme please) + classlikes = classlikes.map { it.asJava() }, // TODO: public static final class DefaultImpls with impls for methods + generics = generics.map { it.asJava() }, + supertypes = supertypes.copy( + map = supertypes.mapValues { it.value.map { it.possiblyAsJava() } } + ) ) internal fun Annotation.asJava(): Annotation = copy( @@ -215,8 +255,11 @@ internal fun TypeWrapper.getAsType(classId: ClassId, fqName: String, top: Boolea ) } +private fun DRI.partialFqName() = packageName?.let { "$it." } + classNames +private fun DRI.possiblyAsJava() = this.partialFqName().mapToJava()?.toDRI(this) ?: this + internal fun TypeWrapper.asJava(top: Boolean = true): TypeWrapper = constructorFqName - ?.takeUnless { it.endsWith(".Unit") } // TODO: ??? +// ?.takeUnless { it.endsWith(".Unit") } // TODO: ??? ?.let { fqName -> fqName.mapToJava()?.let { getAsType(it, fqName, top) } } ?: this @@ -231,6 +274,12 @@ internal fun ClassId.toDRI(dri: DRI?): DRI = DRI( target = null ) +private fun PropertyContainer.mergeAdditionalModifiers(second: List) = + this[AdditionalModifiers.AdditionalKey]?.squash(AdditionalModifiers(second)) ?: AdditionalModifiers(second) + +private fun AdditionalModifiers.squash(second: AdditionalModifiers) = + AdditionalModifiers((content + second.content).distinct()) + internal fun ClassId.classNames(): String = shortClassName.identifier + (outerClassId?.classNames()?.let { ".$it" } ?: "") -- cgit From fc875fe5f8bc52ac75053db097b3349465705732 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 4 Mar 2020 17:04:50 +0100 Subject: Refactor Modifiers --- core/src/main/kotlin/model/Documentable.kt | 25 +++++++++++++----- .../kotlin/signatures/KotlinSignatureProvider.kt | 4 +-- .../DefaultDescriptorToDocumentableTranslator.kt | 10 ++++---- .../psi/DefaultPsiToDocumentableTranslator.kt | 6 ++--- .../src/main/kotlin/JavaSignatureProvider.kt | 6 ++--- .../kotlin/converters/KotlinToJavaConverter.kt | 30 +++++++--------------- 6 files changed, 40 insertions(+), 41 deletions(-) (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 9116b6e6..d073d39a 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -73,10 +73,21 @@ interface WithType { interface WithAbstraction { val modifier: Modifier +} - enum class Modifier { - Abstract, Open, Final, Sealed, Empty - } +sealed class Modifier(val name: String) +sealed class KotlinModifier(name: String) : Modifier(name) { + object Abstract : KotlinModifier("abstract") + object Open : KotlinModifier("open") + object Final : KotlinModifier("final") + object Sealed : KotlinModifier("sealed") + object Empty : KotlinModifier("") +} + +sealed class JavaModifier(name: String) : Modifier(name) { + object Abstract : JavaModifier("abstract") + object Final : JavaModifier("final") + object Empty : JavaModifier("") } interface WithCompanion { @@ -145,7 +156,7 @@ data class Class( override val generics: List, override val supertypes: PlatformDependent>, override val documentation: PlatformDependent, - override val modifier: WithAbstraction.Modifier, + override val modifier: Modifier, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Classlike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes, @@ -206,7 +217,7 @@ data class Function( override val type: TypeWrapper, override val generics: List, override val receiver: Parameter?, - override val modifier: WithAbstraction.Modifier, + override val modifier: Modifier, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithGenerics, WithExtraProperties { @@ -286,7 +297,7 @@ data class Property( override val receiver: Parameter?, val setter: Function?, val getter: Function?, - override val modifier: WithAbstraction.Modifier, + override val modifier: Modifier, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithExtraProperties { @@ -331,7 +342,7 @@ data class OtherParameter(val name: String) : Bound() object Star : Projection() data class TypeConstructor(val dri: DRI, val projections: List) : Bound() data class Nullable(val inner: Bound) : Bound() -data class Variance(val kind: Kind, val inner: Bound): Projection() { +data class Variance(val kind: Kind, val inner: Bound) : Projection() { enum class Kind { In, Out } } diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 97445b2b..c8a5105d 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -29,7 +29,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun signature(c: Classlike) = contentBuilder.contentFor(c, ContentKind.Symbol) { platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } if (c is Class) { - text(c.modifier.toString() + " ") + text(c.modifier.name + " ") } when (c) { is Class -> text("class ") @@ -50,7 +50,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol) { platformText(f.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } - text(f.modifier.toString().toLowerCase() + " ") + text(f.modifier.name + " ") text("fun ") f.receiver?.also { type(it.type) diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index f30ffa00..29441ac1 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -434,11 +434,11 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv } fun MemberDescriptor.modifier() = when (modality) { - Modality.FINAL -> WithAbstraction.Modifier.Final - Modality.SEALED -> WithAbstraction.Modifier.Sealed - Modality.OPEN -> WithAbstraction.Modifier.Open - Modality.ABSTRACT -> WithAbstraction.Modifier.Abstract - else -> WithAbstraction.Modifier.Empty + Modality.FINAL -> KotlinModifier.Final + Modality.SEALED -> KotlinModifier.Sealed + Modality.OPEN -> KotlinModifier.Open + Modality.ABSTRACT -> KotlinModifier.Abstract + else -> KotlinModifier.Empty } private fun MemberDescriptor.createSources(): PlatformDependent = if (isExpect()) { diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 6b25639f..81de12eb 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -243,9 +243,9 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { } private fun PsiModifierListOwner.getModifier() = when { - hasModifier(JvmModifier.ABSTRACT) -> WithAbstraction.Modifier.Abstract - hasModifier(JvmModifier.FINAL) -> WithAbstraction.Modifier.Final - else -> WithAbstraction.Modifier.Empty + hasModifier(JvmModifier.ABSTRACT) -> JavaModifier.Abstract + hasModifier(JvmModifier.FINAL) -> JavaModifier.Final + else -> JavaModifier.Empty } private fun PsiTypeParameterListOwner.mapTypeParameters(dri: DRI): List { diff --git a/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt index 8e2c783e..06224a7a 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt @@ -18,7 +18,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge private val ignoredVisibilities = setOf(JavaVisibility.Default, KotlinVisibility.Public) private val ignoredModifiers = - setOf(WithAbstraction.Modifier.Open, WithAbstraction.Modifier.Empty, WithAbstraction.Modifier.Sealed) + setOf(KotlinModifier.Open, JavaModifier.Empty, KotlinModifier.Empty, KotlinModifier.Sealed) override fun signature(documentable: Documentable): ContentNode = when (documentable) { @@ -34,7 +34,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } if (c is Class) { - text(c.modifier.takeIf { it !in ignoredModifiers }?.toString()?.toLowerCase().orEmpty() + " ") + text(c.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") } when (c) { @@ -60,7 +60,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge } private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol) { - text(f.modifier.takeIf { it != WithAbstraction.Modifier.Empty }?.toString()?.toLowerCase().orEmpty() + " ") + text(f.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") val returnType = f.type if (!f.isConstructor && returnType.constructorFqName != Unit::class.qualifiedName) { type(returnType) diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index a8b45db0..7c66e91f 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -42,7 +42,7 @@ internal fun Package.asJava(): Package { generics = emptyList(), supertypes = PlatformDependent.empty(), documentation = PlatformDependent.empty(), - modifier = WithAbstraction.Modifier.Final, + modifier = JavaModifier.Final, platformData = platformData, extra = PropertyContainer.empty() ) @@ -64,9 +64,9 @@ internal fun Property.asJava(isTopLevel: Boolean = false, relocateToClass: Strin dri.withClass(relocateToClass) }, modifier = if (setter == null) { - WithAbstraction.Modifier.Final + JavaModifier.Final } else { - WithAbstraction.Modifier.Empty + JavaModifier.Empty }, visibility = visibility.copy( map = visibility.mapValues { JavaVisibility.Private } @@ -87,9 +87,9 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass }, name = "get" + name.capitalize(), modifier = if (setter == null) { - WithAbstraction.Modifier.Final + JavaModifier.Final } else { - WithAbstraction.Modifier.Empty + JavaModifier.Empty }, visibility = visibility.copy( map = visibility.mapValues { JavaVisibility.Public } @@ -105,9 +105,9 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass }, name = "set" + name.capitalize(), modifier = if (setter == null) { - WithAbstraction.Modifier.Final + JavaModifier.Final } else { - WithAbstraction.Modifier.Empty + JavaModifier.Empty }, visibility = visibility.copy( map = visibility.mapValues { JavaVisibility.Public } @@ -189,7 +189,7 @@ internal fun Object.asJava(): Object = copy( properties = properties.map { it.asJava() } + Property( name = "INSTANCE", - modifier = WithAbstraction.Modifier.Final, + modifier = JavaModifier.Final, dri = dri.copy(callable = Callable("INSTANCE", null, emptyList())), documentation = PlatformDependent.empty(), sources = PlatformDependent.empty(), @@ -281,16 +281,4 @@ private fun AdditionalModifiers.squash(second: AdditionalModifiers) = AdditionalModifiers((content + second.content).distinct()) internal fun ClassId.classNames(): String = - shortClassName.identifier + (outerClassId?.classNames()?.let { ".$it" } ?: "") - -//fun TypeConstructor.asJava(): TypeReference = -// fullyQualifiedName.mapToJava() -// ?.let { tc.copy(fullyQualifiedName = it.asString(), params = tc.params.map { it.asJava() }) } ?: tc - -//fun TypeParam.asJava(): TypeReference = copy(bounds = bounds.map { it.asJava() }) - -//fun TypeReference.asJava(): TypeReference = when (this) { -// is TypeConstructor -> asJava() -// is TypeParam -> asJava() -// else -> this -//} \ No newline at end of file + shortClassName.identifier + (outerClassId?.classNames()?.let { ".$it" } ?: "") \ No newline at end of file -- cgit From 91d785711dde2108f7494102eceb53ea8f4938ca Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 4 Mar 2020 17:49:28 +0100 Subject: Implement some additional modifiers --- .../src/main/kotlin/JavaSignatureProvider.kt | 112 --------------------- .../src/main/kotlin/KotlinAsJavaPlugin.kt | 7 +- .../kotlin/converters/KotlinToJavaConverter.kt | 42 +++++--- .../kotlin/signatures/JavaSignatureProvider.kt | 109 ++++++++++++++++++++ 4 files changed, 145 insertions(+), 125 deletions(-) delete mode 100644 plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt create mode 100644 plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt deleted file mode 100644 index 06224a7a..00000000 --- a/plugins/kotlin-as-java/src/main/kotlin/JavaSignatureProvider.kt +++ /dev/null @@ -1,112 +0,0 @@ -package org.jetbrains.dokka.kotlinAsJava - -import org.jetbrains.dokka.base.signatures.SignatureProvider -import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter -import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder -import org.jetbrains.dokka.links.sureClassNames -import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.Annotation -import org.jetbrains.dokka.model.Enum -import org.jetbrains.dokka.model.Function -import org.jetbrains.dokka.pages.ContentKind -import org.jetbrains.dokka.pages.ContentNode -import org.jetbrains.dokka.pages.PlatformData -import org.jetbrains.dokka.utilities.DokkaLogger - -class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider { - private val contentBuilder = PageContentBuilder(ctcc, this, logger) - - private val ignoredVisibilities = setOf(JavaVisibility.Default, KotlinVisibility.Public) - private val ignoredModifiers = - setOf(KotlinModifier.Open, JavaModifier.Empty, KotlinModifier.Empty, KotlinModifier.Sealed) - - - override fun signature(documentable: Documentable): ContentNode = when (documentable) { - is Function -> signature(documentable) - is Classlike -> signature(documentable) - is TypeParameter -> signature(documentable) - else -> throw NotImplementedError( - "Cannot generate signature for ${documentable::class.qualifiedName} ${documentable.name}" - ) - } - - private fun signature(c: Classlike) = contentBuilder.contentFor(c, ContentKind.Symbol) { - platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } - - if (c is Class) { - text(c.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") - } - - when (c) { - is Class -> text("class ") - is Interface -> text("interface ") - is Enum -> text("enum ") - is Object -> text("class ") - is Annotation -> text("@interface ") - } - text(c.name!!) - if (c is WithGenerics) { - list(c.generics, prefix = "<", suffix = ">") { - +buildSignature(it) - } - } - if (c is WithSupertypes) { - c.supertypes.map { (p, dris) -> - list(dris, prefix = " extends ", platformData = setOf(p)) { - link(it.sureClassNames, it, platformData = setOf(p)) - } - } - } - } - - private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol) { - text(f.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") - val returnType = f.type - if (!f.isConstructor && returnType.constructorFqName != Unit::class.qualifiedName) { - type(returnType) - } - text(" ") - link(f.name, f.dri) - list(f.generics, prefix = "<", suffix = ">") { - +buildSignature(it) - } - text("(") - list(f.parameters) { - type(it.type) - text(" ") - link(it.name!!, it.dri) - } - text(")") - } - - private fun signature(t: TypeParameter) = contentBuilder.contentFor(t, ContentKind.Symbol) { - text(t.name.substringAfterLast(".")) - list(t.bounds, prefix = " extends ") { - signatureForProjection(it) - } - } - - - 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 Variance -> group { - text(p.kind.toString() + " ") - signatureForProjection(p.inner) - } - - is Star -> text("?") - - is Nullable -> signatureForProjection(p.inner) - } - - private fun Collection.filterOnPlatform(platformData: PlatformData) = - this.filter { it.platformData.contains(platformData) } -} \ No newline at end of file diff --git a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt index 0ca278ce..bf9b8dc0 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.kotlinAsJava import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.kotlinAsJava.signatures.JavaSignatureProvider import org.jetbrains.dokka.kotlinAsJava.transformers.KotlinAsJavaDocumentableTransformer import org.jetbrains.dokka.plugability.DokkaPlugin @@ -12,7 +13,11 @@ class KotlinAsJavaPlugin : DokkaPlugin() { val javaSignatureProvider by extending { val dokkaBasePlugin = plugin() dokkaBasePlugin.signatureProvider providing { ctx -> - JavaSignatureProvider(ctx.single(dokkaBasePlugin.commentsToContentConverter), ctx.logger) + JavaSignatureProvider( + ctx.single( + dokkaBasePlugin.commentsToContentConverter + ), ctx.logger + ) } } } \ No newline at end of file diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index 7c66e91f..4bf75101 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -32,12 +32,17 @@ internal fun Package.asJava(): Package { properties = nodes.filterIsInstance().map { it.asJava() }, constructors = emptyList(), functions = ( - nodes.filterIsInstance().map { it.javaAccessors() } + - nodes.filterIsInstance().map { it.asJava(syntheticClassName) } - ) as List, // TODO: methods are static and receiver is a param + nodes.filterIsInstance() + .map { it.javaAccessors() } + + nodes.filterIsInstance() + .map { it.asJava(syntheticClassName) }) as List, // TODO: methods are static and receiver is a param classlikes = emptyList(), sources = PlatformDependent.empty(), - visibility = PlatformDependent.empty(), // TODO: fix this with the new visibility model -> public + visibility = PlatformDependent( + platformData.map { + it to JavaVisibility.Public + }.toMap() + ), companion = null, generics = emptyList(), supertypes = PlatformDependent.empty(), @@ -127,9 +132,10 @@ internal fun Function.asJava(containingClassName: String): Function { // dri = dri.copy(callable = dri.callable?.asJava()), name = newName, type = type.asJava(), + modifier = if(modifier is KotlinModifier.Final && isConstructor) JavaModifier.Empty else modifier, parameters = listOfNotNull(receiver?.asJava()) + parameters.map { it.asJava() }, receiver = null - ) // TODO: should receiver be the first param? + ) // TODO static if toplevel } internal fun Classlike.asJava(): Classlike = when (this) { @@ -151,8 +157,9 @@ internal fun Class.asJava(): Class = copy( generics = generics.map { it.asJava() }, supertypes = supertypes.copy( map = supertypes.mapValues { it.value.map { it.possiblyAsJava() } } - ) -) // TODO: if modifier is from Kotlin, then Empty -> Final I think, Java ones stay the same + ), + modifier = if (modifier is KotlinModifier.Empty) JavaModifier.Final else modifier +) private fun TypeParameter.asJava(): TypeParameter = copy( dri = dri.possiblyAsJava(), @@ -180,7 +187,7 @@ internal fun Enum.asJava(): Enum = copy( map = supertypes.mapValues { it.value.map { it.possiblyAsJava() } } ) // , entries = entries.map { it.asJava() } -) // TODO: if modifier is from Kotlin, then Empty -> Final I think, Java ones stay the same +) internal fun Object.asJava(): Object = copy( functions = (functions + properties.map { it.getter } + properties.map { it.setter }) @@ -193,7 +200,11 @@ internal fun Object.asJava(): Object = copy( dri = dri.copy(callable = Callable("INSTANCE", null, emptyList())), documentation = PlatformDependent.empty(), sources = PlatformDependent.empty(), - visibility = PlatformDependent.empty(), // TODO: public and static + visibility = PlatformDependent( + platformData.map { + it to JavaVisibility.Public + }.toMap() + ), type = JavaTypeWrapper( dri.packageName?.split(".").orEmpty() + dri.classNames?.split(".").orEmpty(), @@ -204,7 +215,8 @@ internal fun Object.asJava(): Object = copy( setter = null, getter = null, platformData = platformData, - receiver = null + receiver = null, + extra = PropertyContainer.empty() + AdditionalModifiers(listOf(ExtraModifiers.STATIC)) ), classlikes = classlikes.map { it.asJava() }, supertypes = supertypes.copy( @@ -259,9 +271,15 @@ private fun DRI.partialFqName() = packageName?.let { "$it." } + classNames private fun DRI.possiblyAsJava() = this.partialFqName().mapToJava()?.toDRI(this) ?: this internal fun TypeWrapper.asJava(top: Boolean = true): TypeWrapper = constructorFqName -// ?.takeUnless { it.endsWith(".Unit") } // TODO: ??? + ?.let { if (it.endsWith(".Unit")) return VoidTypeWrapper() else it } ?.let { fqName -> fqName.mapToJava()?.let { getAsType(it, fqName, top) } } ?: this +private data class VoidTypeWrapper( + override val constructorFqName: String = "void", + override val constructorNamePathSegments: List = listOf("void"), + override val arguments: List = emptyList(), + override val dri: DRI = DRI("java.lang", "Void") +) : TypeWrapper private fun String.mapToJava(): ClassId? = JavaToKotlinClassMap.mapKotlinToJava(FqName(this).toUnsafe()) @@ -269,7 +287,7 @@ private fun String.mapToJava(): ClassId? = internal fun ClassId.toDRI(dri: DRI?): DRI = DRI( packageName = packageFqName.asString(), classNames = classNames(), - callable = dri?.callable,//?.asJava(), TODO: ???? + callable = dri?.callable,//?.asJava(), TODO: check this extra = null, target = null ) diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt new file mode 100644 index 00000000..91e5164d --- /dev/null +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -0,0 +1,109 @@ +package org.jetbrains.dokka.kotlinAsJava.signatures + +import org.jetbrains.dokka.base.signatures.SignatureProvider +import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter +import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder +import org.jetbrains.dokka.links.sureClassNames +import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.Annotation +import org.jetbrains.dokka.model.Enum +import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.pages.ContentKind +import org.jetbrains.dokka.pages.ContentNode +import org.jetbrains.dokka.pages.PlatformData +import org.jetbrains.dokka.utilities.DokkaLogger + +class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider { + private val contentBuilder = PageContentBuilder(ctcc, this, logger) + + private val ignoredVisibilities = setOf(JavaVisibility.Default, KotlinVisibility.Public) + private val ignoredModifiers = + setOf(KotlinModifier.Open, JavaModifier.Empty, KotlinModifier.Empty, KotlinModifier.Sealed) + + + override fun signature(documentable: Documentable): ContentNode = when (documentable) { + is Function -> signature(documentable) + is Classlike -> signature(documentable) + is TypeParameter -> signature(documentable) + else -> throw NotImplementedError( + "Cannot generate signature for ${documentable::class.qualifiedName} ${documentable.name}" + ) + } + + private fun signature(c: Classlike) = contentBuilder.contentFor(c, ContentKind.Symbol) { + platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } + + if (c is Class) { + text(c.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") + } + + when (c) { + is Class -> text("class ") + is Interface -> text("interface ") + is Enum -> text("enum ") + is Object -> text("class ") + is Annotation -> text("@interface ") + } + text(c.name!!) + if (c is WithGenerics) { + list(c.generics, prefix = "<", suffix = ">") { + +buildSignature(it) + } + } + if (c is WithSupertypes) { + c.supertypes.map { (p, dris) -> + list(dris, prefix = " extends ", platformData = setOf(p)) { + link(it.sureClassNames, it, platformData = setOf(p)) + } + } + } + } + + private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol) { + text(f.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") + val returnType = f.type + if (!f.isConstructor && returnType.constructorFqName != Unit::class.qualifiedName) { + type(returnType) + } + text(" ") + link(f.name, f.dri) + list(f.generics, prefix = "<", suffix = ">") { + +buildSignature(it) + } + text("(") + list(f.parameters) { + type(it.type) + text(" ") + link(it.name!!, it.dri) + } + text(")") + } + + private fun signature(t: TypeParameter) = contentBuilder.contentFor(t, ContentKind.Symbol) { + text(t.name.substringAfterLast(".")) + list(t.bounds, prefix = " extends ") { + signatureForProjection(it) + } + } + + + 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 Variance -> group { + text(p.kind.toString() + " ") + signatureForProjection(p.inner) + } + + is Star -> text("?") + + is Nullable -> signatureForProjection(p.inner) + } +} \ No newline at end of file -- cgit From 35851c4f00bde0b66ce1d9ae8ca02bab761df819 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Tue, 10 Mar 2020 14:18:11 +0100 Subject: Remove nested packages from packages --- core/src/main/kotlin/model/Documentable.kt | 13 ++++--------- .../transformers/documentables/DefaultDocumentableMerger.kt | 1 - .../DefaultDescriptorToDocumentableTranslator.kt | 1 - .../kotlin/translators/documentables/DefaultPageCreator.kt | 3 +-- .../translators/psi/DefaultPsiToDocumentableTranslator.kt | 1 - .../src/main/kotlin/converters/KotlinToJavaConverter.kt | 3 +-- 6 files changed, 6 insertions(+), 16 deletions(-) (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index d073d39a..8ff5969c 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -59,10 +59,6 @@ interface WithScope { val classlikes: List } -interface WithPackages { - val packages: List -} - interface WithVisibility { val visibility: PlatformDependent } @@ -114,11 +110,11 @@ abstract class Classlike : Documentable(), WithScope, WithVisibility, WithExpect data class Module( override val name: String, - override val packages: List, + val packages: List, override val documentation: PlatformDependent, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), WithPackages, WithExtraProperties { +) : Documentable(), WithExtraProperties { override val dri: DRI = DRI.topLevel override val children: List get() = packages @@ -131,14 +127,13 @@ data class Package( override val functions: List, override val properties: List, override val classlikes: List, - override val packages: List, override val documentation: PlatformDependent, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), WithScope, WithPackages, WithExtraProperties { +) : Documentable(), WithScope, WithExtraProperties { override val name = dri.packageName.orEmpty() override val children: List - get() = (properties + functions + classlikes + packages) as List + get() = (properties + functions + classlikes) as List override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt index 8ae2065b..654238a8 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt @@ -97,7 +97,6 @@ fun Package.mergeWith(other: Package): Package = copy( functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), - packages = merge(packages + other.packages, Package::mergeWith), documentation = documentation.mergeWith(other.documentation), platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 72ce296d..a1fda688 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -78,7 +78,6 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv functions = scope.functions(driWithPlatform), properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), - packages = scope.packages(driWithPlatform), documentation = descriptor.resolveDescriptorData(platformData), platformData = listOf(platformData) ) diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index d92bec19..c82af936 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -24,8 +24,7 @@ open class DefaultPageCreator( open fun pageForPackage(p: Package): PackagePageNode = PackagePageNode( p.name, contentForPackage(p), setOf(p.dri), p, p.classlikes.map(::pageForClasslike) + - p.functions.map(::pageForFunction) + - p.packages.map(::pageForPackage) + p.functions.map(::pageForFunction) ) open fun pageForClasslike(c: Classlike): ClasslikePageNode { diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 28391741..b07d248d 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -47,7 +47,6 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { psiFiles.flatMap { psFile -> psFile.classes.map { docParser.parseClasslike(it, dri) } }, - emptyList(), PlatformDependent.empty(), listOf(platformData) ) diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index 4bf75101..2d73786b 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -56,8 +56,7 @@ internal fun Package.asJava(): Package { return copy( functions = emptyList(), properties = emptyList(), - classlikes = classlikes.map { it.asJava() } + syntheticClasses, - packages = packages.map { it.asJava() } + classlikes = classlikes.map { it.asJava() } + syntheticClasses ) } -- cgit From 11b223daa2c54d2b86efb5e6054fd7205ed0b37a Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Wed, 11 Mar 2020 11:51:57 +0100 Subject: Properly merge AdditionalModifiers from different platforms --- core/src/main/kotlin/model/aditionalExtras.kt | 10 ++++++++-- .../descriptors/DefaultDescriptorToDocumentableTranslator.kt | 2 +- .../src/main/kotlin/converters/KotlinToJavaConverter.kt | 12 ++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/core/src/main/kotlin/model/aditionalExtras.kt b/core/src/main/kotlin/model/aditionalExtras.kt index 69e89a2a..d9587fe3 100644 --- a/core/src/main/kotlin/model/aditionalExtras.kt +++ b/core/src/main/kotlin/model/aditionalExtras.kt @@ -1,9 +1,15 @@ package org.jetbrains.dokka.model import org.jetbrains.dokka.model.properties.ExtraProperty +import org.jetbrains.dokka.model.properties.MergeStrategy -class AdditionalModifiers(val content: List) : ExtraProperty { - object AdditionalKey : ExtraProperty.Key +class AdditionalModifiers(val content: Set) : ExtraProperty { + object AdditionalKey : ExtraProperty.Key { + override fun mergeStrategyFor( + left: AdditionalModifiers, + right: AdditionalModifiers + ): MergeStrategy = MergeStrategy.Replace(AdditionalModifiers(left.content + right.content)) + } override fun equals(other: Any?): Boolean = if (other is AdditionalModifiers) other.content == content else false override fun hashCode() = content.hashCode() diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index a1fda688..2b73dc7f 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -495,7 +495,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv inline fun List.toContainer( container: PropertyContainer = PropertyContainer.empty() ): PropertyContainer = - container + AdditionalModifiers(this) + container + AdditionalModifiers(this.toSet()) data class ClassInfo(val supertypes: List, val docs: PlatformDependent) diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index 2d73786b..3b0f69f6 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -78,7 +78,7 @@ internal fun Property.asJava(isTopLevel: Boolean = false, relocateToClass: Strin type = type.asJava(isTopLevel), // TODO: check setter = null, getter = null, // Removing getters and setters as they will be available as functions - extra = if (isTopLevel) extra.plus(extra.mergeAdditionalModifiers(listOf(ExtraModifiers.STATIC))) else extra + extra = if (isTopLevel) extra.plus(extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else extra ) internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass: String? = null): List = @@ -99,7 +99,7 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass map = visibility.mapValues { JavaVisibility.Public } ), type = type.asJava(isTopLevel), // TODO: check - extra = if (isTopLevel) getter!!.extra.plus(getter!!.extra.mergeAdditionalModifiers(listOf(ExtraModifiers.STATIC))) else getter!!.extra + extra = if (isTopLevel) getter!!.extra.plus(getter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else getter!!.extra ), setter?.copy( dri = if (relocateToClass.isNullOrBlank()) { @@ -117,7 +117,7 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass map = visibility.mapValues { JavaVisibility.Public } ), type = type.asJava(isTopLevel), // TODO: check - extra = if (isTopLevel) setter!!.extra.plus(setter!!.extra.mergeAdditionalModifiers(listOf(ExtraModifiers.STATIC))) else setter!!.extra + extra = if (isTopLevel) setter!!.extra.plus(setter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else setter!!.extra ) ) @@ -215,7 +215,7 @@ internal fun Object.asJava(): Object = copy( getter = null, platformData = platformData, receiver = null, - extra = PropertyContainer.empty() + AdditionalModifiers(listOf(ExtraModifiers.STATIC)) + extra = PropertyContainer.empty() + AdditionalModifiers(setOf(ExtraModifiers.STATIC)) ), classlikes = classlikes.map { it.asJava() }, supertypes = supertypes.copy( @@ -291,11 +291,11 @@ internal fun ClassId.toDRI(dri: DRI?): DRI = DRI( target = null ) -private fun PropertyContainer.mergeAdditionalModifiers(second: List) = +private fun PropertyContainer.mergeAdditionalModifiers(second: Set) = this[AdditionalModifiers.AdditionalKey]?.squash(AdditionalModifiers(second)) ?: AdditionalModifiers(second) private fun AdditionalModifiers.squash(second: AdditionalModifiers) = - AdditionalModifiers((content + second.content).distinct()) + AdditionalModifiers(content + second.content) internal fun ClassId.classNames(): String = shortClassName.identifier + (outerClassId?.classNames()?.let { ".$it" } ?: "") \ No newline at end of file -- cgit From 8e4ffa367b43cdc57c3921fab2182a4209913a51 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Wed, 11 Mar 2020 16:55:40 +0100 Subject: Use Bounds instead of Wrappers to describe types --- core/src/main/kotlin/links/DRI.kt | 2 + core/src/main/kotlin/model/Documentable.kt | 11 ++- core/src/main/kotlin/model/typeWrappers.kt | 101 --------------------- .../kotlin/signatures/KotlinSignatureProvider.kt | 23 +++-- .../DefaultDescriptorToDocumentableTranslator.kt | 20 ++-- .../documentables/PageContentBuilder.kt | 19 +--- .../psi/DefaultPsiToDocumentableTranslator.kt | 30 ++++-- .../kotlin/converters/KotlinToJavaConverter.kt | 41 +-------- .../kotlin/signatures/JavaSignatureProvider.kt | 10 +- 9 files changed, 68 insertions(+), 189 deletions(-) delete mode 100644 core/src/main/kotlin/model/typeWrappers.kt (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt index 57ac96e5..cc78ab6f 100644 --- a/core/src/main/kotlin/links/DRI.kt +++ b/core/src/main/kotlin/links/DRI.kt @@ -56,6 +56,8 @@ data class DRI( } } +val DriOfUnit = DRI("kotlin", "Unit") + fun DRI.withClass(name: String) = copy(classNames = if (classNames.isNullOrBlank()) name else "$classNames.$name") val DRI.parent: DRI diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 176647fa..b697f4e4 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -58,7 +58,7 @@ interface WithVisibility { } interface WithType { - val type: TypeWrapper + val type: Bound } interface WithAbstraction { @@ -203,7 +203,7 @@ data class Function( override val documentation: PlatformDependent, override val sources: PlatformDependent, override val visibility: PlatformDependent, - override val type: TypeWrapper, + override val type: Bound, override val generics: List, override val receiver: Parameter?, override val modifier: Modifier, @@ -282,7 +282,7 @@ data class Property( override val documentation: PlatformDependent, override val sources: PlatformDependent, override val visibility: PlatformDependent, - override val type: TypeWrapper, + override val type: Bound, override val receiver: Parameter?, val setter: Function?, val getter: Function?, @@ -301,7 +301,7 @@ data class Parameter( override val dri: DRI, override val name: String?, override val documentation: PlatformDependent, - val type: TypeWrapper, + val type: Bound, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithExtraProperties { @@ -334,6 +334,9 @@ data class Nullable(val inner: Bound) : Bound() data class Variance(val kind: Kind, val inner: Bound) : Projection() { enum class Kind { In, Out } } +data class PrimitiveJavaType(val name: String): Bound() + +val VoidBound = PrimitiveJavaType("void") enum class ExtraModifiers { STATIC, INLINE, INFIX, SUSPEND, REIFIED, CROSSINLINE, NOINLINE, diff --git a/core/src/main/kotlin/model/typeWrappers.kt b/core/src/main/kotlin/model/typeWrappers.kt deleted file mode 100644 index b26a3f6d..00000000 --- a/core/src/main/kotlin/model/typeWrappers.kt +++ /dev/null @@ -1,101 +0,0 @@ -package org.jetbrains.dokka.model - -import com.intellij.psi.PsiArrayType -import com.intellij.psi.PsiEllipsisType -import com.intellij.psi.PsiPrimitiveType -import com.intellij.psi.PsiType -import com.intellij.psi.impl.source.PsiClassReferenceType -import org.jetbrains.dokka.links.DRI -import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe -import org.jetbrains.kotlin.types.KotlinType - -interface TypeWrapper { - val constructorFqName: String? - val constructorNamePathSegments: List - val arguments: List - val dri: DRI? -} - -class KotlinTypeWrapper(private val kotlinType: KotlinType) : TypeWrapper { - private val declarationDescriptor = kotlinType.constructor.declarationDescriptor - private val fqNameSafe = declarationDescriptor?.fqNameSafe - override val constructorFqName = fqNameSafe?.asString() - override val constructorNamePathSegments: List = - fqNameSafe?.pathSegments()?.map { it.asString() } ?: emptyList() - override val arguments: List by lazy { - kotlinType.arguments.map { - KotlinTypeWrapper( - it.type - ) - } - } - override val dri: DRI? by lazy { declarationDescriptor?.let { DRI.from(it) } } -} - -class JavaTypeWrapper : TypeWrapper { - - override val constructorFqName: String? - override val constructorNamePathSegments: List - override val arguments: List - override val dri: DRI? - val isPrimitive: Boolean - - constructor( - constructorNamePathSegments: List, - arguments: List, - dri: DRI?, - isPrimitiveType: Boolean - ) { - this.constructorFqName = constructorNamePathSegments.joinToString(".") - this.constructorNamePathSegments = constructorNamePathSegments - this.arguments = arguments - this.dri = dri - this.isPrimitive = isPrimitiveType - } - - constructor(type: PsiType) { - if (type is PsiClassReferenceType) { - val resolved = type.resolve() - constructorFqName = resolved?.qualifiedName - constructorNamePathSegments = resolved?.qualifiedName?.split('.') ?: emptyList() - arguments = type.parameters.mapNotNull { - if (it is PsiClassReferenceType) JavaTypeWrapper(it) else null - } - dri = fromPsi(type) - this.isPrimitive = false - } else if (type is PsiEllipsisType) { - constructorFqName = type.canonicalText - constructorNamePathSegments = listOf(type.canonicalText) // TODO - arguments = emptyList() - dri = DRI("java.lang", "Object") // TODO - this.isPrimitive = false - } else if (type is PsiArrayType) { - constructorFqName = type.canonicalText - constructorNamePathSegments = listOf(type.canonicalText) - arguments = emptyList() - dri = (type as? PsiClassReferenceType)?.let { fromPsi(it) } // TODO - this.isPrimitive = false - } else { - type as PsiPrimitiveType - constructorFqName = type.name - constructorNamePathSegments = type.name.split('.') - arguments = emptyList() - dri = null - this.isPrimitive = true - } - } - - private fun fromPsi(type: PsiClassReferenceType): DRI { - val className = type.className - val pkg = type.canonicalText.removeSuffix(className).removeSuffix(".") - return DRI(packageName = pkg, classNames = className) - } - - override fun toString(): String { - return constructorFqName.orEmpty() - } - - companion object { - val VOID = JavaTypeWrapper(listOf("void"), listOf(), null, true) - } -} diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index b468c56b..3c4698fe 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -2,6 +2,8 @@ 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.DriOfUnit import org.jetbrains.dokka.links.sureClassNames import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.Annotation @@ -53,25 +55,25 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog platformText(f.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } text(f.modifier.name + " ") text("fun ") + list(f.generics, prefix = "<", suffix = "> ") { + +buildSignature(it) + } f.receiver?.also { - type(it.type) + signatureForProjection(it.type) text(".") } link(f.name, f.dri) - list(f.generics, prefix = "<", suffix = ">") { - +buildSignature(it) - } text("(") list(f.parameters) { text(it.name!!) text(": ") - type(it.type) + signatureForProjection(it.type) } text(")") val returnType = f.type - if (!f.isConstructor && returnType.constructorFqName != Unit::class.qualifiedName) { + if (!f.isConstructor && returnType is TypeConstructor && returnType.dri != DriOfUnit) { text(": ") - type(returnType) + signatureForProjection(returnType) } } @@ -103,5 +105,12 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog signatureForProjection(p.inner) text("?") } + + is PrimitiveJavaType -> signatureForProjection(p.translateToKotlin()) } } + +private fun PrimitiveJavaType.translateToKotlin() = TypeConstructor( + dri = DRI("kotlin", name.capitalize()), + projections = emptyList() +) diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 2b73dc7f..9a71145f 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -223,7 +223,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv visibility = PlatformDependent(mapOf(platformData to descriptor.visibility.toDokkaVisibility())), documentation = descriptor.resolveDescriptorData(platformData), modifier = descriptor.modifier(), - type = KotlinTypeWrapper(descriptor.returnType!!), + type = descriptor.returnType!!.toBound(), platformData = listOf(platformData), extra = descriptor.additionalExtras() ) @@ -248,7 +248,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv generics = descriptor.typeParameters.map { it.toTypeParameter() }, documentation = descriptor.resolveDescriptorData(platformData), modifier = descriptor.modifier(), - type = KotlinTypeWrapper(descriptor.returnType!!), + type = descriptor.returnType!!.toBound(), platformData = listOf(platformData), extra = descriptor.additionalExtras() ) @@ -270,7 +270,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv sources = actual, visibility = PlatformDependent(mapOf(platformData to descriptor.visibility.toDokkaVisibility())), documentation = descriptor.resolveDescriptorData(platformData), - type = KotlinTypeWrapper(descriptor.returnType), + type = descriptor.returnType.toBound(), modifier = descriptor.modifier(), generics = descriptor.typeParameters.map { it.toTypeParameter() }, platformData = listOf(platformData), @@ -284,7 +284,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ) = Parameter( dri = parent.dri.copy(target = 0), name = null, - type = KotlinTypeWrapper(descriptor.type), + type = descriptor.type.toBound(), documentation = descriptor.resolveDescriptorData(platformData), platformData = listOf(platformData) ) @@ -301,7 +301,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv Parameter( parent.copy(target = 1), this.name.asString(), - type = KotlinTypeWrapper(this.type), + type = this.type.toBound(), documentation = descriptor.resolveDescriptorData(platformData), platformData = listOf(platformData), extra = descriptor.additionalExtras() @@ -327,7 +327,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv parameters = parameters, visibility = PlatformDependent(mapOf(platformData to descriptor.visibility.toDokkaVisibility())), documentation = descriptor.resolveDescriptorData(platformData), - type = KotlinTypeWrapper(descriptor.returnType!!), + type = descriptor.returnType!!.toBound(), generics = descriptor.typeParameters.map { it.toTypeParameter() }, modifier = descriptor.modifier(), receiver = descriptor.extensionReceiverParameter?.let { @@ -346,7 +346,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv Parameter( dri = parent.dri.copy(target = index + 1), name = descriptor.name.asString(), - type = KotlinTypeWrapper(descriptor.type), + type = descriptor.type.toBound(), documentation = descriptor.resolveDescriptorData(platformData), platformData = listOf(platformData), extra = descriptor.additionalExtras() @@ -393,15 +393,15 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv private fun TypeParameterDescriptor.toTypeParameter() = TypeParameter( DRI.from(this), - fqNameSafe.asString(), + name.identifier, PlatformDependent.from(platformData, getDocumentation()), upperBounds.map { it.toBound() }, listOf(platformData), extra = additionalExtras() ) - private fun KotlinType.toBound(): Bound = when (constructor.declarationDescriptor) { - is TypeParameterDescriptor -> OtherParameter(fqName.toString()).let { + private fun KotlinType.toBound(): Bound = when (val ctor = constructor.declarationDescriptor) { + is TypeParameterDescriptor -> OtherParameter(ctor.name.asString()).let { if (isMarkedNullable) Nullable(it) else it } else -> TypeConstructor( diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index f5880656..681b8c71 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -3,9 +3,7 @@ package org.jetbrains.dokka.base.translators.documentables import org.jetbrains.dokka.base.signatures.SignatureProvider import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.Documentable -import org.jetbrains.dokka.model.PlatformDependent -import org.jetbrains.dokka.model.TypeWrapper +import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.doc.DocTag import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.pages.* @@ -256,21 +254,6 @@ open class PageContentBuilder( ) = ContentText(text, DCI(setOf(mainDRI), kind), platformData, styles, extra) - fun type(t: TypeWrapper) { - if (t.constructorNamePathSegments.isNotEmpty() && t.dri != null) - link(t.constructorNamePathSegments.last(), t.dri!!) - else if (t.constructorNamePathSegments.isNotEmpty() && t.dri == null) - text(t.toString()) - else { - logger.error("type $t cannot be resolved") - text("???") - } - list(t.arguments, prefix = "<", suffix = ">") { - type(it) - } - } - - fun platformText( value: PlatformDependent, transform: (T) -> String diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index b07d248d..8bf556af 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.base.translators.psi import com.intellij.lang.jvm.JvmModifier import com.intellij.lang.jvm.types.JvmReferenceType import com.intellij.psi.* +import com.intellij.psi.impl.source.PsiClassReferenceType import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.JavaClassReference @@ -63,7 +64,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { private val javadocParser: JavaDocumentationParser = JavadocParser(logger) - private val typeWrappers = hashMapOf() + private val cachedBounds = hashMapOf() private fun PsiModifierListOwner.getVisibility() = modifierList?.children?.toList()?.let { ml -> when { @@ -226,14 +227,14 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { dri.copy(target = index + 1), psiParameter.name, javadocParser.parseDocumentation(psiParameter).toPlatformDependant(), - getTypeWrapper(psiParameter.type), + getBound(psiParameter.type), listOf(platformData) ) }, javadocParser.parseDocumentation(psi).toPlatformDependant(), PsiDocumentableSource(psi).toPlatformDependant(), psi.getVisibility().toPlatformDependant(), - psi.returnType?.let { getTypeWrapper(type = it) } ?: JavaTypeWrapper.VOID, + psi.returnType?.let { getBound(type = it) } ?: VoidBound, psi.mapTypeParameters(dri), null, psi.getModifier(), @@ -244,8 +245,22 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { ) } - private fun getTypeWrapper(type: PsiType) : TypeWrapper = - typeWrappers.getOrPut(type.canonicalText, { JavaTypeWrapper(type) }) + private fun getBound(type: PsiType): Bound = + cachedBounds.getOrPut(type.canonicalText) { + when (type) { + 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) + } + is PsiArrayType -> TypeConstructor(DRI("kotlin", "Array"), listOf(getProjection(type.componentType))) + is PsiPrimitiveType -> PrimitiveJavaType(type.name) + else -> throw IllegalStateException("${type.presentableText} is not supported by PSI parser") + } + } + + private fun getProjection(type: PsiType): Projection = if (type is PsiEllipsisType) Star else getBound(type) private fun PsiModifierListOwner.getModifier() = when { hasModifier(JvmModifier.ABSTRACT) -> JavaModifier.Abstract @@ -278,7 +293,8 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { getAnnotation(DescriptorUtils.JVM_NAME.asString())?.findAttributeValue("name")?.text ?: when { JvmAbi.isGetterName(name) -> propertyNameByGetMethodName(Name.identifier(name))?.asString() - JvmAbi.isSetterName(name) -> propertyNamesBySetMethodName(Name.identifier(name)).firstOrNull()?.asString() + JvmAbi.isSetterName(name) -> propertyNamesBySetMethodName(Name.identifier(name)).firstOrNull() + ?.asString() else -> null } @@ -311,7 +327,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { javadocParser.parseDocumentation(psi).toPlatformDependant(), PsiDocumentableSource(psi).toPlatformDependant(), psi.getVisibility().toPlatformDependant(), - getTypeWrapper(psi.type), + getBound(psi.type), null, accessors.firstOrNull { it.hasParameters() }?.let { parseFunction(it, parent) }, accessors.firstOrNull { it.returnType == psi.type }?.let { parseFunction(it, parent) }, diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index 3b0f69f6..cf777e67 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -75,7 +75,7 @@ internal fun Property.asJava(isTopLevel: Boolean = false, relocateToClass: Strin visibility = visibility.copy( map = visibility.mapValues { JavaVisibility.Private } ), - type = type.asJava(isTopLevel), // TODO: check + type = type.asJava(), // TODO: check setter = null, getter = null, // Removing getters and setters as they will be available as functions extra = if (isTopLevel) extra.plus(extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else extra @@ -98,7 +98,7 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass visibility = visibility.copy( map = visibility.mapValues { JavaVisibility.Public } ), - type = type.asJava(isTopLevel), // TODO: check + type = type.asJava(), // TODO: check extra = if (isTopLevel) getter!!.extra.plus(getter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else getter!!.extra ), setter?.copy( @@ -116,7 +116,7 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass visibility = visibility.copy( map = visibility.mapValues { JavaVisibility.Public } ), - type = type.asJava(isTopLevel), // TODO: check + type = type.asJava(), // TODO: check extra = if (isTopLevel) setter!!.extra.plus(setter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else setter!!.extra ) ) @@ -204,13 +204,7 @@ internal fun Object.asJava(): Object = copy( it to JavaVisibility.Public }.toMap() ), - type = JavaTypeWrapper( - dri.packageName?.split(".").orEmpty() + - dri.classNames?.split(".").orEmpty(), - emptyList(), - dri, - false - ), + type = TypeConstructor(dri, emptyList()), setter = null, getter = null, platformData = platformData, @@ -250,36 +244,9 @@ internal fun String.getAsPrimitive(): JvmPrimitiveType? = org.jetbrains.kotlin.b .find { it.typeFqName.asString() == this } ?.let { JvmPrimitiveType.get(it) } -internal fun TypeWrapper.getAsType(classId: ClassId, fqName: String, top: Boolean): TypeWrapper { - val fqNameSplit = fqName - .takeIf { top } - ?.getAsPrimitive() - ?.name?.toLowerCase() - ?.let(::listOf) - ?: classId.asString().split("/") - - return JavaTypeWrapper( - fqNameSplit, - arguments.map { it.asJava(false) }, - classId.toDRI(dri), - fqNameSplit.last()[0].isLowerCase() - ) -} - private fun DRI.partialFqName() = packageName?.let { "$it." } + classNames private fun DRI.possiblyAsJava() = this.partialFqName().mapToJava()?.toDRI(this) ?: this -internal fun TypeWrapper.asJava(top: Boolean = true): TypeWrapper = constructorFqName - ?.let { if (it.endsWith(".Unit")) return VoidTypeWrapper() else it } - ?.let { fqName -> fqName.mapToJava()?.let { getAsType(it, fqName, top) } } ?: this - -private data class VoidTypeWrapper( - override val constructorFqName: String = "void", - override val constructorNamePathSegments: List = listOf("void"), - override val arguments: List = emptyList(), - override val dri: DRI = DRI("java.lang", "Void") -) : TypeWrapper - private fun String.mapToJava(): ClassId? = JavaToKotlinClassMap.mapKotlinToJava(FqName(this).toUnsafe()) 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 91e5164d..265e05cd 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -62,9 +62,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol) { text(f.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") val returnType = f.type - if (!f.isConstructor && returnType.constructorFqName != Unit::class.qualifiedName) { - type(returnType) - } + signatureForProjection(returnType) text(" ") link(f.name, f.dri) list(f.generics, prefix = "<", suffix = ">") { @@ -72,7 +70,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge } text("(") list(f.parameters) { - type(it.type) + signatureForProjection(it.type) text(" ") link(it.name!!, it.dri) } @@ -98,12 +96,14 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge } is Variance -> group { - text(p.kind.toString() + " ") + text(p.kind.toString() + " ") // TODO: "super" && "extends" signatureForProjection(p.inner) } is Star -> text("?") is Nullable -> signatureForProjection(p.inner) + + is PrimitiveJavaType -> text(p.name) } } \ No newline at end of file -- cgit From 996feefe717ac623daabaadda71b5b9d2bbe1cf1 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Mon, 16 Mar 2020 14:33:38 +0100 Subject: Rename Documentables to avoid name conflicts --- core/src/main/kotlin/DokkaGenerator.kt | 12 +- core/src/main/kotlin/model/Documentable.kt | 190 ++++++++++----------- .../main/kotlin/model/documentableProperties.kt | 6 +- .../DescriptorToDocumentableTranslator.kt | 4 +- .../documentation/DocumentableMerger.kt | 4 +- .../documentation/DocumentableToPageTranslator.kt | 4 +- .../documentation/DocumentableTransformer.kt | 4 +- .../psi/PsiToDocumentableTranslator.kt | 4 +- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 4 +- .../kotlin/signatures/KotlinSignatureProvider.kt | 35 ++-- .../documentables/DefaultDocumentableMerger.kt | 116 ++++++------- .../DefaultDescriptorToDocumentableTranslator.kt | 78 +++++---- .../DefaultDocumentableToPageTranslator.kt | 4 +- .../documentables/DefaultPageCreator.kt | 18 +- .../psi/DefaultPsiToDocumentableTranslator.kt | 40 ++--- plugins/base/src/test/kotlin/enums/EnumsTest.kt | 5 +- plugins/base/src/test/kotlin/issues/IssuesTest.kt | 18 +- plugins/base/src/test/kotlin/markdown/KDocTest.kt | 4 +- plugins/base/src/test/kotlin/model/ClassesTest.kt | 60 +++---- plugins/base/src/test/kotlin/model/CommentTest.kt | 32 ++-- .../base/src/test/kotlin/model/FunctionsTest.kt | 18 +- plugins/base/src/test/kotlin/model/JavaTest.kt | 38 ++--- plugins/base/src/test/kotlin/model/PackagesTest.kt | 16 +- plugins/base/src/test/kotlin/model/PropertyTest.kt | 20 +-- plugins/base/src/test/kotlin/utils/ModelUtils.kt | 6 +- plugins/base/src/test/kotlin/utils/TestUtils.kt | 8 +- .../kotlin/converters/KotlinToJavaConverter.kt | 54 +++--- .../kotlin/signatures/JavaSignatureProvider.kt | 34 ++-- .../KotlinAsJavaDocumentableTransformer.kt | 4 +- .../main/kotlin/testApi/testRunner/TestRunner.kt | 14 +- 30 files changed, 422 insertions(+), 432 deletions(-) (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 1a0822d7..a3f72220 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -5,7 +5,7 @@ import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager import org.jetbrains.dokka.analysis.AnalysisEnvironment import org.jetbrains.dokka.analysis.DokkaResolutionFacade -import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext @@ -76,17 +76,17 @@ class DokkaGenerator( platforms.map { (pdata, _) -> translatePsi(pdata, context) } fun mergeDocumentationModels( - modulesFromPlatforms: List, + modulesFromPlatforms: List, context: DokkaContext ) = context.single(CoreExtensions.documentableMerger).invoke(modulesFromPlatforms, context) fun transformDocumentationModel( - documentationModel: Module, + documentationModel: DModule, context: DokkaContext ) = context[CoreExtensions.documentableTransformer].fold(documentationModel) { acc, t -> t(acc, context) } fun createPages( - transformedDocumentation: Module, + transformedDocumentation: DModule, context: DokkaContext ) = context.single(CoreExtensions.documentableToPageTranslator).invoke(transformedDocumentation) @@ -119,7 +119,7 @@ class DokkaGenerator( EnvironmentAndFacade(environment, facade) } - private fun translateDescriptors(platformData: PlatformData, context: DokkaContext): Module { + private fun translateDescriptors(platformData: PlatformData, context: DokkaContext): DModule { val (environment, facade) = context.platforms.getValue(platformData) val packageFragments = environment.getSourceFiles().asSequence() @@ -132,7 +132,7 @@ class DokkaGenerator( .invoke(platformData.name, packageFragments, platformData) } - private fun translatePsi(platformData: PlatformData, context: DokkaContext): Module { + private fun translatePsi(platformData: PlatformData, context: DokkaContext): DModule { val (environment, _) = context.platforms.getValue(platformData) val sourceRoots = environment.configuration.get(CLIConfigurationKeys.CONTENT_ROOTS) diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index b697f4e4..22930bf2 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -48,9 +48,9 @@ interface WithExpectActual { } interface WithScope { - val functions: List - val properties: List - val classlikes: List + val functions: List + val properties: List + val classlikes: List } interface WithVisibility { @@ -81,15 +81,15 @@ sealed class JavaModifier(name: String) : Modifier(name) { } interface WithCompanion { - val companion: Object? + val companion: DObject? } interface WithConstructors { - val constructors: List + val constructors: List } interface WithGenerics { - val generics: List + val generics: List } interface WithSupertypes { @@ -97,232 +97,232 @@ interface WithSupertypes { } interface Callable : WithVisibility, WithType, WithAbstraction, WithExpectActual { - val receiver: Parameter? + val receiver: DParameter? } -abstract class Classlike : Documentable(), WithScope, WithVisibility, WithExpectActual +abstract class DClasslike : Documentable(), WithScope, WithVisibility, WithExpectActual -data class Module( +data class DModule( override val name: String, - val packages: List, + val packages: List, override val documentation: PlatformDependent, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : Documentable(), WithExtraProperties { override val dri: DRI = DRI.topLevel override val children: List get() = packages - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } -data class Package( +data class DPackage( override val dri: DRI, - override val functions: List, - override val properties: List, - override val classlikes: List, + override val functions: List, + override val properties: List, + override val classlikes: List, override val documentation: PlatformDependent, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), WithScope, WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : Documentable(), WithScope, WithExtraProperties { override val name = dri.packageName.orEmpty() override val children: List get() = (properties + functions + classlikes) as List - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } -data class Class( +data class DClass( override val dri: DRI, override val name: String, - override val constructors: List, - override val functions: List, - override val properties: List, - override val classlikes: List, + override val constructors: List, + override val functions: List, + override val properties: List, + override val classlikes: List, override val sources: PlatformDependent, override val visibility: PlatformDependent, - override val companion: Object?, - override val generics: List, + override val companion: DObject?, + override val generics: List, override val supertypes: PlatformDependent>, override val documentation: PlatformDependent, override val modifier: Modifier, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Classlike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes, - WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : DClasslike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes, + WithExtraProperties { override val children: List get() = (functions + properties + classlikes + constructors) as List - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } -data class Enum( +data class DEnum( override val dri: DRI, override val name: String, - val entries: List, + val entries: List, override val documentation: PlatformDependent, override val sources: PlatformDependent, - override val functions: List, - override val properties: List, - override val classlikes: List, + override val functions: List, + override val properties: List, + override val classlikes: List, override val visibility: PlatformDependent, - override val companion: Object?, - override val constructors: List, + override val companion: DObject?, + override val constructors: List, override val supertypes: PlatformDependent>, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Classlike(), WithCompanion, WithConstructors, WithSupertypes, WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : DClasslike(), WithCompanion, WithConstructors, WithSupertypes, WithExtraProperties { override val children: List get() = (entries + functions + properties + classlikes + constructors) as List - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } -data class EnumEntry( +data class DEnumEntry( override val dri: DRI, override val name: String, override val documentation: PlatformDependent, - override val functions: List, - override val properties: List, - override val classlikes: List, + override val functions: List, + override val properties: List, + override val classlikes: List, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), WithScope, WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : Documentable(), WithScope, WithExtraProperties { override val children: List get() = (functions + properties + classlikes) as List - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } -data class Function( +data class DFunction( override val dri: DRI, override val name: String, val isConstructor: Boolean, - val parameters: List, + val parameters: List, override val documentation: PlatformDependent, override val sources: PlatformDependent, override val visibility: PlatformDependent, override val type: Bound, - override val generics: List, - override val receiver: Parameter?, + override val generics: List, + override val receiver: DParameter?, override val modifier: Modifier, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), Callable, WithGenerics, WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : Documentable(), Callable, WithGenerics, WithExtraProperties { override val children: List get() = parameters - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } -data class Interface( +data class DInterface( override val dri: DRI, override val name: String, override val documentation: PlatformDependent, override val sources: PlatformDependent, - override val functions: List, - override val properties: List, - override val classlikes: List, + override val functions: List, + override val properties: List, + override val classlikes: List, override val visibility: PlatformDependent, - override val companion: Object?, - override val generics: List, + override val companion: DObject?, + override val generics: List, override val supertypes: PlatformDependent>, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Classlike(), WithCompanion, WithGenerics, WithSupertypes, WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : DClasslike(), WithCompanion, WithGenerics, WithSupertypes, WithExtraProperties { override val children: List get() = (functions + properties + classlikes) as List - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } -data class Object( +data class DObject( override val name: String?, override val dri: DRI, override val documentation: PlatformDependent, override val sources: PlatformDependent, - override val functions: List, - override val properties: List, - override val classlikes: List, + override val functions: List, + override val properties: List, + override val classlikes: List, override val visibility: PlatformDependent, override val supertypes: PlatformDependent>, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Classlike(), WithSupertypes, WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : DClasslike(), WithSupertypes, WithExtraProperties { override val children: List get() = (functions + properties + classlikes) as List - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } -data class Annotation( +data class DAnnotation( override val name: String, override val dri: DRI, override val documentation: PlatformDependent, override val sources: PlatformDependent, - override val functions: List, - override val properties: List, - override val classlikes: List, + override val functions: List, + override val properties: List, + override val classlikes: List, override val visibility: PlatformDependent, - override val companion: Object?, - override val constructors: List, + override val companion: DObject?, + override val constructors: List, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Classlike(), WithCompanion, WithConstructors, WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : DClasslike(), WithCompanion, WithConstructors, WithExtraProperties { override val children: List get() = (functions + properties + classlikes + constructors) as List - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } -data class Property( +data class DProperty( override val dri: DRI, override val name: String, override val documentation: PlatformDependent, override val sources: PlatformDependent, override val visibility: PlatformDependent, override val type: Bound, - override val receiver: Parameter?, - val setter: Function?, - val getter: Function?, + override val receiver: DParameter?, + val setter: DFunction?, + val getter: DFunction?, override val modifier: Modifier, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), Callable, WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : Documentable(), Callable, WithExtraProperties { override val children: List get() = emptyList() - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } // TODO: treat named Parameters and receivers differently -data class Parameter( +data class DParameter( override val dri: DRI, override val name: String?, override val documentation: PlatformDependent, val type: Bound, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : Documentable(), WithExtraProperties { override val children: List get() = emptyList() - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } -data class TypeParameter( +data class DTypeParameter( override val dri: DRI, override val name: String, override val documentation: PlatformDependent, val bounds: List, override val platformData: List, - override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), WithExtraProperties { + override val extra: PropertyContainer = PropertyContainer.empty() +) : Documentable(), WithExtraProperties { override val children: List get() = emptyList() - override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) + override fun withNewExtras(newExtras: PropertyContainer) = copy(extra = newExtras) } sealed class Projection diff --git a/core/src/main/kotlin/model/documentableProperties.kt b/core/src/main/kotlin/model/documentableProperties.kt index 38a06451..67e5e88d 100644 --- a/core/src/main/kotlin/model/documentableProperties.kt +++ b/core/src/main/kotlin/model/documentableProperties.kt @@ -3,12 +3,12 @@ package org.jetbrains.dokka.model import org.jetbrains.dokka.model.properties.ExtraProperty import org.jetbrains.dokka.model.properties.MergeStrategy -data class InheritedFunction(val isInherited: Boolean): ExtraProperty { - object InheritedFunctionKey: ExtraProperty.Key { +data class InheritedFunction(val isInherited: Boolean): ExtraProperty { + object InheritedFunctionKey: ExtraProperty.Key { override fun mergeStrategyFor(left: Boolean, right: Boolean) = MergeStrategy.Fail { throw IllegalArgumentException("Function inheritance should be consistent!") } } - override val key: ExtraProperty.Key = + override val key: ExtraProperty.Key = InheritedFunctionKey } \ No newline at end of file diff --git a/core/src/main/kotlin/transformers/descriptors/DescriptorToDocumentableTranslator.kt b/core/src/main/kotlin/transformers/descriptors/DescriptorToDocumentableTranslator.kt index d72eeafd..ca66b90a 100644 --- a/core/src/main/kotlin/transformers/descriptors/DescriptorToDocumentableTranslator.kt +++ b/core/src/main/kotlin/transformers/descriptors/DescriptorToDocumentableTranslator.kt @@ -1,6 +1,6 @@ package org.jetbrains.dokka.transformers.descriptors -import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor @@ -9,5 +9,5 @@ interface DescriptorToDocumentableTranslator { moduleName: String, packageFragments: Iterable, platformData: PlatformData - ): Module + ): DModule } \ No newline at end of file diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt b/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt index 5a17bc24..c8ae9c02 100644 --- a/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt +++ b/core/src/main/kotlin/transformers/documentation/DocumentableMerger.kt @@ -1,8 +1,8 @@ package org.jetbrains.dokka.transformers.documentation -import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.plugability.DokkaContext interface DocumentableMerger { - operator fun invoke(modules: Collection, context: DokkaContext): Module + operator fun invoke(modules: Collection, context: DokkaContext): DModule } \ No newline at end of file diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt b/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt index e41e0c84..83456f01 100644 --- a/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt +++ b/core/src/main/kotlin/transformers/documentation/DocumentableToPageTranslator.kt @@ -1,8 +1,8 @@ package org.jetbrains.dokka.transformers.documentation -import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.pages.ModulePageNode interface DocumentableToPageTranslator { - operator fun invoke(module: Module): ModulePageNode + operator fun invoke(module: DModule): ModulePageNode } \ No newline at end of file diff --git a/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt b/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt index 88a1514d..3eb4704e 100644 --- a/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt +++ b/core/src/main/kotlin/transformers/documentation/DocumentableTransformer.kt @@ -1,8 +1,8 @@ package org.jetbrains.dokka.transformers.documentation -import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.plugability.DokkaContext interface DocumentableTransformer { - operator fun invoke(original: Module, context: DokkaContext): Module + operator fun invoke(original: DModule, context: DokkaContext): DModule } \ No newline at end of file diff --git a/core/src/main/kotlin/transformers/psi/PsiToDocumentableTranslator.kt b/core/src/main/kotlin/transformers/psi/PsiToDocumentableTranslator.kt index 1ea07ff3..6f5025bd 100644 --- a/core/src/main/kotlin/transformers/psi/PsiToDocumentableTranslator.kt +++ b/core/src/main/kotlin/transformers/psi/PsiToDocumentableTranslator.kt @@ -1,7 +1,7 @@ package org.jetbrains.dokka.transformers.psi import com.intellij.psi.PsiJavaFile -import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.plugability.DokkaContext @@ -11,5 +11,5 @@ interface PsiToDocumentableTranslator { psiFiles: List, platformData: PlatformData, context: DokkaContext - ): Module + ): DModule } diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index d7b2a912..34dac9f4 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -4,7 +4,7 @@ import kotlinx.html.* import kotlinx.html.stream.createHTML import org.jetbrains.dokka.base.renderers.DefaultRenderer import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.DFunction import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import java.io.File @@ -269,7 +269,7 @@ private fun PageNode.pageKind() = when (this) { is PackagePageNode -> "package" is ClasslikePageNode -> "class" is MemberPageNode -> when (this.documentable) { - is Function -> "function" + is DFunction -> "function" else -> "other" } else -> "other" diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index f600a3bf..8a080bb9 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -6,12 +6,11 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.DriOfUnit import org.jetbrains.dokka.links.sureClassNames import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.Annotation -import org.jetbrains.dokka.model.Enum -import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.DAnnotation +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 @@ -21,26 +20,26 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private val ignoredVisibilities = setOf(JavaVisibility.Default, KotlinVisibility.Public) override fun signature(documentable: Documentable): ContentNode = when (documentable) { - is Function -> signature(documentable) - is Property -> signature(documentable) - is Classlike -> signature(documentable) - is TypeParameter -> signature(documentable) + is DFunction -> signature(documentable) + is DProperty -> signature(documentable) + is DClasslike -> signature(documentable) + is DTypeParameter -> signature(documentable) else -> throw NotImplementedError( "Cannot generate signature for ${documentable::class.qualifiedName} ${documentable.name}" ) } - private fun signature(c: Classlike) = contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace)) { + private fun signature(c: DClasslike) = contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace)) { platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } - if (c is Class) { + if (c is DClass) { text(c.modifier.name + " ") } when (c) { - is Class -> text("class ") - is Interface -> text("interface ") - is Enum -> text("enum ") - is Object -> text("object ") - is Annotation -> text("annotation class ") + is DClass -> text("class ") + is DInterface -> text("interface ") + is DEnum -> text("enum ") + is DObject -> text("object ") + is DAnnotation -> text("annotation class ") } link(c.name!!, c.dri) if (c is WithSupertypes) { @@ -52,11 +51,11 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog } } - private fun signature(p: Property) = contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace)) { + private fun signature(p: DProperty) = contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace)) { signatureForProjection(p.type) } - private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace)) { + private fun signature(f: DFunction) = contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace)) { platformText(f.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } text(f.modifier.name + " ") text("fun ") @@ -82,7 +81,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog } } - private fun signature(t: TypeParameter) = contentBuilder.contentFor(t) { + private fun signature(t: DTypeParameter) = contentBuilder.contentFor(t) { link(t.name, t.dri) list(t.bounds, prefix = " : ") { signatureForProjection(it) diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt index 4d47401b..bb7dbaaf 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentableMerger.kt @@ -1,10 +1,10 @@ package org.jetbrains.dokka.base.transformers.documentables import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.Enum -import org.jetbrains.dokka.model.Function -import org.jetbrains.dokka.model.Package -import org.jetbrains.dokka.model.Annotation +import org.jetbrains.dokka.model.DEnum +import org.jetbrains.dokka.model.DFunction +import org.jetbrains.dokka.model.DPackage +import org.jetbrains.dokka.model.DAnnotation import org.jetbrains.dokka.model.properties.mergeExtras import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.plugability.DokkaContext @@ -12,7 +12,7 @@ import org.jetbrains.dokka.transformers.documentation.DocumentableMerger import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult internal object DefaultDocumentableMerger : DocumentableMerger { - override fun invoke(modules: Collection, context: DokkaContext): Module { + override fun invoke(modules: Collection, context: DokkaContext): DModule { val name = modules.map { it.name }.distinct().singleOrNull() ?: run { context.logger.error("All module names need to be the same") modules.first().name @@ -21,11 +21,11 @@ internal object DefaultDocumentableMerger : DocumentableMerger { return modules.reduce { left, right -> val list = listOf(left, right) - Module( + DModule( name = name, packages = merge( list.flatMap { it.packages }, - Package::mergeWith + DPackage::mergeWith ), documentation = list.platformDependentFor { documentation }, platformData = list.flatMap { it.platformData }.distinct() @@ -106,25 +106,25 @@ private sealed class Expect { } } -fun Package.mergeWith(other: Package): Package = copy( - functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, - properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, - classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), +fun DPackage.mergeWith(other: DPackage): DPackage = copy( + functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) }, + properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) }, + classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData), documentation = documentation.mergeWith(other.documentation), platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) -fun Function.mergeWith(other: Function): Function = copy( - parameters = merge(this.parameters + other.parameters, Parameter::mergeWith), +fun DFunction.mergeWith(other: DFunction): DFunction = copy( + parameters = merge(this.parameters + other.parameters, DParameter::mergeWith), receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver, documentation = documentation.mergeWith(other.documentation), sources = sources.mergeWith(other.sources), visibility = visibility.mergeWith(other.visibility), platformData = (platformData + other.platformData).distinct(), - generics = merge(generics + other.generics, TypeParameter::mergeWith) + generics = merge(generics + other.generics, DTypeParameter::mergeWith) ).mergeExtras(this, other) -fun Property.mergeWith(other: Property): Property = copy( +fun DProperty.mergeWith(other: DProperty): DProperty = copy( receiver = receiver?.let { r -> other.receiver?.let { r.mergeWith(it) } ?: r } ?: other.receiver, documentation = documentation.mergeWith(other.documentation), sources = sources.mergeWith(other.sources), @@ -134,33 +134,33 @@ fun Property.mergeWith(other: Property): Property = copy( setter = setter?.let { s -> other.setter?.let { s.mergeWith(it) } ?: s } ?: other.setter ).mergeExtras(this, other) -fun Classlike.setPlatformData(platformData: List): Classlike = when (this) { - is Class -> copy(platformData = platformData) - is Enum -> copy(platformData = platformData) - is Interface -> copy(platformData = platformData) - is Object -> copy(platformData = platformData) +fun DClasslike.setPlatformData(platformData: List): DClasslike = when (this) { + is DClass -> copy(platformData = platformData) + is DEnum -> copy(platformData = platformData) + is DInterface -> copy(platformData = platformData) + is DObject -> copy(platformData = platformData) else -> throw IllegalStateException("${this::class.qualifiedName} ${this.name} cannot have platform set") } -fun Classlike.mergeWith(other: Classlike): Classlike = when { - this is Class && other is Class -> mergeWith(other) - this is Enum && other is Enum -> mergeWith(other) - this is Interface && other is Interface -> mergeWith(other) - this is Object && other is Object -> mergeWith(other) - this is Annotation && other is Annotation -> mergeWith(other) +fun DClasslike.mergeWith(other: DClasslike): DClasslike = when { + this is DClass && other is DClass -> mergeWith(other) + this is DEnum && other is DEnum -> mergeWith(other) + this is DInterface && other is DInterface -> mergeWith(other) + this is DObject && other is DObject -> mergeWith(other) + this is DAnnotation && other is DAnnotation -> mergeWith(other) else -> throw IllegalStateException("${this::class.qualifiedName} ${this.name} cannot be mergesd with ${other::class.qualifiedName} ${other.name}") } -fun Class.mergeWith(other: Class): Class = copy( +fun DClass.mergeWith(other: DClass): DClass = copy( constructors = mergeExpectActual( constructors + other.constructors, - Function::mergeWith + DFunction::mergeWith ) { copy(platformData = it) }, - functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, - properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, - classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), + functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) }, + properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) }, + classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData), companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, - generics = merge(generics + other.generics, TypeParameter::mergeWith), + generics = merge(generics + other.generics, DTypeParameter::mergeWith), supertypes = supertypes.mergeWith(other.supertypes), documentation = documentation.mergeWith(other.documentation), sources = sources.mergeWith(other.sources), @@ -168,15 +168,15 @@ fun Class.mergeWith(other: Class): Class = copy( platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) -fun Enum.mergeWith(other: Enum): Enum = copy( - entries = merge(entries + other.entries, EnumEntry::mergeWith), +fun DEnum.mergeWith(other: DEnum): DEnum = copy( + entries = merge(entries + other.entries, DEnumEntry::mergeWith), constructors = mergeExpectActual( constructors + other.constructors, - Function::mergeWith + DFunction::mergeWith ) { copy(platformData = it) }, - functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, - properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, - classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), + functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) }, + properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) }, + classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData), companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, supertypes = supertypes.mergeWith(other.supertypes), documentation = documentation.mergeWith(other.documentation), @@ -185,18 +185,18 @@ fun Enum.mergeWith(other: Enum): Enum = copy( platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) -fun EnumEntry.mergeWith(other: EnumEntry): EnumEntry = copy( - functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, - properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, - classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), +fun DEnumEntry.mergeWith(other: DEnumEntry): DEnumEntry = copy( + functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) }, + properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) }, + classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData), documentation = documentation.mergeWith(other.documentation), platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) -fun Object.mergeWith(other: Object): Object = copy( - functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, - properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, - classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), +fun DObject.mergeWith(other: DObject): DObject = copy( + functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) }, + properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) }, + classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData), supertypes = supertypes.mergeWith(other.supertypes), documentation = documentation.mergeWith(other.documentation), sources = sources.mergeWith(other.sources), @@ -204,12 +204,12 @@ fun Object.mergeWith(other: Object): Object = copy( platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) -fun Interface.mergeWith(other: Interface): Interface = copy( - functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, - properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, - classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), +fun DInterface.mergeWith(other: DInterface): DInterface = copy( + functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) }, + properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) }, + classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData), companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, - generics = merge(generics + other.generics, TypeParameter::mergeWith), + generics = merge(generics + other.generics, DTypeParameter::mergeWith), supertypes = supertypes.mergeWith(other.supertypes), documentation = documentation.mergeWith(other.documentation), sources = sources.mergeWith(other.sources), @@ -217,14 +217,14 @@ fun Interface.mergeWith(other: Interface): Interface = copy( platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) -fun Annotation.mergeWith(other: Annotation): Annotation = copy( +fun DAnnotation.mergeWith(other: DAnnotation): DAnnotation = copy( constructors = mergeExpectActual( constructors + other.constructors, - Function::mergeWith + DFunction::mergeWith ) { copy(platformData = it) }, - functions = mergeExpectActual(functions + other.functions, Function::mergeWith) { copy(platformData = it) }, - properties = mergeExpectActual(properties + other.properties, Property::mergeWith) { copy(platformData = it) }, - classlikes = mergeExpectActual(classlikes + other.classlikes, Classlike::mergeWith, Classlike::setPlatformData), + functions = mergeExpectActual(functions + other.functions, DFunction::mergeWith) { copy(platformData = it) }, + properties = mergeExpectActual(properties + other.properties, DProperty::mergeWith) { copy(platformData = it) }, + classlikes = mergeExpectActual(classlikes + other.classlikes, DClasslike::mergeWith, DClasslike::setPlatformData), companion = companion?.let { c -> other.companion?.let { c.mergeWith(it) } ?: c } ?: other.companion, documentation = documentation.mergeWith(other.documentation), sources = sources.mergeWith(other.sources), @@ -232,12 +232,12 @@ fun Annotation.mergeWith(other: Annotation): Annotation = copy( platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) -fun Parameter.mergeWith(other: Parameter): Parameter = copy( +fun DParameter.mergeWith(other: DParameter): DParameter = copy( documentation = documentation.mergeWith(other.documentation), platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) -fun TypeParameter.mergeWith(other: TypeParameter): TypeParameter = copy( +fun DTypeParameter.mergeWith(other: DTypeParameter): DTypeParameter = copy( documentation = documentation.mergeWith(other.documentation), platformData = (platformData + other.platformData).distinct() ).mergeExtras(this, other) \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 9a71145f..eb23ffd7 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -5,8 +5,8 @@ import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.withClass import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.Enum -import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.DEnum +import org.jetbrains.dokka.model.DFunction import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.pages.PlatformData @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBo import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.components.isVararg import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic -import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperclassesWithoutAny import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces @@ -30,7 +29,6 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeProjection import org.jetbrains.dokka.model.Variance -import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.fqName import org.jetbrains.kotlin.idea.kdoc.findKDoc class DefaultDescriptorToDocumentableTranslator( @@ -47,7 +45,7 @@ class DefaultDescriptorToDocumentableTranslator( DRIWithPlatformInfo(DRI.topLevel, PlatformDependent.empty()) ) } - }.let { Module(moduleName, it, PlatformDependent.empty(), listOf(platformData)) } + }.let { DModule(moduleName, it, PlatformDependent.empty(), listOf(platformData)) } } @@ -69,11 +67,11 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv override fun visitPackageFragmentDescriptor( descriptor: PackageFragmentDescriptor, parent: DRIWithPlatformInfo - ): Package { + ): DPackage { val driWithPlatform = DRI(packageName = descriptor.fqName.asString()).withEmptyInfo() val scope = descriptor.getMemberScope() - return Package( + return DPackage( dri = driWithPlatform.dri, functions = scope.functions(driWithPlatform), properties = scope.properties(driWithPlatform), @@ -83,7 +81,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ) } - override fun visitClassDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): Classlike = + override fun visitClassDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): DClasslike = when (descriptor.kind) { ClassKind.ENUM_CLASS -> enumDescriptor(descriptor, parent) ClassKind.OBJECT -> objectDescriptor(descriptor, parent) @@ -91,12 +89,12 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv else -> classDescriptor(descriptor, parent) } - private fun interfaceDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): Interface { + private fun interfaceDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): DInterface { val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo() val scope = descriptor.unsubstitutedMemberScope val info = descriptor.resolveClassDescriptionData(platformData) - return Interface( + return DInterface( dri = driWithPlatform.dri, name = descriptor.name.asString(), functions = scope.functions(driWithPlatform), @@ -113,12 +111,12 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ) } - private fun objectDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): Object { + private fun objectDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): DObject { val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo() val scope = descriptor.unsubstitutedMemberScope val info = descriptor.resolveClassDescriptionData(platformData) - return Object( + return DObject( dri = driWithPlatform.dri, name = descriptor.name.asString(), functions = scope.functions(driWithPlatform), @@ -133,12 +131,12 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ) } - private fun enumDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): Enum { + private fun enumDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): DEnum { val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo() val scope = descriptor.unsubstitutedMemberScope val info = descriptor.resolveClassDescriptionData(platformData) - return Enum( + return DEnum( dri = driWithPlatform.dri, name = descriptor.name.asString(), entries = scope.enumEntries(driWithPlatform), @@ -156,11 +154,11 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ) } - private fun enumEntryDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): EnumEntry { + private fun enumEntryDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): DEnumEntry { val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo() val scope = descriptor.unsubstitutedMemberScope - return EnumEntry( + return DEnumEntry( dri = driWithPlatform.dri, name = descriptor.name.asString(), documentation = descriptor.resolveDescriptorData(platformData), @@ -172,13 +170,13 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ) } - private fun classDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): Class { + private fun classDescriptor(descriptor: ClassDescriptor, parent: DRIWithPlatformInfo): DClass { val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo() val scope = descriptor.unsubstitutedMemberScope val info = descriptor.resolveClassDescriptionData(platformData) val actual = descriptor.createSources() - return Class( + return DClass( dri = driWithPlatform.dri, name = descriptor.name.asString(), constructors = descriptor.constructors.map { @@ -203,11 +201,11 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ) } - override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, parent: DRIWithPlatformInfo): Property { + override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, parent: DRIWithPlatformInfo): DProperty { val dri = parent.dri.copy(callable = Callable.from(descriptor)) val actual = descriptor.createSources() - return Property( + return DProperty( dri = dri, name = descriptor.name.asString(), receiver = descriptor.extensionReceiverParameter?.let { @@ -229,11 +227,11 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ) } - override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, parent: DRIWithPlatformInfo): Function { + override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, parent: DRIWithPlatformInfo): DFunction { val dri = parent.dri.copy(callable = Callable.from(descriptor)) val actual = descriptor.createSources() - return Function( + return DFunction( dri = dri, name = descriptor.name.asString(), isConstructor = false, @@ -254,10 +252,10 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ) } - override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor, parent: DRIWithPlatformInfo): Function { + override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor, parent: DRIWithPlatformInfo): DFunction { val dri = parent.dri.copy(callable = Callable.from(descriptor)) val actual = descriptor.createSources() - return Function( + return DFunction( dri = dri, name = "", isConstructor = true, @@ -281,7 +279,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv override fun visitReceiverParameterDescriptor( descriptor: ReceiverParameterDescriptor, parent: DRIWithPlatformInfo - ) = Parameter( + ) = DParameter( dri = parent.dri.copy(target = 0), name = null, type = descriptor.type.toBound(), @@ -293,12 +291,12 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv descriptor: PropertyAccessorDescriptor, propertyDescriptor: PropertyDescriptor, parent: DRI - ): Function { + ): DFunction { val dri = parent.copy(callable = Callable.from(descriptor)) val isGetter = descriptor is PropertyGetterDescriptor fun PropertyDescriptor.asParameter(parent: DRI) = - Parameter( + DParameter( parent.copy(target = 1), this.name.asString(), type = this.type.toBound(), @@ -320,7 +318,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv listOf(propertyDescriptor.asParameter(dri)) } - return Function( + return DFunction( dri, name, isConstructor = false, @@ -343,7 +341,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv } private fun parameter(index: Int, descriptor: ValueParameterDescriptor, parent: DRIWithPlatformInfo) = - Parameter( + DParameter( dri = parent.dri.copy(target = index + 1), name = descriptor.name.asString(), type = descriptor.type.toBound(), @@ -352,28 +350,28 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv extra = descriptor.additionalExtras() ) - private fun MemberScope.functions(parent: DRIWithPlatformInfo): List = + private fun MemberScope.functions(parent: DRIWithPlatformInfo): List = getContributedDescriptors(DescriptorKindFilter.FUNCTIONS) { true } .filterIsInstance() .map { visitFunctionDescriptor(it, parent) } - private fun MemberScope.properties(parent: DRIWithPlatformInfo): List = + private fun MemberScope.properties(parent: DRIWithPlatformInfo): List = getContributedDescriptors(DescriptorKindFilter.VALUES) { true } .filterIsInstance() .map { visitPropertyDescriptor(it, parent) } - private fun MemberScope.classlikes(parent: DRIWithPlatformInfo): List = + private fun MemberScope.classlikes(parent: DRIWithPlatformInfo): List = getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS) { true } .filterIsInstance() .map { visitClassDescriptor(it, parent) } - .mapNotNull { it as? Classlike } + .mapNotNull { it as? DClasslike } - private fun MemberScope.packages(parent: DRIWithPlatformInfo): List = + private fun MemberScope.packages(parent: DRIWithPlatformInfo): List = getContributedDescriptors(DescriptorKindFilter.PACKAGES) { true } .filterIsInstance() .map { visitPackageFragmentDescriptor(it, parent) } - private fun MemberScope.enumEntries(parent: DRIWithPlatformInfo): List = + private fun MemberScope.enumEntries(parent: DRIWithPlatformInfo): List = this.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS) { true } .filterIsInstance() .filter { it.kind == ClassKind.ENUM_ENTRY } @@ -391,7 +389,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv } private fun TypeParameterDescriptor.toTypeParameter() = - TypeParameter( + DTypeParameter( DRI.from(this), name.identifier, PlatformDependent.from(platformData, getDocumentation()), @@ -428,7 +426,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv MarkdownParser(resolutionFacade, this).parseFromKDocTag(it) } - fun ClassDescriptor.companion(dri: DRIWithPlatformInfo): Object? = companionObjectDescriptor?.let { + fun ClassDescriptor.companion(dri: DRIWithPlatformInfo): DObject? = companionObjectDescriptor?.let { objectDescriptor(it, dri) } @@ -467,7 +465,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ExtraModifiers.OVERRIDE.takeIf { getSuperInterfaces().isNotEmpty() || getSuperClassNotAny() != null } ).toContainer() - fun ValueParameterDescriptor.additionalExtras(): PropertyContainer = + fun ValueParameterDescriptor.additionalExtras(): PropertyContainer = listOfNotNull( ExtraModifiers.DYNAMIC.takeIf { isDynamic() }, ExtraModifiers.NOINLINE.takeIf { isNoinline }, @@ -477,13 +475,13 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv ExtraModifiers.VARARG.takeIf { isVararg } ).toContainer() - fun TypeParameterDescriptor.additionalExtras(): PropertyContainer = + fun TypeParameterDescriptor.additionalExtras(): PropertyContainer = listOfNotNull( ExtraModifiers.DYNAMIC.takeIf { isDynamic() }, ExtraModifiers.REIFIED.takeIf { isReified } ).toContainer() - fun PropertyDescriptor.additionalExtras(): PropertyContainer = listOfNotNull( + fun PropertyDescriptor.additionalExtras(): PropertyContainer = listOfNotNull( ExtraModifiers.DYNAMIC.takeIf { isDynamic() }, ExtraModifiers.CONST.takeIf { isConst }, ExtraModifiers.LATEINIT.takeIf { isLateInit }, diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt index 16f9b9b3..04251947 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultDocumentableToPageTranslator.kt @@ -2,7 +2,7 @@ package org.jetbrains.dokka.base.translators.documentables import org.jetbrains.dokka.base.signatures.SignatureProvider import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter -import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.pages.ModulePageNode import org.jetbrains.dokka.transformers.documentation.DocumentableToPageTranslator import org.jetbrains.dokka.utilities.DokkaLogger @@ -12,6 +12,6 @@ class DefaultDocumentableToPageTranslator( private val signatureProvider: SignatureProvider, private val logger: DokkaLogger ) : DocumentableToPageTranslator { - override fun invoke(module: Module): ModulePageNode = + override fun invoke(module: DModule): ModulePageNode = DefaultPageCreator(commentsToContentConverter, signatureProvider, logger).pageForModule(module) } \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index 560bda71..a0b5a072 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -4,7 +4,7 @@ import org.jetbrains.dokka.base.signatures.SignatureProvider import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.DFunction import org.jetbrains.dokka.model.doc.Property import org.jetbrains.dokka.model.doc.TagWrapper import org.jetbrains.dokka.pages.* @@ -17,16 +17,16 @@ open class DefaultPageCreator( ) { protected open val contentBuilder = PageContentBuilder(commentsToContentConverter, signatureProvider, logger) - open fun pageForModule(m: Module) = + open fun pageForModule(m: DModule) = ModulePageNode(m.name.ifEmpty { "" }, contentForModule(m), m, m.packages.map(::pageForPackage)) - open fun pageForPackage(p: Package): PackagePageNode = PackagePageNode( + open fun pageForPackage(p: DPackage): PackagePageNode = PackagePageNode( p.name, contentForPackage(p), setOf(p.dri), p, p.classlikes.map(::pageForClasslike) + p.functions.map(::pageForFunction) ) - open fun pageForClasslike(c: Classlike): ClasslikePageNode { + open fun pageForClasslike(c: DClasslike): ClasslikePageNode { val constructors = if (c is WithConstructors) c.constructors else emptyList() return ClasslikePageNode( @@ -37,9 +37,9 @@ open class DefaultPageCreator( ) } - open fun pageForFunction(f: Function) = MemberPageNode(f.name, contentForFunction(f), setOf(f.dri), f) + open fun pageForFunction(f: DFunction) = MemberPageNode(f.name, contentForFunction(f), setOf(f.dri), f) - protected open fun contentForModule(m: Module) = contentBuilder.contentFor(m) { + protected open fun contentForModule(m: DModule) = contentBuilder.contentFor(m) { header(1) { text(m.name) } block("Packages", 2, ContentKind.Packages, m.packages, m.platformData.toSet()) { link(it.name, it.dri) @@ -48,7 +48,7 @@ open class DefaultPageCreator( // text("Link to allpage here") } - protected open fun contentForPackage(p: Package) = contentBuilder.contentFor(p) { + protected open fun contentForPackage(p: DPackage) = contentBuilder.contentFor(p) { header(1) { text("Package ${p.name}") } +contentForScope(p, p.dri, p.platformData) } @@ -87,7 +87,7 @@ open class DefaultPageCreator( } } - protected open fun contentForClasslike(c: Classlike) = contentBuilder.contentFor(c) { + protected open fun contentForClasslike(c: DClasslike) = contentBuilder.contentFor(c) { header(1) { text(c.name.orEmpty()) } +buildSignature(c) @@ -126,7 +126,7 @@ open class DefaultPageCreator( } }.children - protected open fun contentForFunction(f: Function) = contentBuilder.contentFor(f) { + protected open fun contentForFunction(f: DFunction) = contentBuilder.contentFor(f) { header(1) { text(f.name) } +buildSignature(f) +contentForComments(f) diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 65f94843..c5c72a65 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -9,9 +9,9 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.JavaClassReference import org.jetbrains.dokka.links.withClass import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.Annotation -import org.jetbrains.dokka.model.Enum -import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.DAnnotation +import org.jetbrains.dokka.model.DEnum +import org.jetbrains.dokka.model.DFunction import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.plugability.DokkaContext @@ -31,17 +31,17 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { psiFiles: List, platformData: PlatformData, context: DokkaContext - ): Module { + ): DModule { val docParser = DokkaPsiParser( platformData, context.logger ) - return Module( + return DModule( moduleName, psiFiles.groupBy { it.packageName }.map { (packageName, psiFiles) -> val dri = DRI(packageName = packageName) - Package( + DPackage( dri, emptyList(), emptyList(), @@ -93,7 +93,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { private fun T.toPlatformDependant() = PlatformDependent(mapOf(platformData to this)) - fun parseClasslike(psi: PsiClass, parent: DRI): Classlike = with(psi) { + fun parseClasslike(psi: PsiClass, parent: DRI): DClasslike = with(psi) { val dri = parent.withClass(name.toString()) val ancestorsSet = hashSetOf() val superMethodsKeys = hashSetOf() @@ -133,7 +133,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { val ancestors = ancestorsSet.toList().toPlatformDependant() return when { isAnnotationType -> - Annotation( + DAnnotation( name.orEmpty(), dri, documentation, @@ -146,11 +146,11 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { constructors.map { parseFunction(it, dri, true) }, listOf(platformData) ) - isEnum -> Enum( + isEnum -> DEnum( dri, name.orEmpty(), fields.filterIsInstance().map { entry -> - EnumEntry( + DEnumEntry( dri.withClass("$name.${entry.name}"), entry.name.orEmpty(), javadocParser.parseDocumentation(entry).toPlatformDependant(), @@ -171,7 +171,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { ancestors, listOf(platformData) ) - isInterface -> Interface( + isInterface -> DInterface( dri, name.orEmpty(), documentation, @@ -185,7 +185,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { ancestors, listOf(platformData) ) - else -> Class( + else -> DClass( dri, name.orEmpty(), constructors.map { parseFunction(it, dri, true) }, @@ -209,7 +209,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { parent: DRI, isConstructor: Boolean = false, isInherited: Boolean = false - ): Function { + ): DFunction { val dri = parent.copy( callable = Callable( psi.name, @@ -218,12 +218,12 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { JavaClassReference(parameter.type.canonicalText) }) ) - return Function( + return DFunction( dri, if (isConstructor) "" else psi.name, isConstructor, psi.parameterList.parameters.mapIndexed { index, psiParameter -> - Parameter( + DParameter( dri.copy(target = index + 1), psiParameter.name, javadocParser.parseDocumentation(psiParameter).toPlatformDependant(), @@ -239,7 +239,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { null, psi.getModifier(), listOf(platformData), - PropertyContainer.empty() + InheritedFunction( + PropertyContainer.empty() + InheritedFunction( isInherited ) ) @@ -278,7 +278,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { else -> JavaModifier.Empty } - private fun PsiTypeParameterListOwner.mapTypeParameters(dri: DRI): List { + private fun PsiTypeParameterListOwner.mapTypeParameters(dri: DRI): List { fun mapBounds(bounds: Array): List = if (bounds.isEmpty()) emptyList() else bounds.mapNotNull { (it as? PsiClassType)?.let { classType -> @@ -286,7 +286,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { } } return typeParameters.mapIndexed { index, type -> - TypeParameter( + DTypeParameter( dri.copy(genericTarget = index), type.name.orEmpty(), javadocParser.parseDocumentation(type).toPlatformDependant(), @@ -323,7 +323,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { return regularMethods to accessors } - private fun parseField(psi: PsiField, parent: DRI, accessors: List): Property { + private fun parseField(psi: PsiField, parent: DRI, accessors: List): DProperty { val dri = parent.copy( callable = Callable( psi.name!!, // TODO: Investigate if this is indeed nullable @@ -331,7 +331,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { emptyList() ) ) - return Property( + return DProperty( dri, psi.name!!, // TODO: Investigate if this is indeed nullable javadocParser.parseDocumentation(psi).toPlatformDependant(), diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt index ea3238a5..34e92d82 100644 --- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt +++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt @@ -1,9 +1,8 @@ package enums -import org.jetbrains.dokka.model.Enum +import org.jetbrains.dokka.model.DEnum import org.jetbrains.dokka.pages.ClasslikePageNode import org.jetbrains.dokka.pages.ModulePageNode -import org.junit.Assert import org.junit.Assert.* import org.junit.Test import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest @@ -72,7 +71,7 @@ class EnumsTest : AbstractCoreTest() { p.first().classlikes.let { c -> assertTrue("Classlikes list cannot be empty", c.isNotEmpty()) - val enum = c.first() as Enum + val enum = c.first() as DEnum assertEquals(enum.name, "Test") assertEquals(enum.entries.count(), 2) assertNotNull(enum.companion) diff --git a/plugins/base/src/test/kotlin/issues/IssuesTest.kt b/plugins/base/src/test/kotlin/issues/IssuesTest.kt index ea2f0f8e..e34c610a 100644 --- a/plugins/base/src/test/kotlin/issues/IssuesTest.kt +++ b/plugins/base/src/test/kotlin/issues/IssuesTest.kt @@ -1,7 +1,7 @@ package issues -import org.jetbrains.dokka.model.Class -import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.DClass +import org.jetbrains.dokka.model.DFunction import org.junit.Test import utils.AbstractModelTest @@ -33,16 +33,16 @@ class IssuesTest : AbstractModelTest("/src/main/kotlin/issues/Test.kt", "issues" |} """ ) { - with((this / "issues" / "Test").cast()) { + with((this / "issues" / "Test").cast()) { // passes - (this / "working").cast().type.constructorFqName equals "kotlin.String" - (this / "doSomething").cast().type.constructorFqName equals "kotlin.String" + (this / "working").cast().type.constructorFqName equals "kotlin.String" + (this / "doSomething").cast().type.constructorFqName equals "kotlin.String" // fails - (this / "brokenGenerics").cast().type.constructorFqName equals "kotlin.collections.List" - (this / "brokenApply").cast().type.constructorFqName equals "issues.Test" - (this / "brokenRun").cast().type.constructorFqName equals "issues.Test" - (this / "brokenLet").cast().type.constructorFqName equals "issues.Test" + (this / "brokenGenerics").cast().type.constructorFqName equals "kotlin.collections.List" + (this / "brokenApply").cast().type.constructorFqName equals "issues.Test" + (this / "brokenRun").cast().type.constructorFqName equals "issues.Test" + (this / "brokenLet").cast().type.constructorFqName equals "issues.Test" } } } diff --git a/plugins/base/src/test/kotlin/markdown/KDocTest.kt b/plugins/base/src/test/kotlin/markdown/KDocTest.kt index e250670a..fa538c3e 100644 --- a/plugins/base/src/test/kotlin/markdown/KDocTest.kt +++ b/plugins/base/src/test/kotlin/markdown/KDocTest.kt @@ -1,6 +1,6 @@ package markdown -import org.jetbrains.dokka.model.Package +import org.jetbrains.dokka.model.DPackage import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.pages.ModulePageNode import org.junit.Assert @@ -26,7 +26,7 @@ open class KDocTest : AbstractCoreTest() { """.trimMargin() private fun actualDocumentationNode(modulePageNode: ModulePageNode) = - (modulePageNode.documentable?.children?.first() as Package) + (modulePageNode.documentable?.children?.first() as DPackage) .classlikes.single() .documentation.values.single() diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt index a59174bf..d627dab4 100644 --- a/plugins/base/src/test/kotlin/model/ClassesTest.kt +++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt @@ -2,7 +2,7 @@ package model import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.KotlinModifier.* -import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.DFunction import org.junit.Test import utils.AbstractModelTest import utils.assertNotNull @@ -17,7 +17,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class """ |class Klass {}""" ) { - with((this / "classes" / "Klass").cast()) { + with((this / "classes" / "Klass").cast()) { name equals "Klass" children counts 4 } @@ -31,7 +31,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |object Obj {} """ ) { - with((this / "classes" / "Obj").cast()) { + with((this / "classes" / "Obj").cast()) { name equals "Obj" children counts 3 } @@ -45,7 +45,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |class Klass(name: String) """ ) { - with((this / "classes" / "Klass").cast()) { + with((this / "classes" / "Klass").cast()) { name equals "Klass" children counts 4 @@ -71,11 +71,11 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |} """ ) { - with((this / "classes" / "Klass").cast()) { + with((this / "classes" / "Klass").cast()) { name equals "Klass" children counts 5 - with((this / "fn").cast()) { + with((this / "fn").cast()) { type.constructorFqName equals "kotlin.Unit" parameters counts 0 visibility.values allEquals KotlinVisibility.Public @@ -93,11 +93,11 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |} """ ) { - with((this / "classes" / "Klass").cast()) { + with((this / "classes" / "Klass").cast()) { name equals "Klass" children counts 5 - with((this / "name").cast()) { + with((this / "name").cast()) { name equals "name" // TODO property name } @@ -117,19 +117,19 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |} """ ) { - with((this / "classes" / "Klass").cast()) { + with((this / "classes" / "Klass").cast()) { name equals "Klass" children counts 5 - with((this / "Companion").cast()) { + with((this / "Companion").cast()) { name equals "Companion" children counts 5 - with((this / "x").cast()) { + with((this / "x").cast()) { name equals "x" } - with((this / "foo").cast()) { + with((this / "foo").cast()) { name equals "foo" parameters counts 0 type.constructorFqName equals "kotlin.Unit" @@ -146,7 +146,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |data class Klass() {} """ ) { - with((this / "classes" / "Klass").cast()) { + with((this / "classes" / "Klass").cast()) { name equals "Klass" visibility.values allEquals KotlinVisibility.Public with(extra[AdditionalModifiers.AdditionalKey].assertNotNull("Extras")) { @@ -170,7 +170,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |sealed class Klass() {} """ ) { - with((this / "classes" / "Klass").cast()) { + with((this / "classes" / "Klass").cast()) { name equals "Klass" modifier equals KotlinModifier.Sealed } @@ -215,18 +215,18 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |} """ ) { - val C = (this / "classes" / "C").cast() - val D = (this / "classes" / "D").cast() + val C = (this / "classes" / "C").cast() + val D = (this / "classes" / "D").cast() with(C) { modifier equals Open - with((this / "f").cast()) { + with((this / "f").cast()) { modifier equals Open } } with(D) { modifier equals Final - with((this / "f").cast()) { + with((this / "f").cast()) { modifier equals Open } D.supertypes.flatMap { it.component2() }.firstOrNull() equals C.dri @@ -249,13 +249,13 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |} """ ) { - val C = (this / "classes" / "C").cast() - val D = (this / "classes" / "D").cast() - val E = (this / "classes" / "E").cast() + val C = (this / "classes" / "C").cast() + val D = (this / "classes" / "D").cast() + val E = (this / "classes" / "E").cast() with(C) { modifier equals Abstract - ((this / "foo").cast()).modifier equals Abstract + ((this / "foo").cast()).modifier equals Abstract } with(D) { @@ -280,9 +280,9 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |} """ ) { - with((this / "classes" / "C").cast()) { + with((this / "classes" / "C").cast()) { - with((this / "D").cast()) { + with((this / "D").cast()) { } } } @@ -312,10 +312,10 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |val Klass.Default.x: Int get() = 1 """ ) { - with((this / "classes" / "Klass").cast()) { + with((this / "classes" / "Klass").cast()) { name equals "Klass" - with((this / "Default").cast()) { + with((this / "Default").cast()) { name equals "Default" // TODO extensions } @@ -342,7 +342,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |} """ ) { - with((this / "classes" / "C").cast()) { + with((this / "classes" / "C").cast()) { name equals "C" constructors counts 2 @@ -384,14 +384,14 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class |} """ ) { - with((this / "classes" / "Klass").cast()) { + with((this / "classes" / "Klass").cast()) { name equals "Klass" - with((this / "Companion").cast()) { + with((this / "Companion").cast()) { name equals "Companion" visibility.values allEquals KotlinVisibility.Private - with((this / "fn").cast()) { + with((this / "fn").cast()) { name equals "fn" parameters counts 0 receiver equals null diff --git a/plugins/base/src/test/kotlin/model/CommentTest.kt b/plugins/base/src/test/kotlin/model/CommentTest.kt index d576cf49..055892af 100644 --- a/plugins/base/src/test/kotlin/model/CommentTest.kt +++ b/plugins/base/src/test/kotlin/model/CommentTest.kt @@ -1,6 +1,6 @@ package model -import org.jetbrains.dokka.model.Property +import org.jetbrains.dokka.model.DProperty import org.jetbrains.dokka.model.doc.CustomWrapperTag import org.jetbrains.dokka.model.doc.Text import org.junit.Test @@ -28,7 +28,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val prop2 = "" """ ) { - with((this / "comment" / "prop1").cast()) { + with((this / "comment" / "prop1").cast()) { name equals "prop1" with(this.docs().firstOrNull()?.root.assertNotNull("Code")) { (children.firstOrNull() as? Text) @@ -37,7 +37,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme params["lang"] equals "brainfuck" } } - with((this / "comment" / "prop2").cast()) { + with((this / "comment" / "prop2").cast()) { name equals "prop2" comments() equals "a + b - c" } @@ -51,7 +51,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { name equals "property" comments() equals "" } @@ -68,7 +68,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme """ ) { val p = this - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals "" } } @@ -87,7 +87,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals "doc1\ndoc2 doc3" } } @@ -107,7 +107,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals "doc1\ndoc2 doc3" } } @@ -121,7 +121,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals "doc" } } @@ -136,7 +136,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals "doc" } } @@ -151,7 +151,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals "doc" } } @@ -168,7 +168,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals "Summary\none: []" docs().find { it is CustomWrapperTag && it.name == "one" }.let { with(it.assertNotNull("'one' entry")) { @@ -188,7 +188,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals """it's "useful"""" } } @@ -205,7 +205,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals "Summary\none: [section one]" } } @@ -224,7 +224,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals "Summary\none: [section one]\ntwo: [section two]" } } @@ -243,7 +243,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |val property = "test" """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { comments() equals "Summary\none: [line one line two]" } } @@ -290,7 +290,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme |} """ ) { - with((this / "comment" / "property").cast()) { + with((this / "comment" / "property").cast()) { this } } diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt index 9554ad02..f3a7adc7 100644 --- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt +++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt @@ -1,7 +1,7 @@ package model -import org.jetbrains.dokka.model.Function -import org.jetbrains.dokka.model.Package +import org.jetbrains.dokka.model.DFunction +import org.jetbrains.dokka.model.DPackage import org.junit.Test import utils.* @@ -17,7 +17,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun |fun fn() {} """ ) { - with((this / "function" / "fn").cast()) { + with((this / "function" / "fn").cast()) { name equals "fn" type.constructorFqName equals "kotlin.Unit" this.children.assertCount(0, "Function children: ") @@ -39,7 +39,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun |fun fn(i: Int) {} """ ) { - with((this / "function").cast()) { + with((this / "function").cast()) { val fn1 = functions.find { it.name == "fn" && it.parameters.isNullOrEmpty() }.assertNotNull("fn()") @@ -76,7 +76,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun |fun String.fn(x: Int) {} """ ) { - with((this / "function").cast()) { + with((this / "function").cast()) { val fn1 = functions.find { it.name == "fn" && it.parameters.isNullOrEmpty() }.assertNotNull("fn()") @@ -114,7 +114,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun |} """ ) { - with((this / "function" / "function").cast()) { + with((this / "function" / "function").cast()) { comments() equals "Multiline\nFunction Documentation" name equals "function" @@ -141,7 +141,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun ) { // TODO add annotations - with((this / "function" / "f").cast()) { + with((this / "function" / "f").cast()) { assert(false) { "No annotation data" } } } @@ -162,7 +162,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun ) { // TODO add data about inline - with((this / "function" / "f").cast()) { + with((this / "function" / "f").cast()) { assert(false) { "No inline data" } } } @@ -184,7 +184,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun ) { // TODO add data about suspend - with((this / "function" / "f").cast()) { + with((this / "function" / "f").cast()) { assert(false) { "No suspend data" } } } diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index ea454763..c2545e7a 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -1,8 +1,8 @@ package model import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.Enum -import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.DEnum +import org.jetbrains.dokka.model.DFunction import org.junit.Assert.assertTrue import org.junit.Test import utils.AbstractModelTest @@ -24,10 +24,10 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |} """ ) { - with((this / "java" / "Test").cast()) { + with((this / "java" / "Test").cast()) { name equals "Test" children counts 1 - with((this / "fn").cast()) { + with((this / "fn").cast()) { name equals "fn" this } @@ -82,7 +82,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |} """ ) { - with((this / "java" / "Test" / "fn").cast()) { + with((this / "java" / "Test" / "fn").cast()) { this } } @@ -108,7 +108,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |public class Foo extends Exception implements Cloneable {} """ ) { - with((this / "java" / "Foo").cast()) { + with((this / "java" / "Foo").cast()) { val sups = listOf("Exception", "Cloneable") assertTrue( "Foo must extend ${sups.joinToString(", ")}", @@ -128,11 +128,11 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |} """ ) { - with((this / "java" / "Test").cast()) { + with((this / "java" / "Test").cast()) { name equals "Test" children counts 1 - with((this / "arrayToString").cast()) { + with((this / "arrayToString").cast()) { name equals "arrayToString" type.constructorFqName equals "java.lang.String[]" with(parameters.firstOrNull().assertNotNull("parameters")) { @@ -153,7 +153,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |} """ ) { - with((this / "java" / "Foo").cast()) { + with((this / "java" / "Foo").cast()) { this } } @@ -189,7 +189,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |} """ ) { - with((this / "java" / "Test").cast()) { + with((this / "java" / "Test").cast()) { name equals "Test" constructors counts 2 @@ -211,9 +211,9 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |} """ ) { - with((this / "java" / "InnerClass").cast()) { + with((this / "java" / "InnerClass").cast()) { children counts 1 - with((this / "D").cast()) { + with((this / "D").cast()) { name equals "D" children counts 0 } @@ -230,11 +230,11 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |} """ ) { - with((this / "java" / "Foo").cast()) { + with((this / "java" / "Foo").cast()) { name equals "Foo" children counts 1 - with((this / "bar").cast()) { + with((this / "bar").cast()) { name equals "bar" with(parameters.firstOrNull().assertNotNull("parameter")) { name equals "x" @@ -255,15 +255,15 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |} """ ) { - with((this / "java" / "Test").cast()) { + with((this / "java" / "Test").cast()) { children counts 2 - with((this / "i").cast()) { + with((this / "i").cast()) { getter.assertNotNull("i.get") setter.assertNotNull("i.set") } - with((this / "s").cast()) { + with((this / "s").cast()) { getter.assertNotNull("s.get") setter.assertNotNull("s.set") @@ -344,11 +344,11 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { |} """ ) { - with((this / "java" / "E").cast()) { + with((this / "java" / "E").cast()) { name equals "E" entries counts 1 - with((this / "Foo").cast()) { + with((this / "Foo").cast()) { name equals "Foo" } } diff --git a/plugins/base/src/test/kotlin/model/PackagesTest.kt b/plugins/base/src/test/kotlin/model/PackagesTest.kt index e19cc82d..008ae14d 100644 --- a/plugins/base/src/test/kotlin/model/PackagesTest.kt +++ b/plugins/base/src/test/kotlin/model/PackagesTest.kt @@ -1,6 +1,6 @@ package model -import org.jetbrains.dokka.model.Package +import org.jetbrains.dokka.model.DPackage import org.junit.Test import utils.AbstractModelTest @@ -14,7 +14,7 @@ class PackagesTest : AbstractModelTest("/src/main/kotlin/packages/Test.kt", "pac """.trimIndent(), prependPackage = false ) { - with((this / "").cast()) { + with((this / "").cast()) { name equals "" children counts 0 } @@ -29,7 +29,7 @@ class PackagesTest : AbstractModelTest("/src/main/kotlin/packages/Test.kt", "pac """.trimIndent(), prependPackage = false ) { - with((this / "simple").cast()) { + with((this / "simple").cast()) { name equals "simple" children counts 0 } @@ -44,7 +44,7 @@ class PackagesTest : AbstractModelTest("/src/main/kotlin/packages/Test.kt", "pac """.trimIndent(), prependPackage = false ) { - with((this / "dot.name").cast()) { + with((this / "dot.name").cast()) { name equals "dot.name" children counts 0 } @@ -63,11 +63,11 @@ class PackagesTest : AbstractModelTest("/src/main/kotlin/packages/Test.kt", "pac prependPackage = false ) { children counts 2 - with((this / "dot.name").cast()) { + with((this / "dot.name").cast()) { name equals "dot.name" children counts 0 } - with((this / "simple").cast()) { + with((this / "simple").cast()) { name equals "simple" children counts 0 } @@ -85,7 +85,7 @@ class PackagesTest : AbstractModelTest("/src/main/kotlin/packages/Test.kt", "pac prependPackage = false ) { children counts 1 - with((this / "simple").cast()) { + with((this / "simple").cast()) { name equals "simple" children counts 0 } @@ -102,7 +102,7 @@ class PackagesTest : AbstractModelTest("/src/main/kotlin/packages/Test.kt", "pac """.trimIndent(), prependPackage = false ) { - with((this / "simple.name").cast()) { + with((this / "simple.name").cast()) { name equals "simple.name" children counts 1 } diff --git a/plugins/base/src/test/kotlin/model/PropertyTest.kt b/plugins/base/src/test/kotlin/model/PropertyTest.kt index e4ef0aec..d12e292b 100644 --- a/plugins/base/src/test/kotlin/model/PropertyTest.kt +++ b/plugins/base/src/test/kotlin/model/PropertyTest.kt @@ -1,8 +1,8 @@ package model import org.jetbrains.dokka.model.KotlinVisibility -import org.jetbrains.dokka.model.Package -import org.jetbrains.dokka.model.Property +import org.jetbrains.dokka.model.DPackage +import org.jetbrains.dokka.model.DProperty import org.junit.Test import utils.AbstractModelTest import utils.assertNotNull @@ -15,7 +15,7 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro """ |val property = "test"""" ) { - with((this / "property" / "property").cast()) { + with((this / "property" / "property").cast()) { name equals "property" children counts 0 with(getter.assertNotNull("Getter")) { @@ -33,7 +33,7 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro |var property = "test" """ ) { - with((this / "property" / "property").cast()) { + with((this / "property" / "property").cast()) { name equals "property" children counts 0 setter.assertNotNull("Setter") @@ -53,7 +53,7 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro | get() = "test" """ ) { - with((this / "property" / "property").cast()) { + with((this / "property" / "property").cast()) { name equals "property" children counts 0 with(getter.assertNotNull("Getter")) { @@ -73,7 +73,7 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro | set(value) {} """ ) { - with((this / "property" / "property").cast()) { + with((this / "property" / "property").cast()) { name equals "property" children counts 0 setter.assertNotNull("Setter") @@ -93,7 +93,7 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro | get() = size() * 2 """ ) { - with((this / "property" / "property").cast()) { + with((this / "property" / "property").cast()) { name equals "property" children counts 0 with(receiver.assertNotNull("property receiver")) { @@ -120,15 +120,15 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro |} """ ) { - with((this / "property").cast()) { - with((this / "Foo" / "property").cast()) { + with((this / "property").cast()) { + with((this / "Foo" / "property").cast()) { name equals "property" children counts 0 with(getter.assertNotNull("Getter")) { type.constructorFqName equals "kotlin.Int" } } - with((this / "Bar" / "property").cast()) { + with((this / "Bar" / "property").cast()) { name equals "property" children counts 0 with(getter.assertNotNull("Getter")) { diff --git a/plugins/base/src/test/kotlin/utils/ModelUtils.kt b/plugins/base/src/test/kotlin/utils/ModelUtils.kt index 75c8e008..1e6f64c6 100644 --- a/plugins/base/src/test/kotlin/utils/ModelUtils.kt +++ b/plugins/base/src/test/kotlin/utils/ModelUtils.kt @@ -1,8 +1,6 @@ package utils -import org.jetbrains.dokka.model.Module -import org.jetbrains.dokka.model.doc.DocumentationNode -import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.jetbrains.dokka.model.DModule abstract class AbstractModelTest(val path: String? = null, val pkg: String) : ModelDSL(), AssertDSL { @@ -11,7 +9,7 @@ abstract class AbstractModelTest(val path: String? = null, val pkg: String) : Mo platform: String = "jvm", targetList: List = listOf("jvm"), prependPackage: Boolean = true, - block: Module.() -> Unit + block: DModule.() -> Unit ) { val configuration = dokkaConfiguration { passes { diff --git a/plugins/base/src/test/kotlin/utils/TestUtils.kt b/plugins/base/src/test/kotlin/utils/TestUtils.kt index 6913ba5b..bf86c1b1 100644 --- a/plugins/base/src/test/kotlin/utils/TestUtils.kt +++ b/plugins/base/src/test/kotlin/utils/TestUtils.kt @@ -1,13 +1,9 @@ package utils -import org.jetbrains.dokka.model.Class +import org.jetbrains.dokka.model.DClass import org.jetbrains.dokka.model.Documentable -import org.jetbrains.dokka.model.Function -import org.jetbrains.dokka.model.Property import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest -import kotlin.reflect.KClass -import kotlin.reflect.full.safeCast @DslMarker annotation class TestDSL @@ -64,5 +60,5 @@ fun T?.assertNotNull(name: String = ""): T = this ?: throw AssertionError("$ fun T?.docs() = this?.documentation.orEmpty().values.flatMap { it.children } -val Class.supers +val DClass.supers get() = supertypes.flatMap{it.component2()} \ No newline at end of file diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index cf777e67..991ee07d 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -4,9 +4,9 @@ import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.withClass import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.Annotation -import org.jetbrains.dokka.model.Enum -import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.DAnnotation +import org.jetbrains.dokka.model.DEnum +import org.jetbrains.dokka.model.DFunction import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap import org.jetbrains.kotlin.name.ClassId @@ -21,21 +21,21 @@ private fun List.groupedByLocation() = } // TODO: first() does not look reasonable }) { it.second } -internal fun Package.asJava(): Package { +internal fun DPackage.asJava(): DPackage { @Suppress("UNCHECKED_CAST") val syntheticClasses = ((properties + functions) as List) .groupedByLocation() .map { (syntheticClassName, nodes) -> - Class( + DClass( dri = dri.withClass(syntheticClassName), name = syntheticClassName, - properties = nodes.filterIsInstance().map { it.asJava() }, + properties = nodes.filterIsInstance().map { it.asJava() }, constructors = emptyList(), functions = ( - nodes.filterIsInstance() + nodes.filterIsInstance() .map { it.javaAccessors() } + - nodes.filterIsInstance() - .map { it.asJava(syntheticClassName) }) as List, // TODO: methods are static and receiver is a param + nodes.filterIsInstance() + .map { it.asJava(syntheticClassName) }) as List, // TODO: methods are static and receiver is a param classlikes = emptyList(), sources = PlatformDependent.empty(), visibility = PlatformDependent( @@ -60,7 +60,7 @@ internal fun Package.asJava(): Package { ) } -internal fun Property.asJava(isTopLevel: Boolean = false, relocateToClass: String? = null) = +internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: String? = null) = copy( dri = if (relocateToClass.isNullOrBlank()) { dri @@ -81,7 +81,7 @@ internal fun Property.asJava(isTopLevel: Boolean = false, relocateToClass: Strin extra = if (isTopLevel) extra.plus(extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else extra ) -internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass: String? = null): List = +internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClass: String? = null): List = listOfNotNull( getter?.copy( dri = if (relocateToClass.isNullOrBlank()) { @@ -122,7 +122,7 @@ internal fun Property.javaAccessors(isTopLevel: Boolean = false, relocateToClass ) -internal fun Function.asJava(containingClassName: String): Function { +internal fun DFunction.asJava(containingClassName: String): DFunction { val newName = when { isConstructor -> containingClassName else -> name @@ -137,16 +137,16 @@ internal fun Function.asJava(containingClassName: String): Function { ) // TODO static if toplevel } -internal fun Classlike.asJava(): Classlike = when (this) { - is Class -> asJava() - is Enum -> asJava() - is Annotation -> asJava() - is Object -> asJava() - is Interface -> asJava() +internal fun DClasslike.asJava(): DClasslike = when (this) { + is DClass -> asJava() + is DEnum -> asJava() + is DAnnotation -> asJava() + is DObject -> asJava() + is DInterface -> asJava() else -> throw IllegalArgumentException("$this shouldn't be here") } -internal fun Class.asJava(): Class = copy( +internal fun DClass.asJava(): DClass = copy( constructors = constructors.map { it.asJava(name) }, functions = (functions + properties.map { it.getter } + properties.map { it.setter }).filterNotNull().map { it.asJava(name) @@ -160,7 +160,7 @@ internal fun Class.asJava(): Class = copy( modifier = if (modifier is KotlinModifier.Empty) JavaModifier.Final else modifier ) -private fun TypeParameter.asJava(): TypeParameter = copy( +private fun DTypeParameter.asJava(): DTypeParameter = copy( dri = dri.possiblyAsJava(), bounds = bounds.map { it.asJava() } ) @@ -175,7 +175,7 @@ private fun Bound.asJava(): Bound = when (this) { else -> this } -internal fun Enum.asJava(): Enum = copy( +internal fun DEnum.asJava(): DEnum = copy( constructors = constructors.map { it.asJava(name) }, functions = (functions + properties.map { it.getter } + properties.map { it.setter }).filterNotNull().map { it.asJava(name) @@ -188,12 +188,12 @@ internal fun Enum.asJava(): Enum = copy( // , entries = entries.map { it.asJava() } ) -internal fun Object.asJava(): Object = copy( +internal fun DObject.asJava(): DObject = copy( functions = (functions + properties.map { it.getter } + properties.map { it.setter }) .filterNotNull() .map { it.asJava(name.orEmpty()) }, properties = properties.map { it.asJava() } + - Property( + DProperty( name = "INSTANCE", modifier = JavaModifier.Final, dri = dri.copy(callable = Callable("INSTANCE", null, emptyList())), @@ -209,7 +209,7 @@ internal fun Object.asJava(): Object = copy( getter = null, platformData = platformData, receiver = null, - extra = PropertyContainer.empty() + AdditionalModifiers(setOf(ExtraModifiers.STATIC)) + extra = PropertyContainer.empty() + AdditionalModifiers(setOf(ExtraModifiers.STATIC)) ), classlikes = classlikes.map { it.asJava() }, supertypes = supertypes.copy( @@ -217,7 +217,7 @@ internal fun Object.asJava(): Object = copy( ) ) -internal fun Interface.asJava(): Interface = copy( +internal fun DInterface.asJava(): DInterface = copy( functions = (functions + properties.map { it.getter } + properties.map { it.setter }) .filterNotNull() .map { it.asJava(name) }, @@ -229,13 +229,13 @@ internal fun Interface.asJava(): Interface = copy( ) ) -internal fun Annotation.asJava(): Annotation = copy( +internal fun DAnnotation.asJava(): DAnnotation = copy( properties = properties.map { it.asJava() }, constructors = emptyList(), classlikes = classlikes.map { it.asJava() } ) // TODO investigate if annotation class can have methods and properties not from constructor -internal fun Parameter.asJava(): Parameter = copy( +internal fun DParameter.asJava(): DParameter = copy( type = type.asJava(), name = if (name.isNullOrBlank()) "\$self" else name ) 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 55dd7a97..0ec7d0af 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -5,9 +5,9 @@ import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentCon import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.links.sureClassNames import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.Annotation -import org.jetbrains.dokka.model.Enum -import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.DAnnotation +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.TextStyle @@ -22,28 +22,28 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge override fun signature(documentable: Documentable): ContentNode = when (documentable) { - is Function -> signature(documentable) - is Property -> signature(documentable) - is Classlike -> signature(documentable) - is TypeParameter -> signature(documentable) + is DFunction -> signature(documentable) + is DProperty -> signature(documentable) + is DClasslike -> signature(documentable) + is DTypeParameter -> signature(documentable) else -> throw NotImplementedError( "Cannot generate signature for ${documentable::class.qualifiedName} ${documentable.name}" ) } - private fun signature(c: Classlike) = contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace)) { + private fun signature(c: DClasslike) = contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace)) { platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } - if (c is Class) { + if (c is DClass) { text(c.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") } when (c) { - is Class -> text("class ") - is Interface -> text("interface ") - is Enum -> text("enum ") - is Object -> text("class ") - is Annotation -> text("@interface ") + is DClass -> text("class ") + is DInterface -> text("interface ") + is DEnum -> text("enum ") + is DObject -> text("class ") + is DAnnotation -> text("@interface ") } link(c.name!!, c.dri) if (c is WithGenerics) { @@ -60,11 +60,11 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge } } - private fun signature(p: Property) = contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace)) { + private fun signature(p: DProperty) = contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace)) { signatureForProjection(p.type) } - private fun signature(f: Function) = contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace)) { + private fun signature(f: DFunction) = contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace)) { text(f.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") val returnType = f.type signatureForProjection(returnType) @@ -82,7 +82,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge text(")") } - private fun signature(t: TypeParameter) = contentBuilder.contentFor(t) { + private fun signature(t: DTypeParameter) = contentBuilder.contentFor(t) { text(t.name.substringAfterLast(".")) list(t.bounds, prefix = " extends ") { signatureForProjection(it) diff --git a/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt b/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt index 8f51e105..8b07670f 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/transformers/KotlinAsJavaDocumentableTransformer.kt @@ -1,11 +1,11 @@ package org.jetbrains.dokka.kotlinAsJava.transformers import org.jetbrains.dokka.kotlinAsJava.converters.asJava -import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer class KotlinAsJavaDocumentableTransformer : DocumentableTransformer { - override fun invoke(original: Module, context: DokkaContext): Module = + override fun invoke(original: DModule, context: DokkaContext): DModule = original.copy(packages = original.packages.map { it.asJava() }) } diff --git a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt index 641cc5f9..a0e3b709 100644 --- a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt +++ b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt @@ -1,7 +1,7 @@ package org.jetbrains.dokka.testApi.testRunner import org.jetbrains.dokka.* -import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.pages.ModulePageNode import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.pages.RootPageNode @@ -104,9 +104,9 @@ abstract class AbstractCoreTest { protected class TestBuilder { var analysisSetupStage: (Map) -> Unit = {} var pluginsSetupStage: (DokkaContext) -> Unit = {} - var documentablesCreationStage: (List) -> Unit = {} - var documentablesMergingStage: (Module) -> Unit = {} - var documentablesTransformationStage: (Module) -> Unit = {} + var documentablesCreationStage: (List) -> Unit = {} + var documentablesMergingStage: (DModule) -> Unit = {} + var documentablesTransformationStage: (DModule) -> Unit = {} var pagesGenerationStage: (ModulePageNode) -> Unit = {} var pagesTransformationStage: (RootPageNode) -> Unit = {} var renderingStage: (RootPageNode, DokkaContext) -> Unit = { a, b -> } @@ -216,9 +216,9 @@ abstract class AbstractCoreTest { data class TestMethods( val analysisSetupStage: (Map) -> Unit, val pluginsSetupStage: (DokkaContext) -> Unit, - val documentablesCreationStage: (List) -> Unit, - val documentablesMergingStage: (Module) -> Unit, - val documentablesTransformationStage: (Module) -> Unit, + val documentablesCreationStage: (List) -> Unit, + val documentablesMergingStage: (DModule) -> Unit, + val documentablesTransformationStage: (DModule) -> Unit, val pagesGenerationStage: (ModulePageNode) -> Unit, val pagesTransformationStage: (RootPageNode) -> Unit, val renderingStage: (RootPageNode, DokkaContext) -> Unit -- cgit From 03329b0eb98b309d208839344052633028e00984 Mon Sep 17 00:00:00 2001 From: Szymon Świstun Date: Wed, 18 Mar 2020 14:19:54 +0100 Subject: Fix minor bugs and add core tests --- core/src/main/kotlin/model/aditionalExtras.kt | 22 +- .../DefaultDescriptorToDocumentableTranslator.kt | 2 +- plugins/base/src/test/kotlin/enums/EnumsTest.kt | 6 +- plugins/base/src/test/kotlin/model/ClassesTest.kt | 173 +++++------ .../base/src/test/kotlin/model/FunctionsTest.kt | 321 ++++++++++++--------- .../base/src/test/kotlin/model/InheritorsTest.kt | 4 +- plugins/base/src/test/kotlin/model/JavaTest.kt | 109 +++++-- plugins/base/src/test/kotlin/model/PropertyTest.kt | 59 +++- .../test/kotlin/pageMerger/PageNodeMergerTest.kt | 10 +- plugins/base/src/test/kotlin/utils/TestUtils.kt | 5 + .../kotlin/converters/KotlinToJavaConverter.kt | 2 +- 11 files changed, 431 insertions(+), 282 deletions(-) (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/core/src/main/kotlin/model/aditionalExtras.kt b/core/src/main/kotlin/model/aditionalExtras.kt index b0755759..f7d37111 100644 --- a/core/src/main/kotlin/model/aditionalExtras.kt +++ b/core/src/main/kotlin/model/aditionalExtras.kt @@ -5,22 +5,34 @@ import org.jetbrains.dokka.model.properties.ExtraProperty import org.jetbrains.dokka.model.properties.MergeStrategy class AdditionalModifiers(val content: Set) : ExtraProperty { - object AdditionalKey : ExtraProperty.Key { + companion object : ExtraProperty.Key { override fun mergeStrategyFor( left: AdditionalModifiers, right: AdditionalModifiers ): MergeStrategy = MergeStrategy.Replace(AdditionalModifiers(left.content + right.content)) } - override fun equals(other: Any?): Boolean = if (other is AdditionalModifiers) other.content == content else false + override fun equals(other: Any?): Boolean = + if (other is AdditionalModifiers) other.content == content else false + override fun hashCode() = content.hashCode() - override val key: ExtraProperty.Key = AdditionalKey + override val key: ExtraProperty.Key = AdditionalModifiers } class Annotations(val content: List) : ExtraProperty { - companion object : ExtraProperty.Key + companion object : ExtraProperty.Key { + override fun mergeStrategyFor(left: Annotations, right: Annotations): MergeStrategy = + MergeStrategy.Replace(Annotations((left.content + right.content).distinct())) + } override val key: ExtraProperty.Key = Annotations - data class Annotation(val dri: DRI, val params: Map) + data class Annotation(val dri: DRI, val params: Map) { + override fun equals(other: Any?): Boolean = when(other) { + is Annotation -> dri.equals(other.dri) + else -> false + } + + override fun hashCode(): Int = dri.hashCode() + } } \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 8e0f1231..44679d8d 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -367,7 +367,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv type = descriptor.type.toBound(), documentation = descriptor.resolveDescriptorData(platformData), platformData = listOf(platformData), - extra = PropertyContainer.withAll(descriptor.additionalExtras()) + extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) ) private fun MemberScope.functions(parent: DRIWithPlatformInfo): List = diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt index 55ad0fbc..c9024a72 100644 --- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt +++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt @@ -34,9 +34,9 @@ class EnumsTest : AbstractCoreTest() { pagesGenerationStage = { val map = it.getClasslikeToMemberMap() val test = map.filterKeys { it.name == "Test" }.values.firstOrNull() - assert(test != null) { "Test not found" } - assert(test!!.any { it.name == "E1" } && test.any { it.name == "E2" }) { "Enum entries missing in parent" } - assert(map.keys.any { it.name == "E1" } && map.keys.any { it.name == "E2" }) { "Enum entries missing" } + assertTrue(test != null) { "Test not found" } + assertTrue(test!!.any { it.name == "E1" } && test.any { it.name == "E2" }) { "Enum entries missing in parent" } + assertTrue(map.keys.any { it.name == "E1" } && map.keys.any { it.name == "E2" }) { "Enum entries missing" } } } } diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt index bd35afc5..336023da 100644 --- a/plugins/base/src/test/kotlin/model/ClassesTest.kt +++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt @@ -1,7 +1,6 @@ package model import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.DFunction import org.jetbrains.dokka.model.KotlinModifier.* import org.junit.jupiter.api.Test import utils.AbstractModelTest @@ -150,20 +149,14 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class with((this / "classes" / "Klass").cast()) { name equals "Klass" visibility.values allEquals KotlinVisibility.Public - with(extra[AdditionalModifiers.AdditionalKey].assertNotNull("Extras")) { - content.find { it == ExtraModifiers.DATA }.assertNotNull("data modifier") + with(extra[AdditionalModifiers].assertNotNull("Extras")) { + content counts 1 + content.first() equals ExtraModifiers.DATA } } } } -// @Test fun dataClass() { -// verifyPackageMember("testdata/classes/dataClass.kt", defaultModelConfig) { cls -> -// val modifiers = cls.details(NodeKind.Modifier).map { it.name } -// assertTrue("data" in modifiers) -// } -// } - @Test fun sealedClass() { inlineModelTest( @@ -178,30 +171,25 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class } } -// // TODO modifiers -// @Test fun annotatedClassWithAnnotationParameters() { -// checkSourceExistsAndVerifyModel( -// "testdata/classes/annotatedClassWithAnnotationParameters.kt", -// defaultModelConfig -// ) { model -> -// with(model.members.single().members.single()) { -// with(deprecation!!) { -// assertEquals("Deprecated", name) -// assertEquals(Content.Empty, content) -// assertEquals(NodeKind.Annotation, kind) -// assertEquals(1, details.count()) -// with(details[0]) { -// assertEquals(NodeKind.Parameter, kind) -// assertEquals(1, details.count()) -// with(details[0]) { -// assertEquals(NodeKind.Value, kind) -// assertEquals("\"should no longer be used\"", name) -// } -// } -// } -// } -// } -// } + @Test + fun annotatedClassWithAnnotationParameters() { + inlineModelTest( + """ + |@Deprecated("should no longer be used") class Foo() {} + """ + ) { + with((this / "classes" / "Foo").cast()) { + with(extra[Annotations].assertNotNull("Annotations")) { + this.content counts 1 + with(content.first()) { + dri.classNames equals "Deprecated" + params.entries counts 1 + params["message"].assertNotNull("message") equals "should no longer be used" + } + } + } + } + } @Test fun notOpenClass() { @@ -272,7 +260,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class } } - @Test // todo inner class + @Test fun innerClass() { inlineModelTest( """ @@ -284,21 +272,15 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class with((this / "classes" / "C").cast()) { with((this / "D").cast()) { + with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) { + content counts 1 + content.first() equals ExtraModifiers.INNER + } } } } } -// // TODO modifiers -// @Test fun innerClass() { -// verifyPackageMember("testdata/classes/innerClass.kt", defaultModelConfig) { cls -> -// val innerClass = cls.members.single { it.name == "D" } -// val modifiers = innerClass.details(NodeKind.Modifier) -// assertEquals(3, modifiers.size) -// assertEquals("inner", modifiers[2].name) -// } -// } - @Test fun companionObjectExtension() { inlineModelTest( @@ -364,14 +346,29 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class } } - // TODO modifiers -// @Test fun sinceKotlin() { -// checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model -> -// with(model.members.single().members.single()) { -// assertEquals("1.1", sinceKotlin) -// } -// } -// } + @Test + fun sinceKotlin() { + inlineModelTest( + """ + |/** + | * Useful + | */ + |@SinceKotlin("1.1") + |class C + """ + ) { + with((this / "classes" / "C").cast()) { + with(extra[Annotations].assertNotNull("Annotations")) { + this.content counts 1 + with(content.first()) { + dri.classNames equals "SinceKotlin" + params.entries counts 1 + params["version"].assertNotNull("version") equals "1.1" + } + } + } + } + } @Test fun privateCompanionObject() { @@ -402,7 +399,8 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class } } - @Test fun annotatedClass() { + @Test + fun annotatedClass() { inlineModelTest( """@Suppress("abc") class Foo() {}""" ) { @@ -417,47 +415,30 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class } } - // TODO annotations -// @Test fun annotatedClass() { -// verifyPackageMember("testdata/classes/annotatedClass.kt", ModelConfig( -// analysisPlatform = analysisPlatform, -// withKotlinRuntime = true -// ) -// ) { cls -> -// Assert.assertEquals(1, cls.annotations.count()) -// with(cls.annotations[0]) { -// Assert.assertEquals("Strictfp", name) -// Assert.assertEquals(Content.Empty, content) -// Assert.assertEquals(NodeKind.Annotation, kind) -// } -// } -// } - - -// TODO annotations - -// @Test fun javaAnnotationClass() { -// checkSourceExistsAndVerifyModel( -// "testdata/classes/javaAnnotationClass.kt", -// modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true) -// ) { model -> -// with(model.members.single().members.single()) { -// Assert.assertEquals(1, annotations.count()) -// with(annotations[0]) { -// Assert.assertEquals("Retention", name) -// Assert.assertEquals(Content.Empty, content) -// Assert.assertEquals(NodeKind.Annotation, kind) -// with(details[0]) { -// Assert.assertEquals(NodeKind.Parameter, kind) -// Assert.assertEquals(1, details.count()) -// with(details[0]) { -// Assert.assertEquals(NodeKind.Value, kind) -// Assert.assertEquals("RetentionPolicy.SOURCE", name) -// } -// } -// } -// } -// } -// } + @Test fun javaAnnotationClass() { + inlineModelTest( + """ + |import java.lang.annotation.Retention + |import java.lang.annotation.RetentionPolicy + | + |@Retention(RetentionPolicy.SOURCE) + |public annotation class throws() + """ + ) { + with((this / "classes" / "throws").cast()) { + with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) { + content counts 1 + content.first() equals ExtraModifiers.OVERRIDE // ?? + } + with(extra[Annotations].assertNotNull("Annotations")) { + content counts 1 + with(content.first()) { + dri.classNames equals "Retention" + params["value"].assertNotNull("value") equals "(java/lang/annotation/RetentionPolicy, SOURCE)" + } + } + } + } + } } \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt index c8b8f2ba..068c2895 100644 --- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt +++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt @@ -1,9 +1,11 @@ package model -import org.jetbrains.dokka.model.DFunction -import org.jetbrains.dokka.model.DPackage +import org.jetbrains.dokka.model.* import org.junit.jupiter.api.Test -import utils.* +import utils.AbstractModelTest +import utils.assertNotNull +import utils.comments +import utils.name class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "function") { @@ -130,8 +132,6 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun } } -// TODO add modifiers - start - @Test fun functionWithNotDocumentedAnnotation() { inlineModelTest( @@ -139,20 +139,19 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun |@Suppress("FOO") fun f() {} """ ) { - // TODO add annotations - with((this / "function" / "f").cast()) { - assert(false) { "No annotation data" } + with(extra[Annotations].assertNotNull("Annotations")) { + content counts 1 + with(content.first()) { + dri.classNames equals "Suppress" + params.entries counts 1 + params["names"].assertNotNull("names") equals "[\"FOO\"]" + } + } } } } -// @Test fun functionWithNotDocumentedAnnotation() { -// verifyPackageMember("testdata/functions/functionWithNotDocumentedAnnotation.kt", defaultModelConfig) { func -> -// assertEquals(0, func.annotations.count()) -// } -// } - @Test fun inlineFunction() { inlineModelTest( @@ -160,21 +159,13 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun |inline fun f(a: () -> String) {} """ ) { - // TODO add data about inline - with((this / "function" / "f").cast()) { - assert(false) { "No inline data" } + extra[AdditionalModifiers]?.content counts 1 + extra[AdditionalModifiers]?.content exists ExtraModifiers.INLINE } } } -// @Test fun inlineFunction() { -// verifyPackageMember("testdata/functions/inlineFunction.kt", defaultModelConfig) { func -> -// val modifiers = func.details(NodeKind.Modifier).map { it.name } -// assertTrue("inline" in modifiers) -// } -// } - @Test fun suspendFunction() { inlineModelTest( @@ -182,112 +173,167 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun |suspend fun f() {} """ ) { - // TODO add data about suspend + with((this / "function" / "f").cast()) { + extra[AdditionalModifiers]?.content counts 1 + extra[AdditionalModifiers]?.content exists ExtraModifiers.SUSPEND + } + } + } + @Test + fun suspendInlineFunctionOrder() { + inlineModelTest( + """ + |suspend inline fun f(a: () -> String) {} + """ + ) { with((this / "function" / "f").cast()) { - assert(false) { "No suspend data" } + extra[AdditionalModifiers]?.content counts 2 + extra[AdditionalModifiers]?.content exists ExtraModifiers.SUSPEND + extra[AdditionalModifiers]?.content exists ExtraModifiers.INLINE } } } -// @Test fun suspendFunction() { -// verifyPackageMember("testdata/functions/suspendFunction.kt") { func -> -// val modifiers = func.details(NodeKind.Modifier).map { it.name } -// assertTrue("suspend" in modifiers) -// } -// } + @Test + fun inlineSuspendFunctionOrderChanged() { + inlineModelTest( + """ + |inline suspend fun f(a: () -> String) {} + """ + ) { + with((this / "function" / "f").cast()) { + with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) { + content counts 2 + content exists ExtraModifiers.SUSPEND + content exists ExtraModifiers.INLINE + } + } + } + } -// @Test fun suspendInlineFunctionOrder() { -// verifyPackageMember("testdata/functions/suspendInlineFunction.kt") { func -> -// val modifiers = func.details(NodeKind.Modifier).map { it.name }.filter { -// it == "suspend" || it == "inline" -// } -// -// assertEquals(listOf("suspend", "inline"), modifiers) -// } -// } -// -// @Test fun inlineSuspendFunctionOrderChanged() { -// verifyPackageMember("testdata/functions/inlineSuspendFunction.kt") { func -> -// val modifiers = func.details(NodeKind.Modifier).map { it.name }.filter { -// it == "suspend" || it == "inline" -// } -// -// assertEquals(listOf("suspend", "inline"), modifiers) -// } -// } -// -// @Test fun functionWithAnnotatedParam() { -// checkSourceExistsAndVerifyModel("testdata/functions/functionWithAnnotatedParam.kt", defaultModelConfig) { model -> -// with(model.members.single().members.single { it.name == "function" }) { -// with(details(NodeKind.Parameter).first()) { -// assertEquals(1, annotations.count()) -// with(annotations[0]) { -// assertEquals("Fancy", name) -// assertEquals(Content.Empty, content) -// assertEquals(NodeKind.Annotation, kind) -// } -// } -// } -// } -// } -// -// @Test fun functionWithNoinlineParam() { -// verifyPackageMember("testdata/functions/functionWithNoinlineParam.kt", defaultModelConfig) { func -> -// with(func.details(NodeKind.Parameter).first()) { -// val modifiers = details(NodeKind.Modifier).map { it.name } -// assertTrue("noinline" in modifiers) -// } -// } -// } -// -// @Test fun annotatedFunctionWithAnnotationParameters() { -// checkSourceExistsAndVerifyModel( -// "testdata/functions/annotatedFunctionWithAnnotationParameters.kt", -// defaultModelConfig -// ) { model -> -// with(model.members.single().members.single { it.name == "f" }) { -// assertEquals(1, annotations.count()) -// with(annotations[0]) { -// assertEquals("Fancy", name) -// assertEquals(Content.Empty, content) -// assertEquals(NodeKind.Annotation, kind) -// assertEquals(1, details.count()) -// with(details[0]) { -// assertEquals(NodeKind.Parameter, kind) -// assertEquals(1, details.count()) -// with(details[0]) { -// assertEquals(NodeKind.Value, kind) -// assertEquals("1", name) -// } -// } -// } -// } -// } -// } + @Test + fun functionWithAnnotatedParam() { + inlineModelTest( + """ + |@Target(AnnotationTarget.VALUE_PARAMETER) + |@Retention(AnnotationRetention.SOURCE) + |@MustBeDocumented + |public annotation class Fancy + | + |fun function(@Fancy notInlined: () -> Unit) {} + """ + ) { + with((this / "function" / "Fancy").cast()) { + with(extra[Annotations].assertNotNull("Annotations")) { + content counts 3 + with(content.map { it.dri.classNames to it }.toMap()) { + with(this["Target"].assertNotNull("Target")) { + params["allowedTargets"].assertNotNull("allowedTargets") equals "[AnnotationTarget.VALUE_PARAMETER]" + } + with(this["Retention"].assertNotNull("Retention")) { + params["value"].assertNotNull("value") equals "(kotlin/annotation/AnnotationRetention, SOURCE)" + } + this["MustBeDocumented"].assertNotNull("MustBeDocumented").params.entries counts 0 + } + } + + } + with((this / "function" / "function" / "notInlined").cast()) { + with(this.extra[Annotations].assertNotNull("Annotations")) { + content counts 1 + with(content.first()) { + dri.classNames equals "Fancy" + params.entries counts 0 + } + } + } + } + } -// TODO add modifiers - end + @Test + fun functionWithNoinlineParam() { + inlineModelTest( + """ + |fun f(noinline notInlined: () -> Unit) {} + """ + ) { + with((this / "function" / "f" / "notInlined").cast()) { + extra[AdditionalModifiers]?.content counts 1 + extra[AdditionalModifiers]?.content exists ExtraModifiers.NOINLINE + } + } + } -// @Test -// fun functionWithDefaultParameter() { -// inlineModelTest( -// """ -// |/src/main/kotlin/function/Test.kt -// |package function -// |fun f(x: String = "") {} -// """ -// ) { -// // TODO add default value data -// -// with(this / "function" / "f" cast Function::class) { -// parameters.forEach { p -> -// p.name equals "x" -// p.type.constructorFqName.assertNotNull("Parameter type: ") equals "kotlin.String" -// assert(false) { "Add default value data" } -// } -// } -// } -// } + @Test + fun annotatedFunctionWithAnnotationParameters() { + inlineModelTest( + """ + |@Target(AnnotationTarget.VALUE_PARAMETER) + |@Retention(AnnotationRetention.SOURCE) + |@MustBeDocumented + |public annotation class Fancy(val size: Int) + | + |@Fancy(1) fun f() {} + """ + ) { + with((this / "function" / "Fancy").cast()) { + constructors counts 1 + with(constructors.first()) { + parameters counts 1 + with(parameters.first()) { + type.name equals "Int" + name equals "size" + } + } + + with(extra[Annotations].assertNotNull("Annotations")) { + content counts 3 + with(content.map { it.dri.classNames to it }.toMap()) { + with(this["Target"].assertNotNull("Target")) { + params["allowedTargets"].assertNotNull("allowedTargets") equals "[AnnotationTarget.VALUE_PARAMETER]" + } + with(this["Retention"].assertNotNull("Retention")) { + params["value"].assertNotNull("value") equals "(kotlin/annotation/AnnotationRetention, SOURCE)" + } + this["MustBeDocumented"].assertNotNull("MustBeDocumented").params.entries counts 0 + } + } + + } + with((this / "function" / "f").cast()) { + with(this.extra[Annotations].assertNotNull("Annotations")) { + content counts 1 + with(content.first()) { + dri.classNames equals "Fancy" + params.entries counts 1 + params["size"] equals "1" + } + } + } + } + } + + @Test + fun functionWithDefaultParameter() { + inlineModelTest( + """ + |/src/main/kotlin/function/Test.kt + |package function + |fun f(x: String = "") {} + """ + ) { + // TODO add default value data + + with((this / "function" / "f").cast()) { + parameters.forEach { p -> + p.name equals "x" + p.type.name.assertNotNull("Parameter type: ") equals "String" + assert(false) { "No default value data" } + } + } + } + } // @Test fun functionWithDefaultParameter() { // checkSourceExistsAndVerifyModel("testdata/functions/functionWithDefaultParameter.kt", defaultModelConfig) { model -> @@ -302,14 +348,29 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun // } // } // } -// -// @Test fun sinceKotlin() { -// checkSourceExistsAndVerifyModel("testdata/functions/sinceKotlin.kt", defaultModelConfig) { model -> -// with(model.members.single().members.single()) { -// assertEquals("1.1", sinceKotlin) -// } -// } -// } -//} + + @Test + fun sinceKotlin() { + inlineModelTest( + """ + |/** + | * Quite useful [String] + | */ + |@SinceKotlin("1.1") + |fun f(): String = "1.1 rulezz" + """ + ) { + with((this / "function" / "f").cast()) { + with(extra[Annotations].assertNotNull("Annotations")) { + this.content counts 1 + with(content.first()) { + dri.classNames equals "SinceKotlin" + params.entries counts 1 + params["version"].assertNotNull("version") equals "1.1" + } + } + } + } + } } \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/model/InheritorsTest.kt b/plugins/base/src/test/kotlin/model/InheritorsTest.kt index da128803..e1717fe4 100644 --- a/plugins/base/src/test/kotlin/model/InheritorsTest.kt +++ b/plugins/base/src/test/kotlin/model/InheritorsTest.kt @@ -5,8 +5,8 @@ import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.transformers.documentables.InheritorsExtractorTransformer import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo import org.jetbrains.dokka.model.DInterface -import org.jetbrains.dokka.model.DPackage import org.jetbrains.dokka.plugability.DokkaPlugin +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import utils.AbstractModelTest import utils.assertNotNull @@ -83,7 +83,7 @@ class InheritorsTest : AbstractModelTest("/src/main/kotlin/inheritors/Test.kt", with(find { it.platformType == Platform.js }.assertNotNull("js key").let { map[it]!! }) { this counts 2 val classes = listOf("B", "C") - assert(all{ classes.contains(it.classNames) }){"One of subclasses missing in js"} + assertTrue(all { classes.contains(it.classNames) }, "One of subclasses missing in js" ) } } diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index c6d111a4..a3fcce42 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -1,8 +1,7 @@ package model +import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.DEnum -import org.jetbrains.dokka.model.DFunction import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import utils.AbstractModelTest @@ -113,7 +112,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { val sups = listOf("Exception", "Cloneable") assertTrue( sups.all { s -> supertypes.map.values.flatten().any { it.classNames == s } }) - "Foo must extend ${sups.joinToString(", ")}" + "Foo must extend ${sups.joinToString(", ")}" } } } @@ -155,7 +154,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { """ ) { with((this / "java" / "Foo").cast()) { - this + throw AssertionError("No type parameters data for class") } } } @@ -286,6 +285,24 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { // } // } + @Test + fun staticMethod() { + inlineModelTest( + """ + |class C { + | public static void foo() {} + |} + """ + ) { + with((this / "java" / "C" / "foo").cast()) { + with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) { + content counts 1 + content.first() equals ExtraModifiers.STATIC + } + } + } + } + // @Test fun staticMethod() { todo // verifyJavaPackageMember("testdata/java/staticMethod.java", defaultModelConfig) { cls -> // val m = cls.members(NodeKind.Function).single { it.name == "foo" } @@ -304,31 +321,53 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { // assertEquals(1, cls.members(NodeKind.Function).size) // } // } - // - // @Test fun annotatedAnnotation() { - // verifyJavaPackageMember("testdata/java/annotatedAnnotation.java", defaultModelConfig) { cls -> - // assertEquals(1, cls.annotations.size) - // with(cls.annotations[0]) { - // assertEquals(1, details.count()) - // with(details[0]) { - // assertEquals(NodeKind.Parameter, kind) - // assertEquals(1, details.count()) - // with(details[0]) { - // assertEquals(NodeKind.Value, kind) - // assertEquals("[AnnotationTarget.FIELD, AnnotationTarget.CLASS, AnnotationTarget.FILE, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER]", name) - // } - // } - // } - // } - // } - // + + @Test + fun annotatedAnnotation() { + inlineModelTest( + """ + |import java.lang.annotation.*; + | + |@Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD}) + |public @interface Attribute { + | String value() default ""; + |} + """ + ) { + with((this / "java" / "Attribute").cast()) { + with(extra[Annotations].assertNotNull("Annotations")) { + content counts 1 + with(content.first()) { + dri.classNames equals "Target" + params["value"].assertNotNull("value") equals "PsiArrayInitializerMemberValue:{ElementType.FIELD, ElementType.TYPE, ElementType.METHOD}" + } + } + } + } + } + // @Test fun deprecation() { // verifyJavaPackageMember("testdata/java/deprecation.java", defaultModelConfig) { cls -> // val fn = cls.members(NodeKind.Function).single() // assertEquals("This should no longer be used", fn.deprecation!!.content.toTestString()) // } // } - // + + @Test + fun javaLangObject() { + inlineModelTest( + """ + |class Test { + | public Object fn() { return null; } + |} + """ + ) { + with((this / "java" / "Test" / "fn").cast()) { + type.name equals "Any" + } + } + } + // @Test fun javaLangObject() { // verifyJavaPackageMember("testdata/java/javaLangObject.java", defaultModelConfig) { cls -> // val fn = cls.members(NodeKind.Function).single() @@ -356,6 +395,30 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { } } + @Test + fun inheritorLinks() { + inlineModelTest( + """ + |public class InheritorLinks { + | public static class Foo {} + | + | public static class Bar extends Foo {} + |} + """ + ) { + with((this / "java" / "InheritorLinks").cast()) { + val dri = (this / "Foo").assertNotNull("Foo dri").dri + with((this / "Bar").cast()) { + with(extra[InheritorsInfo].assertNotNull("InheritorsInfo")) { + with(value.map.values.flatten().distinct()) { + this counts 1 + first() equals dri + } + } + } + } + } + } // todo // @Test fun inheritorLinks() { diff --git a/plugins/base/src/test/kotlin/model/PropertyTest.kt b/plugins/base/src/test/kotlin/model/PropertyTest.kt index f391df4e..f6f7f3c0 100644 --- a/plugins/base/src/test/kotlin/model/PropertyTest.kt +++ b/plugins/base/src/test/kotlin/model/PropertyTest.kt @@ -1,8 +1,6 @@ package model -import org.jetbrains.dokka.model.KotlinVisibility -import org.jetbrains.dokka.model.DPackage -import org.jetbrains.dokka.model.DProperty +import org.jetbrains.dokka.model.* import org.junit.jupiter.api.Test import utils.AbstractModelTest import utils.assertNotNull @@ -140,19 +138,48 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro } } - // todo -// @Test fun sinceKotlin() { -// checkSourceExistsAndVerifyModel("testdata/properties/sinceKotlin.kt", defaultModelConfig) { model -> -// with(model.members.single().members.single()) { -// assertEquals("1.1", sinceKotlin) -// } -// } -// } -//} -// -//class JSPropertyTest: BasePropertyTest(Platform.js) {} -// -//class JVMPropertyTest : BasePropertyTest(Platform.jvm) { + @Test + fun sinceKotlin() { + inlineModelTest( + """ + |/** + | * Quite useful [String] + | */ + |@SinceKotlin("1.1") + |val prop: String = "1.1 rulezz" + """ + ) { + with((this / "property" / "prop").cast()) { + with(extra[Annotations].assertNotNull("Annotations")) { + this.content counts 1 + with(content.first()) { + dri.classNames equals "SinceKotlin" + params.entries counts 1 + params["version"].assertNotNull("version") equals "1.1" + } + } + } + } + } + + @Test + fun annotatedProperty() { + inlineModelTest( + """ + |@Strictfp var property = "test" + """ + ) { + with((this / "property" / "property").cast()) { + with(extra[Annotations].assertNotNull("Annotations")) { + this.content counts 1 + with(content.first()) { + dri.classNames equals "Strictfp" + params.entries counts 0 + } + } + } + } + } // @Test // fun annotatedProperty() { // checkSourceExistsAndVerifyModel( diff --git a/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt b/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt index 15dc5581..6ef38aa9 100644 --- a/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt +++ b/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt @@ -110,13 +110,13 @@ class PageNodeMergerTest : AbstractCoreTest() { val testT = allChildren.filter { it.name == "testT" } val test = allChildren.filter { it.name == "test" } - assert(testT.size == 1) { "There can be only one testT page" } - assert(testT.first().dri.size == 1) { "testT page should have single DRI, but has ${testT.first().dri.size}" } + assertTrue(testT.size == 1) { "There can be only one testT page" } + assertTrue(testT.first().dri.size == 1) { "testT page should have single DRI, but has ${testT.first().dri.size}" } - assert(test.size == 1) { "There can be only one test page" } - assert(test.first().dri.size == 1) { "test page should have single DRI, but has ${test.first().dri.size}" } + assertTrue(test.size == 1) { "There can be only one test page" } + assertTrue(test.first().dri.size == 1) { "test page should have single DRI, but has ${test.first().dri.size}" } - assert(strList.count() == 2) { "Expected 2 warnings, got ${strList.count()}" } + assertTrue(strList.count() == 2) { "Expected 2 warnings, got ${strList.count()}" } } } } diff --git a/plugins/base/src/test/kotlin/utils/TestUtils.kt b/plugins/base/src/test/kotlin/utils/TestUtils.kt index 68ab7120..8a3053b3 100644 --- a/plugins/base/src/test/kotlin/utils/TestUtils.kt +++ b/plugins/base/src/test/kotlin/utils/TestUtils.kt @@ -3,6 +3,7 @@ package utils import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Assertions.assertTrue import kotlin.collections.orEmpty @DslMarker @@ -22,6 +23,10 @@ interface AssertDSL { infix fun Any?.equals(other: Any?) = this.assertEqual(other) infix fun Collection?.allEquals(other: Any?) = this?.also { c -> c.forEach { it equals other } } ?: run { assert(false) { "Collection is empty" } } + infix fun Collection?.exists(e: T) { + assertTrue(this.orEmpty().isNotEmpty(), "Collection cannot be null or empty") + assertTrue(this!!.any{it == e}, "Collection doesn't contain $e") + } infix fun Collection?.counts(n: Int) = this.orEmpty().assertCount(n) diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index 991ee07d..ce41562b 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -259,7 +259,7 @@ internal fun ClassId.toDRI(dri: DRI?): DRI = DRI( ) private fun PropertyContainer.mergeAdditionalModifiers(second: Set) = - this[AdditionalModifiers.AdditionalKey]?.squash(AdditionalModifiers(second)) ?: AdditionalModifiers(second) + this[AdditionalModifiers]?.squash(AdditionalModifiers(second)) ?: AdditionalModifiers(second) private fun AdditionalModifiers.squash(second: AdditionalModifiers) = AdditionalModifiers(content + second.content) -- cgit From fc30a08beb509a03112298a6dd52c5001a2c6a53 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Fri, 20 Mar 2020 12:19:47 +0100 Subject: Add missing flatmap and remove unnecessary cast making tests fail --- .../src/main/kotlin/converters/KotlinToJavaConverter.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index ce41562b..6de3f121 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -33,9 +33,9 @@ internal fun DPackage.asJava(): DPackage { constructors = emptyList(), functions = ( nodes.filterIsInstance() - .map { it.javaAccessors() } + + .flatMap { it.javaAccessors() } + nodes.filterIsInstance() - .map { it.asJava(syntheticClassName) }) as List, // TODO: methods are static and receiver is a param + .map { it.asJava(syntheticClassName) }), // TODO: methods are static and receiver is a param classlikes = emptyList(), sources = PlatformDependent.empty(), visibility = PlatformDependent( -- cgit From 8a87b5e0bd2eda12f4e44512e3f8856c72e53b3e Mon Sep 17 00:00:00 2001 From: Filip Zybała Date: Fri, 20 Mar 2020 15:27:30 +0100 Subject: Changed modifier to PlatformDependent --- core/src/main/kotlin/model/Documentable.kt | 8 ++++---- .../kotlin/signatures/KotlinSignatureProvider.kt | 9 ++++----- .../DefaultDescriptorToDocumentableTranslator.kt | 15 +++++++++----- .../documentables/DefaultPageCreator.kt | 1 + .../psi/DefaultPsiToDocumentableTranslator.kt | 7 ++++--- .../kotlin/converters/KotlinToJavaConverter.kt | 23 ++++++++++++---------- .../kotlin/signatures/JavaSignatureProvider.kt | 4 ++-- 7 files changed, 38 insertions(+), 29 deletions(-) (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 6215be18..00a26d90 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -63,7 +63,7 @@ interface WithType { } interface WithAbstraction { - val modifier: Modifier + val modifier: PlatformDependent } sealed class Modifier(val name: String) @@ -146,7 +146,7 @@ data class DClass( override val generics: List, override val supertypes: PlatformDependent>, override val documentation: PlatformDependent, - override val modifier: Modifier, + override val modifier: PlatformDependent, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes, @@ -207,7 +207,7 @@ data class DFunction( override val type: Bound, override val generics: List, override val receiver: DParameter?, - override val modifier: Modifier, + override val modifier: PlatformDependent, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithGenerics, WithExtraProperties { @@ -287,7 +287,7 @@ data class DProperty( override val receiver: DParameter?, val setter: DFunction?, val getter: DFunction?, - override val modifier: Modifier, + override val modifier: PlatformDependent, override val platformData: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithExtraProperties { diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index c40c5b7c..d87152d5 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -34,10 +34,9 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun signature(c: DClasslike) = contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace)) { platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } if (c is DClass) { - if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.DATA) == true) { - text("data ") - } else { - text(c.modifier.name + " ") + platformText(c.modifier){ + if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.DATA) == true && it.name == "final") "data " + else it.name + " " } } when (c) { @@ -72,7 +71,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun signature(f: DFunction) = contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace)) { platformText(f.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } - text(f.modifier.name + " ") + platformText(f.modifier) { it.name } text("fun ") list(f.generics, prefix = "<", suffix = "> ") { +buildSignature(it) diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index ccee7269..bed6c25c 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -233,7 +233,8 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv else PlatformDependent.from(platformData,info.supertypes), generics = descriptor.typeConstructor.parameters.map { it.toTypeParameter() }, documentation = info.docs, - modifier = descriptor.modifier(), + modifier = if(isExpect) PlatformDependent.expectFrom(descriptor.modifier()) + else PlatformDependent.from(platformData, descriptor.modifier()), companion = descriptor.companion(driWithPlatform), platformData = listOf(platformData), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) @@ -261,7 +262,8 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv visibility = if(isExpect) PlatformDependent.expectFrom(descriptor.visibility.toDokkaVisibility()) else PlatformDependent.from(platformData,descriptor.visibility.toDokkaVisibility()), documentation = descriptor.resolveDescriptorData(if (!isExpect) platformData else null), - modifier = descriptor.modifier(), + modifier = if(isExpect) PlatformDependent.expectFrom(descriptor.modifier()) + else PlatformDependent.from(platformData, descriptor.modifier()), type = descriptor.returnType!!.toBound(), platformData = listOf(platformData), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) @@ -288,7 +290,8 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv else PlatformDependent.from(platformData,descriptor.visibility.toDokkaVisibility()), generics = descriptor.typeParameters.map { it.toTypeParameter() }, documentation = descriptor.resolveDescriptorData(if (!isExpect) platformData else null), - modifier = descriptor.modifier(), + modifier = if(isExpect) PlatformDependent.expectFrom(descriptor.modifier()) + else PlatformDependent.from(platformData, descriptor.modifier()), type = descriptor.returnType!!.toBound(), platformData = listOf(platformData), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) @@ -315,7 +318,8 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv else PlatformDependent.from(platformData,descriptor.visibility.toDokkaVisibility()), documentation = descriptor.resolveDescriptorData(if (!isExpect) platformData else null), type = descriptor.returnType.toBound(), - modifier = descriptor.modifier(), + modifier = if(isExpect) PlatformDependent.expectFrom(descriptor.modifier()) + else PlatformDependent.from(platformData, descriptor.modifier()), generics = descriptor.typeParameters.map { it.toTypeParameter() }, platformData = listOf(platformData), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()).let { @@ -377,7 +381,8 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv documentation = descriptor.resolveDescriptorData(if (!isExpect) platformData else null), type = descriptor.returnType!!.toBound(), generics = descriptor.typeParameters.map { it.toTypeParameter() }, - modifier = descriptor.modifier(), + modifier = if(isExpect) PlatformDependent.expectFrom(descriptor.modifier()) + else PlatformDependent.from(platformData, descriptor.modifier()), receiver = descriptor.extensionReceiverParameter?.let { visitReceiverParameterDescriptor( it, diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index 3f3ebe3a..b9e02398 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -166,6 +166,7 @@ open class DefaultPageCreator( protected open fun contentForFunction(f: DFunction) = contentBuilder.contentFor(f) { header(1) { text(f.name) } platformDependentHint(f.dri, f.platformData.toSet()){ + if(f.sources.expect != null) text("actual") +buildSignature(f) +contentForComments(f) } diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 218f8c82..ee862fb8 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -122,6 +122,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { val classlikes = innerClasses.map { parseClasslike(it, dri) } val visibility = getVisibility().toPlatformDependant() val ancestors = ancestorsSet.toList().toPlatformDependant() + val modifiers = getModifier().toPlatformDependant() return when { isAnnotationType -> DAnnotation( @@ -193,7 +194,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { mapTypeParameters(dri), ancestors, documentation, - getModifier(), + modifiers, listOf(platformData), PropertyContainer.empty() + annotations.toList().toExtra() ) @@ -226,7 +227,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { psi.returnType?.let { getBound(type = it) } ?: Void, psi.mapTypeParameters(dri), null, - psi.getModifier(), + psi.getModifier().toPlatformDependant(), listOf(platformData), PropertyContainer.withAll( InheritedFunction(isInherited), @@ -339,7 +340,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { null, accessors.firstOrNull { it.hasParameters() }?.let { parseFunction(it, parent) }, accessors.firstOrNull { it.returnType == psi.type }?.let { parseFunction(it, parent) }, - psi.getModifier(), + psi.getModifier().toPlatformDependant(), listOf(platformData), PropertyContainer.empty() + psi.annotations.toList().toExtra() ) diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index 6de3f121..dac937c0 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -47,7 +47,7 @@ internal fun DPackage.asJava(): DPackage { generics = emptyList(), supertypes = PlatformDependent.empty(), documentation = PlatformDependent.empty(), - modifier = JavaModifier.Final, + modifier = PlatformDependent(map = platformData.map{ it to JavaModifier.Final}.toMap()), platformData = platformData, extra = PropertyContainer.empty() ) @@ -68,9 +68,9 @@ internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: Stri dri.withClass(relocateToClass) }, modifier = if (setter == null) { - JavaModifier.Final + PlatformDependent(map = platformData.map{it to JavaModifier.Final}.toMap()) } else { - JavaModifier.Empty + PlatformDependent(map = platformData.map{it to JavaModifier.Empty}.toMap()) }, visibility = visibility.copy( map = visibility.mapValues { JavaVisibility.Private } @@ -91,9 +91,9 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas }, name = "get" + name.capitalize(), modifier = if (setter == null) { - JavaModifier.Final + PlatformDependent(map = platformData.map{it to JavaModifier.Final}.toMap()) } else { - JavaModifier.Empty + PlatformDependent(map = platformData.map{it to JavaModifier.Empty}.toMap()) }, visibility = visibility.copy( map = visibility.mapValues { JavaVisibility.Public } @@ -109,9 +109,9 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas }, name = "set" + name.capitalize(), modifier = if (setter == null) { - JavaModifier.Final + PlatformDependent(map = platformData.map{it to JavaModifier.Final}.toMap()) } else { - JavaModifier.Empty + PlatformDependent(map = platformData.map{it to JavaModifier.Empty}.toMap()) }, visibility = visibility.copy( map = visibility.mapValues { JavaVisibility.Public } @@ -131,7 +131,9 @@ internal fun DFunction.asJava(containingClassName: String): DFunction { // dri = dri.copy(callable = dri.callable?.asJava()), name = newName, type = type.asJava(), - modifier = if(modifier is KotlinModifier.Final && isConstructor) JavaModifier.Empty else modifier, + modifier = if(modifier.all{(_,v)-> v is KotlinModifier.Final} && isConstructor) + PlatformDependent(map = platformData.map{it to JavaModifier.Empty}.toMap()) + else PlatformDependent(map = platformData.map{it to modifier.allValues.first()}.toMap()), parameters = listOfNotNull(receiver?.asJava()) + parameters.map { it.asJava() }, receiver = null ) // TODO static if toplevel @@ -157,7 +159,8 @@ internal fun DClass.asJava(): DClass = copy( supertypes = supertypes.copy( map = supertypes.mapValues { it.value.map { it.possiblyAsJava() } } ), - modifier = if (modifier is KotlinModifier.Empty) JavaModifier.Final else modifier + modifier = if (modifier.all{(_,v) -> v is KotlinModifier.Empty}) PlatformDependent(map = platformData.map{it to JavaModifier.Final}.toMap()) + else PlatformDependent(map = platformData.map{it to modifier.allValues.first()}.toMap()) ) private fun DTypeParameter.asJava(): DTypeParameter = copy( @@ -195,7 +198,7 @@ internal fun DObject.asJava(): DObject = copy( properties = properties.map { it.asJava() } + DProperty( name = "INSTANCE", - modifier = JavaModifier.Final, + modifier = PlatformDependent(map = platformData.map{it to JavaModifier.Final}.toMap()), dri = dri.copy(callable = Callable("INSTANCE", null, emptyList())), documentation = PlatformDependent.empty(), sources = PlatformDependent.empty(), 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 6a571660..54bf663d 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -33,7 +33,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge platformText(c.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } if (c is DClass) { - text(c.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") + platformText(c.modifier){ it.takeIf{it !in ignoredModifiers}?.name.orEmpty() + " "} } when (c) { @@ -63,7 +63,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge } private fun signature(f: DFunction) = contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace)) { - text(f.modifier.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " ") + platformText(f.modifier){ it.takeIf{it !in ignoredModifiers}?.name.orEmpty() + " "} val returnType = f.type signatureForProjection(returnType) text(" ") -- cgit 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 --- core/src/main/kotlin/model/Documentable.kt | 3 +- .../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 +- .../kotlin/converters/KotlinToJavaConverter.kt | 1 + 9 files changed, 74 insertions(+), 3 deletions(-) (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 38b9ee71..313f4cd4 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -308,8 +308,9 @@ data class DProperty( val getter: DFunction?, override val modifier: PlatformDependent, override val platformData: List, + override val generics: List, override val extra: PropertyContainer = PropertyContainer.empty() -) : Documentable(), Callable, WithExtraProperties { +) : Documentable(), Callable, WithExtraProperties, WithGenerics { override val children: List get() = emptyList() 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
diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt index dac937c0..0befe077 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -212,6 +212,7 @@ internal fun DObject.asJava(): DObject = copy( getter = null, platformData = platformData, receiver = null, + generics = emptyList(), extra = PropertyContainer.empty() + AdditionalModifiers(setOf(ExtraModifiers.STATIC)) ), classlikes = classlikes.map { it.asJava() }, -- cgit From 3f2a790190da4f40ea6d8a976aa1929b2a1b002b Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Tue, 5 May 2020 17:45:12 +0200 Subject: Changing approach from platform-driven to source-set-driven --- .idea/compiler.xml | 36 +++ core/src/main/kotlin/DokkaGenerator.kt | 36 +-- core/src/main/kotlin/configuration.kt | 6 +- core/src/main/kotlin/defaultConfiguration.kt | 2 + core/src/main/kotlin/model/Documentable.kt | 168 ++++++-------- core/src/main/kotlin/model/SourceSetData.kt | 23 ++ core/src/main/kotlin/model/aditionalExtras.kt | 4 +- core/src/main/kotlin/model/documentableUtils.kt | 15 +- core/src/main/kotlin/pages/ContentNodes.kt | 29 +-- core/src/main/kotlin/pages/PageNodes.kt | 5 +- core/src/main/kotlin/plugability/DokkaContext.kt | 14 +- .../PreMergeDocumentableTransformer.kt | 2 +- .../sources/SourceToDocumentableTranslator.kt | 4 +- plugins/base/src/main/kotlin/DokkaBase.kt | 6 +- .../src/main/kotlin/renderers/DefaultRenderer.kt | 21 +- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 58 ++--- .../main/kotlin/renderers/html/NavigationPage.kt | 4 +- .../resolvers/local/DefaultLocationProvider.kt | 9 +- .../kotlin/resolvers/local/LocationProvider.kt | 4 +- .../kotlin/signatures/KotlinSignatureProvider.kt | 35 ++- .../documentables/ActualTypealiasAdder.kt | 8 +- .../documentables/DefaultDocumentableMerger.kt | 233 ++++++++----------- .../documentables/DocumentableVisibilityFilter.kt | 55 +++-- .../InheritorsExtractorTransformer.kt | 23 +- .../ModuleAndPackageDocumentationTransformer.kt | 42 ++-- .../pages/comments/CommentsToContentConverter.kt | 3 +- .../pages/comments/DocTagToContentConverter.kt | 33 +-- .../merger/SameMethodNamePageMergerStrategy.kt | 2 +- .../pages/samples/SamplesTransformer.kt | 25 +- .../pages/sourcelinks/SourceLinksTransformer.kt | 23 +- .../DefaultDescriptorToDocumentableTranslator.kt | 252 ++++++++++----------- .../documentables/DefaultPageCreator.kt | 111 +++++---- .../documentables/PageContentBuilder.kt | 98 ++++---- .../psi/DefaultPsiToDocumentableTranslator.kt | 57 +++-- .../src/test/kotlin/expect/AbstractExpectTest.kt | 2 +- .../kotlin/linkableContent/LinkableContentTest.kt | 6 + plugins/base/src/test/kotlin/model/ClassesTest.kt | 20 +- .../base/src/test/kotlin/model/InheritorsTest.kt | 10 +- plugins/base/src/test/kotlin/model/JavaTest.kt | 4 +- plugins/base/src/test/kotlin/model/PackagesTest.kt | 4 +- .../test/kotlin/renderers/RenderingOnlyTestBase.kt | 7 +- .../renderers/html/PlatformDependentHintTest.kt | 120 ---------- .../renderers/html/SourceSetDependentHintTest.kt | 121 ++++++++++ .../annotatedFunction/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../annotatedFunction/out/html/root/index.html | 4 +- .../annotatedFunction/out/html/root/package-list | 4 +- .../annotatedFunction/out/html/scripts/pages.js | 0 .../out/html/navigation.html | 10 +- .../out/html/root/[jvm root]/-fancy/-init-.html | 32 --- .../out/html/root/[jvm root]/-fancy/equals.html | 32 --- .../out/html/root/[jvm root]/-fancy/hash-code.html | 32 --- .../out/html/root/[jvm root]/-fancy/index.html | 102 --------- .../out/html/root/[jvm root]/-fancy/to-string.html | 32 --- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 69 ------ .../out/html/root/[main root]/-fancy/-init-.html | 32 +++ .../out/html/root/[main root]/-fancy/equals.html | 32 +++ .../html/root/[main root]/-fancy/hash-code.html | 32 +++ .../out/html/root/[main root]/-fancy/index.html | 102 +++++++++ .../html/root/[main root]/-fancy/to-string.html | 32 +++ .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 69 ++++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 10 +- .../expect/function/out/html/navigation.html | 6 +- .../function/out/html/root/[jvm root]/fn.html | 34 --- .../function/out/html/root/[jvm root]/index.html | 50 ---- .../function/out/html/root/[main root]/fn.html | 34 +++ .../function/out/html/root/[main root]/index.html | 50 ++++ .../expect/function/out/html/root/index.html | 4 +- .../expect/function/out/html/root/package-list | 4 +- .../out/html/navigation.html | 10 +- .../out/html/root/[jvm root]/-fancy/-init-.html | 32 --- .../out/html/root/[jvm root]/-fancy/equals.html | 32 --- .../out/html/root/[jvm root]/-fancy/hash-code.html | 32 --- .../out/html/root/[jvm root]/-fancy/index.html | 83 ------- .../out/html/root/[jvm root]/-fancy/to-string.html | 32 --- .../out/html/root/[jvm root]/function.html | 32 --- .../out/html/root/[jvm root]/index.html | 69 ------ .../out/html/root/[main root]/-fancy/-init-.html | 32 +++ .../out/html/root/[main root]/-fancy/equals.html | 32 +++ .../html/root/[main root]/-fancy/hash-code.html | 32 +++ .../out/html/root/[main root]/-fancy/index.html | 83 +++++++ .../html/root/[main root]/-fancy/to-string.html | 32 +++ .../out/html/root/[main root]/function.html | 32 +++ .../out/html/root/[main root]/index.html | 69 ++++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 10 +- .../out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- .../out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/function.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/function.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- .../out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- .../functionWithParams/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/function.html | 34 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/function.html | 34 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../functionWithParams/out/html/root/index.html | 4 +- .../functionWithParams/out/html/root/package-list | 4 +- .../functionWithReceiver/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/fn.html | 40 ---- .../out/html/root/[jvm root]/index.html | 66 ------ .../out/html/root/[main root]/fn.html | 40 ++++ .../out/html/root/[main root]/index.html | 66 ++++++ .../functionWithReceiver/out/html/root/index.html | 4 +- .../out/html/root/package-list | 6 +- .../genericFunction/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/generic.html | 34 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/generic.html | 34 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../genericFunction/out/html/root/index.html | 4 +- .../genericFunction/out/html/root/package-list | 4 +- .../out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/generic.html | 34 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/generic.html | 34 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- .../expect/inlineFunction/out/html/navigation.html | 6 +- .../inlineFunction/out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../expect/inlineFunction/out/html/root/index.html | 4 +- .../inlineFunction/out/html/root/package-list | 4 +- .../inlineSuspendFunction/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../inlineSuspendFunction/out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- .../expect/signatureTest/out/html/root/index.html | 2 +- .../out/html/root/signatureTest/index.html | 8 +- .../out/html/root/signatureTest/test.html | 2 +- .../out/html/root/signatureTest/test2.html | 2 +- .../expect/sinceKotlin/out/html/navigation.html | 6 +- .../html/root/[jvm root]/available-since1.1.html | 34 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../html/root/[main root]/available-since1.1.html | 34 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../expect/sinceKotlin/out/html/root/index.html | 4 +- .../expect/sinceKotlin/out/html/root/package-list | 4 +- .../suspendFunction/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../suspendFunction/out/html/root/index.html | 4 +- .../suspendFunction/out/html/root/package-list | 4 +- .../suspendInlineFunction/out/html/navigation.html | 6 +- .../out/html/root/[jvm root]/f.html | 32 --- .../out/html/root/[jvm root]/index.html | 50 ---- .../out/html/root/[main root]/f.html | 32 +++ .../out/html/root/[main root]/index.html | 50 ++++ .../suspendInlineFunction/out/html/root/index.html | 4 +- .../out/html/root/package-list | 4 +- plugins/gfm/src/main/kotlin/GfmPlugin.kt | 11 +- .../kotlin/converters/KotlinToJavaConverter.kt | 86 +++---- .../kotlin/signatures/JavaSignatureProvider.kt | 4 +- runners/cli/src/main/kotlin/cli/main.kt | 11 + .../dokka/gradle/ConfigurationExtractor.kt | 144 ++++++------ .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 47 ++-- .../dokka/gradle/configurationImplementations.kt | 2 + .../main/kotlin/org/jetbrains/dokka/gradle/main.kt | 4 +- .../kotlin/org/jetbrains/dokka/gradle/utils.kt | 14 +- runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 7 +- .../src/main/kotlin/testApi/context/MockContext.kt | 12 +- .../testApi/testRunner/DokkaTestGenerator.kt | 11 +- .../main/kotlin/testApi/testRunner/TestRunner.kt | 10 +- 193 files changed, 3010 insertions(+), 3003 deletions(-) create mode 100644 core/src/main/kotlin/model/SourceSetData.kt delete mode 100644 plugins/base/src/test/kotlin/renderers/html/PlatformDependentHintTest.kt create mode 100644 plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/[main root]/index.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunction/out/html/scripts/pages.js delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/-init-.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/equals.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/hash-code.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/index.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/-fancy/to-string.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/-fancy/-init-.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/-fancy/equals.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/-fancy/hash-code.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/-fancy/index.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/-fancy/to-string.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/function/out/html/root/[jvm root]/fn.html delete mode 100644 plugins/base/src/test/resources/expect/function/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/function/out/html/root/[main root]/fn.html create mode 100644 plugins/base/src/test/resources/expect/function/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/-fancy/-init-.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/-fancy/equals.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/-fancy/hash-code.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/-fancy/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/-fancy/to-string.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/function.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/-fancy/-init-.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/-fancy/equals.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/-fancy/hash-code.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/-fancy/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/-fancy/to-string.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/function.html create mode 100644 plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/[jvm root]/function.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/[main root]/function.html create mode 100644 plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithParams/out/html/root/[jvm root]/function.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithParams/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithParams/out/html/root/[main root]/function.html create mode 100644 plugins/base/src/test/resources/expect/functionWithParams/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/[jvm root]/fn.html delete mode 100644 plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/[main root]/fn.html create mode 100644 plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/genericFunction/out/html/root/[jvm root]/generic.html delete mode 100644 plugins/base/src/test/resources/expect/genericFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/genericFunction/out/html/root/[main root]/generic.html create mode 100644 plugins/base/src/test/resources/expect/genericFunction/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/[jvm root]/generic.html delete mode 100644 plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/[main root]/generic.html create mode 100644 plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/inlineFunction/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/inlineFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/inlineFunction/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/inlineFunction/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/[jvm root]/available-since1.1.html delete mode 100644 plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/[main root]/available-since1.1.html create mode 100644 plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/suspendFunction/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/suspendFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/suspendFunction/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/suspendFunction/out/html/root/[main root]/index.html delete mode 100644 plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/[jvm root]/f.html delete mode 100644 plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/[jvm root]/index.html create mode 100644 plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/[main root]/f.html create mode 100644 plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/[main root]/index.html (limited to 'plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt') diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 7ee14d19..a7e03ba2 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -16,8 +16,14 @@ + + + + + + @@ -78,14 +84,24 @@ + + + + + + + + + + @@ -101,6 +117,8 @@ + + @@ -110,6 +128,10 @@ + + + + @@ -126,6 +148,8 @@ + + @@ -150,6 +174,18 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 053b4cb6..6e62c033 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -1,23 +1,20 @@ package org.jetbrains.dokka -import com.intellij.openapi.vfs.VirtualFileManager -import com.intellij.psi.PsiJavaFile -import com.intellij.psi.PsiManager import org.jetbrains.dokka.analysis.AnalysisEnvironment import org.jetbrains.dokka.analysis.DokkaResolutionFacade import org.jetbrains.dokka.model.DModule -import org.jetbrains.dokka.pages.PlatformData +import org.jetbrains.dokka.model.SourceSetCache +import org.jetbrains.dokka.model.SourceSetData +import org.jetbrains.dokka.model.sourceSet import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.utilities.DokkaLogger -import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.utils.PathUtil import java.io.File @@ -31,13 +28,14 @@ class DokkaGenerator( ) { fun generate() = timed { report("Setting up analysis environments") - val platforms: Map = setUpAnalysis(configuration) + val sourceSetsCache = SourceSetCache() + val sourceSets: Map = setUpAnalysis(configuration, sourceSetsCache) report("Initializing plugins") - val context = initializePlugins(configuration, logger, platforms) + val context = initializePlugins(configuration, logger, sourceSets, sourceSetsCache) report("Creating documentation models") - val modulesFromPlatforms = createDocumentationModels(platforms, context) + val modulesFromPlatforms = createDocumentationModels(sourceSets, context) report("Transforming documentation model before merging") val transformedDocumentationBeforeMerge = transformDocumentationModelBeforeMerge(modulesFromPlatforms, context) @@ -62,27 +60,31 @@ class DokkaGenerator( logger.report() }.dump("\n\n === TIME MEASUREMENT ===\n") - fun setUpAnalysis(configuration: DokkaConfiguration): Map = + fun setUpAnalysis( + configuration: DokkaConfiguration, + sourceSetsCache: SourceSetCache + ): Map = configuration.passesConfigurations.map { - it.platformData to createEnvironmentAndFacade(it) + sourceSetsCache.getSourceSet(it) to createEnvironmentAndFacade(it) }.toMap() fun initializePlugins( configuration: DokkaConfiguration, logger: DokkaLogger, - platforms: Map, + sourceSets: Map, + sourceSetsCache: SourceSetCache, pluginOverrides: List = emptyList() - ) = DokkaContext.create(configuration, logger, platforms, pluginOverrides) + ) = DokkaContext.create(configuration, logger, sourceSets, sourceSetsCache, pluginOverrides) fun createDocumentationModels( - platforms: Map, + platforms: Map, context: DokkaContext ) = platforms.flatMap { (pdata, _) -> translateSources(pdata, context) } fun transformDocumentationModelBeforeMerge( modulesFromPlatforms: List, context: DokkaContext - ) = context[CoreExtensions.preMergeDocumentableTransformer].fold(modulesFromPlatforms) { acc, t -> t(acc, context) } + ) = context[CoreExtensions.preMergeDocumentableTransformer].fold(modulesFromPlatforms) { acc, t -> t(acc) } fun mergeDocumentationModels( modulesFromPlatforms: List, @@ -119,7 +121,7 @@ class DokkaGenerator( } pass.classpath.forEach { addClasspath(File(it)) } - addSources(pass.sourceRoots.map { it.path }) + addSources((pass.sourceRoots + pass.dependentSourceRoots).map { it.path }) loadLanguageVersionSettings(pass.languageVersion, pass.apiVersion) @@ -128,7 +130,7 @@ class DokkaGenerator( EnvironmentAndFacade(environment, facade) } - private fun translateSources(platformData: PlatformData, context: DokkaContext) = + private fun translateSources(platformData: SourceSetData, context: DokkaContext) = context[CoreExtensions.sourceToDocumentableTranslator].map { it.invoke(platformData, context) } diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 34671c4e..88924924 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka -import org.jetbrains.dokka.pages.PlatformData import java.io.File import java.net.URL @@ -37,8 +36,10 @@ interface DokkaConfiguration { interface PassConfiguration { val moduleName: String + val sourceSetName: String val classpath: List val sourceRoots: List + val dependentSourceRoots: List val samples: List val includes: List val includeNonPublic: Boolean @@ -59,9 +60,6 @@ interface DokkaConfiguration { val analysisPlatform: Platform val targets: List val sinceKotlin: String? - - val platformData: PlatformData - get() = PlatformData(moduleName, analysisPlatform, targets) } interface SourceRoot { diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index ae674ea1..08f70b45 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -16,8 +16,10 @@ data class DokkaConfigurationImpl( data class PassConfigurationImpl ( override val moduleName: String, + override val sourceSetName: String, override val classpath: List, override val sourceRoots: List, + override val dependentSourceRoots: List, override val samples: List, override val includes: List, override val includeNonPublic: Boolean, diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 313f4cd4..85487725 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -1,11 +1,12 @@ package org.jetbrains.dokka.model import com.intellij.psi.PsiNamedElement +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.properties.WithExtraProperties -import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.load.kotlin.toSourceElement @@ -13,8 +14,9 @@ abstract class Documentable { abstract val name: String? abstract val dri: DRI abstract val children: List - abstract val documentation: PlatformDependent - abstract val platformData: List + abstract val documentation: SourceSetDependent + abstract val sourceSets: List + abstract val expectPresentInSet: SourceSetData? override fun toString(): String = "${javaClass.simpleName}($dri)" @@ -25,45 +27,10 @@ abstract class Documentable { override fun hashCode() = dri.hashCode() } -data class PlatformDependent( - val map: Map, - val expect: T? = null -) : Map by map { - val prevalentValue: T? - get() = map.values.distinct().singleOrNull() - - val allValues: Sequence = sequence { - expect?.also { yield(it) } - yieldAll(map.values) - } - - val allEntries: Sequence> = sequence { - expect?.also { yield(null to it) } - map.forEach { (k, v) -> yield(k to v) } - } - - fun getOrExpect(platform: PlatformData): T? = map[platform] ?: expect - - companion object { - fun empty(): PlatformDependent = PlatformDependent(emptyMap()) - - fun from(platformData: PlatformData, element: T) = PlatformDependent(mapOf(platformData to element)) - - @Suppress("UNCHECKED_CAST") - fun from(pairs: Iterable>) = - PlatformDependent( - pairs.filter { it.first != null }.toMap() as Map, - pairs.firstOrNull { it.first == null }?.second - ) - - fun from(vararg pairs: Pair) = from(pairs.asIterable()) - - fun expectFrom(element: T) = PlatformDependent(map = emptyMap(), expect = element) - } -} +typealias SourceSetDependent = Map interface WithExpectActual { - val sources: PlatformDependent + val sources: SourceSetDependent } interface WithScope { @@ -73,7 +40,7 @@ interface WithScope { } interface WithVisibility { - val visibility: PlatformDependent + val visibility: SourceSetDependent } interface WithType { @@ -81,7 +48,7 @@ interface WithType { } interface WithAbstraction { - val modifier: PlatformDependent + val modifier: SourceSetDependent } sealed class Modifier(val name: String) @@ -112,7 +79,7 @@ interface WithGenerics { } interface WithSupertypes { - val supertypes: PlatformDependent> + val supertypes: SourceSetDependent> } interface Callable : WithVisibility, WithType, WithAbstraction, WithExpectActual { @@ -124,8 +91,9 @@ sealed class DClasslike : Documentable(), WithScope, WithVisibility, WithExpectA data class DModule( override val name: String, val packages: List, - override val documentation: PlatformDependent, - override val platformData: List, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData? = null, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithExtraProperties { override val dri: DRI = DRI.topLevel @@ -141,8 +109,9 @@ data class DPackage( override val properties: List, override val classlikes: List, val typealiases: List, - override val documentation: PlatformDependent, - override val platformData: List, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData? = null, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithScope, WithExtraProperties { override val name = dri.packageName.orEmpty() @@ -159,14 +128,15 @@ data class DClass( override val functions: List, override val properties: List, override val classlikes: List, - override val sources: PlatformDependent, - override val visibility: PlatformDependent, + override val sources: SourceSetDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val generics: List, - override val supertypes: PlatformDependent>, - override val documentation: PlatformDependent, - override val modifier: PlatformDependent, - override val platformData: List, + override val supertypes: SourceSetDependent>, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val modifier: SourceSetDependent, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithAbstraction, WithCompanion, WithConstructors, WithGenerics, WithSupertypes, WithExtraProperties { @@ -181,16 +151,17 @@ data class DEnum( override val dri: DRI, override val name: String, val entries: List, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val constructors: List, - override val supertypes: PlatformDependent>, - override val platformData: List, + override val supertypes: SourceSetDependent>, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithConstructors, WithSupertypes, WithExtraProperties { override val children: List @@ -202,11 +173,12 @@ data class DEnum( data class DEnumEntry( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, override val functions: List, override val properties: List, override val classlikes: List, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithScope, WithExtraProperties { override val children: List @@ -220,14 +192,15 @@ data class DFunction( override val name: String, val isConstructor: Boolean, val parameters: List, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, - override val visibility: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, + override val visibility: SourceSetDependent, override val type: Bound, override val generics: List, override val receiver: DParameter?, - override val modifier: PlatformDependent, - override val platformData: List, + override val modifier: SourceSetDependent, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithGenerics, WithExtraProperties { override val children: List @@ -239,16 +212,17 @@ data class DFunction( data class DInterface( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val generics: List, - override val supertypes: PlatformDependent>, - override val platformData: List, + override val supertypes: SourceSetDependent>, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithGenerics, WithSupertypes, WithExtraProperties { override val children: List @@ -260,14 +234,15 @@ data class DInterface( data class DObject( override val name: String?, override val dri: DRI, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, - override val supertypes: PlatformDependent>, - override val platformData: List, + override val visibility: SourceSetDependent, + override val supertypes: SourceSetDependent>, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithSupertypes, WithExtraProperties { override val children: List @@ -279,15 +254,16 @@ data class DObject( data class DAnnotation( override val name: String, override val dri: DRI, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, override val functions: List, override val properties: List, override val classlikes: List, - override val visibility: PlatformDependent, + override val visibility: SourceSetDependent, override val companion: DObject?, override val constructors: List, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : DClasslike(), WithCompanion, WithConstructors, WithExtraProperties { override val children: List @@ -299,15 +275,16 @@ data class DAnnotation( data class DProperty( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, - override val sources: PlatformDependent, - override val visibility: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sources: SourceSetDependent, + override val visibility: SourceSetDependent, override val type: Bound, override val receiver: DParameter?, val setter: DFunction?, val getter: DFunction?, - override val modifier: PlatformDependent, - override val platformData: List, + override val modifier: SourceSetDependent, + override val sourceSets: List, override val generics: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), Callable, WithExtraProperties, WithGenerics { @@ -321,9 +298,10 @@ data class DProperty( data class DParameter( override val dri: DRI, override val name: String?, - override val documentation: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, val type: Bound, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithExtraProperties { override val children: List @@ -335,9 +313,10 @@ data class DParameter( data class DTypeParameter( override val dri: DRI, override val name: String, - override val documentation: PlatformDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, val bounds: List, - override val platformData: List, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithExtraProperties { override val children: List @@ -350,10 +329,11 @@ data class DTypeAlias( override val dri: DRI, override val name: String, override val type: Bound, - val underlyingType: PlatformDependent, - override val visibility: PlatformDependent, - override val documentation: PlatformDependent, - override val platformData: List, + val underlyingType: SourceSetDependent, + override val visibility: SourceSetDependent, + override val documentation: SourceSetDependent, + override val expectPresentInSet: SourceSetData?, + override val sourceSets: List, override val extra: PropertyContainer = PropertyContainer.empty() ) : Documentable(), WithType, WithVisibility, WithExtraProperties { override val children: List @@ -417,7 +397,7 @@ sealed class JavaVisibility(name: String) : Visibility(name) { object Default : JavaVisibility("") } -fun PlatformDependent?.orEmpty(): PlatformDependent = this ?: PlatformDependent.empty() +fun SourceSetDependent?.orEmpty(): SourceSetDependent = this ?: emptyMap() interface DocumentableSource { val path: String @@ -429,4 +409,4 @@ class DescriptorDocumentableSource(val descriptor: DeclarationDescriptor) : Docu class PsiDocumentableSource(val psi: PsiNamedElement) : DocumentableSource { override val path = psi.containingFile.virtualFile.path -} +} \ No newline at end of file diff --git a/core/src/main/kotlin/model/SourceSetData.kt b/core/src/main/kotlin/model/SourceSetData.kt new file mode 100644 index 00000000..8f67f272 --- /dev/null +++ b/core/src/main/kotlin/model/SourceSetData.kt @@ -0,0 +1,23 @@ +package org.jetbrains.dokka.model + +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.plugability.DokkaContext + +data class SourceSetData( + val moduleName: String, + val sourceSetName: String, + val platform: Platform, + val sourceRoots: List = emptyList() +) + +class SourceSetCache { + private val sourceSets = HashMap() + + fun getSourceSet(pass: DokkaConfiguration.PassConfiguration) = + sourceSets.getOrPut("${pass.moduleName}/${pass.sourceSetName}", + { SourceSetData(pass.moduleName, pass.sourceSetName, pass.analysisPlatform, pass.sourceRoots) } + ) +} + +fun DokkaContext.sourceSet(pass: DokkaConfiguration.PassConfiguration) : SourceSetData = sourceSetCache.getSourceSet(pass) \ No newline at end of file diff --git a/core/src/main/kotlin/model/aditionalExtras.kt b/core/src/main/kotlin/model/aditionalExtras.kt index 58209939..27ad8a55 100644 --- a/core/src/main/kotlin/model/aditionalExtras.kt +++ b/core/src/main/kotlin/model/aditionalExtras.kt @@ -41,13 +41,13 @@ object PrimaryConstructorExtra : ExtraProperty, ExtraProperty.Key = this } -data class ActualTypealias(val underlyingType: PlatformDependent) : ExtraProperty { +data class ActualTypealias(val underlyingType: SourceSetDependent) : ExtraProperty { companion object : ExtraProperty.Key { override fun mergeStrategyFor( left: ActualTypealias, right: ActualTypealias ) = - MergeStrategy.Replace(ActualTypealias(PlatformDependent(left.underlyingType + right.underlyingType))) + MergeStrategy.Replace(ActualTypealias(left.underlyingType + right.underlyingType)) } override val key: ExtraProperty.Key = ActualTypealias diff --git a/core/src/main/kotlin/model/documentableUtils.kt b/core/src/main/kotlin/model/documentableUtils.kt index 7f946344..b09260ee 100644 --- a/core/src/main/kotlin/model/documentableUtils.kt +++ b/core/src/main/kotlin/model/documentableUtils.kt @@ -1,21 +1,18 @@ package org.jetbrains.dokka.model -import org.jetbrains.dokka.pages.PlatformData +fun SourceSetDependent.filtered(platformDataList: List) = filter { it.key in platformDataList } +fun SourceSetData?.filtered(platformDataList: List) = takeIf { this in platformDataList } -fun PlatformDependent.filtered(platformDataList: List) = PlatformDependent( - map.filter { it.key in platformDataList }, - expect -) - -fun DTypeParameter.filter(filteredData: List) = - if (filteredData.containsAll(platformData)) this +fun DTypeParameter.filter(filteredData: List) = + if (filteredData.containsAll(sourceSets)) this else { - val intersection = filteredData.intersect(platformData).toList() + val intersection = filteredData.intersect(sourceSets).toList() if (intersection.isEmpty()) null else DTypeParameter( dri, name, documentation.filtered(intersection), + expectPresentInSet?.takeIf { intersection.contains(expectPresentInSet) }, bounds, intersection, extra diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt index 26bcdf77..bb669199 100644 --- a/core/src/main/kotlin/pages/ContentNodes.kt +++ b/core/src/main/kotlin/pages/ContentNodes.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka.pages import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.properties.WithExtraProperties @@ -10,7 +11,7 @@ data class DCI(val dri: Set, val kind: Kind) { interface ContentNode : WithExtraProperties { val dci: DCI - val platforms: Set + val sourceSets: Set val style: Set