From d47d386ad8c0ff4a2c3b9d5b4450a773bdcba2dc Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Mon, 4 May 2020 13:53:10 +0200 Subject: Enhance signature presentation. Support presetnation Java as Kotlin and Kotlin as Java. Refactor annotations creation from PSI/Descriptors. Add proper rendering of annotation signatures in both kotlin syntax and java syntax. Tests for annotations --- .../annotations/ContentForAnnotationsTest.kt | 153 +++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt (limited to 'plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt') diff --git a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt new file mode 100644 index 00000000..c4640824 --- /dev/null +++ b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt @@ -0,0 +1,153 @@ +package content.annotations + +import matchers.content.* +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.PackagePageNode +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Test +import utils.ParamAttributes +import utils.bareSignature +import utils.functionSignature +import utils.propertySignature + + +class ContentForAnnotationsTest : AbstractCoreTest() { + + + private val testConfiguration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + analysisPlatform = "jvm" + targets = listOf("jvm") + } + } + } + + @Test + fun `function`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, + | AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FIELD + |) + |@Retention(AnnotationRetention.SOURCE) + |@MustBeDocumented + |annotation class Fancy + | + | + |@Fancy + |fun function(@Fancy abc: String): String { + | return "Hello, " + abc + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "function" } as ContentPage + page.content.assertNode { + + header(1) { +"function" } + divergentGroup { + divergentInstance { + divergent { + bareSignature( + mapOf("Fancy" to emptySet()), + "", + "", + emptySet(), + "function", + "String", + "abc" to ParamAttributes(mapOf("Fancy" to emptySet()), emptySet(), "String") + ) + } + } + } + + } + } + } + } + + @Test + fun `property`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |@Suppress + |val property: Int = 6 + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } as PackagePageNode + page.content.assertNode { + propertySignature(mapOf("Suppress" to setOf("names")), "", "", emptySet(), "val", "property", "Int") + } + } + } + } + + + @Test + fun `rich annotation`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |@Retention(AnnotationRetention.SOURCE) + |@Target(AnnotationTarget.FIELD) + |annotation class BugReport( + | val assignedTo: String = "[none]", + | val testCase: KClass = ABC::class, + | val status: Status = Status.UNCONFIRMED, + | val ref: Reference = Reference(value = 1), + | val reportedBy: Array, + | val showStopper: Boolean = false + |) { + | enum class Status { + | UNCONFIRMED, CONFIRMED, FIXED, NOTABUG + | } + | class ABC + |} + |annotation class Reference(val value: Int) + | + | + |@BugReport( + | assignedTo = "me", + | testCase = BugReport.ABC::class, + | status = BugReport.Status.FIXED, + | ref = Reference(value = 2), + | reportedBy = [Reference(value = 2), Reference(value = 4)], + | showStopper = true + |) + |val ltint: Int = 5 + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } as PackagePageNode + page.content.assertNode { + propertySignature( + mapOf( + "BugReport" to setOf( + "assignedTo", + "testCase", + "status", + "ref", + "reportedBy", + "showStopper" + ) + ), "", "", emptySet(), "val", "ltint", "Int" + ) + } + } + } + } + + +} \ No newline at end of file -- cgit From 77fa898e8abdc8e74169fa789f2ba0e32d8fa9d7 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Thu, 21 May 2020 11:29:22 +0200 Subject: Apply request changes --- core/src/main/kotlin/model/Documentable.kt | 17 --- core/src/main/kotlin/model/aditionalExtras.kt | 10 +- core/src/main/kotlin/model/extraModifiers.kt | 60 ++++++++++ .../main/kotlin/signatures/JvmSignatureUtils.kt | 123 ++++++++++++++++++++ .../main/kotlin/signatures/JvmSingatureUtils.kt | 129 --------------------- .../kotlin/signatures/KotlinSignatureProvider.kt | 5 +- .../main/kotlin/signatures/KotlinSignatureUtils.kt | 9 +- .../main/kotlin/signatures/SignatureProvider.kt | 4 - .../DefaultDescriptorToDocumentableTranslator.kt | 66 ++++++----- .../documentables/PageContentBuilder.kt | 6 +- .../psi/DefaultPsiToDocumentableTranslator.kt | 17 +-- .../annotations/ContentForAnnotationsTest.kt | 5 +- .../content/signatures/ContentForSignaturesTest.kt | 26 +++-- plugins/base/src/test/kotlin/model/ClassesTest.kt | 10 +- .../base/src/test/kotlin/model/FunctionsTest.kt | 45 ++++--- plugins/base/src/test/kotlin/model/JavaTest.kt | 10 +- plugins/base/src/test/kotlin/model/PropertyTest.kt | 2 +- plugins/base/src/test/kotlin/utils/contentUtils.kt | 38 +++--- .../kotlin/converters/KotlinToJavaConverter.kt | 35 +++--- .../kotlin/signatures/JavaSignatureProvider.kt | 7 +- .../main/kotlin/signatures/JavaSignatureUtils.kt | 11 +- 21 files changed, 351 insertions(+), 284 deletions(-) create mode 100644 core/src/main/kotlin/model/extraModifiers.kt create mode 100644 plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt delete mode 100644 plugins/base/src/main/kotlin/signatures/JvmSingatureUtils.kt (limited to 'plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt') diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index b808e09c..a7dd0919 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -367,23 +367,6 @@ enum class FunctionModifiers { NONE, FUNCTION, EXTENSION } -enum class ExtraModifiers { - STATIC, INLINE, INFIX, SUSPEND, REIFIED, CROSSINLINE, NOINLINE, - OVERRIDE, DATA, CONST, EXTERNAL, INNER, LATEINIT, OPERATOR, TAILREC, VARARG, - NATIVE, SYNCHRONIZED, STRICTFP, TRANSIENT, VOLATILE, TRANSITIVE; - - companion object { - val kotlinOnlyModifiers = setOf( - INLINE, INFIX, EXTERNAL, SUSPEND, REIFIED, CROSSINLINE, NOINLINE, OVERRIDE, DATA, CONST, INNER, LATEINIT, OPERATOR, - TAILREC, VARARG - ) - - val javaOnlyModifiers = setOf( - STATIC, NATIVE, SYNCHRONIZED, STRICTFP, TRANSIENT, VOLATILE, TRANSITIVE - ) - } -} - private fun String.shorten(maxLength: Int) = lineSequence().first().let { if (it.length != length || it.length > maxLength) it.take(maxLength - 3) + "..." else it } diff --git a/core/src/main/kotlin/model/aditionalExtras.kt b/core/src/main/kotlin/model/aditionalExtras.kt index 05b88f48..2b9d481f 100644 --- a/core/src/main/kotlin/model/aditionalExtras.kt +++ b/core/src/main/kotlin/model/aditionalExtras.kt @@ -39,11 +39,11 @@ class Annotations(val content: List) : ExtraProperty { } sealed class AnnotationParameterValue -class AnnotationValue(val annotation: Annotations.Annotation) : AnnotationParameterValue() -class ArrayValue(val value: List) : AnnotationParameterValue() -class EnumValue(val enumName: String, val enumDri: DRI) : AnnotationParameterValue() -class ClassValue(val className: String, val classDRI: DRI) : AnnotationParameterValue() // TODO Investigate if KtClassValue can be parameter of annotation -class StringValue(val value: String) : AnnotationParameterValue() +data class AnnotationValue(val annotation: Annotations.Annotation) : AnnotationParameterValue() +data class ArrayValue(val value: List) : AnnotationParameterValue() +data class EnumValue(val enumName: String, val enumDri: DRI) : AnnotationParameterValue() +data class ClassValue(val className: String, val classDRI: DRI) : AnnotationParameterValue() +data class StringValue(val value: String) : AnnotationParameterValue() object PrimaryConstructorExtra : ExtraProperty, ExtraProperty.Key { diff --git a/core/src/main/kotlin/model/extraModifiers.kt b/core/src/main/kotlin/model/extraModifiers.kt new file mode 100644 index 00000000..093ce62a --- /dev/null +++ b/core/src/main/kotlin/model/extraModifiers.kt @@ -0,0 +1,60 @@ +package org.jetbrains.dokka.model + +sealed class ExtraModifiers(val name: String) { + + sealed class KotlinOnlyModifiers(name: String) : ExtraModifiers(name) { + object Inline : KotlinOnlyModifiers("inline") + object Infix : KotlinOnlyModifiers("infix") + object External : KotlinOnlyModifiers("external") + object Suspend : KotlinOnlyModifiers("suspend") + object Reified : KotlinOnlyModifiers("reified") + object CrossInline : KotlinOnlyModifiers("crossinline") + object NoInline : KotlinOnlyModifiers("noinline") + object Override : KotlinOnlyModifiers("override") + object Data : KotlinOnlyModifiers("data") + object Const : KotlinOnlyModifiers("const") + object Inner : KotlinOnlyModifiers("inner") + object LateInit : KotlinOnlyModifiers("lateinit") + object Operator : KotlinOnlyModifiers("operator") + object TailRec : KotlinOnlyModifiers("tailrec") + object VarArg : KotlinOnlyModifiers("vararg") + } + + sealed class JavaOnlyModifiers(name: String) : ExtraModifiers(name) { + object Static : JavaOnlyModifiers("static") + object Native : JavaOnlyModifiers("native") + object Synchronized : JavaOnlyModifiers("synchronized") + object StrictFP : JavaOnlyModifiers("strictfp") + object Transient : JavaOnlyModifiers("transient") + object Volatile : JavaOnlyModifiers("volatile") + object Transitive : JavaOnlyModifiers("transitive") + } + + companion object { + fun valueOf(str: String) = when(str) { + "inline" -> KotlinOnlyModifiers.Inline + "infix" -> KotlinOnlyModifiers.Infix + "external" -> KotlinOnlyModifiers.External + "suspend" -> KotlinOnlyModifiers.Suspend + "reified" -> KotlinOnlyModifiers.Reified + "crossinline" -> KotlinOnlyModifiers.CrossInline + "noinline" -> KotlinOnlyModifiers.NoInline + "override" -> KotlinOnlyModifiers.Override + "data" -> KotlinOnlyModifiers.Data + "const" -> KotlinOnlyModifiers.Const + "inner" -> KotlinOnlyModifiers.Inner + "lateinit" -> KotlinOnlyModifiers.LateInit + "operator" -> KotlinOnlyModifiers.Operator + "tailrec" -> KotlinOnlyModifiers.TailRec + "vararg" -> KotlinOnlyModifiers.VarArg + "static" -> JavaOnlyModifiers.Static + "native" -> JavaOnlyModifiers.Native + "synchronized" -> JavaOnlyModifiers.Synchronized + "strictfp" -> JavaOnlyModifiers.StrictFP + "transient" -> JavaOnlyModifiers.Transient + "volatile" -> JavaOnlyModifiers.Volatile + "transitive" -> JavaOnlyModifiers.Transitive + else -> throw IllegalArgumentException("There is no Extra Modifier for given name $str") + } + } +} \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt new file mode 100644 index 00000000..0ae72109 --- /dev/null +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -0,0 +1,123 @@ +package org.jetbrains.dokka.base.signatures + +import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder +import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.properties.WithExtraProperties + +interface JvmSignatureUtils { + + fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: Documentable) + + fun PageContentBuilder.DocumentableContentBuilder.annotationsInline(d: Documentable) + + fun WithExtraProperties.modifiers(): Set + + fun Set.toSignatureString(): String = + joinToString("") { it.name.toLowerCase() + " " } + + fun WithExtraProperties.annotations(): List = + extra[Annotations]?.content ?: emptyList() + + private fun Annotations.Annotation.toSignatureString(): String = + "@" + this.dri.classNames + "(" + this.params.entries.joinToString { it.key + "=" + it.value } + ")" + + private fun PageContentBuilder.DocumentableContentBuilder.annotations( + d: Documentable, + ignored: Set, + operation: (Annotations.Annotation) -> Unit + ): Unit = when (d) { + is DFunction -> d.annotations() + is DProperty -> d.annotations() + is DClass -> d.annotations() + is DInterface -> d.annotations() + is DObject -> d.annotations() + is DEnum -> d.annotations() + is DAnnotation -> d.annotations() + is DTypeParameter -> d.annotations() + is DEnumEntry -> d.annotations() + is DTypeAlias -> d.annotations() + is DParameter -> d.annotations() + else -> null + }?.let { + it.filter { it !in ignored }.forEach { + operation(it) + } + } ?: Unit + + fun PageContentBuilder.DocumentableContentBuilder.toSignatureString( + a: Annotations.Annotation, + renderAtStrategy: AtStrategy, + listBrackets: Pair, + classExtension: String + ) { + when (renderAtStrategy) { + is All, is OnlyOnce -> text("@") + is Never -> Unit + } + link(a.dri.classNames!!, a.dri) + text("(") + a.params.entries.forEachIndexed { i, it -> + text(it.key + " = ") + when (renderAtStrategy) { + is All -> All + is Never, is OnlyOnce -> Never + }.let { strategy -> + valueToSignature(it.value, strategy, listBrackets, classExtension) + } + if (i != a.params.entries.size - 1) text(", ") + } + text(")") + } + + private fun PageContentBuilder.DocumentableContentBuilder.valueToSignature( + a: AnnotationParameterValue, + renderAtStrategy: AtStrategy, + listBrackets: Pair, + classExtension: String + ): Unit = when (a) { + is AnnotationValue -> toSignatureString(a.annotation, renderAtStrategy, listBrackets, classExtension) + is ArrayValue -> { + text(listBrackets.first.toString()) + a.value.forEachIndexed { i, it -> + valueToSignature(it, renderAtStrategy, listBrackets, classExtension) + if (i != a.value.size - 1) text(", ") + } + text(listBrackets.second.toString()) + } + is EnumValue -> link(a.enumName, a.enumDri) + is ClassValue -> link(a.className + classExtension, a.classDRI) + is StringValue -> text(a.value) + } + + fun PageContentBuilder.DocumentableContentBuilder.annotationsBlockWithIgnored( + d: Documentable, + ignored: Set, + renderAtStrategy: AtStrategy, + listBrackets: Pair, + classExtension: String + ) { + annotations(d, ignored) { + group { + toSignatureString(it, renderAtStrategy, listBrackets, classExtension) + } + } + } + + fun PageContentBuilder.DocumentableContentBuilder.annotationsInlineWithIgnored( + d: Documentable, + ignored: Set, + renderAtStrategy: AtStrategy, + listBrackets: Pair, + classExtension: String + ) { + annotations(d, ignored) { + toSignatureString(it, renderAtStrategy, listBrackets, classExtension) + text(Typography.nbsp.toString()) + } + } +} + +sealed class AtStrategy +object All : AtStrategy() +object OnlyOnce : AtStrategy() +object Never : AtStrategy() \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/signatures/JvmSingatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSingatureUtils.kt deleted file mode 100644 index dde553b9..00000000 --- a/plugins/base/src/main/kotlin/signatures/JvmSingatureUtils.kt +++ /dev/null @@ -1,129 +0,0 @@ -package org.jetbrains.dokka.base.signatures - -import javaslang.Tuple2 -import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder -import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.properties.WithExtraProperties - -interface JvmSingatureUtils { - - fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: Documentable) - - fun PageContentBuilder.DocumentableContentBuilder.annotationsInline(d: Documentable) - - fun WithExtraProperties.modifiers(): Set - - fun Set.toSignatureString(): String = - joinToString("") { it.name.toLowerCase() + " " } - - fun WithExtraProperties.annotations(): List = - extra[Annotations]?.content ?: emptyList() - - private fun Annotations.Annotation.toSignatureString(): String = - "@${this.dri.classNames}(${this.params.entries.joinToString { it.key + "=" + it.value }})" - - private fun PageContentBuilder.DocumentableContentBuilder.annotations( - d: Documentable, - ignored: Set, - operation: (Annotations.Annotation) -> Unit - ): Unit = when (d) { - is DFunction -> d.annotations() - is DProperty -> d.annotations() - is DClass -> d.annotations() - is DInterface -> d.annotations() - is DObject -> d.annotations() - is DEnum -> d.annotations() - is DAnnotation -> d.annotations() - is DTypeParameter -> d.annotations() - is DEnumEntry -> d.annotations() - is DTypeAlias -> d.annotations() - is DParameter -> d.annotations() - else -> null - }?.let { - it.filter { it !in ignored }.forEach { - operation(it) - } - } ?: Unit - - fun WithExtraProperties.modifiersWithFilter( - filter: Set = ExtraModifiers.values().toSet() - ): Set = - extra[AdditionalModifiers]?.content?.filter { it in filter }?.toSet() ?: emptySet() - - fun PageContentBuilder.DocumentableContentBuilder.toSignatureString( - a: Annotations.Annotation, - renderAtStrategy: AtStrategy, - listBrackets: Tuple2, - classExtension: String - ) { - when (renderAtStrategy) { - is All, is OnlyOnce -> text("@") - is Never -> Unit - } - link(a.dri.classNames!!, a.dri) - text("(") - a.params.entries.forEachIndexed { i, it -> - text(it.key + " = ") - when (renderAtStrategy) { - is All -> All - is Never, is OnlyOnce -> Never - }.let { strategy -> - valueToSignature(it.value, strategy, listBrackets, classExtension) - } - if (i != a.params.entries.size - 1) text(", ") - } - text(")") - } - - private fun PageContentBuilder.DocumentableContentBuilder.valueToSignature( - a: AnnotationParameterValue, - renderAtStrategy: AtStrategy, - listBrackets: Tuple2, - classExtension: String - ): Unit = when (a) { - is AnnotationValue -> toSignatureString(a.annotation, renderAtStrategy, listBrackets, classExtension) - is ArrayValue -> { - text(listBrackets._1.toString()) - a.value.forEachIndexed { i, it -> - valueToSignature(it, renderAtStrategy, listBrackets, classExtension) - if (i != a.value.size - 1) text(", ") - } - text(listBrackets._2.toString()) - } - is EnumValue -> link(a.enumName, a.enumDri) - is ClassValue -> link(a.className + classExtension, a.classDRI) - is StringValue -> text(a.value) - } - - fun PageContentBuilder.DocumentableContentBuilder.annotationsBlockWithIgnored( - d: Documentable, - ignored: Set, - renderAtStrategy: AtStrategy, - listBrackets: Tuple2, - classExtension: String - ) { - annotations(d, ignored) { - group { - toSignatureString(it, renderAtStrategy, listBrackets, classExtension) - } - } - } - - fun PageContentBuilder.DocumentableContentBuilder.annotationsInlineWithIgnored( - d: Documentable, - ignored: Set, - renderAtStrategy: AtStrategy, - listBrackets: Tuple2, - classExtension: String - ) { - annotations(d, ignored) { - toSignatureString(it, renderAtStrategy, listBrackets, classExtension) - text(Typography.nbsp.toString()) - } - } -} - -sealed class AtStrategy -object All : AtStrategy() -object OnlyOnce : AtStrategy() -object Never : AtStrategy() \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 4c689abc..33c82458 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -6,7 +6,6 @@ import org.jetbrains.dokka.links.* import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.Nullable import org.jetbrains.dokka.model.TypeConstructor -import org.jetbrains.dokka.model.properties.ExtraProperty import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.ContentKind import org.jetbrains.dokka.pages.ContentNode @@ -15,7 +14,7 @@ import org.jetbrains.dokka.utilities.DokkaLogger import kotlin.text.Typography.nbsp class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider, - JvmSingatureUtils by KotlinSignatureUtils { + JvmSignatureUtils by KotlinSignatureUtils { private val contentBuilder = PageContentBuilder(ctcc, this, logger) private val ignoredVisibilities = setOf(JavaVisibility.Public, KotlinVisibility.Public) @@ -69,7 +68,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog if (c is DClass) { platformText(c.modifier, sourceSets) { if (it !in ignoredModifiers) - if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.DATA) == true) "" + if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true) "" else (if (it is JavaModifier.Empty) KotlinModifier.Open else it).let { it.name + " " } else "" diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt index 3ce4be0a..48cfe304 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt @@ -1,16 +1,15 @@ package org.jetbrains.dokka.base.signatures -import javaslang.Tuple2 import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder +import org.jetbrains.dokka.model.AdditionalModifiers import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.model.ExtraModifiers -import org.jetbrains.dokka.model.ExtraModifiers.Companion.kotlinOnlyModifiers import org.jetbrains.dokka.model.properties.WithExtraProperties -object KotlinSignatureUtils : JvmSingatureUtils { +object KotlinSignatureUtils : JvmSignatureUtils { private val strategy = OnlyOnce - private val listBrackets = Tuple2('[', ']') + private val listBrackets = Pair('[', ']') private val classExtension = "::class" override fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: Documentable) = @@ -20,5 +19,5 @@ object KotlinSignatureUtils : JvmSingatureUtils { annotationsInlineWithIgnored(d, emptySet(), strategy, listBrackets, classExtension) override fun WithExtraProperties.modifiers() = - modifiersWithFilter(kotlinOnlyModifiers) + extra[AdditionalModifiers]?.content?.filterIsInstance()?.toSet() ?: emptySet() } \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt index 7d7995b7..c04b6ecf 100644 --- a/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/SignatureProvider.kt @@ -1,11 +1,7 @@ package org.jetbrains.dokka.base.signatures -import javaslang.Tuple2 -import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.ContentNode -import org.jetbrains.dokka.pages.TextStyle interface SignatureProvider { fun signature(documentable: Documentable): ContentNode diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index c24a3384..65b83200 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -46,7 +46,7 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeProjection import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.nio.file.Paths -import java.lang.IllegalArgumentException +import kotlin.IllegalArgumentException import kotlin.reflect.jvm.internal.impl.resolve.constants.KClassValue object DefaultDescriptorToDocumentableTranslator : SourceToDocumentableTranslator { @@ -546,9 +546,7 @@ private class DokkaDescriptorVisitor( is TypeParameterDescriptor -> OtherParameter( declarationDRI = DRI.from(ctor.containingDeclaration), name = ctor.name.asString() - ).let { - if (isMarkedNullable) Nullable(it) else it - } + ) else -> TypeConstructor( DRI.from(constructor.declarationDescriptor!!), // TODO: remove '!!' arguments.map { it.toProjection() }, @@ -556,6 +554,8 @@ private class DokkaDescriptorVisitor( else if (isFunctionType) FunctionModifiers.FUNCTION else FunctionModifiers.NONE ) + }.let { + if (isMarkedNullable) Nullable(it) else it } } @@ -593,43 +593,43 @@ private class DokkaDescriptorVisitor( DescriptorDocumentableSource(this).toSourceSetDependent() private fun FunctionDescriptor.additionalExtras() = listOfNotNull( - ExtraModifiers.INFIX.takeIf { isInfix }, - ExtraModifiers.INLINE.takeIf { isInline }, - ExtraModifiers.SUSPEND.takeIf { isSuspend }, - ExtraModifiers.OPERATOR.takeIf { isOperator }, - ExtraModifiers.STATIC.takeIf { isJvmStaticInObjectOrClassOrInterface() }, - ExtraModifiers.TAILREC.takeIf { isTailrec }, - ExtraModifiers.EXTERNAL.takeIf { isExternal }, - ExtraModifiers.OVERRIDE.takeIf { DescriptorUtils.isOverride(this) } + ExtraModifiers.KotlinOnlyModifiers.Infix.takeIf { isInfix }, + ExtraModifiers.KotlinOnlyModifiers.Inline.takeIf { isInline }, + ExtraModifiers.KotlinOnlyModifiers.Suspend.takeIf { isSuspend }, + ExtraModifiers.KotlinOnlyModifiers.Operator.takeIf { isOperator }, + ExtraModifiers.JavaOnlyModifiers.Static.takeIf { isJvmStaticInObjectOrClassOrInterface() }, + ExtraModifiers.KotlinOnlyModifiers.TailRec.takeIf { isTailrec }, + ExtraModifiers.KotlinOnlyModifiers.External.takeIf { isExternal }, + ExtraModifiers.KotlinOnlyModifiers.Override.takeIf { DescriptorUtils.isOverride(this) } ).toProperty() private fun ClassDescriptor.additionalExtras() = listOfNotNull( - ExtraModifiers.INLINE.takeIf { isInline }, - ExtraModifiers.EXTERNAL.takeIf { isExternal }, - ExtraModifiers.INNER.takeIf { isInner }, - ExtraModifiers.DATA.takeIf { isData } + ExtraModifiers.KotlinOnlyModifiers.Inline.takeIf { isInline }, + ExtraModifiers.KotlinOnlyModifiers.External.takeIf { isExternal }, + ExtraModifiers.KotlinOnlyModifiers.Inner.takeIf { isInner }, + ExtraModifiers.KotlinOnlyModifiers.Data.takeIf { isData } ).toProperty() private fun ValueParameterDescriptor.additionalExtras() = listOfNotNull( - ExtraModifiers.NOINLINE.takeIf { isNoinline }, - ExtraModifiers.CROSSINLINE.takeIf { isCrossinline }, - ExtraModifiers.CONST.takeIf { isConst }, - ExtraModifiers.LATEINIT.takeIf { isLateInit }, - ExtraModifiers.VARARG.takeIf { isVararg } + ExtraModifiers.KotlinOnlyModifiers.NoInline.takeIf { isNoinline }, + ExtraModifiers.KotlinOnlyModifiers.CrossInline.takeIf { isCrossinline }, + ExtraModifiers.KotlinOnlyModifiers.Const.takeIf { isConst }, + ExtraModifiers.KotlinOnlyModifiers.LateInit.takeIf { isLateInit }, + ExtraModifiers.KotlinOnlyModifiers.VarArg.takeIf { isVararg } ).toProperty() private fun TypeParameterDescriptor.additionalExtras() = listOfNotNull( - ExtraModifiers.REIFIED.takeIf { isReified } + ExtraModifiers.KotlinOnlyModifiers.Reified.takeIf { isReified } ).toProperty() private fun PropertyDescriptor.additionalExtras() = listOfNotNull( - ExtraModifiers.CONST.takeIf { isConst }, - ExtraModifiers.LATEINIT.takeIf { isLateInit }, - ExtraModifiers.STATIC.takeIf { isJvmStaticInObjectOrClassOrInterface() }, - ExtraModifiers.EXTERNAL.takeIf { isExternal }, - ExtraModifiers.OVERRIDE.takeIf { DescriptorUtils.isOverride(this) } + ExtraModifiers.KotlinOnlyModifiers.Const.takeIf { isConst }, + ExtraModifiers.KotlinOnlyModifiers.LateInit.takeIf { isLateInit }, + ExtraModifiers.JavaOnlyModifiers.Static.takeIf { isJvmStaticInObjectOrClassOrInterface() }, + ExtraModifiers.KotlinOnlyModifiers.External.takeIf { isExternal }, + ExtraModifiers.KotlinOnlyModifiers.Override.takeIf { DescriptorUtils.isOverride(this) } ) private fun List.toProperty() = @@ -640,11 +640,12 @@ private class DokkaDescriptorVisitor( private fun Annotated.getListOfAnnotations() = annotations.map { it.toAnnotation() } private fun ConstantValue<*>.toValue(): AnnotationParameterValue = when (this) { - is ConstantsAnnotationValue -> AnnotationValue(value.let { it.toAnnotation() }) + is ConstantsAnnotationValue -> AnnotationValue(value.toAnnotation()) is ConstantsArrayValue -> ArrayValue(value.map { it.toValue() }) is ConstantsEnumValue -> EnumValue( - enumEntryName.identifier, - enumClassId.let { DRI(it.packageFqName.asString(), it.relativeClassName.asString()) }) + fullEnumEntryName(), + DRI(enumClassId.packageFqName.asString(), fullEnumEntryName()) + ) is ConstantsKtClassValue -> when(value) { is NormalClass -> (value as NormalClass).value.classId.let { ClassValue( @@ -672,7 +673,7 @@ private class DokkaDescriptorVisitor( private fun FieldDescriptor.getAnnotationsAsExtraModifiers() = getAnnotations().content.mapNotNull { try { - ExtraModifiers.valueOf(it.dri.classNames?.toUpperCase() ?: "") + ExtraModifiers.valueOf(it.dri.classNames?.toLowerCase() ?: "") } catch (e: IllegalArgumentException) { null } @@ -690,4 +691,7 @@ private class DokkaDescriptorVisitor( Visibilities.PRIVATE -> KotlinVisibility.Private else -> KotlinVisibility.Public } + + private fun ConstantsEnumValue.fullEnumEntryName() = + "${this.enumClassId.relativeClassName.asString()}.${this.enumEntryName.identifier}" } diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index 658a86f2..5ff5a954 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -338,8 +338,10 @@ open class PageContentBuilder( value: SourceSetDependent, platforms: Set = value.keys, transform: (T) -> String - ) = value.entries.filter { it.key in platforms }.forEach { (p, v) -> - transform(v).takeIf { it.isNotBlank() }?.also { text(it, sourceSets = setOf(p)) } + ) = value.entries.filter { it.key in platforms }.mapNotNull { (p, v) -> + transform(v).takeIf { it.isNotBlank() }?.let { it to p } + }.groupBy({ it.first }) { it.second }.forEach { + text(it.key, sourceSets = it.value.toSet()) } } diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 0f8fc011..9c731528 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.base.translators.psi +import com.intellij.icons.AllIcons.Nodes.Static import com.intellij.lang.jvm.annotation.JvmAnnotationAttribute import com.intellij.lang.jvm.JvmModifier import com.intellij.lang.jvm.types.JvmReferenceType @@ -275,18 +276,18 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { private fun PsiModifierListOwner.additionalExtras() = AdditionalModifiers( listOfNotNull( - ExtraModifiers.STATIC.takeIf { hasModifier(JvmModifier.STATIC) }, - ExtraModifiers.NATIVE.takeIf { hasModifier(JvmModifier.NATIVE) }, - ExtraModifiers.SYNCHRONIZED.takeIf { hasModifier(JvmModifier.SYNCHRONIZED) }, - ExtraModifiers.STRICTFP.takeIf { hasModifier(JvmModifier.STRICTFP) }, - ExtraModifiers.TRANSIENT.takeIf { hasModifier(JvmModifier.TRANSIENT) }, - ExtraModifiers.VOLATILE.takeIf { hasModifier(JvmModifier.VOLATILE) }, - ExtraModifiers.TRANSITIVE.takeIf { hasModifier(JvmModifier.TRANSITIVE) } + ExtraModifiers.JavaOnlyModifiers.Static.takeIf { hasModifier(JvmModifier.STATIC) }, + ExtraModifiers.JavaOnlyModifiers.Native.takeIf { hasModifier(JvmModifier.NATIVE) }, + ExtraModifiers.JavaOnlyModifiers.Synchronized.takeIf { hasModifier(JvmModifier.SYNCHRONIZED) }, + ExtraModifiers.JavaOnlyModifiers.StrictFP.takeIf { hasModifier(JvmModifier.STRICTFP) }, + ExtraModifiers.JavaOnlyModifiers.Transient.takeIf { hasModifier(JvmModifier.TRANSIENT) }, + ExtraModifiers.JavaOnlyModifiers.Volatile.takeIf { hasModifier(JvmModifier.VOLATILE) }, + ExtraModifiers.JavaOnlyModifiers.Transitive.takeIf { hasModifier(JvmModifier.TRANSITIVE) } ).toSet() ) private fun AdditionalModifiers.toListOfAnnotations() = this.content.map { - if (it.name != "STATIC") + if (it !is ExtraModifiers.JavaOnlyModifiers.Static) Annotations.Annotation(DRI("kotlin.jvm", it.name.toLowerCase().capitalize()), emptyMap()) else Annotations.Annotation(DRI("kotlin.jvm", "JvmStatic"), emptyMap()) diff --git a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt index c4640824..98f572b4 100644 --- a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt +++ b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt @@ -49,8 +49,9 @@ class ContentForAnnotationsTest : AbstractCoreTest() { val page = module.children.single { it.name == "test" } .children.single { it.name == "function" } as ContentPage page.content.assertNode { - - header(1) { +"function" } + group { + header(1) { +"function" } + } divergentGroup { divergentInstance { divergent { diff --git a/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt b/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt index 3f0edec3..68042fd4 100644 --- a/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt +++ b/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt @@ -40,8 +40,9 @@ class ContentForSignaturesTest : AbstractCoreTest() { val page = module.children.single { it.name == "test" } .children.single { it.name == "function" } as ContentPage page.content.assertNode { - - header(1) { +"function" } + group { + header(1) { +"function" } + } divergentGroup { divergentInstance { divergent { @@ -78,7 +79,9 @@ class ContentForSignaturesTest : AbstractCoreTest() { val page = module.children.single { it.name == "test" } .children.single { it.name == "function" } as ContentPage page.content.assertNode { - header(1) { +"function" } + group { + header(1) { +"function" } + } divergentGroup { divergentInstance { divergent { @@ -115,7 +118,9 @@ class ContentForSignaturesTest : AbstractCoreTest() { val page = module.children.single { it.name == "test" } .children.single { it.name == "function" } as ContentPage page.content.assertNode { - header(1) { +"function" } + group { + header(1) { +"function" } + } divergentGroup { divergentInstance { divergent { @@ -152,8 +157,9 @@ class ContentForSignaturesTest : AbstractCoreTest() { val page = module.children.single { it.name == "test" } .children.single { it.name == "function" } as ContentPage page.content.assertNode { - - header(1) { +"function" } + group { + header(1) { +"function" } + } divergentGroup { divergentInstance { divergent { @@ -190,7 +196,9 @@ class ContentForSignaturesTest : AbstractCoreTest() { val page = module.children.single { it.name == "test" } .children.single { it.name == "function" } as ContentPage page.content.assertNode { - header(1) { +"function" } + group { + header(1) { +"function" } + } divergentGroup { divergentInstance { divergent { @@ -227,7 +235,9 @@ class ContentForSignaturesTest : AbstractCoreTest() { val page = module.children.single { it.name == "test" } .children.single { it.name == "function" } as ContentPage page.content.assertNode { - header(1) { +"function" } + group { + header(1) { +"function" } + } divergentGroup { divergentInstance { divergent { diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt index 405ec8b6..4ca34b00 100644 --- a/plugins/base/src/test/kotlin/model/ClassesTest.kt +++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt @@ -152,7 +152,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class visibility.values allEquals KotlinVisibility.Public with(extra[AdditionalModifiers].assertNotNull("Extras")) { content counts 1 - content.first() equals ExtraModifiers.DATA + content.first() equals ExtraModifiers.KotlinOnlyModifiers.Data } } } @@ -185,7 +185,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class with(content.first()) { dri.classNames equals "Deprecated" params.entries counts 1 -// params["message"].assertNotNull("message") equals "should no longer be used" + (params["message"].assertNotNull("message") as StringValue).value equals "\"should no longer be used\"" } } } @@ -275,7 +275,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class with((this / "D").cast()) { with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) { content counts 1 - content.first() equals ExtraModifiers.INNER + content.first() equals ExtraModifiers.KotlinOnlyModifiers.Inner } } } @@ -426,9 +426,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class with((this / "classes" / "Foo").cast()) { with(extra[Annotations]?.content?.firstOrNull().assertNotNull("annotations")) { dri.toString() equals "kotlin/Suppress///PointingToDeclaration/" -// with(params["names"].assertNotNull("param")) { -// this equals "[\"abc\"]" -// } + (params["names"].assertNotNull("param") as ArrayValue).value equals listOf(StringValue("\"abc\"")) } } } diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt index 6cbb84f7..38f64df5 100644 --- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt +++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt @@ -1,5 +1,6 @@ package model +import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* import org.junit.jupiter.api.Test import utils.AbstractModelTest @@ -145,7 +146,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun with(content.first()) { dri.classNames equals "Suppress" params.entries counts 1 -// params["names"].assertNotNull("names") equals "[\"FOO\"]" + (params["names"].assertNotNull("param") as ArrayValue).value equals listOf(StringValue("\"FOO\"")) } } } @@ -161,7 +162,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun ) { with((this / "function" / "f").cast()) { extra[AdditionalModifiers]?.content counts 1 - extra[AdditionalModifiers]?.content exists ExtraModifiers.INLINE + extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Inline } } } @@ -175,7 +176,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun ) { with((this / "function" / "f").cast()) { extra[AdditionalModifiers]?.content counts 1 - extra[AdditionalModifiers]?.content exists ExtraModifiers.SUSPEND + extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Suspend } } } @@ -189,8 +190,8 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun ) { with((this / "function" / "f").cast()) { extra[AdditionalModifiers]?.content counts 2 - extra[AdditionalModifiers]?.content exists ExtraModifiers.SUSPEND - extra[AdditionalModifiers]?.content exists ExtraModifiers.INLINE + extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Suspend + extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Inline } } } @@ -205,8 +206,8 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun with((this / "function" / "f").cast()) { with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) { content counts 2 - content exists ExtraModifiers.SUSPEND - content exists ExtraModifiers.INLINE + content exists ExtraModifiers.KotlinOnlyModifiers.Suspend + content exists ExtraModifiers.KotlinOnlyModifiers.Inline } } } @@ -229,10 +230,18 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun 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]" + (params["allowedTargets"].assertNotNull("allowedTargets") as ArrayValue).value equals listOf( + EnumValue( + "AnnotationTarget.VALUE_PARAMETER", + DRI("kotlin.annotation", "AnnotationTarget.VALUE_PARAMETER") + ) + ) } with(this["Retention"].assertNotNull("Retention")) { -// params["value"].assertNotNull("value") equals "(kotlin/annotation/AnnotationRetention, SOURCE)" + (params["value"].assertNotNull("value") as EnumValue) equals EnumValue( + "AnnotationRetention.SOURCE", + DRI("kotlin.annotation", "AnnotationRetention.SOURCE") + ) } this["MustBeDocumented"].assertNotNull("MustBeDocumented").params.entries counts 0 } @@ -260,7 +269,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun ) { with((this / "function" / "f" / "notInlined").cast()) { extra[AdditionalModifiers]?.content counts 1 - extra[AdditionalModifiers]?.content exists ExtraModifiers.NOINLINE + extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.NoInline } } } @@ -291,10 +300,18 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun 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]" + (params["allowedTargets"].assertNotNull("allowedTargets") as ArrayValue).value equals listOf( + EnumValue( + "AnnotationTarget.VALUE_PARAMETER", + DRI("kotlin.annotation", "AnnotationTarget.VALUE_PARAMETER") + ) + ) } with(this["Retention"].assertNotNull("Retention")) { -// params["value"].assertNotNull("value") equals "(kotlin/annotation/AnnotationRetention, SOURCE)" + (params["value"].assertNotNull("value") as EnumValue) equals EnumValue( + "AnnotationRetention.SOURCE", + DRI("kotlin.annotation", "AnnotationRetention.SOURCE") + ) } this["MustBeDocumented"].assertNotNull("MustBeDocumented").params.entries counts 0 } @@ -307,7 +324,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun with(content.first()) { dri.classNames equals "Fancy" params.entries counts 1 -// params["size"] equals "1" + (params["size"] as StringValue).value equals "1" } } } @@ -369,7 +386,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun with(content.first()) { dri.classNames equals "SinceKotlin" params.entries counts 1 -// params["version"].assertNotNull("version") equals "1.1" + (params["version"].assertNotNull("version") as StringValue).value equals "\"1.1\"" } } } diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index 07af7913..fd293b5c 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -1,9 +1,9 @@ package model import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo +import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import utils.AbstractModelTest import utils.assertNotNull @@ -297,7 +297,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { with((this / "java" / "C" / "foo").cast()) { with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) { content counts 1 - content.first() equals ExtraModifiers.STATIC + content.first() equals ExtraModifiers.JavaOnlyModifiers.Static } } } @@ -338,7 +338,11 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { with(extra[Annotations].assertNotNull("Annotations")) { with(content.single()) { dri.classNames equals "Target" -// params["value"].assertNotNull("value") equals "{ElementType.FIELD, ElementType.TYPE, ElementType.METHOD}" + (params["value"].assertNotNull("value") as ArrayValue).value equals listOf( + EnumValue("ElementType.FIELD", DRI("java.lang.annotation", "ElementType")), + EnumValue("ElementType.TYPE", DRI("java.lang.annotation", "ElementType")), + EnumValue("ElementType.METHOD", DRI("java.lang.annotation", "ElementType")) + ) } } } diff --git a/plugins/base/src/test/kotlin/model/PropertyTest.kt b/plugins/base/src/test/kotlin/model/PropertyTest.kt index 7429257b..90a9d782 100644 --- a/plugins/base/src/test/kotlin/model/PropertyTest.kt +++ b/plugins/base/src/test/kotlin/model/PropertyTest.kt @@ -155,7 +155,7 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro with(content.first()) { dri.classNames equals "SinceKotlin" params.entries counts 1 -// params["version"].assertNotNull("version") equals "1.1" + (params["version"].assertNotNull("version") as StringValue).value equals "\"1.1\"" } } } diff --git a/plugins/base/src/test/kotlin/utils/contentUtils.kt b/plugins/base/src/test/kotlin/utils/contentUtils.kt index a1141832..ec119ebb 100644 --- a/plugins/base/src/test/kotlin/utils/contentUtils.kt +++ b/plugins/base/src/test/kotlin/utils/contentUtils.kt @@ -139,26 +139,28 @@ fun ContentMatcherBuilder<*>.propertySignature( header { +"Package test" } } group { - skipAllNotMatching() - header { +"Properties" } - table { - group { - link { +name } - platformHinted { - group { + group { + skipAllNotMatching() + header { +"Properties" } + table { + group { + link { +name } + platformHinted { group { - annotations.entries.forEach { - group { - unwrapAnnotation(it) + group { + annotations.entries.forEach { + group { + unwrapAnnotation(it) + } } - } - +("$visibility $modifier ${keywords.joinToString("") { "$it " }} $preposition") - link { +name } - if (type != null) { - +(": ") - group { - link { - +(type) + +("$visibility $modifier ${keywords.joinToString("") { "$it " }} $preposition") + link { +name } + if (type != null) { + +(": ") + group { + link { + +(type) + } } } } 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 8d9ac20d..8f20f942 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 = emptyMap(), documentation = emptyMap(), - modifier = sourceSets.map{ it to JavaModifier.Final}.toMap(), + modifier = sourceSets.map { it to JavaModifier.Final }.toMap(), sourceSets = sourceSets, extra = PropertyContainer.empty() ) @@ -68,15 +68,15 @@ internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: Stri dri.withClass(relocateToClass) }, modifier = if (setter == null) { - sourceSets.map{it to JavaModifier.Final}.toMap() + sourceSets.map { it to JavaModifier.Final }.toMap() } else { - sourceSets.map{it to JavaModifier.Empty}.toMap() + sourceSets.map { it to JavaModifier.Empty }.toMap() }, visibility = visibility.mapValues { JavaVisibility.Private }, 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 + extra = if (isTopLevel) extra.plus(extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else extra ) internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClass: String? = null): List = @@ -89,13 +89,13 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas }, name = "get" + name.capitalize(), modifier = if (setter == null) { - sourceSets.map{it to JavaModifier.Final}.toMap() + sourceSets.map { it to JavaModifier.Final }.toMap() } else { - sourceSets.map{it to JavaModifier.Empty}.toMap() + sourceSets.map { it to JavaModifier.Empty }.toMap() }, visibility = visibility.mapValues { JavaVisibility.Public }, type = type.asJava(), // TODO: check - extra = if (isTopLevel) getter!!.extra.plus(getter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else getter!!.extra + extra = if (isTopLevel) getter!!.extra.plus(getter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else getter!!.extra ), setter?.copy( dri = if (relocateToClass.isNullOrBlank()) { @@ -105,13 +105,13 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas }, name = "set" + name.capitalize(), modifier = if (setter == null) { - sourceSets.map{it to JavaModifier.Final}.toMap() + sourceSets.map { it to JavaModifier.Final }.toMap() } else { - sourceSets.map{it to JavaModifier.Empty}.toMap() + sourceSets.map { it to JavaModifier.Empty }.toMap() }, visibility = visibility.mapValues { JavaVisibility.Public }, type = type.asJava(), // TODO: check - extra = if (isTopLevel) setter!!.extra.plus(setter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.STATIC))) else setter!!.extra + extra = if (isTopLevel) setter!!.extra.plus(setter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else setter!!.extra ) ) @@ -125,9 +125,9 @@ internal fun DFunction.asJava(containingClassName: String): DFunction { // dri = dri.copy(callable = dri.callable?.asJava()), name = newName, type = type.asJava(), - modifier = if(modifier.all{(_,v)-> v is KotlinModifier.Final} && isConstructor) - sourceSets.map{it to JavaModifier.Empty}.toMap() - else sourceSets.map{it to modifier.values.first()}.toMap(), + modifier = if (modifier.all { (_, v) -> v is KotlinModifier.Final } && isConstructor) + sourceSets.map { it to JavaModifier.Empty }.toMap() + else sourceSets.map { it to modifier.values.first() }.toMap(), parameters = listOfNotNull(receiver?.asJava()) + parameters.map { it.asJava() }, receiver = null ) // TODO static if toplevel @@ -151,8 +151,9 @@ internal fun DClass.asJava(): DClass = copy( classlikes = classlikes.map { it.asJava() }, generics = generics.map { it.asJava() }, supertypes = supertypes.mapValues { it.value.map { it.possiblyAsJava() } }, - modifier = if (modifier.all{(_,v) -> v is KotlinModifier.Empty}) sourceSets.map{it to JavaModifier.Final}.toMap() - else sourceSets.map{it to modifier.values.first()}.toMap() + modifier = if (modifier.all { (_, v) -> v is KotlinModifier.Empty }) sourceSets.map { it to JavaModifier.Final } + .toMap() + else sourceSets.map { it to modifier.values.first() }.toMap() ) private fun DTypeParameter.asJava(): DTypeParameter = copy( @@ -188,7 +189,7 @@ internal fun DObject.asJava(): DObject = copy( properties = properties.map { it.asJava() } + DProperty( name = "INSTANCE", - modifier = sourceSets.map{it to JavaModifier.Final}.toMap(), + modifier = sourceSets.map { it to JavaModifier.Final }.toMap(), dri = dri.copy(callable = Callable("INSTANCE", null, emptyList())), documentation = emptyMap(), sources = emptyMap(), @@ -202,7 +203,7 @@ internal fun DObject.asJava(): DObject = copy( receiver = null, generics = emptyList(), expectPresentInSet = expectPresentInSet, - extra = PropertyContainer.empty() + AdditionalModifiers(setOf(ExtraModifiers.STATIC)) + extra = PropertyContainer.empty() + AdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static)) ), classlikes = classlikes.map { it.asJava() }, supertypes = supertypes.mapValues { it.value.map { it.possiblyAsJava() } } 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 ec3221e2..a55f9339 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -1,15 +1,12 @@ package org.jetbrains.dokka.kotlinAsJava.signatures -import org.jetbrains.dokka.base.signatures.JvmSingatureUtils -import javaslang.Tuple2 -import org.jetbrains.dokka.base.signatures.All +import org.jetbrains.dokka.base.signatures.JvmSignatureUtils 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.properties.WithExtraProperties import org.jetbrains.dokka.pages.ContentKind import org.jetbrains.dokka.pages.ContentNode import org.jetbrains.dokka.pages.TextStyle @@ -17,7 +14,7 @@ import org.jetbrains.dokka.utilities.DokkaLogger import kotlin.text.Typography.nbsp class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogger) : SignatureProvider, - JvmSingatureUtils by JavaSignatureUtils { + JvmSignatureUtils by JavaSignatureUtils { private val contentBuilder = PageContentBuilder(ctcc, this, logger) private val ignoredVisibilities = setOf(JavaVisibility.Default) diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt index 16c3f25a..e2f73bf9 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt @@ -1,14 +1,13 @@ package org.jetbrains.dokka.kotlinAsJava.signatures -import javaslang.Tuple2 + import org.jetbrains.dokka.base.signatures.All -import org.jetbrains.dokka.base.signatures.JvmSingatureUtils +import org.jetbrains.dokka.base.signatures.JvmSignatureUtils import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.ExtraModifiers.Companion.javaOnlyModifiers import org.jetbrains.dokka.model.properties.WithExtraProperties -object JavaSignatureUtils : JvmSingatureUtils { +object JavaSignatureUtils : JvmSignatureUtils { val ignoredAnnotations = setOf( Annotations.Annotation(DRI("kotlin.jvm", "Transient"), emptyMap()), @@ -19,7 +18,7 @@ object JavaSignatureUtils : JvmSingatureUtils { ) private val strategy = All - private val listBrackets = Tuple2('{', '}') + private val listBrackets = Pair('{', '}') private val classExtension = ".class" override fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: Documentable) = @@ -29,6 +28,6 @@ object JavaSignatureUtils : JvmSingatureUtils { annotationsInlineWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension) override fun WithExtraProperties.modifiers() = - modifiersWithFilter(javaOnlyModifiers) + extra[AdditionalModifiers]?.content?.filterIsInstance()?.toSet() ?: emptySet() } \ No newline at end of file -- cgit From dd44b839eac1b7b647e97f2cc73dd96bd054713b Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Thu, 28 May 2020 21:12:50 +0200 Subject: Refactor of Annotations and ExtraModifiers to be platform depedent --- core/src/main/kotlin/model/aditionalExtras.kt | 6 +- .../main/kotlin/signatures/JvmSignatureUtils.kt | 27 ++-- .../kotlin/signatures/KotlinSignatureProvider.kt | 162 ++++++++++----------- .../main/kotlin/signatures/KotlinSignatureUtils.kt | 4 +- .../DefaultDescriptorToDocumentableTranslator.kt | 154 +++++++++++--------- .../psi/DefaultPsiToDocumentableTranslator.kt | 117 ++++++++------- .../annotations/ContentForAnnotationsTest.kt | 2 - plugins/base/src/test/kotlin/model/ClassesTest.kt | 38 ++--- .../base/src/test/kotlin/model/FunctionsTest.kt | 62 ++++---- plugins/base/src/test/kotlin/model/JavaTest.kt | 10 +- plugins/base/src/test/kotlin/model/PropertyTest.kt | 12 +- plugins/base/src/test/kotlin/utils/contentUtils.kt | 154 ++++++++++---------- .../kotlin/converters/KotlinToJavaConverter.kt | 29 +++- .../kotlin/signatures/JavaSignatureProvider.kt | 8 +- .../main/kotlin/signatures/JavaSignatureUtils.kt | 4 +- 15 files changed, 416 insertions(+), 373 deletions(-) (limited to 'plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt') diff --git a/core/src/main/kotlin/model/aditionalExtras.kt b/core/src/main/kotlin/model/aditionalExtras.kt index fcf1efa6..b4355d4b 100644 --- a/core/src/main/kotlin/model/aditionalExtras.kt +++ b/core/src/main/kotlin/model/aditionalExtras.kt @@ -4,7 +4,7 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.properties.ExtraProperty import org.jetbrains.dokka.model.properties.MergeStrategy -class AdditionalModifiers(val content: Set) : ExtraProperty { +class AdditionalModifiers(val content: SourceSetDependent>) : ExtraProperty { companion object : ExtraProperty.Key { override fun mergeStrategyFor( left: AdditionalModifiers, @@ -19,6 +19,8 @@ class AdditionalModifiers(val content: Set) : ExtraProperty = AdditionalModifiers } +fun SourceSetDependent>.toAdditionalModifiers() = AdditionalModifiers(this) + class Annotations(val content: SourceSetDependent>) : ExtraProperty { companion object : ExtraProperty.Key { override fun mergeStrategyFor(left: Annotations, right: Annotations): MergeStrategy = @@ -37,6 +39,8 @@ class Annotations(val content: SourceSetDependent>) : ExtraProp } } +fun SourceSetDependent>.toAnnotations() = Annotations(this) + sealed class AnnotationParameterValue data class AnnotationValue(val annotation: Annotations.Annotation) : AnnotationParameterValue() data class ArrayValue(val value: List) : AnnotationParameterValue() diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt index 0cf085b8..7f0e985e 100644 --- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.base.signatures import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.properties.WithExtraProperties +import org.jetbrains.dokka.pages.* interface JvmSignatureUtils { @@ -10,7 +11,7 @@ interface JvmSignatureUtils { fun PageContentBuilder.DocumentableContentBuilder.annotationsInline(d: Documentable) - fun WithExtraProperties.modifiers(): Set + fun WithExtraProperties.modifiers(): SourceSetDependent> fun Set.toSignatureString(): String = joinToString("") { it.name.toLowerCase() + " " } @@ -40,9 +41,11 @@ interface JvmSignatureUtils { else -> null }?.let { it.entries.forEach { - group(sourceSets = setOf(it.key)) { - it.value.filter { it !in ignored }.forEach { - operation(it) + it.value.filter { it !in ignored }.takeIf { it.isNotEmpty() }?.let { annotations -> + group(sourceSets = setOf(it.key), styles = setOf(TextStyle.Block)) { + annotations.forEach { + operation(it) + } } } } @@ -62,14 +65,16 @@ interface JvmSignatureUtils { link(a.dri.classNames!!, a.dri) text("(") a.params.entries.forEachIndexed { i, it -> - text(it.key + " = ") - when (renderAtStrategy) { - is All -> All - is Never, is OnlyOnce -> Never - }.let { strategy -> - valueToSignature(it.value, strategy, listBrackets, classExtension) + group(styles = setOf(TextStyle.Span)) { + text(it.key + " = ") + when (renderAtStrategy) { + is All -> All + is Never, is OnlyOnce -> Never + }.let { strategy -> + valueToSignature(it.value, strategy, listBrackets, classExtension) + } + if (i != a.params.entries.size - 1) text(", ") } - if (i != a.params.entries.size - 1) text(", ") } text(")") } diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index 5514f9e5..542f6a1a 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -67,34 +67,34 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun regularSignature(c: DClasslike, sourceSets: Set = c.sourceSets.toSet()) = contentBuilder.contentFor(c, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) { - group(styles = setOf(TextStyle.Block)) { - annotationsBlock(c) - platformText( - c.visibility, - sourceSets - ) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } - if (c is DClass) { - platformText(c.modifier, sourceSets) { - if (it !in ignoredModifiers) - if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true) "" - else (if (it is JavaModifier.Empty) KotlinModifier.Open else it).let { it.name + " " } - else - "" - } - } - when (c) { - is DClass -> text("class ") - is DInterface -> text("interface ") - is DEnum -> text("enum ") - is DObject -> text("object ") - is DAnnotation -> text("annotation class ") + annotationsBlock(c) + platformText( + c.visibility, + sourceSets + ) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } + if (c is DClass) { + platformText(c.modifier, sourceSets) { + if (it !in ignoredModifiers) + if (c.extra[AdditionalModifiers]?.content?.contains(ExtraModifiers.KotlinOnlyModifiers.Data) == true) "" + else (if (it is JavaModifier.Empty) KotlinModifier.Open else it).let { it.name + " " } + else + "" } - link(c.name!!, c.dri) - if (c is WithGenerics) { - list(c.generics, prefix = "<", suffix = "> ") { - +buildSignature(it) - } + } + when (c) { + 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 WithGenerics) { + list(c.generics, prefix = "<", suffix = "> ") { + +buildSignature(it) } + } + if (c is DClass) { if (c is WithConstructors) { val pConstructor = c.constructors.singleOrNull { it.extra[PrimaryConstructorExtra] != null } if (pConstructor?.annotations()?.isNotEmpty() == true) { @@ -115,11 +115,11 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog signatureForProjection(it.type) } } - if (c is WithSupertypes) { - c.supertypes.filter { it.key in sourceSets }.map { (s, dris) -> - list(dris, prefix = " : ", sourceSets = setOf(s)) { - link(it.sureClassNames, it, sourceSets = setOf(s)) - } + } + if (c is WithSupertypes) { + c.supertypes.filter { it.key in sourceSets }.map { (s, dris) -> + list(dris, prefix = " : ", sourceSets = setOf(s)) { + link(it.sureClassNames, it, sourceSets = setOf(s)) } } } @@ -128,62 +128,58 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private fun propertySignature(p: DProperty, sourceSets: Set = p.sourceSets.toSet()) = contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) { - group(styles = setOf(TextStyle.Block)) { - annotationsBlock(p) - platformText(p.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } - platformText(p.modifier) { - it.takeIf { it !in ignoredModifiers }?.let { - if (it is JavaModifier.Empty) KotlinModifier.Open else it - }?.name?.let { "$it " } ?: "" - } - text(p.modifiers().toSignatureString()) - 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) + annotationsBlock(p) + platformText(p.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } + platformText(p.modifier) { + it.takeIf { it !in ignoredModifiers }?.let { + if (it is JavaModifier.Empty) KotlinModifier.Open else it + }?.name?.let { "$it " } ?: "" + } + platformText(p.modifiers()) { it.toSignatureString() } + 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) } private fun functionSignature(f: DFunction, sourceSets: Set = f.sourceSets.toSet()) = contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace), sourceSets = sourceSets) { - group(styles = setOf(TextStyle.Block)) { - annotationsBlock(f) - platformText(f.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } - platformText(f.modifier) { - it.takeIf { it !in ignoredModifiers }?.let { - if (it is JavaModifier.Empty) KotlinModifier.Open else it - }?.name?.let { "$it " } ?: "" - } - text(f.modifiers().toSignatureString()) - text("fun ") - list(f.generics, prefix = "<", suffix = "> ") { - +buildSignature(it) - } - f.receiver?.also { - signatureForProjection(it.type) - text(".") - } - link(f.name, f.dri) - text("(") - list(f.parameters) { - annotationsInline(it) - text(it.modifiers().toSignatureString()) - text(it.name!!) - text(": ") - signatureForProjection(it.type) - } - text(")") - if (f.documentReturnType()) { - text(": ") - signatureForProjection(f.type) - } + annotationsBlock(f) + platformText(f.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } + platformText(f.modifier) { + it.takeIf { it !in ignoredModifiers }?.let { + if (it is JavaModifier.Empty) KotlinModifier.Open else it + }?.name?.let { "$it " } ?: "" + } + platformText(f.modifiers()) { it.toSignatureString() } + text("fun ") + list(f.generics, prefix = "<", suffix = "> ") { + +buildSignature(it) + } + f.receiver?.also { + signatureForProjection(it.type) + text(".") + } + link(f.name, f.dri) + text("(") + list(f.parameters) { + annotationsInline(it) + platformText(it.modifiers()) { it.toSignatureString() } + text(it.name!!) + text(": ") + signatureForProjection(it.type) + } + text(")") + if (f.documentReturnType()) { + text(": ") + signatureForProjection(f.type) } } @@ -204,7 +200,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog sourceSets = platforms.toSet() ) { platformText(t.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } - text(t.modifiers().toSignatureString()) + platformText(t.modifiers()) { it.toSignatureString() } text("typealias ") signatureForProjection(t.type) text(" = ") diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt index 48cfe304..1f323473 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt @@ -19,5 +19,7 @@ object KotlinSignatureUtils : JvmSignatureUtils { annotationsInlineWithIgnored(d, emptySet(), strategy, listBrackets, classExtension) override fun WithExtraProperties.modifiers() = - extra[AdditionalModifiers]?.content?.filterIsInstance()?.toSet() ?: emptySet() + extra[AdditionalModifiers]?.content?.entries?.map { + it.key to it.value.filterIsInstance().toSet() + }?.toMap() ?: emptyMap() } \ 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 a8175405..bf92c849 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -146,7 +146,10 @@ private class DokkaDescriptorVisitor( generics = descriptor.declaredTypeParameters.map { it.toTypeParameter() }, companion = descriptor.companion(driWithPlatform), sourceSets = listOf(sourceSet), - extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) + extra = PropertyContainer.withAll( + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + ) ) } @@ -169,7 +172,10 @@ private class DokkaDescriptorVisitor( supertypes = info.supertypes.toSourceSetDependent(), documentation = info.docs, sourceSets = listOf(sourceSet), - extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) + extra = PropertyContainer.withAll( + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + ) ) } @@ -194,7 +200,10 @@ private class DokkaDescriptorVisitor( documentation = info.docs, companion = descriptor.companion(driWithPlatform), sourceSets = listOf(sourceSet), - extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) + extra = PropertyContainer.withAll( + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + ) ) } @@ -213,8 +222,8 @@ private class DokkaDescriptorVisitor( sourceSets = listOf(sourceSet), expectPresentInSet = sourceSet.takeIf { isExpect }, extra = PropertyContainer.withAll( - descriptor.additionalExtras(), - descriptor.getAnnotations(), + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotations().toSourceSetDependent().toAnnotations(), ConstructorValues(descriptor.getAppliedConstructorParameters().toSourceSetDependent()) ) ) @@ -233,7 +242,10 @@ private class DokkaDescriptorVisitor( properties = scope.properties(driWithPlatform), expectPresentInSet = null, sourceSets = listOf(sourceSet), - extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()), + extra = PropertyContainer.withAll( + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + ), companion = descriptor.companionObjectDescriptor?.let { objectDescriptor(it, driWithPlatform) }, visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), generics = descriptor.declaredTypeParameters.map { it.toTypeParameter() }, @@ -271,7 +283,10 @@ private class DokkaDescriptorVisitor( modifier = descriptor.modifier().toSourceSetDependent(), companion = descriptor.companion(driWithPlatform), sourceSets = listOf(sourceSet), - extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) + extra = PropertyContainer.withAll( + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + ) ) } @@ -301,9 +316,9 @@ private class DokkaDescriptorVisitor( sourceSets = listOf(sourceSet), generics = descriptor.typeParameters.map { it.toTypeParameter() }, extra = PropertyContainer.withAll( - (descriptor.additionalExtras() + (descriptor.backingField?.getAnnotationsAsExtraModifiers()?.entries?.single()?.value - ?: emptyList())).toProperty(), - descriptor.getAllAnnotations() + (descriptor.additionalExtras() + descriptor.getAnnotationsWithBackingField() + .toAdditionalExtras()).toSet().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotationsWithBackingField().toSourceSetDependent().toAnnotations() ) ) } @@ -339,7 +354,8 @@ private class DokkaDescriptorVisitor( sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll( InheritedFunction(isInherited), - descriptor.additionalExtras(), descriptor.getAnnotations() + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotations().toSourceSetDependent().toAnnotations() ) ) } @@ -379,12 +395,14 @@ private class DokkaDescriptorVisitor( modifier = descriptor.modifier().toSourceSetDependent(), generics = descriptor.typeParameters.map { it.toTypeParameter() }, sourceSets = listOf(sourceSet), - extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) - .let { - if (descriptor.isPrimary) { - it + PrimaryConstructorExtra - } else it - } + extra = PropertyContainer.withAll( + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + ).let { + if (descriptor.isPrimary) { + it + PrimaryConstructorExtra + } else it + } ) } @@ -398,7 +416,7 @@ private class DokkaDescriptorVisitor( expectPresentInSet = null, documentation = descriptor.resolveDescriptorData(), sourceSets = listOf(sourceSet), - extra = PropertyContainer.withAll(descriptor.getAnnotations()) + extra = PropertyContainer.withAll(descriptor.getAnnotations().toSourceSetDependent().toAnnotations()) ) private fun visitPropertyAccessorDescriptor( @@ -418,7 +436,10 @@ private class DokkaDescriptorVisitor( expectPresentInSet = sourceSet.takeIf { isExpect }, documentation = descriptor.resolveDescriptorData(), sourceSets = listOf(sourceSet), - extra = PropertyContainer.withAll(descriptor.additionalExtras(), getAllAnnotations()) + extra = PropertyContainer.withAll( + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + getAnnotationsWithBackingField().toSourceSetDependent().toAnnotations() + ) ) val name = run { @@ -453,7 +474,10 @@ private class DokkaDescriptorVisitor( }, sources = descriptor.createSources(), sourceSets = listOf(sourceSet), - extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) + extra = PropertyContainer.withAll( + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotations().toSourceSetDependent().toAnnotations() + ) ) } @@ -479,12 +503,11 @@ private class DokkaDescriptorVisitor( expectPresentInSet = null, documentation = descriptor.resolveDescriptorData(), sourceSets = listOf(sourceSet), - extra = PropertyContainer.withAll( - listOfNotNull( - descriptor.additionalExtras(), - descriptor.getAnnotations(), - descriptor.getDefaultValue()?.let { DefaultValue(it) }) - ) + extra = PropertyContainer.withAll(listOfNotNull( + descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(), + descriptor.getAnnotations().toSourceSetDependent().toAnnotations(), + descriptor.getDefaultValue()?.let { DefaultValue(it) } + )) ) private fun MemberScope.getContributedDescriptors(kindFilter: DescriptorKindFilter, shouldFilter: Boolean) = @@ -542,7 +565,7 @@ private class DokkaDescriptorVisitor( null, upperBounds.map { it.toBound() }, listOf(sourceSet), - extra = PropertyContainer.withAll(additionalExtras()) + extra = PropertyContainer.withAll(additionalExtras().toSourceSetDependent().toAdditionalModifiers()) ) private fun KotlinType.toBound(): Bound = when (this) { @@ -606,28 +629,26 @@ private class DokkaDescriptorVisitor( ExtraModifiers.KotlinOnlyModifiers.TailRec.takeIf { isTailrec }, ExtraModifiers.KotlinOnlyModifiers.External.takeIf { isExternal }, ExtraModifiers.KotlinOnlyModifiers.Override.takeIf { DescriptorUtils.isOverride(this) } - ).toProperty() + ).toSet() private fun ClassDescriptor.additionalExtras() = listOfNotNull( ExtraModifiers.KotlinOnlyModifiers.Inline.takeIf { isInline }, ExtraModifiers.KotlinOnlyModifiers.External.takeIf { isExternal }, ExtraModifiers.KotlinOnlyModifiers.Inner.takeIf { isInner }, ExtraModifiers.KotlinOnlyModifiers.Data.takeIf { isData } - ).toProperty() - - private fun ValueParameterDescriptor.additionalExtras() = - listOfNotNull( - ExtraModifiers.KotlinOnlyModifiers.NoInline.takeIf { isNoinline }, - ExtraModifiers.KotlinOnlyModifiers.CrossInline.takeIf { isCrossinline }, - ExtraModifiers.KotlinOnlyModifiers.Const.takeIf { isConst }, - ExtraModifiers.KotlinOnlyModifiers.LateInit.takeIf { isLateInit }, - ExtraModifiers.KotlinOnlyModifiers.VarArg.takeIf { isVararg } - ).toProperty() - - private fun TypeParameterDescriptor.additionalExtras() = - listOfNotNull( - ExtraModifiers.KotlinOnlyModifiers.Reified.takeIf { isReified } - ).toProperty() + ).toSet() + + private fun ValueParameterDescriptor.additionalExtras() = listOfNotNull( + ExtraModifiers.KotlinOnlyModifiers.NoInline.takeIf { isNoinline }, + ExtraModifiers.KotlinOnlyModifiers.CrossInline.takeIf { isCrossinline }, + ExtraModifiers.KotlinOnlyModifiers.Const.takeIf { isConst }, + ExtraModifiers.KotlinOnlyModifiers.LateInit.takeIf { isLateInit }, + ExtraModifiers.KotlinOnlyModifiers.VarArg.takeIf { isVararg } + ).toSet() + + private fun TypeParameterDescriptor.additionalExtras() = listOfNotNull( + ExtraModifiers.KotlinOnlyModifiers.Reified.takeIf { isReified } + ).toSet() private fun PropertyDescriptor.additionalExtras() = listOfNotNull( ExtraModifiers.KotlinOnlyModifiers.Const.takeIf { isConst }, @@ -637,13 +658,7 @@ private class DokkaDescriptorVisitor( ExtraModifiers.KotlinOnlyModifiers.Override.takeIf { DescriptorUtils.isOverride(this) } ) - private fun List.toProperty() = - AdditionalModifiers(this.toSet()) - - private fun Annotated.getAnnotations() = getListOfSourceSetDependentAnnotations().let(::Annotations) - - private fun Annotated.getListOfSourceSetDependentAnnotations() = - mapOf(sourceSet to annotations.mapNotNull { it.toAnnotation() }) + private fun Annotated.getAnnotations() = annotations.mapNotNull { it.toAnnotation() } private fun ConstantValue<*>.toValue(): AnnotationParameterValue? = when (this) { is ConstantsAnnotationValue -> value.toAnnotation()?.let { AnnotationValue(it) } @@ -670,30 +685,31 @@ private class DokkaDescriptorVisitor( } private fun AnnotationDescriptor.toAnnotation(): Annotations.Annotation? = - DRI.from(annotationClass as DeclarationDescriptor) - .takeIf { it.classNames != "" }?.let { - Annotations.Annotation( - it, - allValueArguments.map { it.key.asString() to it.value.toValue() }.filter { - it.second != null - }.toMap() as Map - ) - } + if(annotationClass?.visibility == Visibilities.PUBLIC) + DRI.from(annotationClass as DeclarationDescriptor) + .takeIf { it.classNames != "" }?.let { + Annotations.Annotation( + it, + allValueArguments.map { it.key.asString() to it.value.toValue() }.filter { + it.second != null + }.toMap() as Map + ) + } + else + null - private fun PropertyDescriptor.getAllAnnotations(): Annotations = - (getListOfSourceSetDependentAnnotations() + (backingField?.getListOfSourceSetDependentAnnotations() - ?: emptyMap())).let(::Annotations) + private fun PropertyDescriptor.getAnnotationsWithBackingField(): List = + getAnnotations() + (backingField?.getAnnotations() ?: emptyList()) - private fun FieldDescriptor.getAnnotationsAsExtraModifiers() = getAnnotations().content.mapValues { - it.value.mapNotNull { - try { - ExtraModifiers.valueOf(it.dri.classNames?.toLowerCase() ?: "") - } catch (e: IllegalArgumentException) { - null - } + private fun List.toAdditionalExtras() = mapNotNull { + try { + ExtraModifiers.valueOf(it.dri.classNames?.toLowerCase() ?: "") + } catch (e: IllegalArgumentException) { + null } } + private fun ValueParameterDescriptor.getDefaultValue(): String? = (source as? KotlinSourceElement)?.psi?.children?.find { it is KtExpression }?.text diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 1f52b2d9..d68f0e01 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -116,8 +116,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { return false } - private fun T.toPlatformDependant() = - mapOf(sourceSetData to this) + private fun T.toSourceSetDependent() = mapOf(sourceSetData to this) fun parseClasslike(psi: PsiClass, parent: DRI): DClasslike = with(psi) { val dri = parent.withClass(name.toString()) @@ -144,14 +143,14 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { } parseSupertypes(superTypes) val (regularFunctions, accessors) = splitFunctionsAndAccessors() - val documentation = javadocParser.parseDocumentation(this).toPlatformDependant() + val documentation = javadocParser.parseDocumentation(this).toSourceSetDependent() val allFunctions = regularFunctions.mapNotNull { if (!it.isConstructor) parseFunction(it) else null } + superMethods.map { parseFunction(it, isInherited = true) } - val source = PsiDocumentableSource(this).toPlatformDependant() + val source = PsiDocumentableSource(this).toSourceSetDependent() val classlikes = innerClasses.map { parseClasslike(it, dri) } - val visibility = getVisibility().toPlatformDependant() - val ancestors = ancestorsSet.toList().toPlatformDependant() - val modifiers = getModifier().toPlatformDependant() + val visibility = getVisibility().toSourceSetDependent() + val ancestors = ancestorsSet.toList().toSourceSetDependent() + val modifiers = getModifier().toSourceSetDependent() return when { isAnnotationType -> DAnnotation( @@ -168,8 +167,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { constructors.map { parseFunction(it, true) }, mapTypeParameters(dri), listOf(sourceSetData), - PropertyContainer.empty() + annotations.toList().toListOfAnnotations() - .let(::Annotations) + PropertyContainer.empty() + annotations.toList().getAnnotations() + .toSourceSetDependent().toAnnotations() ) isEnum -> DEnum( dri, @@ -178,14 +177,14 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { DEnumEntry( dri.withClass("$name.${entry.name}"), entry.name.orEmpty(), - javadocParser.parseDocumentation(entry).toPlatformDependant(), + javadocParser.parseDocumentation(entry).toSourceSetDependent(), null, emptyList(), emptyList(), emptyList(), listOf(sourceSetData), - PropertyContainer.empty() + entry.annotations.toList().toListOfAnnotations() - .let(::Annotations) + PropertyContainer.empty() + entry.annotations.toList().getAnnotations() + .toSourceSetDependent().toAnnotations() ) }, documentation, @@ -199,7 +198,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { constructors.map { parseFunction(it, true) }, ancestors, listOf(sourceSetData), - PropertyContainer.empty() + annotations.toList().toListOfAnnotations().let(::Annotations) + PropertyContainer.empty() + annotations.toList().getAnnotations().toSourceSetDependent() + .toAnnotations() ) isInterface -> DInterface( dri, @@ -215,8 +215,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { mapTypeParameters(dri), ancestors, listOf(sourceSetData), - PropertyContainer.empty() + annotations.toList().toListOfAnnotations() - .let(::Annotations) + PropertyContainer.empty() + annotations.toList().getAnnotations().toSourceSetDependent() + .toAnnotations() ) else -> DClass( dri, @@ -234,7 +234,8 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { null, modifiers, listOf(sourceSetData), - PropertyContainer.empty() + annotations.toList().toListOfAnnotations().let(::Annotations) + PropertyContainer.empty() + annotations.toList().getAnnotations().toSourceSetDependent() + .toAnnotations() ) } } @@ -253,49 +254,49 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { DParameter( dri.copy(target = dri.target.nextTarget()), psiParameter.name, - javadocParser.parseDocumentation(psiParameter).toPlatformDependant(), + javadocParser.parseDocumentation(psiParameter).toSourceSetDependent(), null, getBound(psiParameter.type), listOf(sourceSetData) ) }, - javadocParser.parseDocumentation(psi).toPlatformDependant(), + javadocParser.parseDocumentation(psi).toSourceSetDependent(), null, - PsiDocumentableSource(psi).toPlatformDependant(), - psi.getVisibility().toPlatformDependant(), + PsiDocumentableSource(psi).toSourceSetDependent(), + psi.getVisibility().toSourceSetDependent(), psi.returnType?.let { getBound(type = it) } ?: Void, psi.mapTypeParameters(dri), null, - psi.getModifier().toPlatformDependant(), + psi.getModifier().toSourceSetDependent(), listOf(sourceSetData), psi.additionalExtras().let { PropertyContainer.withAll( InheritedFunction(isInherited), - it, - (psi.annotations.toList().toListOfAnnotations() + it.toListOfAnnotations()).let(::Annotations) + it.toSourceSetDependent().toAdditionalModifiers(), + (psi.annotations.toList().getAnnotations() + it.getAnnotations()).toSourceSetDependent() + .toAnnotations() ) } ) } - private fun PsiModifierListOwner.additionalExtras() = AdditionalModifiers( - listOfNotNull( - ExtraModifiers.JavaOnlyModifiers.Static.takeIf { hasModifier(JvmModifier.STATIC) }, - ExtraModifiers.JavaOnlyModifiers.Native.takeIf { hasModifier(JvmModifier.NATIVE) }, - ExtraModifiers.JavaOnlyModifiers.Synchronized.takeIf { hasModifier(JvmModifier.SYNCHRONIZED) }, - ExtraModifiers.JavaOnlyModifiers.StrictFP.takeIf { hasModifier(JvmModifier.STRICTFP) }, - ExtraModifiers.JavaOnlyModifiers.Transient.takeIf { hasModifier(JvmModifier.TRANSIENT) }, - ExtraModifiers.JavaOnlyModifiers.Volatile.takeIf { hasModifier(JvmModifier.VOLATILE) }, - ExtraModifiers.JavaOnlyModifiers.Transitive.takeIf { hasModifier(JvmModifier.TRANSITIVE) } - ).toSet() - ) + private fun PsiModifierListOwner.additionalExtras() = listOfNotNull( + ExtraModifiers.JavaOnlyModifiers.Static.takeIf { hasModifier(JvmModifier.STATIC) }, + ExtraModifiers.JavaOnlyModifiers.Native.takeIf { hasModifier(JvmModifier.NATIVE) }, + ExtraModifiers.JavaOnlyModifiers.Synchronized.takeIf { hasModifier(JvmModifier.SYNCHRONIZED) }, + ExtraModifiers.JavaOnlyModifiers.StrictFP.takeIf { hasModifier(JvmModifier.STRICTFP) }, + ExtraModifiers.JavaOnlyModifiers.Transient.takeIf { hasModifier(JvmModifier.TRANSIENT) }, + ExtraModifiers.JavaOnlyModifiers.Volatile.takeIf { hasModifier(JvmModifier.VOLATILE) }, + ExtraModifiers.JavaOnlyModifiers.Transitive.takeIf { hasModifier(JvmModifier.TRANSITIVE) } + ).toSet() + - private fun AdditionalModifiers.toListOfAnnotations() = mapOf(sourceSetData to this.content.map { + private fun Set.getAnnotations() = map { if (it !is ExtraModifiers.JavaOnlyModifiers.Static) Annotations.Annotation(DRI("kotlin.jvm", it.name.toLowerCase().capitalize()), emptyMap()) else Annotations.Annotation(DRI("kotlin.jvm", "JvmStatic"), emptyMap()) - }) + } private fun getBound(type: PsiType): Bound = cachedBounds.getOrPut(type.canonicalText) { @@ -346,7 +347,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { DTypeParameter( dri.copy(target = dri.target.nextTarget()), type.name.orEmpty(), - javadocParser.parseDocumentation(type).toPlatformDependant(), + javadocParser.parseDocumentation(type).toSourceSetDependent(), null, mapBounds(type.bounds), listOf(sourceSetData) @@ -383,41 +384,39 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { return DProperty( dri, psi.name!!, // TODO: Investigate if this is indeed nullable - javadocParser.parseDocumentation(psi).toPlatformDependant(), + javadocParser.parseDocumentation(psi).toSourceSetDependent(), null, - PsiDocumentableSource(psi).toPlatformDependant(), - psi.getVisibility().toPlatformDependant(), + PsiDocumentableSource(psi).toSourceSetDependent(), + psi.getVisibility().toSourceSetDependent(), getBound(psi.type), null, accessors.firstOrNull { it.hasParameters() }?.let { parseFunction(it) }, accessors.firstOrNull { it.returnType == psi.type }?.let { parseFunction(it) }, - psi.getModifier().toPlatformDependant(), + psi.getModifier().toSourceSetDependent(), listOf(sourceSetData), emptyList(), psi.additionalExtras().let { PropertyContainer.withAll( - it, - (psi.annotations.toList().toListOfAnnotations() + it.toListOfAnnotations()).let(::Annotations) + it.toSourceSetDependent().toAdditionalModifiers(), + (psi.annotations.toList().getAnnotations() + it.getAnnotations()).toSourceSetDependent() + .toAnnotations() ) } ) } - private fun Collection.toListOfAnnotations() = - mapOf(sourceSetData to filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.toAnnotation() }) + private fun Collection.getAnnotations() = + filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.toAnnotation() } private fun JvmAnnotationAttribute.toValue(): AnnotationParameterValue = when (this) { is PsiNameValuePair -> value?.toValue() ?: StringValue("") else -> StringValue(this.attributeName) } - private fun PsiAnnotationMemberValue.toValue(): AnnotationParameterValue = when (this) { - is PsiAnnotation -> AnnotationValue(toAnnotation()) - is PsiArrayInitializerMemberValue -> ArrayValue(initializers.map { it.toValue() }) - is PsiReferenceExpression -> EnumValue( - text ?: "", - driOfReference() - ) + private fun PsiAnnotationMemberValue.toValue(): AnnotationParameterValue? = when (this) { + is PsiAnnotation -> toAnnotation()?.let { AnnotationValue(it) } + is PsiArrayInitializerMemberValue -> ArrayValue(initializers.mapNotNull { it.toValue() }) + is PsiReferenceExpression -> driOfReference()?.let { EnumValue(text ?: "", it) } is PsiClassObjectAccessExpression -> ClassValue( text ?: "", DRI.from(((type as PsiImmediateClassType).parameters.single() as PsiClassReferenceType).resolve()!!) @@ -425,16 +424,16 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { else -> StringValue(text ?: "") } - private fun PsiAnnotation.toAnnotation() = Annotations.Annotation( - driOfReference(), - attributes.filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.attributeName to it.toValue() } - .toMap() - ) + private fun PsiAnnotation.toAnnotation() = driOfReference()?.let { + Annotations.Annotation( + it, + attributes.filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.attributeName to it.toValue() } + .toMap() + ) + } private fun PsiElement.driOfReference() = getChildOfType()?.resolve()?.let { DRI.from(it) - } ?: DRI("", getChildOfType()?.qualifiedName ?: "").also { - logger.error("$this cannot be resolved to symbol!") } } } diff --git a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt index 98f572b4..d10bd151 100644 --- a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt +++ b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt @@ -149,6 +149,4 @@ class ContentForAnnotationsTest : AbstractCoreTest() { } } } - - } \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt index 4ca34b00..5616a6c3 100644 --- a/plugins/base/src/test/kotlin/model/ClassesTest.kt +++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt @@ -1,5 +1,6 @@ package model +import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.KotlinModifier.* import org.junit.jupiter.api.Assertions.assertNull @@ -150,9 +151,9 @@ 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].assertNotNull("Extras")) { - content counts 1 - content.first() equals ExtraModifiers.KotlinOnlyModifiers.Data + with(extra[AdditionalModifiers]!!.content.entries.single().value.assertNotNull("Extras")) { + this counts 1 + first() equals ExtraModifiers.KotlinOnlyModifiers.Data } } } @@ -180,9 +181,9 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class """ ) { with((this / "classes" / "Foo").cast()) { - with(extra[Annotations].assertNotNull("Annotations")) { - this.content counts 1 - with(content.first()) { + with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 1 + with(first()) { dri.classNames equals "Deprecated" params.entries counts 1 (params["message"].assertNotNull("message") as StringValue).value equals "\"should no longer be used\"" @@ -273,9 +274,9 @@ 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.KotlinOnlyModifiers.Inner + with(extra[AdditionalModifiers]!!.content.entries.single().value.assertNotNull("AdditionalModifiers")) { + this counts 1 + first() equals ExtraModifiers.KotlinOnlyModifiers.Inner } } } @@ -359,9 +360,9 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class """ ) { with((this / "classes" / "C").cast()) { - with(extra[Annotations].assertNotNull("Annotations")) { - this.content counts 1 - with(content.first()) { + with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 1 + with(first()) { dri.classNames equals "SinceKotlin" params.entries counts 1 (params["version"].assertNotNull("version") as StringValue).value equals "\"1.1\"" @@ -424,7 +425,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class """@Suppress("abc") class Foo() {}""" ) { with((this / "classes" / "Foo").cast()) { - with(extra[Annotations]?.content?.firstOrNull().assertNotNull("annotations")) { + with(extra[Annotations]!!.content.entries.single().value.firstOrNull().assertNotNull("annotations")) { dri.toString() equals "kotlin/Suppress///PointingToDeclaration/" (params["names"].assertNotNull("param") as ArrayValue).value equals listOf(StringValue("\"abc\"")) } @@ -444,11 +445,14 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class """ ) { with((this / "classes" / "throws").cast()) { - with(extra[Annotations].assertNotNull("Annotations")) { - content counts 1 - with(content.first()) { + with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 1 + with(first()) { dri.classNames equals "Retention" -// params["value"].assertNotNull("value") equals "(java/lang/annotation/RetentionPolicy, SOURCE)" + params["value"].assertNotNull("value") equals EnumValue( + "RetentionPolicy.SOURCE", + DRI("java.lang.annotation", "RetentionPolicy.SOURCE") + ) } } } diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt index 38f64df5..c96e7df6 100644 --- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt +++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt @@ -141,9 +141,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun """ ) { with((this / "function" / "f").cast()) { - with(extra[Annotations].assertNotNull("Annotations")) { - content counts 1 - with(content.first()) { + with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 1 + with(first()) { dri.classNames equals "Suppress" params.entries counts 1 (params["names"].assertNotNull("param") as ArrayValue).value equals listOf(StringValue("\"FOO\"")) @@ -161,8 +161,8 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun """ ) { with((this / "function" / "f").cast()) { - extra[AdditionalModifiers]?.content counts 1 - extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Inline + extra[AdditionalModifiers]!!.content.entries.single().value counts 1 + extra[AdditionalModifiers]!!.content.entries.single().value exists ExtraModifiers.KotlinOnlyModifiers.Inline } } } @@ -175,8 +175,8 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun """ ) { with((this / "function" / "f").cast()) { - extra[AdditionalModifiers]?.content counts 1 - extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Suspend + extra[AdditionalModifiers]!!.content.entries.single().value counts 1 + extra[AdditionalModifiers]!!.content.entries.single().value exists ExtraModifiers.KotlinOnlyModifiers.Suspend } } } @@ -189,9 +189,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun """ ) { with((this / "function" / "f").cast()) { - extra[AdditionalModifiers]?.content counts 2 - extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Suspend - extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.Inline + extra[AdditionalModifiers]!!.content.entries.single().value counts 2 + extra[AdditionalModifiers]!!.content.entries.single().value exists ExtraModifiers.KotlinOnlyModifiers.Suspend + extra[AdditionalModifiers]!!.content.entries.single().value exists ExtraModifiers.KotlinOnlyModifiers.Inline } } } @@ -204,10 +204,10 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun """ ) { with((this / "function" / "f").cast()) { - with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) { - content counts 2 - content exists ExtraModifiers.KotlinOnlyModifiers.Suspend - content exists ExtraModifiers.KotlinOnlyModifiers.Inline + with(extra[AdditionalModifiers]!!.content.entries.single().value.assertNotNull("AdditionalModifiers")) { + this counts 2 + this exists ExtraModifiers.KotlinOnlyModifiers.Suspend + this exists ExtraModifiers.KotlinOnlyModifiers.Inline } } } @@ -226,9 +226,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun """ ) { with((this / "function" / "Fancy").cast()) { - with(extra[Annotations].assertNotNull("Annotations")) { - content counts 3 - with(content.map { it.dri.classNames to it }.toMap()) { + with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 3 + with(map { it.dri.classNames to it }.toMap()) { with(this["Target"].assertNotNull("Target")) { (params["allowedTargets"].assertNotNull("allowedTargets") as ArrayValue).value equals listOf( EnumValue( @@ -249,9 +249,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun } with((this / "function" / "function" / "notInlined").cast()) { - with(this.extra[Annotations].assertNotNull("Annotations")) { - content counts 1 - with(content.first()) { + with(this.extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 1 + with(first()) { dri.classNames equals "Fancy" params.entries counts 0 } @@ -268,8 +268,8 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun """ ) { with((this / "function" / "f" / "notInlined").cast()) { - extra[AdditionalModifiers]?.content counts 1 - extra[AdditionalModifiers]?.content exists ExtraModifiers.KotlinOnlyModifiers.NoInline + extra[AdditionalModifiers]!!.content.entries.single().value counts 1 + extra[AdditionalModifiers]!!.content.entries.single().value exists ExtraModifiers.KotlinOnlyModifiers.NoInline } } } @@ -296,9 +296,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun } } - with(extra[Annotations].assertNotNull("Annotations")) { - content counts 3 - with(content.map { it.dri.classNames to it }.toMap()) { + with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 3 + with(map { it.dri.classNames to it }.toMap()) { with(this["Target"].assertNotNull("Target")) { (params["allowedTargets"].assertNotNull("allowedTargets") as ArrayValue).value equals listOf( EnumValue( @@ -319,9 +319,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun } with((this / "function" / "f").cast()) { - with(this.extra[Annotations].assertNotNull("Annotations")) { - content counts 1 - with(content.first()) { + with(this.extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 1 + with(this.first()) { dri.classNames equals "Fancy" params.entries counts 1 (params["size"] as StringValue).value equals "1" @@ -381,9 +381,9 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun """ ) { with((this / "function" / "f").cast()) { - with(extra[Annotations].assertNotNull("Annotations")) { - this.content counts 1 - with(content.first()) { + with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 1 + with(first()) { dri.classNames equals "SinceKotlin" params.entries counts 1 (params["version"].assertNotNull("version") as StringValue).value equals "\"1.1\"" diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index fd293b5c..8f52fcc8 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -295,9 +295,9 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { """ ) { with((this / "java" / "C" / "foo").cast()) { - with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) { - content counts 1 - content.first() equals ExtraModifiers.JavaOnlyModifiers.Static + with(extra[AdditionalModifiers]!!.content.entries.single().value.assertNotNull("AdditionalModifiers")) { + this counts 1 + first() equals ExtraModifiers.JavaOnlyModifiers.Static } } } @@ -335,8 +335,8 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { """ ) { with((this / "java" / "Attribute").cast()) { - with(extra[Annotations].assertNotNull("Annotations")) { - with(content.single()) { + with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + with(single()) { dri.classNames equals "Target" (params["value"].assertNotNull("value") as ArrayValue).value equals listOf( EnumValue("ElementType.FIELD", DRI("java.lang.annotation", "ElementType")), diff --git a/plugins/base/src/test/kotlin/model/PropertyTest.kt b/plugins/base/src/test/kotlin/model/PropertyTest.kt index 90a9d782..e384b920 100644 --- a/plugins/base/src/test/kotlin/model/PropertyTest.kt +++ b/plugins/base/src/test/kotlin/model/PropertyTest.kt @@ -150,9 +150,9 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro """ ) { with((this / "property" / "prop").cast()) { - with(extra[Annotations].assertNotNull("Annotations")) { - this.content counts 1 - with(content.first()) { + with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 1 + with(first()) { dri.classNames equals "SinceKotlin" params.entries counts 1 (params["version"].assertNotNull("version") as StringValue).value equals "\"1.1\"" @@ -178,9 +178,9 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro } ) { with((this / "property" / "property").cast()) { - with(extra[Annotations].assertNotNull("Annotations")) { - this.content counts 1 - with(content.first()) { + with(extra[Annotations]!!.content.entries.single().value.assertNotNull("Annotations")) { + this counts 1 + with(first()) { dri.classNames equals "Strictfp" params.entries counts 0 } diff --git a/plugins/base/src/test/kotlin/utils/contentUtils.kt b/plugins/base/src/test/kotlin/utils/contentUtils.kt index 7e1b8bf4..c7cea1f1 100644 --- a/plugins/base/src/test/kotlin/utils/contentUtils.kt +++ b/plugins/base/src/test/kotlin/utils/contentUtils.kt @@ -28,36 +28,34 @@ fun ContentMatcherBuilder<*>.bareSignature( returnType: String? = null, vararg params: Pair ) = group { // TODO: remove it when double wrapping for signatures will be resolved - group { - annotations.entries.forEach { - group { - unwrapAnnotation(it) - } + annotations.entries.forEach { + group { + unwrapAnnotation(it) } - +("$visibility $modifier ${keywords.joinToString("") { "$it " }} fun") - link { +name } - +"(" - params.forEachIndexed { id, (n, t) -> - - t.annotations.forEach { - unwrapAnnotation(it) - } - t.keywords.forEach { - +it - } + } + +("$visibility $modifier ${keywords.joinToString("") { "$it " }} fun") + link { +name } + +"(" + params.forEachIndexed { id, (n, t) -> - +"$n:" - group { link { +(t.type) } } - if (id != params.lastIndex) - +", " + t.annotations.forEach { + unwrapAnnotation(it) } - +")" - if (returnType != null) { - +(": ") - group { - link { - +(returnType) - } + t.keywords.forEach { + +it + } + + +"$n:" + group { link { +(t.type) } } + if (id != params.lastIndex) + +", " + } + +")" + if (returnType != null) { + +(": ") + group { + link { + +(returnType) } } } @@ -87,40 +85,38 @@ fun ContentMatcherBuilder<*>.bareSignatureWithReceiver( returnType: String? = null, vararg params: Pair ) = group { // TODO: remove it when double wrapping for signatures will be resolved - group { - annotations.entries.forEach { - group { - unwrapAnnotation(it) - } - } - +("$visibility $modifier ${keywords.joinToString("") { "$it " }} fun") + annotations.entries.forEach { group { - link { +receiver } + unwrapAnnotation(it) } - +"." - link { +name } - +"(" - params.forEachIndexed { id, (n, t) -> - - t.annotations.forEach { - unwrapAnnotation(it) - } - t.keywords.forEach { - +it - } + } + +("$visibility $modifier ${keywords.joinToString("") { "$it " }} fun") + group { + link { +receiver } + } + +"." + link { +name } + +"(" + params.forEachIndexed { id, (n, t) -> - +"$n:" - group { link { +(t.type) } } - if (id != params.lastIndex) - +", " + t.annotations.forEach { + unwrapAnnotation(it) } - +")" - if (returnType != null) { - +(": ") - group { - link { - +(returnType) - } + t.keywords.forEach { + +it + } + + +"$n:" + group { link { +(t.type) } } + if (id != params.lastIndex) + +", " + } + +")" + if (returnType != null) { + +(": ") + group { + link { + +(returnType) } } } @@ -148,20 +144,18 @@ fun ContentMatcherBuilder<*>.propertySignature( link { +name } platformHinted { group { - group { - annotations.entries.forEach { - group { - unwrapAnnotation(it) - } + annotations.entries.forEach { + group { + unwrapAnnotation(it) } - +("$visibility $modifier ${keywords.joinToString("") { "$it " }} $preposition") - link { +name } - if (type != null) { - +(": ") - group { - link { - +(type) - } + } + +("$visibility $modifier ${keywords.joinToString("") { "$it " }} $preposition") + link { +name } + if (type != null) { + +(": ") + group { + link { + +(type) } } } @@ -184,15 +178,19 @@ fun ContentMatcherBuilder<*>.unnamedTag(tag: String, content: ContentMatcherBuil group { content() } } -fun ContentMatcherBuilder<*>.unwrapAnnotation(elem: Map.Entry>) { - +"@" - link { +elem.key } - +"(" - elem.value.forEach { - +("$it = ") - skipAllNotMatching() +private fun ContentMatcherBuilder<*>.unwrapAnnotation(elem: Map.Entry>) { + group { + +"@" + link { +elem.key } + +"(" + elem.value.forEach { + group { + +("$it = ") + skipAllNotMatching() + } + } + +")" } - +")" } data class ParamAttributes( 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 8f20f942..693fffac 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt @@ -76,7 +76,13 @@ internal fun DProperty.asJava(isTopLevel: Boolean = false, relocateToClass: Stri 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.JavaOnlyModifiers.Static))) else extra + extra = if (isTopLevel) extra + + extra.mergeAdditionalModifiers( + sourceSets.map { + it to setOf(ExtraModifiers.JavaOnlyModifiers.Static) + }.toMap() + ) + else extra ) internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClass: String? = null): List = @@ -95,7 +101,13 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas }, visibility = visibility.mapValues { JavaVisibility.Public }, type = type.asJava(), // TODO: check - extra = if (isTopLevel) getter!!.extra.plus(getter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else getter!!.extra + extra = if (isTopLevel) getter!!.extra + + getter!!.extra.mergeAdditionalModifiers( + sourceSets.map { + it to setOf(ExtraModifiers.JavaOnlyModifiers.Static) + }.toMap() + ) + else getter!!.extra ), setter?.copy( dri = if (relocateToClass.isNullOrBlank()) { @@ -111,7 +123,12 @@ internal fun DProperty.javaAccessors(isTopLevel: Boolean = false, relocateToClas }, visibility = visibility.mapValues { JavaVisibility.Public }, type = type.asJava(), // TODO: check - extra = if (isTopLevel) setter!!.extra.plus(setter!!.extra.mergeAdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static))) else setter!!.extra + extra = if (isTopLevel) setter!!.extra + setter!!.extra.mergeAdditionalModifiers( + sourceSets.map { + it to setOf(ExtraModifiers.JavaOnlyModifiers.Static) + }.toMap() + ) + else setter!!.extra ) ) @@ -203,7 +220,9 @@ internal fun DObject.asJava(): DObject = copy( receiver = null, generics = emptyList(), expectPresentInSet = expectPresentInSet, - extra = PropertyContainer.empty() + AdditionalModifiers(setOf(ExtraModifiers.JavaOnlyModifiers.Static)) + extra = PropertyContainer.withAll(sourceSets.map { + mapOf(it to setOf(ExtraModifiers.JavaOnlyModifiers.Static)).toAdditionalModifiers() + }) ), classlikes = classlikes.map { it.asJava() }, supertypes = supertypes.mapValues { it.value.map { it.possiblyAsJava() } } @@ -248,7 +267,7 @@ internal fun ClassId.toDRI(dri: DRI?): DRI = DRI( target = PointingToDeclaration ) -private fun PropertyContainer.mergeAdditionalModifiers(second: Set) = +private fun PropertyContainer.mergeAdditionalModifiers(second: SourceSetDependent>) = this[AdditionalModifiers]?.squash(AdditionalModifiers(second)) ?: AdditionalModifiers(second) private fun AdditionalModifiers.squash(second: AdditionalModifiers) = 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 a55f9339..5c4985ac 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureProvider.kt @@ -41,7 +41,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge if (c is DClass) { platformText(c.modifier) { it.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " " } - text(c.modifiers().toSignatureString()) + platformText(c.modifiers()) { it.toSignatureString() } } when (c) { @@ -71,7 +71,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge annotationsBlock(p) platformText(p.visibility) { (it.takeIf { it !in ignoredVisibilities }?.name ?: "") + " " } platformText(p.modifier) { it.name + " " } - text(p.modifiers().toSignatureString()) + platformText(p.modifiers()) { it.toSignatureString() } signatureForProjection(p.type) text(nbsp.toString()) link(p.name, p.dri) @@ -82,7 +82,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge group(styles = setOf(TextStyle.Block)) { annotationsBlock(f) platformText(f.modifier) { it.takeIf { it !in ignoredModifiers }?.name.orEmpty() + " " } - text(f.modifiers().toSignatureString()) + platformText(f.modifiers()) { it.toSignatureString() } val returnType = f.type signatureForProjection(returnType) text(nbsp.toString()) @@ -92,7 +92,7 @@ class JavaSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLogge } list(f.parameters, "(", ")") { annotationsInline(it) - text(it.modifiers().toSignatureString()) + platformText(it.modifiers()) { it.toSignatureString() } signatureForProjection(it.type) text(nbsp.toString()) link(it.name!!, it.dri) diff --git a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt index e2f73bf9..b4245834 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/signatures/JavaSignatureUtils.kt @@ -28,6 +28,8 @@ object JavaSignatureUtils : JvmSignatureUtils { annotationsInlineWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension) override fun WithExtraProperties.modifiers() = - extra[AdditionalModifiers]?.content?.filterIsInstance()?.toSet() ?: emptySet() + extra[AdditionalModifiers]?.content?.entries?.map { + it.key to it.value.filterIsInstance().toSet() + }?.toMap() ?: emptyMap() } \ No newline at end of file -- cgit From f3baf10b4c882230d382bfcdd94163d070bd0e25 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 20 May 2020 12:05:26 +0200 Subject: Rework dokka configuration and Gradle plugin --- .idea/compiler.xml | 148 +----------------- build.gradle.kts | 7 + core/src/main/kotlin/DokkaGenerator.kt | 14 +- core/src/main/kotlin/configuration.kt | 10 +- core/src/main/kotlin/defaultConfiguration.kt | 14 +- core/src/main/kotlin/model/SourceSetData.kt | 23 ++- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 29 ++-- .../kotlin/renderers/html/htmlPreprocessors.kt | 2 +- .../resolvers/local/DefaultLocationProvider.kt | 17 +-- .../ModuleAndPackageDocumentationTransformer.kt | 4 +- .../DefaultDescriptorToDocumentableTranslator.kt | 2 +- .../annotations/ContentForAnnotationsTest.kt | 1 - .../kotlin/content/params/ContentForParamsTest.kt | 1 - .../content/seealso/ContentForSeeAlsoTest.kt | 3 +- .../content/signatures/ContentForSignaturesTest.kt | 1 - .../kotlin/linkableContent/LinkableContentTest.kt | 8 +- plugins/base/src/test/kotlin/markdown/LinkTest.kt | 2 +- .../base/src/test/kotlin/model/InheritorsTest.kt | 2 - plugins/base/src/test/kotlin/model/PackagesTest.kt | 4 +- .../test/kotlin/renderers/RenderingOnlyTestBase.kt | 6 +- .../test/kotlin/renderers/html/DivergentTest.kt | 6 +- .../renderers/html/SourceSetDependentHintTest.kt | 6 +- plugins/base/src/test/kotlin/utils/ModelUtils.kt | 2 - plugins/gfm/src/main/kotlin/GfmPlugin.kt | 2 +- runners/cli/src/main/kotlin/cli/main.kt | 64 +++----- .../dokka/gradle/ConfigurationExtractor.kt | 152 ++++++------------ .../jetbrains/dokka/gradle/DokkaCollectorTask.kt | 7 +- .../jetbrains/dokka/gradle/DokkaMultimoduleTask.kt | 10 +- .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 169 +++++++++++---------- .../dokka/gradle/configurationImplementations.kt | 11 +- .../main/kotlin/org/jetbrains/dokka/gradle/main.kt | 24 ++- .../kotlin/org/jetbrains/dokka/gradle/utils.kt | 17 ++- runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 55 +++---- settings.gradle.kts | 5 +- .../main/kotlin/testApi/testRunner/TestRunner.kt | 25 ++- 35 files changed, 319 insertions(+), 534 deletions(-) (limited to 'plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt') diff --git a/.idea/compiler.xml b/.idea/compiler.xml index dd174dd7..a6b0adf4 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -12,148 +12,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0b3c0da8..c94faa77 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,6 +5,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") apply false id("com.jfrog.bintray") apply false + id("java") } val dokka_version: String by project @@ -39,6 +40,12 @@ allprojects { subprojects { apply { plugin("org.jetbrains.kotlin.jvm") + plugin("java") + } + + // Gradle metadata + java { + targetCompatibility = JavaVersion.VERSION_1_8 } } diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 61fb7324..c8a892d7 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -5,7 +5,6 @@ import org.jetbrains.dokka.analysis.DokkaResolutionFacade import org.jetbrains.dokka.model.DModule 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 @@ -81,7 +80,7 @@ class DokkaGenerator( sourceSetsCache: SourceSetCache ): Map = configuration.passesConfigurations.map { - sourceSetsCache.getSourceSet(it) to createEnvironmentAndFacade(it) + sourceSetsCache.getSourceSet(it) to createEnvironmentAndFacade(configuration, it) }.toMap() fun initializePlugins( @@ -139,14 +138,21 @@ class DokkaGenerator( renderer.render(transformedPages) } - private fun createEnvironmentAndFacade(pass: DokkaConfiguration.PassConfiguration): EnvironmentAndFacade = + private fun createEnvironmentAndFacade( + configuration: DokkaConfiguration, + pass: DokkaConfiguration.PassConfiguration + ): EnvironmentAndFacade = AnalysisEnvironment(DokkaMessageCollector(logger), pass.analysisPlatform).run { if (analysisPlatform == Platform.jvm) { addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) } pass.classpath.forEach { addClasspath(File(it)) } - addSources((pass.sourceRoots + pass.dependentSourceRoots).map { it.path }) + addSources( + (pass.sourceRoots + configuration.passesConfigurations.filter { it.sourceSetID in pass.dependentSourceSets } + .flatMap { it.sourceRoots }) + .map { it.path } + ) loadLanguageVersionSettings(pass.languageVersion, pass.apiVersion) diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 0b59f301..fab7af37 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -27,20 +27,19 @@ enum class Platform(val key: String) { interface DokkaConfiguration { val outputDir: String val format: String - val generateIndexPages: Boolean val cacheRoot: String? + val offlineMode: Boolean val passesConfigurations: List val modules: List - val impliedPlatforms: List val pluginsClasspath: List val pluginsConfiguration: Map interface PassConfiguration { val moduleName: String - val sourceSetName: String + val displayName: String + val sourceSetID: String val classpath: List val sourceRoots: List - val dependentSourceRoots: List val dependentSourceSets: List val samples: List val includes: List @@ -58,10 +57,7 @@ interface DokkaConfiguration { val noStdlibLink: Boolean val noJdkLink: Boolean val suppressedFiles: List - val collectInheritedExtensionsFromLibraries: Boolean val analysisPlatform: Platform - val targets: List - val sinceKotlin: String? } interface SourceRoot { diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index 7aaa1c89..23cf7e2d 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -6,21 +6,20 @@ import java.net.URL data class DokkaConfigurationImpl( override val outputDir: String, override val format: String, - override val generateIndexPages: Boolean, override val cacheRoot: String?, - override val impliedPlatforms: List, + override val offlineMode: Boolean, override val passesConfigurations: List, override val pluginsClasspath: List, override val pluginsConfiguration: Map, override val modules: List ) : DokkaConfiguration -data class PassConfigurationImpl ( +data class PassConfigurationImpl( override val moduleName: String, - override val sourceSetName: String, + override val displayName: String, + override val sourceSetID: String, override val classpath: List, override val sourceRoots: List, - override val dependentSourceRoots: List, override val dependentSourceSets: List, override val samples: List, override val includes: List, @@ -38,10 +37,7 @@ data class PassConfigurationImpl ( override val noStdlibLink: Boolean, override val noJdkLink: Boolean, override val suppressedFiles: List, - override val collectInheritedExtensionsFromLibraries: Boolean, - override val analysisPlatform: Platform, - override val targets: List, - override val sinceKotlin: String? + override val analysisPlatform: Platform ) : DokkaConfiguration.PassConfiguration data class DokkaModuleDescriptionImpl( diff --git a/core/src/main/kotlin/model/SourceSetData.kt b/core/src/main/kotlin/model/SourceSetData.kt index 964d5ca9..7d118470 100644 --- a/core/src/main/kotlin/model/SourceSetData.kt +++ b/core/src/main/kotlin/model/SourceSetData.kt @@ -6,22 +6,33 @@ import org.jetbrains.dokka.plugability.DokkaContext data class SourceSetData( val moduleName: String, - val sourceSetName: String, + val sourceSetID: String, + val displayName: String, val platform: Platform, val sourceRoots: List = emptyList(), - val dependentSourceSets: List = emptyList() + val dependentSourceSets: List = emptyList() ) class SourceSetCache { private val sourceSets = HashMap() val allSourceSets: List - get() = sourceSets.values.toList() + get() = sourceSets.values.toList() fun getSourceSet(pass: DokkaConfiguration.PassConfiguration) = - sourceSets.getOrPut("${pass.moduleName}/${pass.sourceSetName}", - { SourceSetData(pass.moduleName, pass.sourceSetName, pass.analysisPlatform, pass.sourceRoots, pass.dependentSourceSets) } + sourceSets.getOrPut("${pass.moduleName}/${pass.sourceSetID}", + { + SourceSetData( + pass.moduleName, + pass.sourceSetID, + pass.displayName, + pass.analysisPlatform, + pass.sourceRoots, + pass.dependentSourceSets + ) + } ) } -fun DokkaContext.sourceSet(pass: DokkaConfiguration.PassConfiguration) : SourceSetData = sourceSetCache.getSourceSet(pass) \ No newline at end of file +fun DokkaContext.sourceSet(pass: DokkaConfiguration.PassConfiguration): SourceSetData = + sourceSetCache.getSourceSet(pass) \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 42273d20..528b7d16 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -22,7 +22,7 @@ open class HtmlRenderer( private val sourceSetDependencyMap = with(context.sourceSetCache) { allSourceSets.map { sourceSet -> - sourceSet to allSourceSets.filter { sourceSet.dependentSourceSets.contains(it.sourceSetName) } + sourceSet to allSourceSets.filter { sourceSet.dependentSourceSets.contains(it.sourceSetID ) } }.toMap() } @@ -93,14 +93,14 @@ open class HtmlRenderer( group.sourceSets.forEach { button(classes = "platform-tag platform-selector") { attributes["data-active"] = "" - attributes["data-filter"] = it.sourceSetName - when (it.platform.key) { + attributes["data-filter"] = it.sourceSetID + when(it.platform.key) { "common" -> classes = classes + "common-like" "native" -> classes = classes + "native-like" "jvm" -> classes = classes + "jvm-like" "js" -> classes = classes + "js-like" } - text(it.sourceSetName) + text(it.displayName) } } } @@ -161,10 +161,10 @@ open class HtmlRenderer( attributes["data-toggle-list"] = "data-toggle-list" contents.forEachIndexed { index, pair -> button(classes = "platform-bookmark") { - attributes["data-filterable-current"] = pair.first.sourceSetName - attributes["data-filterable-set"] = pair.first.sourceSetName + attributes["data-filterable-current"] = pair.first.sourceSetID + attributes["data-filterable-set"] = pair.first.sourceSetID if (index == 0) attributes["data-active"] = "" - attributes["data-toggle"] = pair.first.sourceSetName + attributes["data-toggle"] = pair.first.sourceSetID when ( pair.first.platform.key ) { @@ -173,8 +173,8 @@ open class HtmlRenderer( "jvm" -> classes = classes + "jvm-like" "js" -> classes = classes + "js-like" } - attributes["data-toggle"] = pair.first.sourceSetName - text(pair.first.sourceSetName) + attributes["data-toggle"] = pair.first.sourceSetID + text(pair.first.displayName) } } } @@ -242,10 +242,10 @@ open class HtmlRenderer( consumer.onTagContentUnsafe { +createHTML().div("divergent-group") { attributes["data-filterable-current"] = groupedDivergent.keys.joinToString(" ") { - it.sourceSetName + it.sourceSetID } attributes["data-filterable-set"] = groupedDivergent.keys.joinToString(" ") { - it.sourceSetName + it.sourceSetID } val divergentForPlatformDependent = groupedDivergent.map { (sourceSet, elements) -> @@ -346,12 +346,13 @@ open class HtmlRenderer( div(classes = "table-row") { if (!style.contains(MultimoduleTable)) { attributes["data-filterable-current"] = node.sourceSets.joinToString(" ") { - it.sourceSetName + it.sourceSetID } attributes["data-filterable-set"] = node.sourceSets.joinToString(" ") { - it.sourceSetName + it.sourceSetID } } + it.filterIsInstance().takeIf { it.isNotEmpty() }?.let { div("main-subrow " + node.style.joinToString(" ")) { it.filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } } @@ -396,7 +397,7 @@ open class HtmlRenderer( "jvm" -> classes = classes + "jvm-like" "js" -> classes = classes + "js-like" } - text(it.sourceSetName) + text(it.displayName) } } } diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt index f10c85d5..cdb30555 100644 --- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt +++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt @@ -87,7 +87,7 @@ object StyleAndScriptsAppender : PageTransformer { class SourcesetDependencyAppender(val context: DokkaContext) : PageTransformer{ override fun invoke(input: RootPageNode): RootPageNode { val dependenciesMap = context.configuration.passesConfigurations.map { - it.sourceSetName to it.dependentSourceSets + it.sourceSetID to it.dependentSourceSets }.toMap() fun createDependenciesJson() : String = "sourceset_dependencies = '{${ dependenciesMap.entries.joinToString(", ") { diff --git a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt index 322f4927..a9e58f17 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt @@ -98,26 +98,19 @@ open class DefaultLocationProvider( if (info == null) { toResolve.getOrPut(jdk) { mutableListOf() }.add(link) } else if (info.packages.contains(dri.packageName)) { - return link.url.toExternalForm() + getLink( - dri, - info - ) + return link.url.toExternalForm() + getLink(dri, info) } } } // Not in cache, resolve packageLists for ((jdk, links) in toResolve) { for (link in links) { + if(dokkaContext.configuration.offlineMode && link.packageListUrl.protocol.toLowerCase() != "file") + continue val locationInfo = - loadPackageList( - jdk, - link.packageListUrl - ) + loadPackageList(jdk, link.packageListUrl) if (locationInfo.packages.contains(dri.packageName)) { - return link.url.toExternalForm() + getLink( - dri, - locationInfo - ) + return link.url.toExternalForm() + getLink(dri, locationInfo) } } toResolve.remove(jdk) diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt index 04b2636c..2aab6018 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt @@ -53,7 +53,7 @@ internal class ModuleAndPackageDocumentationTransformer(val context: DokkaContex module.sourceSets.mapNotNull { pd -> val doc = modulesAndPackagesDocumentation[Pair(module.name, pd)] val facade = context.platforms[pd]?.facade - ?: return@mapNotNull null.also { context.logger.warn("Could not find platform data for ${pd.moduleName}/${pd.sourceSetName}") } + ?: return@mapNotNull null.also { context.logger.warn("Could not find platform data for ${pd.moduleName}/${pd.sourceSetID}") } try { doc?.get("Module")?.get(module.name)?.run { pd to MarkdownParser( @@ -72,7 +72,7 @@ internal class ModuleAndPackageDocumentationTransformer(val context: DokkaContex it.name to it.sourceSets.mapNotNull { pd -> val doc = modulesAndPackagesDocumentation[Pair(module.name, pd)] val facade = context.platforms[pd]?.facade - ?: return@mapNotNull null.also { context.logger.warn("Could not find platform data for ${pd.moduleName}/${pd.sourceSetName}") } + ?: return@mapNotNull null.also { context.logger.warn("Could not find platform data for ${pd.moduleName}/${pd.sourceSetID}") } val descriptor = facade.moduleDescriptor.getPackage(FqName(it.name.let { if(it == "[JS root]") "" else it })) doc?.get("Package")?.get(it.name)?.run { pd to MarkdownParser( diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index bf92c849..33cad4f5 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -739,7 +739,7 @@ private class DokkaDescriptorVisitor( private fun ConstantsEnumValue.fullEnumEntryName() = "${this.enumClassId.relativeClassName.asString()}.${this.enumEntryName.identifier}" - private fun fallbackPackageName(): String = "[${sourceSet.sourceSetName} root]"// TODO: error-prone, find a better way to do it + private fun fallbackPackageName(): String = "[${sourceSet.displayName} root]"// TODO: error-prone, find a better way to do it } private fun DRI.withPackageFallbackTo(fallbackPackage: String): DRI { diff --git a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt index d10bd151..f91b82d5 100644 --- a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt +++ b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt @@ -19,7 +19,6 @@ class ContentForAnnotationsTest : AbstractCoreTest() { pass { sourceRoots = listOf("src/") analysisPlatform = "jvm" - targets = listOf("jvm") } } } diff --git a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt index e25567e0..335d834e 100644 --- a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt +++ b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt @@ -12,7 +12,6 @@ class ContentForParamsTest : AbstractCoreTest() { pass { sourceRoots = listOf("src/") analysisPlatform = "jvm" - targets = listOf("jvm") } } } diff --git a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt index c9adc0bf..696c3032 100644 --- a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt +++ b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt @@ -4,9 +4,9 @@ import matchers.content.* import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Test +import utils.ParamAttributes import utils.bareSignature import utils.pWrapped -import utils.ParamAttributes import utils.unnamedTag class ContentForSeeAlsoTest : AbstractCoreTest() { @@ -15,7 +15,6 @@ class ContentForSeeAlsoTest : AbstractCoreTest() { pass { sourceRoots = listOf("src/") analysisPlatform = "jvm" - targets = listOf("jvm") } } } diff --git a/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt b/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt index bdefe45a..dc0488c8 100644 --- a/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt +++ b/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt @@ -16,7 +16,6 @@ class ContentForSignaturesTest : AbstractCoreTest() { pass { sourceRoots = listOf("src/") analysisPlatform = "jvm" - targets = listOf("jvm") } } } diff --git a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt index 7cdb0de3..d49ec8a5 100644 --- a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -27,7 +27,6 @@ class LinkableContentTest : AbstractCoreTest() { pass { moduleName = "example" analysisPlatform = "js" - targets = listOf("js") sourceRoots = listOf("jsMain", "commonMain", "jvmAndJsSecondCommonMain").map { Paths.get("$testDataDir/$it/kotlin").toString() } @@ -37,7 +36,6 @@ class LinkableContentTest : AbstractCoreTest() { pass { moduleName = "example" analysisPlatform = "jvm" - targets = listOf("jvm") sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map { Paths.get("$testDataDir/$it/kotlin").toString() } @@ -68,7 +66,6 @@ class LinkableContentTest : AbstractCoreTest() { pass { moduleName = "example" analysisPlatform = "js" - targets = listOf("js") sourceRoots = listOf("$testDataDir/jsMain/kotlin") sourceLinks = listOf( SourceLinkDefinitionImpl( @@ -82,7 +79,6 @@ class LinkableContentTest : AbstractCoreTest() { pass { moduleName = "example" analysisPlatform = "jvm" - targets = listOf("jvm") sourceRoots = listOf("$testDataDir/jvmMain/kotlin") sourceLinks = listOf( SourceLinkDefinitionImpl( @@ -133,7 +129,6 @@ class LinkableContentTest : AbstractCoreTest() { pass { moduleName = "example" analysisPlatform = "js" - targets = listOf("js") sourceRoots = listOf("$testDataDir/jsMain/kotlin") sourceSetName = "js" samples = listOf("$testDataDir/jsMain/resources/Samples.kt") @@ -141,7 +136,6 @@ class LinkableContentTest : AbstractCoreTest() { pass { moduleName = "example" analysisPlatform = "jvm" - targets = listOf("jvm") sourceRoots = listOf("$testDataDir/jvmMain/kotlin") sourceSetName = "jvm" samples = listOf("$testDataDir/jvmMain/resources/Samples.kt") @@ -199,7 +193,7 @@ class LinkableContentTest : AbstractCoreTest() { pass { sourceRoots = listOf("src/") analysisPlatform = "jvm" - targets = listOf("jvm") + sourceSetName = "js" } } } diff --git a/plugins/base/src/test/kotlin/markdown/LinkTest.kt b/plugins/base/src/test/kotlin/markdown/LinkTest.kt index 20bd24ee..ddcef5db 100644 --- a/plugins/base/src/test/kotlin/markdown/LinkTest.kt +++ b/plugins/base/src/test/kotlin/markdown/LinkTest.kt @@ -70,7 +70,7 @@ class LinkTest : AbstractCoreTest() { val innerClass = root.children.first { it is ClasslikePageNode } val foo = innerClass.children.first { it.name == "foo" } as MemberPageNode - assertEquals(root.dri.first().toString(), "[main root]/Outer///PointingToDeclaration/") + assertEquals(root.dri.first().toString(), "[JVM root]/Outer///PointingToDeclaration/") assertNotNull(foo.content.dfs { it is ContentDRILink && it.address.toString() == root.dri.first().toString() } ) } } diff --git a/plugins/base/src/test/kotlin/model/InheritorsTest.kt b/plugins/base/src/test/kotlin/model/InheritorsTest.kt index ce8a87ca..5daebb73 100644 --- a/plugins/base/src/test/kotlin/model/InheritorsTest.kt +++ b/plugins/base/src/test/kotlin/model/InheritorsTest.kt @@ -48,12 +48,10 @@ class InheritorsTest : AbstractModelTest("/src/main/kotlin/inheritors/Test.kt", pass { sourceRoots = listOf("common/src/", "jvm/src/") analysisPlatform = "jvm" - targets = listOf("jvm") } pass { sourceRoots = listOf("common/src/", "js/src/") analysisPlatform = "js" - targets = listOf("js") } } } diff --git a/plugins/base/src/test/kotlin/model/PackagesTest.kt b/plugins/base/src/test/kotlin/model/PackagesTest.kt index 676f034a..c777ad05 100644 --- a/plugins/base/src/test/kotlin/model/PackagesTest.kt +++ b/plugins/base/src/test/kotlin/model/PackagesTest.kt @@ -14,8 +14,8 @@ class PackagesTest : AbstractModelTest("/src/main/kotlin/packages/Test.kt", "pac """.trimIndent(), prependPackage = false ) { - with((this / "[main root]").cast()) { - name equals "[main root]" + with((this / "[JVM root]").cast()) { + name equals "[JVM root]" children counts 0 } } diff --git a/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt index a3bf9188..a4d7bd04 100644 --- a/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt +++ b/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt @@ -33,10 +33,10 @@ abstract class RenderingOnlyTestBase { DokkaBase().outputWriter to { _ -> files }, DokkaBase().locationProviderFactory to ::DefaultLocationProviderFactory, DokkaBase().htmlPreprocessors to { _ -> RootCreator }, - DokkaBase().externalLocationProviderFactory to { _ -> ::JavadocExternalLocationProviderFactory }, - DokkaBase().externalLocationProviderFactory to { _ -> ::DokkaExternalLocationProviderFactory }, + DokkaBase().externalLocationProviderFactory to { ::JavadocExternalLocationProviderFactory }, + DokkaBase().externalLocationProviderFactory to { ::DokkaExternalLocationProviderFactory }, sourceSetCache = SourceSetCache(), - testConfiguration = DokkaConfigurationImpl("", "", false, null, emptyList(), emptyList(), emptyList(), emptyMap(), emptyList()) + testConfiguration = DokkaConfigurationImpl("", "", null, false, emptyList(), emptyList(), emptyMap(), emptyList()) ) protected val renderedContent: Element by lazy { diff --git a/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt b/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt index fa129760..b10202bb 100644 --- a/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt @@ -10,9 +10,9 @@ import org.junit.jupiter.api.Test import renderers.* class DivergentTest : RenderingOnlyTestBase() { - private val js = SourceSetData("root", "JS", Platform.js, listOf(SourceRootImpl("pl1"))) - private val jvm = SourceSetData("root", "JVM", Platform.jvm, listOf(SourceRootImpl("pl1"))) - private val native = SourceSetData("root", "NATIVE", Platform.native, listOf(SourceRootImpl("pl1"))) + private val js = SourceSetData("root", "js", "JS", Platform.js, listOf(SourceRootImpl("pl1"))) + private val jvm = SourceSetData("root", "jvm", "JVM", Platform.jvm, listOf(SourceRootImpl("pl1"))) + private val native = SourceSetData("root", "native", "NATIVE", Platform.native, listOf(SourceRootImpl("pl1"))) @Test fun simpleWrappingCase() { diff --git a/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt b/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt index c1dc40a7..878f442b 100644 --- a/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt @@ -12,9 +12,9 @@ import renderers.TestPage import renderers.match class SourceSetDependentHintTest : RenderingOnlyTestBase() { - private val pl1 = SourceSetData("root", "pl1", Platform.js, listOf(SourceRootImpl("pl1"))) - private val pl2 = SourceSetData("root","pl2", Platform.jvm, listOf(SourceRootImpl("pl1"))) - private val pl3 = SourceSetData("root","pl3", Platform.native, listOf(SourceRootImpl("pl1"))) + private val pl1 = SourceSetData("root", "pl1", "pl3",Platform.js, listOf(SourceRootImpl("pl1"))) + private val pl2 = SourceSetData("root","pl2", "pl3", Platform.jvm, listOf(SourceRootImpl("pl1"))) + private val pl3 = SourceSetData("root","pl3", "pl3", Platform.native, listOf(SourceRootImpl("pl1"))) @Test fun platformIndependentCase() { diff --git a/plugins/base/src/test/kotlin/utils/ModelUtils.kt b/plugins/base/src/test/kotlin/utils/ModelUtils.kt index f65258b1..9697a843 100644 --- a/plugins/base/src/test/kotlin/utils/ModelUtils.kt +++ b/plugins/base/src/test/kotlin/utils/ModelUtils.kt @@ -9,7 +9,6 @@ abstract class AbstractModelTest(val path: String? = null, val pkg: String) : Mo fun inlineModelTest( query: String, platform: String = "jvm", - targetList: List = listOf("jvm"), prependPackage: Boolean = true, cleanupOutput: Boolean = true, pluginsOverrides: List = emptyList(), @@ -21,7 +20,6 @@ abstract class AbstractModelTest(val path: String? = null, val pkg: String) : Mo pass { sourceRoots = listOf("src/") analysisPlatform = platform - targets = targetList } } } diff --git a/plugins/gfm/src/main/kotlin/GfmPlugin.kt b/plugins/gfm/src/main/kotlin/GfmPlugin.kt index cc79291c..b10a45b8 100644 --- a/plugins/gfm/src/main/kotlin/GfmPlugin.kt +++ b/plugins/gfm/src/main/kotlin/GfmPlugin.kt @@ -120,7 +120,7 @@ open class CommonmarkRenderer( append(distinct.keys.single()) else distinct.forEach { text, platforms -> - append(platforms.joinToString(prefix = " [", postfix = "] $text") { "${it.moduleName}/${it.sourceSetName}" }) + append(platforms.joinToString(prefix = " [", postfix = "] $text") { "${it.moduleName}/${it.sourceSetID}" }) } } diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index be42bc79..d217f83e 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -35,24 +35,22 @@ open class GlobalArguments(parser: DokkaArgumentsParser) : DokkaConfiguration { } } - override val generateIndexPages: Boolean by parser.singleFlag( - listOf("-generateIndexPages"), - "Generate index page" - ) - override val cacheRoot: String? by parser.stringOption( listOf("-cacheRoot"), "Path to cache folder, or 'default' to use ~/.cache/dokka, if not provided caching is disabled", null ) - override val impliedPlatforms: List = emptyList() + override val offlineMode: Boolean by parser.singleFlag( + listOf("-offlineMode"), + "Offline mode (do not download package lists from the Internet)" + ) override val passesConfigurations: List by parser.repeatableFlag( listOf("-pass"), "Single dokka pass" ) { - Arguments(parser).also { if(it.moduleName.isEmpty()) DokkaConsoleLogger.warn("Not specified module name. It can result in unexpected behaviour while including documentation for module") } + Arguments(parser).also { if (it.moduleName.isEmpty()) DokkaConsoleLogger.warn("Not specified module name. It can result in unexpected behaviour while including documentation for module") } } override val modules: List = emptyList() @@ -67,12 +65,17 @@ class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfi "" ) - override val sourceSetName: String by parser.stringOption( - listOf("-sourceSetName"), - "Name of the source set", - "main" + override val displayName: String by parser.stringOption( + listOf("-displayName"), + "Name displayed in the generated documentation", + "" ) + override val sourceSetID: String by parser.stringOption( + listOf("-sourceSetID"), + "Source set ID used for declaring dependent source sets", + "main" + ) override val classpath: List by parser.repeatableOption( listOf("-classpath"), @@ -84,11 +87,6 @@ class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfi "Source file or directory (allows many paths separated by the system path separator)" ) { SourceRootImpl(it) } - override val dependentSourceRoots: List by parser.repeatableOption( - listOf("-dependentRoots"), - "Source roots of dependent source sets" - ) { SourceRootImpl(it) } - override val dependentSourceSets: List by parser.repeatableOption( listOf("-dependentSets"), "Names of dependent source sets" @@ -163,16 +161,6 @@ class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfi "" ) - override val sinceKotlin: String? by parser.stringOption( - listOf("-sinceKotlin"), - "Kotlin Api version to use as base version, if none specified", - null - ) - - override val collectInheritedExtensionsFromLibraries: Boolean by parser.singleFlag( - listOf("-collectInheritedExtensionsFromLibraries"), - "Search for applicable extensions in libraries" - ) override val analysisPlatform: Platform by parser.singleOption( listOf("-analysisPlatform"), @@ -181,10 +169,6 @@ class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfi { Platform.DEFAULT } ) - override val targets: List by parser.repeatableOption( - listOf("-target"), - "Generation targets" - ) override val perPackageOptions: MutableList by parser.singleOption( listOf("-packageOptions"), @@ -215,16 +199,16 @@ class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfi object MainKt { fun defaultLinks(config: DokkaConfiguration.PassConfiguration): MutableList = mutableListOf().apply { - if (!config.noJdkLink) - this += DokkaConfiguration.ExternalDocumentationLink - .Builder("https://docs.oracle.com/javase/${config.jdkVersion}/docs/api/") - .build() - - if (!config.noStdlibLink) - this += DokkaConfiguration.ExternalDocumentationLink - .Builder("https://kotlinlang.org/api/latest/jvm/stdlib/") - .build() - } + if (!config.noJdkLink) + this += DokkaConfiguration.ExternalDocumentationLink + .Builder("https://docs.oracle.com/javase/${config.jdkVersion}/docs/api/") + .build() + + if (!config.noStdlibLink) + this += DokkaConfiguration.ExternalDocumentationLink + .Builder("https://kotlinlang.org/api/latest/jvm/stdlib/") + .build() + } fun parseLinks(links: String): List { val (parsedLinks, parsedOfflineLinks) = links.split("^^") diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt index c69c6f67..44a0635f 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt @@ -1,9 +1,5 @@ package org.jetbrains.dokka.gradle -import com.android.build.gradle.* -import com.android.build.gradle.api.BaseVariant -import com.android.builder.core.BuilderConstants -import org.gradle.api.NamedDomainObjectCollection import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.UnknownDomainObjectException @@ -13,57 +9,60 @@ import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.compile.AbstractCompile import org.jetbrains.dokka.ReflectDsl -import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension -import org.jetbrains.kotlin.gradle.plugin.* +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.io.File import java.io.Serializable class ConfigurationExtractor(private val project: Project) { - fun extractConfiguration(targetName: String, variantName: String?) = - extractFromKotlinProject(targetName, variantName) - - fun extractFromKotlinProject(sourceSetName: String, variantName: String?): PlatformData? { + fun extractConfiguration(sourceSetName: String): PlatformData? { val projectExtension = project.extensions.getByType(KotlinProjectExtension::class.java) val sourceSet = projectExtension.sourceSets.findByName(sourceSetName) ?: run { project.logger.error("No source set with name '$sourceSetName' found"); return null } val compilation = when (projectExtension) { - is KotlinMultiplatformExtension -> projectExtension.targets.flatMap { it.compilations } - .find { it.kotlinSourceSets.contains(sourceSet) } + is KotlinMultiplatformExtension -> { + val targets = projectExtension.targets.flatMap { it.compilations } + targets.find { it.name == sourceSetName } ?: targets.find { it.kotlinSourceSets.contains(sourceSet) } + } is KotlinSingleTargetExtension -> projectExtension.target.compilations.find { it.kotlinSourceSets.contains(sourceSet) } else -> null - } ?: run { project.logger.error("No compilation found for set with name '$sourceSetName'"); return null } + } + + val sourceRoots = sourceSet.sourceFiles + val classpath = compilation?.classpath + ?: sourceRoots + sourceSet.allParentSourceFiles() - val classpath = compilation.compileDependencyFiles.files.filter { it.exists() } - val dependencies = (compilation.allKotlinSourceSets - sourceSet).flatMap { it.kotlin.sourceDirectories } return PlatformData( sourceSetName, - classpath, - sourceSet.kotlin.sourceDirectories.filter { it.exists() }.toList(), - dependencies, - sourceSet.dependsOn.map { it.name }, - compilation.target.targetName + classpath.filter { it.exists() }, + sourceRoots, + sourceSet.dependsOn.map { it.name }, + compilation?.target?.platformType?.name ?: "common" ) } + private fun KotlinSourceSet.allParentSourceFiles(): List = + sourceFiles + dependsOn.flatMap { it.allParentSourceFiles() } + fun extractFromJavaPlugin(): PlatformData? = project.convention.findPlugin(JavaPluginConvention::class.java) ?.run { sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME)?.allSource?.srcDirs } - ?.let { PlatformData(null, emptyList(), it.toList(), emptyList(), emptyList(), "") } + ?.let { PlatformData(null, emptyList(), it.toList(), emptyList(), "") } - fun extractFromKotlinTasks(passName: String, kotlinTasks: List): PlatformData? = + fun extractFromKotlinTasks(kotlinTasks: List): List = try { - kotlinTasks.find { it.toString() == passName }?.let { extractFromKotlinTask(it) } + kotlinTasks.map { extractFromKotlinTask(it) } } catch (e: Throwable) { when (e) { is UnknownDomainObjectException, is NoClassDefFoundError, is ClassNotFoundException -> - extractFromKotlinTasksTheHardWay(passName, kotlinTasks) + listOfNotNull(extractFromKotlinTasksTheHardWay(kotlinTasks)) else -> throw e } } @@ -80,18 +79,17 @@ class ConfigurationExtractor(private val project: Project) { .flatMap { it.compilations }.firstOrNull { it.compileKotlinTask == task } else -> throw e } - }.let { + }.let { compilation -> PlatformData( task.name, - getClasspath(it), - getSourceSet(it), - getDependentSourceSetRoots(it), - getDependentSourceSet(it).map { it.name }, - it?.platformType?.toString() ?: "" + compilation?.classpath.orEmpty(), + compilation?.sourceFiles.orEmpty(), + compilation?.dependentSourceSets?.map { it.name }.orEmpty(), + compilation?.platformType?.toString() ?: "" ) } - private fun extractFromKotlinTasksTheHardWay(passName: String, kotlinTasks: List): PlatformData? { + private fun extractFromKotlinTasksTheHardWay(kotlinTasks: List): PlatformData? { val allClasspath = mutableSetOf() var allClasspathFileCollection: FileCollection = project.files() val allSourceRoots = mutableSetOf() @@ -128,93 +126,41 @@ class ConfigurationExtractor(private val project: Project) { } classpath.addAll(project.files(allClasspath).toList()) - return PlatformData(null, classpath, allSourceRoots.toList(), emptyList(), emptyList(),"") + return PlatformData(null, classpath, allSourceRoots.toList(), emptyList(), "") } - private fun getSourceSet(target: KotlinTarget, variantName: String? = null): List = - if (variantName != null) - getSourceSet(getCompilation(target, variantName)) - else - getSourceSet(getMainCompilation(target)) - - private fun getClasspath(target: KotlinTarget, variantName: String? = null): List = - if (target.isAndroidTarget()) { - if (variantName != null) - getClasspathFromAndroidTask(getCompilation(target, variantName)) - else - getClasspathFromAndroidTask(getMainCompilation(target)) - } else { - getClasspath(getMainCompilation(target)) - } - - private fun getSourceSet(compilation: KotlinCompilation<*>?): List = compilation - ?.kotlinSourceSets - ?.flatMap { it.kotlin.sourceDirectories } - ?.filter { it.exists() } - .orEmpty() + private val KotlinCompilation<*>.sourceFiles: List + get() = kotlinSourceSets.flatMap { it.sourceFiles } - private fun getDependentSourceSet(compilation: KotlinCompilation<*>?) = compilation - ?.let { it.allKotlinSourceSets - it.kotlinSourceSets }.orEmpty() + private val KotlinSourceSet.sourceFiles: List + get() = kotlin.sourceDirectories.filter { it.exists() }.toList() - private fun getDependentSourceSetRoots(compilation: KotlinCompilation<*>?): List = - getDependentSourceSet(compilation)?.flatMap { it.kotlin.sourceDirectories } - .filter { it.exists() } + private val KotlinCompilation<*>.dependentSourceSets: Set + get() = (allKotlinSourceSets - kotlinSourceSets) - private fun getClasspath(compilation: KotlinCompilation<*>?): List = compilation - ?.compileDependencyFiles - ?.files - ?.toList() - ?.filter { it.exists() } - .orEmpty() + private val KotlinCompilation<*>.classpath: List + get() = if (target.isAndroidTarget()) { + getClasspathFromAndroidTask(this) + } else { + getClasspathFromRegularTask(this) + } // This is a workaround for KT-33893 private fun getClasspathFromAndroidTask(compilation: KotlinCompilation<*>): List = (compilation .compileKotlinTask as? KotlinCompile) - ?.classpath?.files?.toList() ?: getClasspath(compilation) - - private fun getMainCompilation(target: KotlinTarget) = - getCompilation(target, getMainCompilationName(target)) - - private fun getCompilation(target: KotlinTarget, name: String) = - target.compilations.getByName(name) - - private fun getMainCompilationName(target: KotlinTarget) = if (target.isAndroidTarget()) - getVariants(project).filter { it.buildType.name == BuilderConstants.RELEASE }.map { it.name }.first() - else - KotlinCompilation.MAIN_COMPILATION_NAME - - private fun getVariants(project: Project): Set { - val androidExtension = project.extensions.getByName("android") - val baseVariants = when (androidExtension) { - is AppExtension -> androidExtension.applicationVariants.toSet() - is LibraryExtension -> { - androidExtension.libraryVariants.toSet() + - if (androidExtension is FeatureExtension) { - androidExtension.featureVariants.toSet() - } else { - emptySet() - } - } - is TestExtension -> androidExtension.applicationVariants.toSet() - else -> emptySet() - } - val testVariants = if (androidExtension is TestedExtension) { - androidExtension.testVariants.toSet() + androidExtension.unitTestVariants.toSet() - } else { - emptySet() - } - - return baseVariants + testVariants - } + ?.classpath?.files?.toList() ?: getClasspathFromRegularTask(compilation) - private fun getPlatformName(platform: KotlinPlatformType): String = - if (platform == KotlinPlatformType.androidJvm) KotlinPlatformType.jvm.toString() else platform.toString() + private fun getClasspathFromRegularTask(compilation: KotlinCompilation<*>): List = + compilation + .compileDependencyFiles + .files + .toList() + .filter { it.exists() } data class PlatformData( val name: String?, val classpath: List, val sourceRoots: List, - val dependentSourceRoots: List, val dependentSourceSets: List, val platform: String ) : Serializable diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt index f4fa7aaa..8c4e0c4c 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt @@ -20,7 +20,7 @@ open class DokkaCollectorTask : DefaultTask() { @TaskAction fun collect() { - val passesConfigurations = getProjects(project).filter { it.name in modules }.map { + val passesConfigurations = getProjects(project).filter { it.name in modules }.mapNotNull { val task = try { it.tasks.getByName(DOKKA_TASK_NAME, DokkaTask::class) } catch (e: UnknownTaskException) { @@ -33,12 +33,11 @@ open class DokkaCollectorTask : DefaultTask() { outputDir = outputDirectory cacheRoot = passesConfigurations.first().cacheRoot format = passesConfigurations.first().format - generateIndexPages = passesConfigurations.first().generateIndexPages } configuration = passesConfigurations.fold(initial) { acc, it: GradleDokkaConfigurationImpl -> - if(acc.format != it.format || acc.generateIndexPages != it.generateIndexPages || acc.cacheRoot != it.cacheRoot) - throw IllegalStateException("Dokka task configurations differ on core arguments (format, generateIndexPages, cacheRoot)") + if(acc.format != it.format || acc.cacheRoot != it.cacheRoot) + throw IllegalStateException("Dokka task configurations differ on core arguments (format, cacheRoot)") acc.passesConfigurations = acc.passesConfigurations + it.passesConfigurations acc.pluginsClasspath = (acc.pluginsClasspath + it.pluginsClasspath).distinct() acc diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt index a1bfdb96..2ef85de2 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaMultimoduleTask.kt @@ -35,9 +35,9 @@ open class DokkaMultimoduleTask : DefaultTask(), Configurable { System.setProperty(DokkaTask.COLORS_ENABLED_PROPERTY, "false") try { - loadFatJar() + loadCore() val bootstrapClass = - ClassloaderContainer.fatJarClassLoader!!.loadClass("org.jetbrains.dokka.DokkaMultimoduleBootstrapImpl") + ClassloaderContainer.coreClassLoader!!.loadClass("org.jetbrains.dokka.DokkaMultimoduleBootstrapImpl") val bootstrapInstance = bootstrapClass.constructors.first().newInstance() val bootstrapProxy: DokkaBootstrap = automagicTypedProxy( javaClass.classLoader, @@ -85,10 +85,10 @@ open class DokkaMultimoduleTask : DefaultTask(), Configurable { } } - private fun loadFatJar() { - if (ClassloaderContainer.fatJarClassLoader == null) { + private fun loadCore() { + if (ClassloaderContainer.coreClassLoader == null) { val jars = dokkaRuntime!!.resolve() - ClassloaderContainer.fatJarClassLoader = URLClassLoader( + ClassloaderContainer.coreClassLoader = URLClassLoader( jars.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader().parent ) diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt index 2de95493..5a420d4d 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt @@ -15,15 +15,16 @@ import org.jetbrains.dokka.ReflectDsl import org.jetbrains.dokka.ReflectDsl.isNotInstance import org.jetbrains.dokka.gradle.ConfigurationExtractor.PlatformData import org.jetbrains.dokka.plugability.Configurable -import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import java.io.File import java.net.URLClassLoader import java.util.concurrent.Callable import java.util.function.BiConsumer +import kotlin.system.exitProcess open class DokkaTask : DefaultTask(), Configurable { private val ANDROID_REFERENCE_URL = Builder("https://developer.android.com/reference/").build() private val GLOBAL_CONFIGURATION_NAME = "global" // Used for copying perPackageOptions to other platforms + private val configExtractor = ConfigurationExtractor(project) @Suppress("MemberVisibilityCanBePrivate") fun defaultKotlinTasks(): List = with(ReflectDsl) { @@ -57,8 +58,6 @@ open class DokkaTask : DefaultTask(), Configurable { var subProjects: List = emptyList() @Input - var impliedPlatforms: MutableList = arrayListOf() - override val pluginsConfiguration: Map = mutableMapOf() @Optional @@ -66,54 +65,47 @@ open class DokkaTask : DefaultTask(), Configurable { var cacheRoot: String? = null @Classpath - lateinit var pluginsConfig: Configuration + lateinit var pluginsClasspathConfiguration: Configuration var dokkaSourceSets: NamedDomainObjectContainer @Suppress("UNCHECKED_CAST") @Nested get() = (DslObject(this).extensions.getByName(SOURCE_SETS_EXTENSION_NAME) as NamedDomainObjectContainer) internal set(value) = DslObject(this).extensions.add(SOURCE_SETS_EXTENSION_NAME, value) - var configuration: GradlePassConfigurationImpl - @Suppress("UNCHECKED_CAST") - @Nested get() = DslObject(this).extensions.getByType(GradlePassConfigurationImpl::class.java) - internal set(value) = DslObject(this).extensions.add(CONFIGURATION_EXTENSION_NAME, value) - - var config: GradleDokkaConfigurationImpl? = null - - // Configure Dokka with closure in Gradle Kotlin DSL - fun configuration(action: Action) = action.execute(configuration) - private val kotlinTasks: List by lazy { - extractKotlinCompileTasks( - configuration.collectKotlinTasks ?: { defaultKotlinTasks() }) + extractKotlinCompileTasks({ + dokkaSourceSets.map { + it.collectKotlinTasks?.invoke() + } + }.takeIf { it().isNotEmpty() } ?: { defaultKotlinTasks() } + ) } - private val configExtractor = ConfigurationExtractor(project) - @Input var disableAutoconfiguration: Boolean = false + @Input + var offlineMode: Boolean = false + private var outputDiagnosticInfo: Boolean = false // Workaround for Gradle, which fires some methods (like collectConfigurations()) multiple times in its lifecycle - private fun loadFatJar() { - if (ClassloaderContainer.fatJarClassLoader == null) { + private fun loadCore() { + if (ClassloaderContainer.coreClassLoader == null) { val jars = dokkaRuntime!!.resolve() - ClassloaderContainer.fatJarClassLoader = URLClassLoader( + ClassloaderContainer.coreClassLoader = URLClassLoader( jars.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader().parent ) } } - private fun extractKotlinCompileTasks(collectTasks: () -> List?): List { + protected fun extractKotlinCompileTasks(collectTasks: () -> List?): List { val inputList = (collectTasks.invoke() ?: emptyList()).filterNotNull() val (paths, other) = inputList.partition { it is String } - val taskContainer = project.tasks - val tasksByPath = paths.map { - taskContainer.findByPath(it as String) ?: throw IllegalArgumentException("Task with path '$it' not found") + project.tasks.findByPath(it as String) ?: throw IllegalArgumentException("Task with path '$it' not found") } other @@ -134,7 +126,7 @@ open class DokkaTask : DefaultTask(), Configurable { private fun Iterable.toProjects(): List = project.subprojects.toList().filter { this.contains(it.name) } - private fun collectSuppressedFiles(sourceRoots: List) = + protected open fun collectSuppressedFiles(sourceRoots: List) = if (project.isAndroidProject()) { val generatedRoot = project.buildDir.resolve("generated").absoluteFile sourceRoots @@ -147,25 +139,21 @@ open class DokkaTask : DefaultTask(), Configurable { } @TaskAction - fun generate() { - generateForConfig(config ?: getConfiguration()) - } + fun generate() = getConfiguration()?.let { generate(it) } ?: exitProcess(0) - internal fun generateForConfig(configuration: GradleDokkaConfigurationImpl) { + protected open fun generate(configuration: GradleDokkaConfigurationImpl) { outputDiagnosticInfo = true val kotlinColorsEnabledBefore = System.getProperty(COLORS_ENABLED_PROPERTY) ?: "false" System.setProperty(COLORS_ENABLED_PROPERTY, "false") try { - loadFatJar() + loadCore() val bootstrapClass = - ClassloaderContainer.fatJarClassLoader!!.loadClass("org.jetbrains.dokka.DokkaBootstrapImpl") + ClassloaderContainer.coreClassLoader!!.loadClass("org.jetbrains.dokka.DokkaBootstrapImpl") val bootstrapInstance = bootstrapClass.constructors.first().newInstance() val bootstrapProxy: DokkaBootstrap = automagicTypedProxy(javaClass.classLoader, bootstrapInstance) - val gson = GsonBuilder().setPrettyPrinting().create() - bootstrapProxy.configure( BiConsumer { level, message -> when (level) { @@ -176,7 +164,7 @@ open class DokkaTask : DefaultTask(), Configurable { "error" -> logger.error(message) } }, - gson.toJson(configuration) + GsonBuilder().setPrettyPrinting().create().toJson(configuration) ) bootstrapProxy.generate() @@ -186,68 +174,78 @@ open class DokkaTask : DefaultTask(), Configurable { } } - internal fun getConfiguration(): GradleDokkaConfigurationImpl { + internal open fun getConfiguration(): GradleDokkaConfigurationImpl? { val globalConfig = dokkaSourceSets.toList().find { it.name.toLowerCase() == GLOBAL_CONFIGURATION_NAME } - val defaultModulesConfiguration = collectConfigurations() - .map { defaultPassConfiguration(it, globalConfig) } + val defaultModulesConfiguration = passConfigurations + .map { defaultPassConfiguration(it, globalConfig) }.takeIf { it.isNotEmpty() } + ?: listOf( + defaultPassConfiguration( + collectSinglePassConfiguration(GradlePassConfigurationImpl("main")), + null + ) + ).takeIf { project.isNotMultiplatformProject() } ?: emptyList() + + if (defaultModulesConfiguration.isEmpty()) { + logger.error("No source sets to document found, exiting") + return null + } + return GradleDokkaConfigurationImpl().apply { outputDir = project.file(outputDirectory).absolutePath format = outputFormat - generateIndexPages = true - cacheRoot = cacheRoot - impliedPlatforms = impliedPlatforms + cacheRoot = this@DokkaTask.cacheRoot + offlineMode = this@DokkaTask.offlineMode passesConfigurations = defaultModulesConfiguration - pluginsClasspath = pluginsConfig.resolve().toList() + pluginsClasspath = pluginsClasspathConfiguration.resolve().toList() pluginsConfiguration = this@DokkaTask.pluginsConfiguration } } - private fun collectConfigurations() = - if (this.dokkaSourceSets.isNotEmpty()) collectMultipassConfiguration() else listOf(collectSinglePassConfiguration(configuration)) - private fun collectMultipassConfiguration() = dokkaSourceSets - .filterNot { it.name.toLowerCase() == GLOBAL_CONFIGURATION_NAME } - .map { collectSinglePassConfiguration(it) } + protected val passConfigurations: List + get() = dokkaSourceSets + .filterNot { it.name.toLowerCase() == GLOBAL_CONFIGURATION_NAME } + .map { collectSinglePassConfiguration(it) } - private fun collectSinglePassConfiguration(config: GradlePassConfigurationImpl): GradlePassConfigurationImpl { + protected fun collectSinglePassConfiguration(config: GradlePassConfigurationImpl): GradlePassConfigurationImpl { val userConfig = config - /*.let { - if (it.collectKotlinTasks != null) { - configExtractor.extractFromKotlinTasks(extractKotlinCompileTasks(it.collectKotlinTasks!!)) - ?.let { platformData -> mergeUserConfigurationAndPlatformData(it, platformData) } ?: it - } else { - it + .apply { + collectKotlinTasks?.let { + configExtractor.extractFromKotlinTasks(extractKotlinCompileTasks(it)) + .fold(this) { config, platformData -> + mergeUserConfigurationAndPlatformData(config, platformData) + } + } } - }*/ if (disableAutoconfiguration) return userConfig - val baseConfig = configExtractor.extractConfiguration(userConfig.name, userConfig.androidVariant) + val baseConfig = configExtractor.extractConfiguration(userConfig.name) ?.let { mergeUserConfigurationAndPlatformData(userConfig, it) } ?: if (this.dokkaSourceSets.isNotEmpty()) { if (outputDiagnosticInfo) logger.warn( - "Could not find target with name: ${userConfig.name} in Kotlin Gradle Plugin, " + - "using only user provided configuration for this target" + "Could not find source set with name: ${userConfig.name} in Kotlin Gradle Plugin, " + + "using only user provided configuration for this source set" ) userConfig } else { - logger.warn("Could not find target with name: ${userConfig.name} in Kotlin Gradle Plugin") - collectFromSinglePlatformOldPlugin(userConfig.name) + if (outputDiagnosticInfo) + logger.warn("Could not find source set with name: ${userConfig.name} in Kotlin Gradle Plugin") + collectFromSinglePlatformOldPlugin(userConfig.name, userConfig) } return if (subProjects.isNotEmpty()) { try { - subProjects.toProjects().fold(baseConfig) { config, subProject -> + subProjects.toProjects().fold(baseConfig) { configAcc, subProject -> mergeUserConfigurationAndPlatformData( - config, - ConfigurationExtractor(subProject).extractConfiguration(config.name, config.androidVariant)!! + configAcc, + ConfigurationExtractor(subProject).extractConfiguration(userConfig.name)!! ) } } catch (e: NullPointerException) { logger.warn( - "Cannot extract sources from subProjects. Do you have the Kotlin plugin in version 1.3.30+ " + - "and the Kotlin plugin applied in the root project?" + "Cannot extract sources from subProjects. Do you have the Kotlin plugin applied in the root project?" ) baseConfig } @@ -256,49 +254,52 @@ open class DokkaTask : DefaultTask(), Configurable { } } - private fun collectFromSinglePlatformOldPlugin(name: String) = - configExtractor.extractFromKotlinTasks(name, kotlinTasks) - ?.let { mergeUserConfigurationAndPlatformData(configuration, it) } + protected fun collectFromSinglePlatformOldPlugin(name: String, userConfig: GradlePassConfigurationImpl) = + kotlinTasks.find { it.name == name } + ?.let { configExtractor.extractFromKotlinTasks(listOf(it)) } + ?.singleOrNull() + ?.let { mergeUserConfigurationAndPlatformData(userConfig, it) } ?: configExtractor.extractFromJavaPlugin() - ?.let { mergeUserConfigurationAndPlatformData(configuration, it) } - ?: configuration + ?.let { mergeUserConfigurationAndPlatformData(userConfig, it) } + ?: userConfig - private fun mergeUserConfigurationAndPlatformData( + protected fun mergeUserConfigurationAndPlatformData( userConfig: GradlePassConfigurationImpl, autoConfig: PlatformData ) = userConfig.copy().apply { - sourceSetName = autoConfig.name ?: "" + sourceSetID = autoConfig.name ?: "" sourceRoots.addAll(userConfig.sourceRoots.union(autoConfig.sourceRoots.toSourceRoots()).distinct()) - dependentSourceRoots.addAll(userConfig.dependentSourceRoots.union(autoConfig.dependentSourceRoots.toSourceRoots()).distinct()) dependentSourceSets.addAll(userConfig.dependentSourceSets.union(autoConfig.dependentSourceSets).distinct()) classpath = userConfig.classpath.union(autoConfig.classpath.map { it.absolutePath }).distinct() if (userConfig.platform == null && autoConfig.platform != "") platform = autoConfig.platform } - private fun defaultPassConfiguration( + protected fun defaultPassConfiguration( config: GradlePassConfigurationImpl, globalConfig: GradlePassConfigurationImpl? ): GradlePassConfigurationImpl { - if (config.moduleName == "") { + if (config.moduleName.isBlank()) { config.moduleName = project.name } - if (config.sourceSetName.isEmpty()) { - config.sourceSetName = config.name.substringBeforeLast("Main").takeIf(String::isNotBlank) ?: config.platform.toString() + if (config.sourceSetID.isBlank()) { + config.sourceSetID = config.name.takeIf(String::isNotBlank) ?: config.analysisPlatform.key } - config.classpath = (config.classpath as List).map { it.toString() }.distinct() // Workaround for Groovy's GStringImpl + config.displayName = config.sourceSetID.substringBeforeLast("Main") + config.classpath = + (config.classpath as List).map { it.toString() }.distinct() // Workaround for Groovy's GStringImpl config.sourceRoots = config.sourceRoots.distinct().toMutableList() config.samples = config.samples.map { project.file(it).absolutePath } config.includes = config.includes.map { project.file(it).absolutePath } config.suppressedFiles += collectSuppressedFiles(config.sourceRoots) - if (project.isAndroidProject() && !config.noAndroidSdkLink) { // TODO: introduce Android as a separate Dokka platform? + if (project.isAndroidProject() && !config.noAndroidSdkLink) { config.externalDocumentationLinks.add(ANDROID_REFERENCE_URL) } - if (config.platform != null && config.platform.toString().isNotBlank()) { + if (config.platform?.isNotBlank() == true) { config.analysisPlatform = dokkaPlatformFromString(config.platform.toString()) } - if (globalConfig != null) { + globalConfig?.let { config.perPackageOptions.addAll(globalConfig.perPackageOptions) config.externalDocumentationLinks.addAll(globalConfig.externalDocumentationLinks) config.sourceLinks.addAll(globalConfig.sourceLinks) @@ -309,7 +310,7 @@ open class DokkaTask : DefaultTask(), Configurable { } private fun dokkaPlatformFromString(platform: String) = when (platform.toLowerCase()) { - KotlinPlatformType.androidJvm.toString().toLowerCase(), "androidjvm", "android" -> Platform.jvm + "androidjvm", "android" -> Platform.jvm "metadata" -> Platform.common else -> Platform.fromString(platform) } @@ -321,7 +322,7 @@ open class DokkaTask : DefaultTask(), Configurable { // Needed for Gradle incremental build @InputFiles fun getInputFiles(): FileCollection { - val config = collectConfigurations() + val config = passConfigurations return project.files(config.flatMap { it.sourceRoots }.map { project.fileTree(File(it.path)) }) + project.files(config.flatMap { it.includes }) + project.files(config.flatMap { it.samples }.map { project.fileTree(File(it)) }) @@ -329,7 +330,7 @@ open class DokkaTask : DefaultTask(), Configurable { @Classpath fun getInputClasspath(): FileCollection = - project.files((collectConfigurations().flatMap { it.classpath } as List).map { project.fileTree(File(it.toString())) }) + project.files((passConfigurations.flatMap { it.classpath } as List).map { project.fileTree(File(it.toString())) }) companion object { const val COLORS_ENABLED_PROPERTY = "kotlin.colors.enabled" diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt index 7fdadd41..2787bb4e 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt @@ -27,9 +27,9 @@ class GradleSourceRootImpl: SourceRoot, Serializable { open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassConfiguration { @Input @Optional override var classpath: List = emptyList() @Input override var moduleName: String = "" - @Input override var sourceSetName: String = "" + @Input override var displayName: String = "" + @Input override var sourceSetID: String = "" @Input override var sourceRoots: MutableList = mutableListOf() - @Input override var dependentSourceRoots: MutableList = mutableListOf() @Input override var dependentSourceSets: MutableList = mutableListOf() @Input override var samples: List = emptyList() @Input override var includes: List = emptyList() @@ -48,13 +48,9 @@ open class GradlePassConfigurationImpl(@Transient val name: String = ""): PassCo @Input override var noJdkLink: Boolean = false @Input var noAndroidSdkLink: Boolean = false @Input override var suppressedFiles: List = emptyList() - @Input override var collectInheritedExtensionsFromLibraries: Boolean = false @Input override var analysisPlatform: Platform = Platform.DEFAULT @Input @Optional var platform: String? = null - @Input override var targets: List = emptyList() - @Input @Optional override var sinceKotlin: String? = null @Transient var collectKotlinTasks: (() -> List?)? = null - @Input @Optional @Transient var androidVariant: String? = null fun kotlinTasks(taskSupplier: Callable>) { collectKotlinTasks = { taskSupplier.call() } @@ -129,9 +125,8 @@ class GradleDokkaModuleDescription: DokkaModuleDescription { class GradleDokkaConfigurationImpl: DokkaConfiguration { override var outputDir: String = "" override var format: String = "html" - override var generateIndexPages: Boolean = false override var cacheRoot: String? = null - override var impliedPlatforms: List = emptyList() + override var offlineMode: Boolean = false override var passesConfigurations: List = emptyList() override var pluginsClasspath: List = emptyList() override var pluginsConfiguration: Map = mutableMapOf() diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt index 1049656e..d2a0f043 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt @@ -8,23 +8,31 @@ import java.io.File import java.io.InputStream import java.util.* -internal const val CONFIGURATION_EXTENSION_NAME = "configuration" internal const val SOURCE_SETS_EXTENSION_NAME = "dokkaSourceSets" internal const val DOKKA_TASK_NAME = "dokka" internal const val DOKKA_COLLECTOR_TASK_NAME = "dokkaCollector" internal const val DOKKA_MULTIMODULE_TASK_NAME = "dokkaMultimodule" open class DokkaPlugin : Plugin { - override fun apply(project: Project) { loadDokkaVersion() val dokkaRuntimeConfiguration = addConfiguration(project) val pluginsConfiguration = project.configurations.create("dokkaPlugins").apply { dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-base:${DokkaVersion.version}")) + attributes.attribute( + org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE, + project.objects.named(org.gradle.api.attributes.Usage::class.java, "java-runtime") + ) + isCanBeConsumed = false } addDokkaTasks(project, dokkaRuntimeConfiguration, pluginsConfiguration, DokkaTask::class.java) addDokkaCollectorTasks(project, DokkaCollectorTask::class.java) - addDokkaMultimoduleTasks(project.rootProject, dokkaRuntimeConfiguration, pluginsConfiguration, DokkaMultimoduleTask::class.java) + addDokkaMultimoduleTasks( + project.rootProject, + dokkaRuntimeConfiguration, + pluginsConfiguration, + DokkaMultimoduleTask::class.java + ) } private fun loadDokkaVersion() = @@ -32,7 +40,9 @@ open class DokkaPlugin : Plugin { private fun addConfiguration(project: Project) = project.configurations.create("dokkaRuntime").apply { - defaultDependencies { dependencies -> dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-core:${DokkaVersion.version}")) } + defaultDependencies { dependencies -> + dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-core:${DokkaVersion.version}")) + } } private fun addDokkaTasks( @@ -48,9 +58,8 @@ open class DokkaPlugin : Plugin { } project.tasks.withType(taskClass) { task -> task.dokkaSourceSets = project.container(GradlePassConfigurationImpl::class.java) - task.configuration = GradlePassConfigurationImpl() task.dokkaRuntime = runtimeConfiguration - task.pluginsConfig = pluginsConfiguration + task.pluginsClasspathConfiguration = pluginsConfiguration task.outputDirectory = File(project.rootProject.buildDir, "$DOKKA_TASK_NAME/${project.name}").absolutePath } } @@ -65,7 +74,6 @@ open class DokkaPlugin : Plugin { project.tasks.create(DOKKA_COLLECTOR_TASK_NAME, taskClass) } project.tasks.withType(taskClass) { task -> - task.modules = emptyList() task.outputDirectory = File(project.buildDir, DOKKA_TASK_NAME).absolutePath } } @@ -103,5 +111,5 @@ object DokkaVersion { object ClassloaderContainer { @JvmField - var fatJarClassLoader: ClassLoader? = null + var coreClassLoader: ClassLoader? = null } \ No newline at end of file diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt index 3369a640..a4bf65ee 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/utils.kt @@ -7,7 +7,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinTarget -fun Project.isAndroidProject() = try { +internal fun Project.isAndroidProject() = try { project.extensions.getByName("android") true } catch(e: UnknownDomainObjectException) { @@ -16,4 +16,17 @@ fun Project.isAndroidProject() = try { false } -fun KotlinTarget.isAndroidTarget() = this.platformType == KotlinPlatformType.androidJvm \ No newline at end of file +internal fun Project.isNotMultiplatformProject() = !isMultiplatformProject() + +internal fun Project.isMultiplatformProject() = try { + project.extensions.getByType(KotlinMultiplatformExtension::class.java) + true +} catch(e: UnknownDomainObjectException) { + false +} catch (e: NoClassDefFoundError){ + false +} catch(e: ClassNotFoundException) { + false +} + +internal fun KotlinTarget.isAndroidTarget() = this.platformType == KotlinPlatformType.androidJvm \ No newline at end of file diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index 8242d0d1..71fe5b40 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -29,11 +29,9 @@ import org.eclipse.aether.transport.file.FileTransporterFactory import org.eclipse.aether.transport.http.HttpTransporterFactory import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator import org.jetbrains.dokka.* -import org.jetbrains.dokka.utilities.DokkaConsoleLogger import java.io.File import java.net.URL - class SourceLinkMapItem { @Parameter(name = "path", required = true) var path: String = "" @@ -92,8 +90,6 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter var sourceRoots: List = emptyList() - @Parameter - var dependentSourceRoots: List = emptyList() @Parameter var dependentSourceSets: List = emptyList() @@ -146,6 +142,12 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter var cacheRoot: String? = null + @Parameter(defaultValue = "JVM") + var displayName: String = "JVM" + + @Parameter(defaultValue = "false") + var offlineMode: Boolean = false + @Parameter var languageVersion: String? = null @@ -158,24 +160,13 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter var suppressedFiles: List = emptyList() - @Parameter - var collectInheritedExtensionsFromLibraries: Boolean = false @Parameter var platform: String = "" - @Parameter - var targets: List = emptyList() - - @Parameter - var sinceKotlin: String? = null - @Parameter var includeNonPublic: Boolean = false - @Parameter - var generateIndexPages: Boolean = false - @Parameter var dokkaPlugins: List = emptyList() @@ -209,19 +200,21 @@ abstract class AbstractDokkaMojo : AbstractMojo() { } val passConfiguration = PassConfigurationImpl( + moduleName = moduleName, + displayName = displayName, + sourceSetID = sourceSetName, classpath = classpath, - sourceSetName = sourceSetName, sourceRoots = sourceDirectories.map { SourceRootImpl(it) }, - dependentSourceRoots = dependentSourceRoots.map { SourceRootImpl(path = it.path) }, dependentSourceSets = dependentSourceSets, samples = samples, includes = includes, - collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries, // TODO: Should we implement this? - sourceLinks = sourceLinks.map { SourceLinkDefinitionImpl(it.path, it.url, it.lineSuffix) }, - jdkVersion = jdkVersion, - skipDeprecated = skipDeprecated, - skipEmptyPackages = skipEmptyPackages, + includeNonPublic = includeNonPublic, + includeRootPackage = includeRootPackage, reportUndocumented = reportUndocumented, + skipEmptyPackages = skipEmptyPackages, + skipDeprecated = skipDeprecated, + jdkVersion = jdkVersion, + sourceLinks = sourceLinks.map { SourceLinkDefinitionImpl(it.path, it.url, it.lineSuffix) }, perPackageOptions = perPackageOptions.map { PackageOptionsImpl( prefix = it.prefix, @@ -232,18 +225,13 @@ abstract class AbstractDokkaMojo : AbstractMojo() { ) }, externalDocumentationLinks = externalDocumentationLinks.map { it.build() as ExternalDocumentationLinkImpl }, - noStdlibLink = noStdlibLink, - noJdkLink = noJdkLink, languageVersion = languageVersion, apiVersion = apiVersion, - moduleName = moduleName, + noStdlibLink = noStdlibLink, + noJdkLink = noJdkLink, suppressedFiles = suppressedFiles, - sinceKotlin = sinceKotlin, - analysisPlatform = if (platform.isNotEmpty()) Platform.fromString(platform) else Platform.DEFAULT, - targets = targets, - includeNonPublic = includeNonPublic, - includeRootPackage = includeRootPackage - ).let{ + analysisPlatform = if (platform.isNotEmpty()) Platform.fromString(platform) else Platform.DEFAULT + ).let { it.copy( externalDocumentationLinks = defaultLinks(it) + it.externalDocumentationLinks ) @@ -254,12 +242,11 @@ abstract class AbstractDokkaMojo : AbstractMojo() { val configuration = DokkaConfigurationImpl( outputDir = getOutDir(), format = getOutFormat(), - impliedPlatforms = impliedPlatforms, + offlineMode = offlineMode, cacheRoot = cacheRoot, passesConfigurations = listOf(passConfiguration).also { - if(passConfiguration.moduleName.isEmpty()) logger.warn("Not specified module name. It can result in unexpected behaviour while including documentation for module") + if (passConfiguration.moduleName.isEmpty()) logger.warn("Not specified module name. It can result in unexpected behaviour while including documentation for module") }, - generateIndexPages = generateIndexPages, pluginsClasspath = getArtifactByAether("org.jetbrains.dokka", "dokka-base", dokkaVersion) + dokkaPlugins.map { getArtifactByAether(it.groupId, it.artifactId, it.version) }.flatten(), pluginsConfiguration = mutableMapOf(), //TODO implement as it is in Gradle diff --git a/settings.gradle.kts b/settings.gradle.kts index 39a82007..b3e15ade 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,7 @@ rootProject.name = "dokka" include("core") +include("plugins:base:search-component") include("coreDependencies") include("testApi") include("test-tools") @@ -31,6 +32,4 @@ pluginManagement { jcenter() gradlePluginPortal() } -} -include("plugins:base:frontend") -findProject(":plugins:base:frontend")?.name = "frontend" +} \ No newline at end of file diff --git a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt index 7f1be6b5..3aec2909 100644 --- a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt +++ b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt @@ -139,7 +139,7 @@ abstract class AbstractCoreTest { protected class DokkaConfigurationBuilder { var outputDir: String = "out" var format: String = "html" - var generateIndexPages: Boolean = true + var offlineMode: Boolean = false var cacheRoot: String? = null var pluginsClasspath: List = emptyList() var pluginsConfigurations: Map = emptyMap() @@ -147,9 +147,8 @@ abstract class AbstractCoreTest { fun build() = DokkaConfigurationImpl( outputDir = outputDir, format = format, - generateIndexPages = generateIndexPages, cacheRoot = cacheRoot, - impliedPlatforms = emptyList(), + offlineMode = offlineMode, passesConfigurations = passesConfigurations, pluginsClasspath = pluginsClasspath, pluginsConfiguration = pluginsConfigurations, @@ -171,9 +170,9 @@ abstract class AbstractCoreTest { protected class DokkaPassConfigurationBuilder( var moduleName: String = "root", var sourceSetName: String = "main", + var displayName: String = "JVM", var classpath: List = emptyList(), var sourceRoots: List = emptyList(), - var dependentSourceRoots: List = emptyList(), var dependentSourceSets: List = emptyList(), var samples: List = emptyList(), var includes: List = emptyList(), @@ -188,20 +187,17 @@ abstract class AbstractCoreTest { var noStdlibLink: Boolean = false, var noJdkLink: Boolean = false, var suppressedFiles: List = emptyList(), - var collectInheritedExtensionsFromLibraries: Boolean = true, var analysisPlatform: String = "jvm", - var targets: List = listOf("jvm"), - var sinceKotlin: String? = null, var perPackageOptions: List = emptyList(), var externalDocumentationLinks: List = emptyList(), var sourceLinks: List = emptyList() ) { fun build() = PassConfigurationImpl( moduleName = moduleName, - sourceSetName = sourceSetName, + displayName = displayName, + sourceSetID = sourceSetName, classpath = classpath, sourceRoots = sourceRoots.map { SourceRootImpl(it) }, - dependentSourceRoots = dependentSourceRoots.map { SourceRootImpl(it) }, dependentSourceSets = dependentSourceSets, samples = samples, includes = includes, @@ -211,18 +207,15 @@ abstract class AbstractCoreTest { skipEmptyPackages = skipEmptyPackages, skipDeprecated = skipDeprecated, jdkVersion = jdkVersion, + sourceLinks = sourceLinks, + perPackageOptions = perPackageOptions, + externalDocumentationLinks = externalDocumentationLinks, languageVersion = languageVersion, apiVersion = apiVersion, noStdlibLink = noStdlibLink, noJdkLink = noJdkLink, suppressedFiles = suppressedFiles, - collectInheritedExtensionsFromLibraries = collectInheritedExtensionsFromLibraries, - analysisPlatform = Platform.fromString(analysisPlatform), - targets = targets, - sinceKotlin = sinceKotlin, - perPackageOptions = perPackageOptions, - externalDocumentationLinks = externalDocumentationLinks, - sourceLinks = sourceLinks + analysisPlatform = Platform.fromString(analysisPlatform) ) } -- cgit From cc89f0b74a870303c854fcb892d469d4c8fb17a8 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Tue, 9 Jun 2020 16:31:58 +0200 Subject: Gives text presentation for `SinceKotlin` and hides it from rendering. Hides `Deprecated`. #944 --- core/src/main/kotlin/model/doc/TagWrapper.kt | 2 +- core/src/main/kotlin/parsers/MarkdownParser.kt | 2 +- core/src/main/kotlin/parsers/Parser.kt | 2 +- plugins/base/src/main/kotlin/DokkaBase.kt | 5 ++ .../main/kotlin/signatures/KotlinSignatureUtils.kt | 10 ++- .../pages/annotations/SinceKotlinTransformer.kt | 82 ++++++++++++++++++++++ .../documentables/DefaultPageCreator.kt | 26 +++++-- .../annotations/ContentForAnnotationsTest.kt | 3 + plugins/base/src/test/kotlin/enums/EnumsTest.kt | 2 + plugins/base/src/test/kotlin/model/CommentTest.kt | 4 +- plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt | 4 +- 11 files changed, 129 insertions(+), 13 deletions(-) create mode 100644 plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt (limited to 'plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt') diff --git a/core/src/main/kotlin/model/doc/TagWrapper.kt b/core/src/main/kotlin/model/doc/TagWrapper.kt index 6652f5a1..af45e7eb 100644 --- a/core/src/main/kotlin/model/doc/TagWrapper.kt +++ b/core/src/main/kotlin/model/doc/TagWrapper.kt @@ -32,4 +32,4 @@ class Sample(root: DocTag, name: String) : NamedTagWrapper(root, name) class Deprecated(root: DocTag) : TagWrapper(root) class Property(root: DocTag, name: String) : NamedTagWrapper(root, name) class Suppress(root: DocTag) : TagWrapper(root) -class CustomWrapperTag(root: DocTag, name: String) : NamedTagWrapper(root, name) \ No newline at end of file +class CustomTagWrapper(root: DocTag, name: String) : NamedTagWrapper(root, name) \ No newline at end of file diff --git a/core/src/main/kotlin/parsers/MarkdownParser.kt b/core/src/main/kotlin/parsers/MarkdownParser.kt index 308a8fb6..07e1fcc3 100644 --- a/core/src/main/kotlin/parsers/MarkdownParser.kt +++ b/core/src/main/kotlin/parsers/MarkdownParser.kt @@ -371,7 +371,7 @@ class MarkdownParser( DocumentationNode( (listOf(kDocTag) + getAllKDocTags(findParent(kDocTag))).map { when (it.knownTag) { - null -> if (it.name == null) Description(parseStringToDocNode(it.getContent())) else CustomWrapperTag( + null -> if (it.name == null) Description(parseStringToDocNode(it.getContent())) else CustomTagWrapper( parseStringToDocNode(it.getContent()), it.name!! ) diff --git a/core/src/main/kotlin/parsers/Parser.kt b/core/src/main/kotlin/parsers/Parser.kt index 11dcafb0..05adc4d5 100644 --- a/core/src/main/kotlin/parsers/Parser.kt +++ b/core/src/main/kotlin/parsers/Parser.kt @@ -27,7 +27,7 @@ abstract class Parser { "deprecated" -> Deprecated(parseStringToDocNode(it.second)) "sample" -> Sample(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' ')) "suppress" -> Suppress(parseStringToDocNode(it.second)) - else -> CustomWrapperTag(parseStringToDocNode(it.second), it.first) + else -> CustomTagWrapper(parseStringToDocNode(it.second), it.first) } } return DocumentationNode(mappedList) diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index 46c92c15..9a04e729 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -15,6 +15,7 @@ import org.jetbrains.dokka.base.transformers.documentables.DocumentableVisibilit import org.jetbrains.dokka.base.transformers.documentables.ModuleAndPackageDocumentationTransformer import org.jetbrains.dokka.base.transformers.documentables.ReportUndocumentedTransformer import org.jetbrains.dokka.base.transformers.pages.annotations.DeprecatedStrikethroughTransformer +import org.jetbrains.dokka.base.transformers.pages.annotations.SinceKotlinTransformer import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter import org.jetbrains.dokka.base.transformers.pages.merger.FallbackPageMergerStrategy @@ -65,6 +66,10 @@ class DokkaBase : DokkaPlugin() { } } + val sinceKotlinTransformer by extending { + CoreExtensions.documentableTransformer providing ::SinceKotlinTransformer + } + val inheritorsExtractor by extending { CoreExtensions.documentableTransformer with InheritorsExtractorTransformer() } diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt index c8ff3fac..b312c8f0 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt @@ -1,7 +1,9 @@ package org.jetbrains.dokka.base.signatures import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder +import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.AdditionalModifiers +import org.jetbrains.dokka.model.Annotations import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.model.ExtraModifiers import org.jetbrains.dokka.model.properties.WithExtraProperties @@ -11,13 +13,17 @@ object KotlinSignatureUtils : JvmSignatureUtils { private val strategy = OnlyOnce private val listBrackets = Pair('[', ']') private val classExtension = "::class" + val ignoredAnnotations = setOf( + Annotations.Annotation(DRI("kotlin", "SinceKotlin"), emptyMap()), + Annotations.Annotation(DRI("kotlin", "Deprecated"), emptyMap()) + ) override fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: Documentable) = - annotationsBlockWithIgnored(d, emptySet(), strategy, listBrackets, classExtension) + annotationsBlockWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension) override fun PageContentBuilder.DocumentableContentBuilder.annotationsInline(d: Documentable) = - annotationsInlineWithIgnored(d, emptySet(), strategy, listBrackets, classExtension) + annotationsInlineWithIgnored(d, ignoredAnnotations, strategy, listBrackets, classExtension) override fun WithExtraProperties.modifiers() = extra[AdditionalModifiers]?.content?.entries?.map { diff --git a/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt new file mode 100644 index 00000000..7914e88f --- /dev/null +++ b/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt @@ -0,0 +1,82 @@ +package org.jetbrains.dokka.base.transformers.pages.annotations + +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.doc.CustomTagWrapper +import org.jetbrains.dokka.model.doc.Text +import org.jetbrains.dokka.model.properties.WithExtraProperties +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer +import org.jetbrains.kotlin.utils.addToStdlib.safeAs + +class SinceKotlinTransformer(val context: DokkaContext) : DocumentableTransformer { + + override fun invoke(original: DModule, context: DokkaContext) = original.transform() as DModule + + private fun T.transform(): Documentable = + when (this) { + is DModule -> copy( + packages = packages.map { it.transform() as DPackage } + ) + is DPackage -> copy( + classlikes = classlikes.map { it.transform() as DClasslike }, + functions = functions.map { it.transform() as DFunction }, + properties = properties.map { it.transform() as DProperty } + ) + is DClass -> copy( + documentation = appendSinceKotlin(), + classlikes = classlikes.map { it.transform() as DClasslike }, + functions = functions.map { it.transform() as DFunction }, + properties = properties.map { it.transform() as DProperty } + ) + is DEnum -> copy( + documentation = appendSinceKotlin(), + classlikes = classlikes.map { it.transform() as DClasslike }, + functions = functions.map { it.transform() as DFunction }, + properties = properties.map { it.transform() as DProperty } + ) + is DInterface -> copy( + documentation = appendSinceKotlin(), + classlikes = classlikes.map { it.transform() as DClasslike }, + functions = functions.map { it.transform() as DFunction }, + properties = properties.map { it.transform() as DProperty } + ) + is DObject -> copy( + documentation = appendSinceKotlin(), + classlikes = classlikes.map { it.transform() as DClasslike }, + functions = functions.map { it.transform() as DFunction }, + properties = properties.map { it.transform() as DProperty } + ) + is DAnnotation -> copy( + documentation = appendSinceKotlin(), + classlikes = classlikes.map { it.transform() as DClasslike }, + functions = functions.map { it.transform() as DFunction }, + properties = properties.map { it.transform() as DProperty } + ) + is DFunction -> copy( + documentation = appendSinceKotlin() + ) + is DProperty -> copy( + documentation = appendSinceKotlin() + ) + is DParameter -> copy( + documentation = appendSinceKotlin() + ) + else -> this.also { context.logger.warn("Unrecognized documentable $this while SinceKotlin transformation") } + } + + private fun Documentable.appendSinceKotlin() = + sourceSets.fold(documentation) { acc, sourceSet -> + safeAs>()?.extra?.get(Annotations)?.content?.get(sourceSet)?.find { + it.dri == DRI("kotlin", "SinceKotlin") + }?.params?.get("version").safeAs()?.value?.let { version -> + acc.mapValues { + if (it.key == sourceSet) it.value.copy( + it.value.children + listOf( + CustomTagWrapper(Text(version.dropWhile { it == '"' }.dropLastWhile { it == '"' }), "Since Kotlin") + ) + ) else it.value + } + } ?: acc + } +} \ 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 a6dd337a..8c7707f8 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -247,6 +247,8 @@ open class DefaultPageCreator( } } } + + contentForSinceKotlin(d) }.children } @@ -352,9 +354,9 @@ open class DefaultPageCreator( }.children } - protected open fun DocumentableContentBuilder.contentForBrief(content: Documentable) { - content.sourceSets.forEach { sourceSet -> - content.documentation[sourceSet]?.children?.firstOrNull()?.root?.let { + protected open fun DocumentableContentBuilder.contentForBrief(documentable: Documentable) { + documentable.sourceSets.forEach { sourceSet -> + documentable.documentation[sourceSet]?.children?.firstOrNull()?.root?.let { group(sourceSets = setOf(sourceSet), kind = ContentKind.BriefComment) { comment(it) } @@ -362,6 +364,21 @@ open class DefaultPageCreator( } } + protected open fun DocumentableContentBuilder.contentForSinceKotlin(documentable: Documentable) { + documentable.documentation.mapValues { + it.value.children.find { it is CustomTagWrapper && it.name == "Since Kotlin" } as CustomTagWrapper? + }.run { + documentable.sourceSets.forEach { sourceSet -> + this[sourceSet]?.also { tag -> + group(sourceSets = setOf(sourceSet)) { + header(4, (tag as CustomTagWrapper).name) + comment(tag.root) + } + } + } + } + } + protected open fun contentForFunction(f: DFunction) = contentForMember(f) protected open fun contentForTypeAlias(t: DTypeAlias) = contentForMember(t) protected open fun contentForMember(d: Documentable) = contentBuilder.contentFor(d) { @@ -385,7 +402,7 @@ open class DefaultPageCreator( name: String, collection: Collection, kind: ContentKind, - extra: PropertyContainer = mainExtra, + extra: PropertyContainer = mainExtra ) { if (collection.any()) { header(2, name) @@ -405,6 +422,7 @@ open class DefaultPageCreator( instance(setOf(it.dri), it.sourceSets.toSet()) { before { contentForBrief(it) + contentForSinceKotlin(it) } divergent { group { diff --git a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt index f91b82d5..ff4e3024 100644 --- a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt +++ b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt @@ -4,6 +4,7 @@ import matchers.content.* import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.pages.PackagePageNode import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import utils.ParamAttributes import utils.bareSignature @@ -72,6 +73,7 @@ class ContentForAnnotationsTest : AbstractCoreTest() { } } + @Disabled @Test fun `property`() { testInline( @@ -100,6 +102,7 @@ class ContentForAnnotationsTest : AbstractCoreTest() { |/src/main/kotlin/test/source.kt |package test | + |@MustBeDocumented |@Retention(AnnotationRetention.SOURCE) |@Target(AnnotationTarget.FIELD) |annotation class BugReport( diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt index 125e37e2..7feba710 100644 --- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt +++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt @@ -6,6 +6,7 @@ import org.jetbrains.dokka.model.DEnum import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import utils.unwrapAnnotation @@ -176,6 +177,7 @@ class EnumsTest : AbstractCoreTest() { } } + @Disabled @Test fun enumWithAnnotationsOnEntries(){ val configuration = dokkaConfiguration { diff --git a/plugins/base/src/test/kotlin/model/CommentTest.kt b/plugins/base/src/test/kotlin/model/CommentTest.kt index b1faa07f..c1da8ee0 100644 --- a/plugins/base/src/test/kotlin/model/CommentTest.kt +++ b/plugins/base/src/test/kotlin/model/CommentTest.kt @@ -1,7 +1,7 @@ package model import org.jetbrains.dokka.model.DProperty -import org.jetbrains.dokka.model.doc.CustomWrapperTag +import org.jetbrains.dokka.model.doc.CustomTagWrapper import org.jetbrains.dokka.model.doc.Text import org.junit.jupiter.api.Test import utils.* @@ -170,7 +170,7 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme ) { with((this / "comment" / "property").cast()) { comments() equals "Summary\none: []" - docs().find { it is CustomWrapperTag && it.name == "one" }.let { + docs().find { it is CustomTagWrapper && it.name == "one" }.let { with(it.assertNotNull("'one' entry")) { root.children counts 0 root.params.keys counts 0 diff --git a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt index 1d62fd17..9e6ed965 100644 --- a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt +++ b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt @@ -2,7 +2,7 @@ package org.jetbrains.dokka.mathjax import org.jetbrains.dokka.CoreExtensions -import org.jetbrains.dokka.model.doc.CustomWrapperTag +import org.jetbrains.dokka.model.doc.CustomTagWrapper import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaPlugin @@ -28,5 +28,5 @@ object MathjaxTransformer : PageTransformer { get() = documentable?.documentation?.values ?.flatMap { it.children } .orEmpty() - .any { (it as? CustomWrapperTag)?.name == ANNOTATION } + .any { (it as? CustomTagWrapper)?.name == ANNOTATION } } \ No newline at end of file -- cgit From 75efaa5662fd7bfe9ada0756509f34bdb35f3341 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Wed, 10 Jun 2020 11:52:29 +0200 Subject: Tests for SinceKotlin and Deprecated --- .../annotations/ContentForAnnotationsTest.kt | 81 ++++++++++++++-- .../annotations/DepredatedAndSinceKotlinTest.kt | 107 +++++++++++++++++++++ plugins/base/src/test/kotlin/enums/EnumsTest.kt | 16 +-- 3 files changed, 185 insertions(+), 19 deletions(-) create mode 100644 plugins/base/src/test/kotlin/content/annotations/DepredatedAndSinceKotlinTest.kt (limited to 'plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt') diff --git a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt index ff4e3024..7add4119 100644 --- a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt +++ b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt @@ -4,11 +4,9 @@ import matchers.content.* import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.pages.PackagePageNode import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import utils.ParamAttributes import utils.bareSignature -import utils.functionSignature import utils.propertySignature @@ -25,7 +23,7 @@ class ContentForAnnotationsTest : AbstractCoreTest() { } @Test - fun `function`() { + fun `function with documented annotation`() { testInline( """ |/src/main/kotlin/test/source.kt @@ -73,9 +71,55 @@ class ContentForAnnotationsTest : AbstractCoreTest() { } } - @Disabled @Test - fun `property`() { + fun `function with undocumented annotation`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, + | AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.EXPRESSION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FIELD + |) + |@Retention(AnnotationRetention.SOURCE) + |annotation class Fancy + | + |@Fancy + |fun function(@Fancy abc: String): String { + | return "Hello, " + abc + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "function" } as ContentPage + page.content.assertNode { + group { + header(1) { +"function" } + } + divergentGroup { + divergentInstance { + divergent { + bareSignature( + emptyMap(), + "", + "", + emptySet(), + "function", + "String", + "abc" to ParamAttributes(emptyMap(), emptySet(), "String") + ) + } + } + } + + } + } + } + } + + @Test + fun `property with undocumented annotation`() { testInline( """ |/src/main/kotlin/test/source.kt @@ -88,7 +132,30 @@ class ContentForAnnotationsTest : AbstractCoreTest() { pagesTransformationStage = { module -> val page = module.children.single { it.name == "test" } as PackagePageNode page.content.assertNode { - propertySignature(mapOf("Suppress" to setOf("names")), "", "", emptySet(), "val", "property", "Int") + propertySignature(emptyMap(), "", "", emptySet(), "val", "property", "Int") + } + } + } + } + + @Test + fun `property with documented annotation`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |@MustBeDocumented + |annotation class Fancy + | + |@Fancy + |val property: Int = 6 + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } as PackagePageNode + page.content.assertNode { + propertySignature(mapOf("Fancy" to emptySet()), "", "", emptySet(), "val", "property", "Int") } } } @@ -96,7 +163,7 @@ class ContentForAnnotationsTest : AbstractCoreTest() { @Test - fun `rich annotation`() { + fun `rich documented annotation`() { testInline( """ |/src/main/kotlin/test/source.kt diff --git a/plugins/base/src/test/kotlin/content/annotations/DepredatedAndSinceKotlinTest.kt b/plugins/base/src/test/kotlin/content/annotations/DepredatedAndSinceKotlinTest.kt new file mode 100644 index 00000000..b5150ed1 --- /dev/null +++ b/plugins/base/src/test/kotlin/content/annotations/DepredatedAndSinceKotlinTest.kt @@ -0,0 +1,107 @@ +package content.annotations + + +import matchers.content.* +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.PackagePageNode +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Test +import utils.ParamAttributes +import utils.bareSignature +import utils.propertySignature + + +class DepredatedAndSinceKotlinTest : AbstractCoreTest() { + + private val testConfiguration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + analysisPlatform = "jvm" + targets = listOf("jvm") + } + } + } + + @Test + fun `function with deprecated annotation`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |@Deprecated("And some things that should not have been forgotten were lost. History became legend. Legend became myth.") + |fun ring(abc: String): String { + | return "My precious " + abc + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "ring" } as ContentPage + page.content.assertNode { + group { + header(1) { +"ring" } + } + divergentGroup { + divergentInstance { + divergent { + bareSignature( + emptyMap(), + "", + "", + emptySet(), + "ring", + "String", + "abc" to ParamAttributes(emptyMap(), emptySet(), "String") + ) + } + } + } + + } + } + } + } + + @Test + fun `function with since kotlin annotation`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |@SinceKotlin("1.3") + |fun ring(abc: String): String { + | return "My precious " + abc + |} + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } + .children.single { it.name == "ring" } as ContentPage + page.content.assertNode { + group { + header(1) { +"ring" } + } + divergentGroup { + divergentInstance { + divergent { + bareSignature( + emptyMap(), + "", + "", + emptySet(), + "ring", + "String", + "abc" to ParamAttributes(emptyMap(), emptySet(), "String") + ) + } + } + } + + } + } + } + } +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt index 7feba710..695a8fd2 100644 --- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt +++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt @@ -6,9 +6,7 @@ import org.jetbrains.dokka.model.DEnum import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import utils.unwrapAnnotation class EnumsTest : AbstractCoreTest() { @@ -177,7 +175,6 @@ class EnumsTest : AbstractCoreTest() { } } - @Disabled @Test fun enumWithAnnotationsOnEntries(){ val configuration = dokkaConfiguration { @@ -197,7 +194,7 @@ class EnumsTest : AbstractCoreTest() { | /** | Sample docs for E1 | **/ - | @SinceKotlin("1.3") + | @SinceKotlin("1.3") // This annotation is transparent due to lack of @MustBeDocumented annotation | E1 |} """.trimMargin(), @@ -216,14 +213,9 @@ class EnumsTest : AbstractCoreTest() { } } group { - mapOf("SinceKotlin" to setOf("version")).entries.forEach { - group { - group { - unwrapAnnotation(it) - } - link { +"E1" } - +"()" - } + group { + link { +"E1" } + +"()" } } } -- cgit From b0e8622f374f6499058b0f083367b4a54512b702 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 30 Jun 2020 23:06:03 +0200 Subject: Enforce workspace unique SourceSetID --- build.gradle.kts | 4 +- core/src/main/kotlin/DokkaBootstrapImpl.kt | 5 +- core/src/main/kotlin/DokkaGenerator.kt | 2 +- .../main/kotlin/DokkaMultimoduleBootstrapImpl.kt | 5 +- core/src/main/kotlin/configuration.kt | 27 ++- core/src/main/kotlin/defaultConfiguration.kt | 22 ++- core/src/main/kotlin/plugability/DokkaPlugin.kt | 2 +- .../org/jetbrains/dokka/analysis/KotlinAnalysis.kt | 5 +- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 22 +-- .../main/kotlin/signatures/JvmSignatureUtils.kt | 3 +- .../DocumentableVisibilityFilterTransformer.kt | 12 +- .../EmptyPackagesFilterTransformer.kt | 6 +- .../ModuleAndPackageDocumentationTransformer.kt | 4 +- .../pages/samples/SamplesTransformer.kt | 4 +- .../DefaultDescriptorToDocumentableTranslator.kt | 4 +- .../psi/DefaultPsiToDocumentableTranslator.kt | 2 +- plugins/base/src/test/kotlin/basic/DRITest.kt | 40 ++-- .../base/src/test/kotlin/basic/DokkaBasicTests.kt | 6 +- .../src/test/kotlin/basic/FailOnWarningTest.kt | 18 +- .../annotations/ContentForAnnotationsTest.kt | 6 +- .../annotations/DepredatedAndSinceKotlinTest.kt | 8 +- .../kotlin/content/params/ContentForParamsTest.kt | 4 +- .../content/seealso/ContentForSeeAlsoTest.kt | 6 +- .../content/signatures/ContentForSignaturesTest.kt | 4 +- .../SkippingParenthesisForConstructorsTest.kt | 6 +- plugins/base/src/test/kotlin/enums/EnumsTest.kt | 20 +- .../src/test/kotlin/expect/AbstractExpectTest.kt | 6 +- .../test/kotlin/filter/DeprecationFilterTest.kt | 22 +-- .../test/kotlin/filter/EmptyPackagesFilterTest.kt | 11 +- .../src/test/kotlin/filter/VisibilityFilterTest.kt | 22 +-- plugins/base/src/test/kotlin/issues/IssuesTest.kt | 6 +- .../kotlin/linkableContent/LinkableContentTest.kt | 38 ++-- .../DefaultLocationProviderTest.kt | 6 +- plugins/base/src/test/kotlin/markdown/KDocTest.kt | 6 +- plugins/base/src/test/kotlin/markdown/LinkTest.kt | 10 +- .../base/src/test/kotlin/model/InheritorsTest.kt | 8 +- plugins/base/src/test/kotlin/model/PropertyTest.kt | 6 +- .../kotlin/multiplatform/BasicMultiplatformTest.kt | 10 +- .../test/kotlin/pageMerger/PageNodeMergerTest.kt | 10 +- .../test/kotlin/renderers/html/DivergentTest.kt | 8 +- .../renderers/html/SourceSetDependentHintTest.kt | 8 +- .../test/kotlin/renderers/html/defaultSourceSet.kt | 9 +- .../test/kotlin/resourceLinks/ResourceLinksTest.kt | 6 +- .../PageTransformerBuilderTest.kt | 12 +- .../ReportUndocumentedTransformerTest.kt | 136 ++++++------- .../DefaultPsiToDocumentableTranslatorTest.kt | 14 +- plugins/base/src/test/kotlin/utils/ModelUtils.kt | 4 +- plugins/gfm/src/main/kotlin/GfmPlugin.kt | 6 +- .../javadoc/AbstractJavadocTemplateMapTest.kt | 5 +- .../javadoc/src/test/kotlin/javadoc/JavadocTest.kt | 4 +- .../kotlin/javadoc/location/JavadocLocationTest.kt | 6 +- .../src/test/kotlin/KotlinAsJavaPluginTest.kt | 13 +- runners/ant/build.gradle | 18 -- runners/ant/src/main/kotlin/ant/dokka.kt | 210 --------------------- runners/ant/src/main/resources/dokka-antlib.xml | 3 - runners/cli/build.gradle.kts | 3 +- runners/cli/src/main/kotlin/cli/main.kt | 57 +++--- runners/gradle-plugin/build.gradle.kts | 2 + .../dokka/gradle/ConfigurationExtractor.kt | 2 +- .../jetbrains/dokka/gradle/DokkaCollectorTask.kt | 8 +- .../dokka/gradle/DokkaSourceSetIDFactory.kt | 10 + .../kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt | 36 ++-- .../dokka/gradle/configurationImplementations.kt | 93 +++++++-- .../main/kotlin/org/jetbrains/dokka/gradle/main.kt | 4 +- .../gradle/KotlinDslDokkaTaskConfigurationTest.kt | 77 ++++++++ runners/maven-plugin/src/main/kotlin/DokkaMojo.kt | 14 +- .../src/main/kotlin/testApi/context/MockContext.kt | 3 +- .../testApi/testRunner/DokkaTestGenerator.kt | 3 +- .../main/kotlin/testApi/testRunner/TestRunner.kt | 19 +- 69 files changed, 567 insertions(+), 634 deletions(-) delete mode 100644 runners/ant/build.gradle delete mode 100644 runners/ant/src/main/kotlin/ant/dokka.kt delete mode 100644 runners/ant/src/main/resources/dokka-antlib.xml create mode 100644 runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaSourceSetIDFactory.kt (limited to 'plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt') diff --git a/build.gradle.kts b/build.gradle.kts index c94faa77..04f4afd4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,7 +19,7 @@ allprojects { val language_version: String by project tasks.withType(KotlinCompile::class).all { kotlinOptions { - freeCompilerArgs += "-Xjsr305=strict -Xskip-metadata-version-check" + freeCompilerArgs += "-Xjsr305=strict -Xskip-metadata-version-check -Xopt-in=kotlin.RequiresOptIn." languageVersion = language_version apiVersion = language_version jvmTarget = "1.8" @@ -49,4 +49,4 @@ subprojects { } } -println("Publication version: $dokka_version") \ No newline at end of file +println("Publication version: $dokka_version") diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index bd632546..be3d6c9b 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -1,8 +1,6 @@ package org.jetbrains.dokka -import com.google.gson.Gson import org.jetbrains.dokka.DokkaConfiguration.PackageOptions -import org.jetbrains.dokka.utilities.DokkaConsoleLogger import org.jetbrains.dokka.utilities.DokkaLogger import java.util.function.BiConsumer @@ -80,7 +78,6 @@ class DokkaBootstrapImpl : DokkaBootstrap { } private lateinit var generator: DokkaGenerator - val gson = Gson() fun configure(logger: DokkaLogger, configuration: DokkaConfigurationImpl) = with(configuration) { @@ -113,7 +110,7 @@ class DokkaBootstrapImpl : DokkaBootstrap { override fun configure(logger: BiConsumer, serializedConfigurationJSON: String) = configure( DokkaProxyLogger(logger), - gson.fromJson(serializedConfigurationJSON, DokkaConfigurationImpl::class.java) + DokkaConfigurationImpl(serializedConfigurationJSON) ) override fun generate() = generator.generate() diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index ce8d229a..ee1adf0b 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -68,7 +68,7 @@ class DokkaGenerator( fun createDocumentationModels( context: DokkaContext ) = context.configuration.sourceSets - .flatMap { passConfiguration -> translateSources(passConfiguration, context) } + .flatMap { sourceSet -> translateSources(sourceSet, context) } fun transformDocumentationModelBeforeMerge( modulesFromPlatforms: List, diff --git a/core/src/main/kotlin/DokkaMultimoduleBootstrapImpl.kt b/core/src/main/kotlin/DokkaMultimoduleBootstrapImpl.kt index 6825ce64..70b99f8d 100644 --- a/core/src/main/kotlin/DokkaMultimoduleBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaMultimoduleBootstrapImpl.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka -import com.google.gson.Gson import org.jetbrains.dokka.DokkaBootstrapImpl.DokkaProxyLogger import org.jetbrains.dokka.utilities.DokkaLogger import java.util.function.BiConsumer @@ -15,11 +14,11 @@ class DokkaMultimoduleBootstrapImpl : DokkaBootstrap { override fun configure(logger: BiConsumer, serializedConfigurationJSON: String) = configure( DokkaProxyLogger(logger), - Gson().fromJson(serializedConfigurationJSON, DokkaConfigurationImpl::class.java) + DokkaConfigurationImpl(serializedConfigurationJSON) ) override fun generate() { generator.generateAllModulesPage() } -} \ No newline at end of file +} diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 463d2342..c531ab9a 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -1,6 +1,10 @@ +@file:Suppress("FunctionName") + package org.jetbrains.dokka +import com.google.gson.Gson import java.io.File +import java.io.Serializable import java.net.URL object DokkaDefaults { @@ -43,6 +47,23 @@ enum class Platform(val key: String) { } } +data class DokkaSourceSetID( + val moduleName: String, + val sourceSetName: String +) : Serializable { + override fun toString(): String { + return "$moduleName/$sourceSetName" + } +} + +fun DokkaConfigurationImpl(json: String): DokkaConfigurationImpl { + return Gson().fromJson(json, DokkaConfigurationImpl::class.java) +} + +fun DokkaConfiguration.toJson(): String { + return Gson().toJson(this) +} + interface DokkaConfiguration { val outputDir: String val format: String @@ -55,12 +76,12 @@ interface DokkaConfiguration { val pluginsConfiguration: Map interface DokkaSourceSet { - val moduleName: String + val sourceSetID: DokkaSourceSetID val displayName: String - val sourceSetID: String + val moduleDisplayName: String val classpath: List val sourceRoots: List - val dependentSourceSets: List + val dependentSourceSets: Set val samples: List val includes: List val includeNonPublic: Boolean diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index d3ac9df2..47bd7fe2 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka +import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import java.io.File import java.net.URL @@ -16,12 +17,12 @@ data class DokkaConfigurationImpl( ) : DokkaConfiguration data class DokkaSourceSetImpl( - override val moduleName: String, + override val moduleDisplayName: String, override val displayName: String, - override val sourceSetID: String, + override val sourceSetID: DokkaSourceSetID, override val classpath: List, override val sourceRoots: List, - override val dependentSourceSets: List, + override val dependentSourceSets: Set, override val samples: List, override val includes: List, override val includeNonPublic: Boolean, @@ -39,23 +40,23 @@ data class DokkaSourceSetImpl( override val noJdkLink: Boolean, override val suppressedFiles: List, override val analysisPlatform: Platform -) : DokkaConfiguration.DokkaSourceSet +) : DokkaSourceSet data class DokkaModuleDescriptionImpl( override val name: String, override val path: String, override val docFile: String -): DokkaConfiguration.DokkaModuleDescription +) : DokkaConfiguration.DokkaModuleDescription data class SourceRootImpl( override val path: String -): DokkaConfiguration.SourceRoot +) : DokkaConfiguration.SourceRoot data class SourceLinkDefinitionImpl( override val path: String, override val url: String, override val lineSuffix: String? -): DokkaConfiguration.SourceLinkDefinition { +) : DokkaConfiguration.SourceLinkDefinition { companion object { fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinitionImpl { val (path, urlAndLine) = srcLink.split('=') @@ -73,9 +74,10 @@ data class PackageOptionsImpl( override val reportUndocumented: Boolean?, override val skipDeprecated: Boolean, override val suppress: Boolean -): DokkaConfiguration.PackageOptions +) : DokkaConfiguration.PackageOptions -data class ExternalDocumentationLinkImpl(override val url: URL, - override val packageListUrl: URL +data class ExternalDocumentationLinkImpl( + override val url: URL, + override val packageListUrl: URL ) : DokkaConfiguration.ExternalDocumentationLink diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt index fe472b12..7ead43b8 100644 --- a/core/src/main/kotlin/plugability/DokkaPlugin.kt +++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt @@ -82,4 +82,4 @@ inline fun configuratio } } } -} \ No newline at end of file +} diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/KotlinAnalysis.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/KotlinAnalysis.kt index 426ffdde..e723768c 100644 --- a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/KotlinAnalysis.kt +++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/KotlinAnalysis.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.analysis import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet +import org.jetbrains.dokka.DokkaSourceSetID import org.jetbrains.dokka.model.SourceSetDependent import org.jetbrains.dokka.plugability.DokkaContext @@ -21,7 +22,7 @@ fun KotlinAnalysis(context: DokkaContext): KotlinAnalysis { interface KotlinAnalysis : SourceSetDependent { override fun get(key: DokkaSourceSet): EnvironmentAndFacade - operator fun get(sourceSetID: String): EnvironmentAndFacade + operator fun get(sourceSetID: DokkaSourceSetID): EnvironmentAndFacade } internal class KotlinAnalysisImpl( @@ -32,7 +33,7 @@ internal class KotlinAnalysisImpl( return environments[key] ?: throw IllegalStateException("Missing EnvironmentAndFacade for sourceSet $key") } - override fun get(sourceSetID: String): EnvironmentAndFacade { + override fun get(sourceSetID: DokkaSourceSetID): EnvironmentAndFacade { return environments.entries.first { (sourceSet, _) -> sourceSet.sourceSetID == sourceSetID }.value } } diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index de892bb1..f8fa3b2e 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -94,7 +94,7 @@ open class HtmlRenderer( group.sourceSets.forEach { button(classes = "platform-tag platform-selector") { attributes["data-active"] = "" - attributes["data-filter"] = it.sourceSetID + attributes["data-filter"] = it.sourceSetID.toString() when (it.analysisPlatform.key) { "common" -> classes = classes + "common-like" "native" -> classes = classes + "native-like" @@ -168,10 +168,10 @@ open class HtmlRenderer( attributes["data-toggle-list"] = "data-toggle-list" contents.forEachIndexed { index, pair -> button(classes = "platform-bookmark") { - attributes["data-filterable-current"] = pair.first.sourceSetID - attributes["data-filterable-set"] = pair.first.sourceSetID + attributes["data-filterable-current"] = pair.first.sourceSetID.toString() + attributes["data-filterable-set"] = pair.first.sourceSetID.toString() if (index == 0) attributes["data-active"] = "" - attributes["data-toggle"] = pair.first.sourceSetID + attributes["data-toggle"] = pair.first.sourceSetID.toString() when ( pair.first.analysisPlatform.key ) { @@ -180,7 +180,7 @@ open class HtmlRenderer( "jvm" -> classes = classes + "jvm-like" "js" -> classes = classes + "js-like" } - attributes["data-toggle"] = pair.first.sourceSetID + attributes["data-toggle"] = pair.first.sourceSetID.toString() text(pair.first.displayName) } } @@ -212,7 +212,7 @@ open class HtmlRenderer( }.map { it to createHTML(prettyPrint = false).div(classes = "content sourceset-depenent-content") { if (counter++ == 0) attributes["data-active"] = "" - attributes["data-togglable"] = it.sourceSetID + attributes["data-togglable"] = it.sourceSetID.toString() unsafe { +html } @@ -249,10 +249,10 @@ open class HtmlRenderer( consumer.onTagContentUnsafe { +createHTML().div("divergent-group") { attributes["data-filterable-current"] = groupedDivergent.keys.joinToString(" ") { - it.sourceSetID + it.sourceSetID.toString() } attributes["data-filterable-set"] = groupedDivergent.keys.joinToString(" ") { - it.sourceSetID + it.sourceSetID.toString() } val divergentForPlatformDependent = groupedDivergent.map { (sourceSet, elements) -> @@ -353,10 +353,10 @@ open class HtmlRenderer( div(classes = "table-row") { if (!style.contains(MultimoduleTable)) { attributes["data-filterable-current"] = node.sourceSets.joinToString(" ") { - it.sourceSetID + it.sourceSetID.toString() } attributes["data-filterable-set"] = node.sourceSets.joinToString(" ") { - it.sourceSetID + it.sourceSetID.toString() } } @@ -728,4 +728,4 @@ private fun String.stripDiv() = drop(5).dropLast(6) // TODO: Find a way to do it private val PageNode.isNavigable: Boolean get() = this !is RendererSpecificPage || strategy != RenderingStrategy.DoNothing -fun PropertyContainer.extraHtmlAttributes() = allOfType() \ No newline at end of file +fun PropertyContainer.extraHtmlAttributes() = allOfType() diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt index f042eae3..2a242948 100644 --- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka.base.signatures -import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* @@ -142,4 +141,4 @@ interface JvmSignatureUtils { sealed class AtStrategy object All : AtStrategy() object OnlyOnce : AtStrategy() -object Never : AtStrategy() \ No newline at end of file +object Never : AtStrategy() diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt index c3cc4d38..ff05beed 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt @@ -9,11 +9,9 @@ import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMergeDocumentableTransformer { override fun invoke(modules: List) = modules.map { original -> - val passOptions = original.sourceSets.single() - val packageOptions = passOptions.perPackageOptions - original.let { - DocumentableVisibilityFilter(packageOptions, passOptions).processModule(it) - } + val sourceSet = original.sourceSets.single() + val packageOptions = sourceSet.perPackageOptions + DocumentableVisibilityFilter(packageOptions, sourceSet).processModule(original) } private class DocumentableVisibilityFilter( @@ -45,7 +43,7 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe private fun filterPackages(packages: List): Pair> { var packagesListChanged = false - val filteredPackages = packages.mapNotNull { + val filteredPackages = packages.map { var modified = false val functions = filterFunctions(it.functions).let { (listModified, list) -> modified = modified || listModified @@ -326,4 +324,4 @@ class DocumentableVisibilityFilterTransformer(val context: DokkaContext) : PreMe return Pair(classlikesListChanged, filteredClasslikes) } } -} \ No newline at end of file +} diff --git a/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt index 3fd0081a..61abfbd7 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt @@ -14,9 +14,9 @@ class EmptyPackagesFilterTransformer(val context: DokkaContext) : PreMergeDocume } private class EmptyPackagesFilter( - val passOptions: DokkaConfiguration.DokkaSourceSet + val sourceSet: DokkaConfiguration.DokkaSourceSet ) { - fun DPackage.shouldBeSkipped() = passOptions.skipEmptyPackages && + fun DPackage.shouldBeSkipped() = sourceSet.skipEmptyPackages && functions.isEmpty() && properties.isEmpty() && classlikes.isEmpty() @@ -25,4 +25,4 @@ class EmptyPackagesFilterTransformer(val context: DokkaContext) : PreMergeDocume packages = module.packages.filter { !it.shouldBeSkipped() } ) } -} \ No newline at end of file +} diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt index 1f718a7c..a0800da8 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt @@ -1,12 +1,10 @@ package org.jetbrains.dokka.base.transformers.documentables -import org.jetbrains.dokka.analysis.EnvironmentAndFacade import org.jetbrains.dokka.analysis.KotlinAnalysis import org.jetbrains.dokka.model.DModule import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.base.parsers.MarkdownParser -import org.jetbrains.dokka.model.SourceSetDependent import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer import org.jetbrains.kotlin.name.FqName @@ -24,7 +22,7 @@ internal class ModuleAndPackageDocumentationTransformer( val modulesAndPackagesDocumentation = context.configuration.sourceSets .map { - Pair(it.moduleName, it) to + Pair(it.moduleDisplayName, it) to it.includes.map { Paths.get(it) } .also { it.forEach { diff --git a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt index b39715a7..41dea1a2 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt @@ -67,7 +67,7 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { analysis: Map ): ContentNode { val facade = analysis[platform]?.facade - ?: return this.also { context.logger.warn("Cannot resolve facade for platform ${platform.moduleName}") } + ?: return this.also { context.logger.warn("Cannot resolve facade for platform ${platform.moduleDisplayName}") } val psiElement = fqNameToPsiElement(facade, fqName) ?: return this.also { context.logger.warn("Cannot find PsiElement corresponding to $fqName") } val imports = @@ -147,4 +147,4 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { style = styles + ContentStyle.RunnableSample + TextStyle.Monospace, extra = extra ) -} \ 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 9cdd251c..b0374014 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotated import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies import org.jetbrains.kotlin.idea.kdoc.findKDoc -import org.jetbrains.kotlin.idea.kdoc.isBoringBuiltinClass import org.jetbrains.kotlin.load.kotlin.toSourceElement import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.* @@ -36,7 +35,6 @@ import org.jetbrains.kotlin.resolve.constants.KClassValue.Value.NormalClass import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperclassesWithoutAny import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces -import org.jetbrains.kotlin.resolve.jvm.isInlineClassThatRequiresMangling import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.resolve.source.KotlinSourceElement @@ -71,7 +69,7 @@ class DefaultDescriptorToDocumentableTranslator( DRIWithPlatformInfo(DRI.topLevel, emptyMap()) ) } - }.let { DModule(sourceSet.moduleName, it, emptyMap(), null, setOf(sourceSet)) } + }.let { DModule(sourceSet.moduleDisplayName, it, emptyMap(), null, setOf(sourceSet)) } } } diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 76f8319d..5a55e3ec 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -68,7 +68,7 @@ class DefaultPsiToDocumentableTranslator( context.logger ) return DModule( - sourceSet.moduleName, + sourceSet.moduleDisplayName, psiFiles.mapNotNull { it.safeAs() }.groupBy { it.packageName }.map { (packageName, psiFiles) -> val dri = DRI(packageName = packageName) DPackage( diff --git a/plugins/base/src/test/kotlin/basic/DRITest.kt b/plugins/base/src/test/kotlin/basic/DRITest.kt index 1f4c7d93..559a2dbf 100644 --- a/plugins/base/src/test/kotlin/basic/DRITest.kt +++ b/plugins/base/src/test/kotlin/basic/DRITest.kt @@ -5,19 +5,19 @@ import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.Nullable import org.jetbrains.dokka.links.TypeConstructor import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.pages.* -import org.jetbrains.dokka.pages.dfs -import org.junit.jupiter.api.Assertions.assertEquals +import org.jetbrains.dokka.pages.ClasslikePageNode +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.MemberPageNode import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest - +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class DRITest : AbstractCoreTest() { @Test fun issue634() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -52,8 +52,8 @@ class DRITest : AbstractCoreTest() { @Test fun issue634WithImmediateNullableSelf() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -82,8 +82,8 @@ class DRITest : AbstractCoreTest() { @Test fun issue634WithGenericNullableReceiver() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -112,8 +112,8 @@ class DRITest : AbstractCoreTest() { @Test fun issue642WithStarAndAny() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { analysisPlatform = "js" sourceRoots = listOf("src/") } @@ -171,8 +171,8 @@ class DRITest : AbstractCoreTest() { @Test fun driForGenericClass(){ val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -201,8 +201,8 @@ class DRITest : AbstractCoreTest() { @Test fun driForGenericFunction(){ val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") classpath = listOfNotNull(jvmStdlibPath) } @@ -243,8 +243,8 @@ class DRITest : AbstractCoreTest() { @Test fun driForFunctionNestedInsideInnerClass() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") classpath = listOfNotNull(jvmStdlibPath) } @@ -280,8 +280,8 @@ class DRITest : AbstractCoreTest() { @Test fun driForGenericExtensionFunction(){ val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } diff --git a/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt b/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt index 5cc17bf3..bceb79ae 100644 --- a/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt +++ b/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt @@ -11,8 +11,8 @@ class DokkaBasicTests : AbstractCoreTest() { @Test fun basic1() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/basic/Test.kt") } } @@ -39,4 +39,4 @@ class DokkaBasicTests : AbstractCoreTest() { private fun ModulePageNode.getClasslikeToMemberMap() = this.parentMap.filterValues { it is ClasslikePageNode }.entries.groupBy({ it.value }) { it.key } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt b/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt index d548b75b..9d2c5825 100644 --- a/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt +++ b/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt @@ -14,8 +14,8 @@ class FailOnWarningTest : AbstractCoreTest() { fun `throws exception if one or more warnings were emitted`() { val configuration = dokkaConfiguration { failOnWarning = true - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin") } } @@ -39,8 +39,8 @@ class FailOnWarningTest : AbstractCoreTest() { fun `throws exception if one or more error were emitted`() { val configuration = dokkaConfiguration { failOnWarning = true - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin") } } @@ -66,8 +66,8 @@ class FailOnWarningTest : AbstractCoreTest() { val configuration = dokkaConfiguration { failOnWarning = true - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin") } } @@ -88,8 +88,8 @@ class FailOnWarningTest : AbstractCoreTest() { fun `does not throw if disabled`() { val configuration = dokkaConfiguration { failOnWarning = false - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin") } } @@ -115,4 +115,4 @@ private class ZeroErrorOrWarningCountDokkaLogger( ) : DokkaLogger by logger { override var warningsCount: Int = 0 override var errorsCount: Int = 0 -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt index 7add4119..bf78b847 100644 --- a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt +++ b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt @@ -14,8 +14,8 @@ class ContentForAnnotationsTest : AbstractCoreTest() { private val testConfiguration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") analysisPlatform = "jvm" } @@ -218,4 +218,4 @@ class ContentForAnnotationsTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/content/annotations/DepredatedAndSinceKotlinTest.kt b/plugins/base/src/test/kotlin/content/annotations/DepredatedAndSinceKotlinTest.kt index 99ec25c5..69de1bcd 100644 --- a/plugins/base/src/test/kotlin/content/annotations/DepredatedAndSinceKotlinTest.kt +++ b/plugins/base/src/test/kotlin/content/annotations/DepredatedAndSinceKotlinTest.kt @@ -3,19 +3,17 @@ package content.annotations import matchers.content.* import org.jetbrains.dokka.pages.ContentPage -import org.jetbrains.dokka.pages.PackagePageNode import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Test import utils.ParamAttributes import utils.bareSignature -import utils.propertySignature class DepredatedAndSinceKotlinTest : AbstractCoreTest() { private val testConfiguration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") analysisPlatform = "jvm" } @@ -102,4 +100,4 @@ class DepredatedAndSinceKotlinTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt index f6e80891..a9689bc5 100644 --- a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt +++ b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt @@ -17,8 +17,8 @@ import utils.* class ContentForParamsTest : AbstractCoreTest() { private val testConfiguration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") analysisPlatform = "jvm" } diff --git a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt index 696c3032..24970660 100644 --- a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt +++ b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt @@ -11,8 +11,8 @@ import utils.unnamedTag class ContentForSeeAlsoTest : AbstractCoreTest() { private val testConfiguration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") analysisPlatform = "jvm" } @@ -456,4 +456,4 @@ class ContentForSeeAlsoTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt b/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt index 6cb8b0f4..cabe822d 100644 --- a/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt +++ b/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt @@ -14,8 +14,8 @@ import utils.typealiasSignature class ContentForSignaturesTest : AbstractCoreTest() { private val testConfiguration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") analysisPlatform = "jvm" includeNonPublic = true diff --git a/plugins/base/src/test/kotlin/content/signatures/SkippingParenthesisForConstructorsTest.kt b/plugins/base/src/test/kotlin/content/signatures/SkippingParenthesisForConstructorsTest.kt index d203025b..c2fbd26f 100644 --- a/plugins/base/src/test/kotlin/content/signatures/SkippingParenthesisForConstructorsTest.kt +++ b/plugins/base/src/test/kotlin/content/signatures/SkippingParenthesisForConstructorsTest.kt @@ -8,8 +8,8 @@ import utils.functionSignature class ConstructorsSignaturesTest : AbstractCoreTest() { private val testConfiguration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") analysisPlatform = "jvm" } @@ -190,4 +190,4 @@ class ConstructorsSignaturesTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt index be910b5c..6a973f8e 100644 --- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt +++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt @@ -14,8 +14,8 @@ class EnumsTest : AbstractCoreTest() { @Test fun basicEnum() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -45,8 +45,8 @@ class EnumsTest : AbstractCoreTest() { @Test fun enumWithCompanion() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -90,8 +90,8 @@ class EnumsTest : AbstractCoreTest() { @Test fun enumWithConstructor() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -136,8 +136,8 @@ class EnumsTest : AbstractCoreTest() { @Test fun enumWithMethods() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -179,8 +179,8 @@ class EnumsTest : AbstractCoreTest() { @Test fun enumWithAnnotationsOnEntries(){ val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } diff --git a/plugins/base/src/test/kotlin/expect/AbstractExpectTest.kt b/plugins/base/src/test/kotlin/expect/AbstractExpectTest.kt index 3b69a54e..4dfdc410 100644 --- a/plugins/base/src/test/kotlin/expect/AbstractExpectTest.kt +++ b/plugins/base/src/test/kotlin/expect/AbstractExpectTest.kt @@ -15,8 +15,8 @@ abstract class AbstractExpectTest( protected fun generateOutput(path: Path, outFormat: String): Path? { val config = dokkaConfiguration { format = outFormat - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf(path.toAbsolutePath().asString()) } } @@ -101,4 +101,4 @@ abstract class AbstractExpectTest( ret?.let { Files.list(it).forEach { f -> f.copyRecursively(out.resolve(f.fileName)) } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/filter/DeprecationFilterTest.kt b/plugins/base/src/test/kotlin/filter/DeprecationFilterTest.kt index c15e53e8..c8b9f2d4 100644 --- a/plugins/base/src/test/kotlin/filter/DeprecationFilterTest.kt +++ b/plugins/base/src/test/kotlin/filter/DeprecationFilterTest.kt @@ -9,8 +9,8 @@ class DeprecationFilterTest : AbstractCoreTest() { @Test fun `function with false global skipDeprecated`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { skipDeprecated = false sourceRoots = listOf("src/main/kotlin/basic/Test.kt") } @@ -39,8 +39,8 @@ class DeprecationFilterTest : AbstractCoreTest() { @Test fun `deprecated function with false global skipDeprecated`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { skipDeprecated = false sourceRoots = listOf("src/main/kotlin/basic/Test.kt") } @@ -69,8 +69,8 @@ class DeprecationFilterTest : AbstractCoreTest() { @Test fun `deprecated function with true global skipDeprecated`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/basic/Test.kt") skipDeprecated = true } @@ -99,8 +99,8 @@ class DeprecationFilterTest : AbstractCoreTest() { @Test fun `deprecated function with false global true package skipDeprecated`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/basic/Test.kt") skipDeprecated = false perPackageOptions = mutableListOf( @@ -136,8 +136,8 @@ class DeprecationFilterTest : AbstractCoreTest() { @Test fun `deprecated function with true global false package skipDeprecated`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/basic/Test.kt") skipDeprecated = true perPackageOptions = mutableListOf( @@ -170,4 +170,4 @@ class DeprecationFilterTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt b/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt index 7d96541b..e5b9e9c2 100644 --- a/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt +++ b/plugins/base/src/test/kotlin/filter/EmptyPackagesFilterTest.kt @@ -1,6 +1,5 @@ package filter -import org.jetbrains.dokka.PackageOptionsImpl import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test @@ -9,8 +8,8 @@ class EmptyPackagesFilterTest : AbstractCoreTest() { @Test fun `empty package with false skipEmptyPackages`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { skipEmptyPackages = false sourceRoots = listOf("src/main/kotlin/basic/Test.kt") } @@ -37,8 +36,8 @@ class EmptyPackagesFilterTest : AbstractCoreTest() { @Test fun `empty package with true skipEmptyPackages`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { skipEmptyPackages = true sourceRoots = listOf("src/main/kotlin/basic/Test.kt") } @@ -61,4 +60,4 @@ class EmptyPackagesFilterTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt b/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt index 5e8e33dc..192de449 100644 --- a/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt +++ b/plugins/base/src/test/kotlin/filter/VisibilityFilterTest.kt @@ -9,8 +9,8 @@ class VisibilityFilterTest : AbstractCoreTest() { @Test fun `public function with false global includeNonPublic`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { includeNonPublic = false sourceRoots = listOf("src/main/kotlin/basic/Test.kt") } @@ -39,8 +39,8 @@ class VisibilityFilterTest : AbstractCoreTest() { @Test fun `private function with false global includeNonPublic`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { includeNonPublic = false sourceRoots = listOf("src/main/kotlin/basic/Test.kt") } @@ -69,8 +69,8 @@ class VisibilityFilterTest : AbstractCoreTest() { @Test fun `private function with true global includeNonPublic`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/basic/Test.kt") includeNonPublic = true } @@ -99,8 +99,8 @@ class VisibilityFilterTest : AbstractCoreTest() { @Test fun `private function with false global true package includeNonPublic`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/basic/Test.kt") includeNonPublic = false perPackageOptions = mutableListOf( @@ -136,8 +136,8 @@ class VisibilityFilterTest : AbstractCoreTest() { @Test fun `private function with true global false package includeNonPublic`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/basic/Test.kt") includeNonPublic = true perPackageOptions = mutableListOf( @@ -170,4 +170,4 @@ class VisibilityFilterTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/issues/IssuesTest.kt b/plugins/base/src/test/kotlin/issues/IssuesTest.kt index f67229b7..7b065349 100644 --- a/plugins/base/src/test/kotlin/issues/IssuesTest.kt +++ b/plugins/base/src/test/kotlin/issues/IssuesTest.kt @@ -34,8 +34,8 @@ class IssuesTest : AbstractModelTest("/src/main/kotlin/issues/Test.kt", "issues" |} """, configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") classpath = listOfNotNull(jvmStdlibPath) } @@ -70,4 +70,4 @@ class IssuesTest : AbstractModelTest("/src/main/kotlin/issues/Test.kt", "issues" // } // } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt index 191df066..2775fcf4 100644 --- a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -23,23 +23,23 @@ class LinkableContentTest : AbstractCoreTest() { val includesDir = getTestDataDir("linkable/includes").toAbsolutePath() val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { moduleName = "example" analysisPlatform = "js" sourceRoots = listOf("jsMain", "commonMain", "jvmAndJsSecondCommonMain").map { Paths.get("$testDataDir/$it/kotlin").toString() } - sourceSetID = "js" + name = "js" includes = listOf(Paths.get("$includesDir/include2.md").toString()) } - pass { + sourceSet { moduleName = "example" analysisPlatform = "jvm" sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map { Paths.get("$testDataDir/$it/kotlin").toString() } - sourceSetID = "jvm" + name = "jvm" includes = listOf(Paths.get("$includesDir/include1.md").toString()) } } @@ -62,8 +62,8 @@ class LinkableContentTest : AbstractCoreTest() { val testDataDir = getTestDataDir("linkable/sources").toAbsolutePath() val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { moduleName = "example" analysisPlatform = "js" sourceRoots = listOf("$testDataDir/jsMain/kotlin") @@ -74,9 +74,9 @@ class LinkableContentTest : AbstractCoreTest() { lineSuffix = "#L" ) ) - sourceSetID = "js" + name = "js" } - pass { + sourceSet { moduleName = "example" analysisPlatform = "jvm" sourceRoots = listOf("$testDataDir/jvmMain/kotlin") @@ -87,7 +87,7 @@ class LinkableContentTest : AbstractCoreTest() { lineSuffix = "#L" ) ) - sourceSetID = "jvm" + name = "jvm" } } } @@ -127,19 +127,19 @@ class LinkableContentTest : AbstractCoreTest() { val testDataDir = getTestDataDir("linkable/samples").toAbsolutePath() val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { moduleName = "example" analysisPlatform = "js" sourceRoots = listOf("$testDataDir/jsMain/kotlin") - sourceSetID = "js" + name = "js" samples = listOf("$testDataDir/jsMain/resources/Samples.kt") } - pass { + sourceSet { moduleName = "example" analysisPlatform = "jvm" sourceRoots = listOf("$testDataDir/jvmMain/kotlin") - sourceSetID = "jvm" + name = "jvm" samples = listOf("$testDataDir/jvmMain/resources/Samples.kt") } } @@ -196,11 +196,11 @@ class LinkableContentTest : AbstractCoreTest() { | """.trimIndent(), dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") analysisPlatform = "jvm" - sourceSetID = "js" + name = "js" } } } @@ -222,4 +222,4 @@ class LinkableContentTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt b/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt index 1bc3ea29..a219fb04 100644 --- a/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt +++ b/plugins/base/src/test/kotlin/locationProvider/DefaultLocationProviderTest.kt @@ -10,8 +10,8 @@ class DefaultLocationProviderTest: AbstractCoreTest() { @Test fun `#644 same directory for module and package`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -38,4 +38,4 @@ class DefaultLocationProviderTest: AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/markdown/KDocTest.kt b/plugins/base/src/test/kotlin/markdown/KDocTest.kt index 218f7244..f5b29322 100644 --- a/plugins/base/src/test/kotlin/markdown/KDocTest.kt +++ b/plugins/base/src/test/kotlin/markdown/KDocTest.kt @@ -9,8 +9,8 @@ import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest abstract class KDocTest : AbstractCoreTest() { private val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/example/Test.kt") } } @@ -44,4 +44,4 @@ abstract class KDocTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/markdown/LinkTest.kt b/plugins/base/src/test/kotlin/markdown/LinkTest.kt index ddcef5db..8e4e588e 100644 --- a/plugins/base/src/test/kotlin/markdown/LinkTest.kt +++ b/plugins/base/src/test/kotlin/markdown/LinkTest.kt @@ -13,8 +13,8 @@ class LinkTest : AbstractCoreTest() { @Test fun linkToClassLoader() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/parser") } } @@ -46,8 +46,8 @@ class LinkTest : AbstractCoreTest() { @Test fun returnTypeShouldHaveLinkToOuterClassFromInner() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin") } } @@ -75,4 +75,4 @@ class LinkTest : AbstractCoreTest() { } } } -} \ 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 f5517abb..503cf50c 100644 --- a/plugins/base/src/test/kotlin/model/InheritorsTest.kt +++ b/plugins/base/src/test/kotlin/model/InheritorsTest.kt @@ -44,12 +44,12 @@ class InheritorsTest : AbstractModelTest("/src/main/kotlin/inheritors/Test.kt", @Test fun multiplatform() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("common/src/", "jvm/src/") analysisPlatform = "jvm" } - pass { + sourceSet { sourceRoots = listOf("common/src/", "js/src/") analysisPlatform = "js" } @@ -92,4 +92,4 @@ class InheritorsTest : AbstractModelTest("/src/main/kotlin/inheritors/Test.kt", } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/model/PropertyTest.kt b/plugins/base/src/test/kotlin/model/PropertyTest.kt index e384b920..af952b43 100644 --- a/plugins/base/src/test/kotlin/model/PropertyTest.kt +++ b/plugins/base/src/test/kotlin/model/PropertyTest.kt @@ -169,8 +169,8 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro |@Strictfp var property = "test" """, configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") classpath = listOfNotNull(jvmStdlibPath) } @@ -262,4 +262,4 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro // } // //} -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt b/plugins/base/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt index 5facd194..b3ac7b07 100644 --- a/plugins/base/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt +++ b/plugins/base/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt @@ -11,8 +11,8 @@ class BasicMultiplatformTest : AbstractCoreTest() { val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("$testDataDir/jvmMain/") } } @@ -28,8 +28,8 @@ class BasicMultiplatformTest : AbstractCoreTest() { @Test fun inlineTestExample() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/multiplatform/Test.kt") } } @@ -51,4 +51,4 @@ class BasicMultiplatformTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt b/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt index 6ef38aa9..935b9377 100644 --- a/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt +++ b/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt @@ -39,8 +39,8 @@ class PageNodeMergerTest : AbstractCoreTest() { fun sameNameStrategyTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt") } } @@ -82,8 +82,8 @@ class PageNodeMergerTest : AbstractCoreTest() { val strList: MutableList = mutableListOf() val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt") } } @@ -123,4 +123,4 @@ class PageNodeMergerTest : AbstractCoreTest() { fun PageNode.childrenRec(): List = listOf(this) + children.flatMap { it.childrenRec() } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt b/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt index 6ceb805b..d4778a8e 100644 --- a/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt @@ -12,14 +12,14 @@ class DivergentTest : RenderingOnlyTestBase() { private val js = defaultSourceSet.copy( "root", "JS", - "js", + defaultSourceSet.sourceSetID.copy(sourceSetName = "js"), analysisPlatform = Platform.js, sourceRoots = listOf(SourceRootImpl("pl1")) ) private val jvm = defaultSourceSet.copy( "root", "JVM", - "jvm", + defaultSourceSet.sourceSetID.copy(sourceSetName = "jvm"), analysisPlatform = Platform.jvm, sourceRoots = listOf(SourceRootImpl("pl1")) @@ -27,7 +27,7 @@ class DivergentTest : RenderingOnlyTestBase() { private val native = defaultSourceSet.copy( "root", "NATIVE", - "native", + defaultSourceSet.sourceSetID.copy(sourceSetName = "native"), analysisPlatform = Platform.native, sourceRoots = listOf(SourceRootImpl("pl1")) ) @@ -344,4 +344,4 @@ class DivergentTest : RenderingOnlyTestBase() { Div(Div("b-", Span()), Div(Div(Div(("b")))), "ab+") ) } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt b/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt index c868cfd5..ea1ea9ae 100644 --- a/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt @@ -15,21 +15,21 @@ class SourceSetDependentHintTest : RenderingOnlyTestBase() { private val pl1 = defaultSourceSet.copy( "root", "pl1", - "pl1", + defaultSourceSet.sourceSetID.copy(sourceSetName = "pl1"), analysisPlatform = Platform.js, sourceRoots = listOf(SourceRootImpl("pl1")) ) private val pl2 = defaultSourceSet.copy( "root", "pl2", - "pl2", + defaultSourceSet.sourceSetID.copy(sourceSetName = "pl2"), analysisPlatform = Platform.jvm, sourceRoots = listOf(SourceRootImpl("pl1")) ) private val pl3 = defaultSourceSet.copy( "root", "pl3", - "pl3", + defaultSourceSet.sourceSetID.copy(sourceSetName = "pl3"), analysisPlatform = Platform.native, sourceRoots = listOf(SourceRootImpl("pl1")) ) @@ -135,4 +135,4 @@ class SourceSetDependentHintTest : RenderingOnlyTestBase() { HtmlRenderer(context).render(page) renderedContent.match(Div(Div(Div("a")), Div(Div("b")))) } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/renderers/html/defaultSourceSet.kt b/plugins/base/src/test/kotlin/renderers/html/defaultSourceSet.kt index 771cabaa..a9be1cfd 100644 --- a/plugins/base/src/test/kotlin/renderers/html/defaultSourceSet.kt +++ b/plugins/base/src/test/kotlin/renderers/html/defaultSourceSet.kt @@ -1,15 +1,16 @@ package renderers.html +import org.jetbrains.dokka.DokkaSourceSetID import org.jetbrains.dokka.DokkaSourceSetImpl import org.jetbrains.dokka.Platform internal val defaultSourceSet = DokkaSourceSetImpl( - moduleName = "DEFAULT", + moduleDisplayName = "DEFAULT", displayName = "DEFAULT", - sourceSetID = "DEFAULT", + sourceSetID = DokkaSourceSetID("DEFAULT", "DEFAULT"), classpath = emptyList(), sourceRoots = emptyList(), - dependentSourceSets = emptyList(), + dependentSourceSets = emptySet(), samples = emptyList(), includes = emptyList(), includeNonPublic = false, @@ -27,4 +28,4 @@ internal val defaultSourceSet = DokkaSourceSetImpl( noJdkLink = false, suppressedFiles = emptyList(), analysisPlatform = Platform.DEFAULT -) \ No newline at end of file +) diff --git a/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt b/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt index be87813b..4f8a834b 100644 --- a/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt +++ b/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt @@ -26,8 +26,8 @@ class ResourceLinksTest : AbstractCoreTest() { @Test fun resourceLinksTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/test/Test.kt") } } @@ -68,4 +68,4 @@ class ResourceLinksTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt b/plugins/base/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt index e66490c1..d8e057da 100644 --- a/plugins/base/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt +++ b/plugins/base/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt @@ -21,8 +21,8 @@ class PageTransformerBuilderTest : AbstractCoreTest() { @Test fun scannerTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/transformerBuilder/Test.kt") } } @@ -58,8 +58,8 @@ class PageTransformerBuilderTest : AbstractCoreTest() { @Test fun mapperTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/transformerBuilder/Test.kt") } } @@ -98,8 +98,8 @@ class PageTransformerBuilderTest : AbstractCoreTest() { @Test fun structureTransformerTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/kotlin/transformerBuilder/Test.kt") } } diff --git a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt index 523813fc..72948372 100644 --- a/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt +++ b/plugins/base/src/test/kotlin/transformers/ReportUndocumentedTransformerTest.kt @@ -12,8 +12,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented class gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -39,8 +39,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented non-public class does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -65,8 +65,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented function gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -95,8 +95,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented property gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -125,8 +125,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented primary constructor does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -153,8 +153,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `data class component functions do not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin") } @@ -183,8 +183,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented secondary constructor gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -213,8 +213,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented inherited function does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -246,8 +246,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `undocumented inherited property does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -279,8 +279,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `overridden function does not get reported when super is documented`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -315,8 +315,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `overridden property does not get reported when super is documented`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -349,10 +349,10 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { } @Test - fun `report disabled by pass configuration`() { + fun `report disabled by source set`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = false sourceRoots = listOf("src/main/kotlin/Test.kt") } @@ -377,8 +377,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `report enabled by package configuration`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { perPackageOptions += packageOptions( prefix = "sample", reportUndocumented = true, @@ -407,8 +407,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `report enabled by more specific package configuration`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { perPackageOptions += packageOptions( prefix = "sample", reportUndocumented = false, @@ -445,8 +445,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `report disabled by more specific package configuration`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { perPackageOptions += packageOptions( prefix = "sample", reportUndocumented = true, @@ -483,22 +483,22 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `multiplatform undocumented class gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + val commonMain = sourceSet { reportUndocumented = true analysisPlatform = Platform.common.toString() - sourceSetID = "commonMain" + name = "commonMain" displayName = "commonMain" sourceRoots = listOf("src/commonMain/kotlin") } - pass { + sourceSet { reportUndocumented = true analysisPlatform = Platform.jvm.toString() - sourceSetID = "jvmMain" + name = "jvmMain" displayName = "jvmMain" sourceRoots = listOf("src/jvmMain/kotlin") - dependentSourceSets = listOf("commonMain") + dependentSourceSets = setOf(commonMain.sourceSetID) } } } @@ -526,22 +526,22 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `multiplatform undocumented class does not get reported if expect is documented`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + val commonMain = sourceSet { reportUndocumented = true analysisPlatform = Platform.common.toString() - sourceSetID = "commonMain" + name = "commonMain" displayName = "commonMain" sourceRoots = listOf("src/commonMain/kotlin") } - pass { + sourceSet { reportUndocumented = true analysisPlatform = Platform.jvm.toString() - sourceSetID = "jvmMain" + name = "jvmMain" displayName = "jvmMain" sourceRoots = listOf("src/jvmMain/kotlin") - dependentSourceSets = listOf("commonMain") + dependentSourceSets = setOf(commonMain.sourceSetID) } } } @@ -568,31 +568,31 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `multiplatform undocumented function gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + val commonMain = sourceSet { reportUndocumented = true analysisPlatform = Platform.common.toString() - sourceSetID = "commonMain" + name = "commonMain" displayName = "commonMain" sourceRoots = listOf("src/commonMain/kotlin") } - pass { + sourceSet { reportUndocumented = true analysisPlatform = Platform.jvm.toString() - sourceSetID = "jvmMain" + name = "jvmMain" displayName = "jvmMain" sourceRoots = listOf("src/jvmMain/kotlin") - dependentSourceSets = listOf("commonMain") + dependentSourceSets = setOf(commonMain.sourceSetID) } - pass { + sourceSet { reportUndocumented = true analysisPlatform = Platform.native.toString() - sourceSetID = "macosMain" + name = "macosMain" displayName = "macosMain" sourceRoots = listOf("src/macosMain/kotlin") - dependentSourceSets = listOf("commonMain") + dependentSourceSets = setOf(commonMain.sourceSetID) } } } @@ -625,8 +625,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `java undocumented class gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/java") } @@ -652,8 +652,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `java undocumented non-public class does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/java") } @@ -677,8 +677,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `java undocumented constructor does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/java") } @@ -706,8 +706,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `java undocumented method gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/java") } @@ -736,8 +736,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `java undocumented property gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/java") } @@ -766,8 +766,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `java undocumented inherited method gets reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/java") } @@ -805,8 +805,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `java documented inherited method does not get reported`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/java") } @@ -842,8 +842,8 @@ class ReportUndocumentedTransformerTest : AbstractCoreTest() { @Test fun `java overridden function does not get reported when super is documented`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { reportUndocumented = true sourceRoots = listOf("src/main/java") } diff --git a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt index 5f8a7864..95fbb3c6 100644 --- a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt +++ b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt @@ -12,8 +12,8 @@ class DefaultPsiToDocumentableTranslatorTest : AbstractCoreTest() { @Test fun `method overriding two documented classes picks closest class documentation`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/java") } } @@ -57,8 +57,8 @@ class DefaultPsiToDocumentableTranslatorTest : AbstractCoreTest() { @Test fun `method overriding class and interface picks class documentation`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/java") } } @@ -102,8 +102,8 @@ class DefaultPsiToDocumentableTranslatorTest : AbstractCoreTest() { @Test fun `method overriding two classes picks closest documented class documentation`() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/main/java") } } @@ -153,4 +153,4 @@ class DefaultPsiToDocumentableTranslatorTest : AbstractCoreTest() { ?.body.orEmpty() } -} \ No newline at end of file +} diff --git a/plugins/base/src/test/kotlin/utils/ModelUtils.kt b/plugins/base/src/test/kotlin/utils/ModelUtils.kt index 9697a843..87a9c802 100644 --- a/plugins/base/src/test/kotlin/utils/ModelUtils.kt +++ b/plugins/base/src/test/kotlin/utils/ModelUtils.kt @@ -16,8 +16,8 @@ abstract class AbstractModelTest(val path: String? = null, val pkg: String) : Mo block: DModule.() -> Unit ) { val testConfiguration = configuration ?: dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") analysisPlatform = platform } diff --git a/plugins/gfm/src/main/kotlin/GfmPlugin.kt b/plugins/gfm/src/main/kotlin/GfmPlugin.kt index b955d403..287ef74f 100644 --- a/plugins/gfm/src/main/kotlin/GfmPlugin.kt +++ b/plugins/gfm/src/main/kotlin/GfmPlugin.kt @@ -140,7 +140,7 @@ open class CommonmarkRenderer( platforms.joinToString( prefix = " [", postfix = "] $text " - ) { "${it.moduleName}/${it.sourceSetID}" }) + ) { "${it.moduleDisplayName}/${it.sourceSetID}" }) buildNewLine() } } @@ -157,7 +157,7 @@ open class CommonmarkRenderer( ) { if(node.dci.kind == ContentKind.Sample || node.dci.kind == ContentKind.Parameters){ node.sourceSets.forEach {sourcesetData -> - append("${sourcesetData.moduleName}/${sourcesetData.sourceSetID}") + append("${sourcesetData.moduleDisplayName}/${sourcesetData.sourceSetID}") buildNewLine() buildTable(node.copy(children = node.children.filter { it.sourceSets.contains(sourcesetData) }, dci = node.dci.copy(kind = ContentKind.Main)), pageContext, sourceSetRestriction) buildNewLine() @@ -286,4 +286,4 @@ class MarkdownLocationProvider( dokkaContext ) { override val extension = ".md" -} \ No newline at end of file +} diff --git a/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt index 138208ae..4fa65c58 100644 --- a/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt +++ b/plugins/javadoc/src/test/kotlin/javadoc/AbstractJavadocTemplateMapTest.kt @@ -15,8 +15,8 @@ import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest internal abstract class AbstractJavadocTemplateMapTest : AbstractCoreTest() { protected var config: DokkaConfigurationImpl = dokkaConfiguration { format = "javadoc" - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src") analysisPlatform = "jvm" } @@ -62,7 +62,6 @@ internal abstract class AbstractJavadocTemplateMapTest : AbstractCoreTest() { ) { testInline(query, configuration) { renderingStage = { rootPageNode, dokkaContext -> - // TODO NOW: Clarify preprocessors! val transformedRootPageNode = preprocessors.fold(rootPageNode) { acc, pageTransformer -> pageTransformer(acc) } diff --git a/plugins/javadoc/src/test/kotlin/javadoc/JavadocTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/JavadocTest.kt index 905cb61b..31a33ad5 100644 --- a/plugins/javadoc/src/test/kotlin/javadoc/JavadocTest.kt +++ b/plugins/javadoc/src/test/kotlin/javadoc/JavadocTest.kt @@ -10,8 +10,8 @@ class JavadocTest : AbstractCoreTest() { fun test() { val config = dokkaConfiguration { format = "javadoc" - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("jvmSrc/") analysisPlatform = "jvm" } diff --git a/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt index cbaa3dd6..a47f0142 100644 --- a/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt +++ b/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt @@ -23,8 +23,8 @@ class JavadocTest : AbstractCoreTest() { val config = dokkaConfiguration { format = "javadoc" - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("jvmSrc/") externalDocumentationLinks = listOf( externalLink("https://docs.oracle.com/javase/8/docs/api/"), @@ -60,4 +60,4 @@ class JavadocTest : AbstractCoreTest() { } } } -} \ No newline at end of file +} diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt index db87051b..96446201 100644 --- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt +++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt @@ -3,7 +3,6 @@ package kotlinAsJavaPlugin import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.jetbrains.kotlin.utils.addToStdlib.cast -import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.junit.jupiter.api.Test class KotlinAsJavaPluginTest : AbstractCoreTest() { @@ -11,8 +10,8 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { @Test fun topLevelTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -49,8 +48,8 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { @Test fun topLevelWithClassTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } @@ -90,8 +89,8 @@ class KotlinAsJavaPluginTest : AbstractCoreTest() { @Test fun kotlinAndJavaTest() { val configuration = dokkaConfiguration { - passes { - pass { + sourceSets { + sourceSet { sourceRoots = listOf("src/") } } diff --git a/runners/ant/build.gradle b/runners/ant/build.gradle deleted file mode 100644 index 216420c6..00000000 --- a/runners/ant/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ -apply plugin: 'kotlin' - -sourceCompatibility = 1.8 - -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { - kotlinOptions { - freeCompilerArgs += "-Xjsr305=strict" - languageVersion = language_version - apiVersion = language_version - jvmTarget = "1.8" - } -} - -dependencies { - compile project(":core") - compileOnly group: 'org.apache.ant', name: 'ant', version: ant_version -} - diff --git a/runners/ant/src/main/kotlin/ant/dokka.kt b/runners/ant/src/main/kotlin/ant/dokka.kt deleted file mode 100644 index d275ed82..00000000 --- a/runners/ant/src/main/kotlin/ant/dokka.kt +++ /dev/null @@ -1,210 +0,0 @@ -package org.jetbrains.dokka.ant - -import org.apache.tools.ant.BuildException -import org.apache.tools.ant.Project -import org.apache.tools.ant.Task -import org.apache.tools.ant.types.Path -import org.apache.tools.ant.types.Reference -import org.jetbrains.dokka.* -import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink -import org.jetbrains.dokka.utilities.DokkaConsoleLogger -import org.jetbrains.dokka.utilities.DokkaLogger -import java.io.File - -class AntLogger(val task: Task): DokkaLogger { - override var warningsCount: Int = 0 - override var errorsCount: Int = 0 - override fun debug(message: String) = task.log(message, Project.MSG_DEBUG) - override fun info(message: String) = task.log(message, Project.MSG_VERBOSE) - override fun progress(message: String) = task.log(message, Project.MSG_INFO) - override fun warn(message: String) = task.log(message, Project.MSG_WARN).also { warningsCount++ } - override fun error(message: String) = task.log(message, Project.MSG_ERR).also { errorsCount++ } - override fun report() { - if (warningsCount > 0 || errorsCount > 0) { - task.log("Generation completed with $warningsCount warning" + - (if(warningsCount == 1) "" else "s") + - " and $errorsCount error" + - if(errorsCount == 1) "" else "s" - ) - } else { - task.log("generation completed successfully") - } - } -} - -class AntSourceLinkDefinition(var path: String? = null, var url: String? = null, var lineSuffix: String? = null) - -class AntSourceRoot(var path: String? = null) { - fun toSourceRoot(): SourceRootImpl? = path?.let { path -> - SourceRootImpl(path) - } -} - -class TextProperty(var value: String = "") - -class AntPassConfig(task: Task) : DokkaConfiguration.PassConfiguration { - override var moduleName: String = "" - override val classpath: List - get() = buildClassPath.list().toList() - - override val sourceRoots: List - get() = sourcePath.list().map { SourceRootImpl(it) } + antSourceRoots.mapNotNull { it.toSourceRoot() } - - override val samples: List - get() = samplesPath.list().toList() - override val includes: List - get() = includesPath.list().toList() - override var includeNonPublic: Boolean = false - override var includeRootPackage: Boolean = true - override var reportUndocumented: Boolean = false - override var skipEmptyPackages: Boolean = true - override var skipDeprecated: Boolean = false - override var jdkVersion: Int = 8 - override val sourceLinks: List - get() = antSourceLinkDefinition.map { - val path = it.path!! - val url = it.url!! - SourceLinkDefinitionImpl(File(path).canonicalFile.absolutePath, url, it.lineSuffix) - } - override val perPackageOptions: MutableList = mutableListOf() - override val externalDocumentationLinks: List - get() = buildExternalLinksBuilders.map { it.build() } + defaultExternalDocumentationLinks - - override var languageVersion: String? = null - override var apiVersion: String? = null - override var noStdlibLink: Boolean = false - override var noJdkLink: Boolean = false - override var suppressedFiles: MutableList = mutableListOf() - override var collectInheritedExtensionsFromLibraries: Boolean = false - override var analysisPlatform: Platform = Platform.DEFAULT - override var targets: List = listOf() - get() = buildTargets.filter { it.value != "" } - .map { it.value } - - override var sinceKotlin: String? = null - - private val samplesPath: Path by lazy { Path(task.project) } - private val includesPath: Path by lazy { Path(task.project) } - private val buildClassPath: Path by lazy { Path(task.project) } - val sourcePath: Path by lazy { Path(task.project) } - val antSourceRoots: MutableList = mutableListOf() - - private val buildTargets: MutableList = mutableListOf() - private val buildExternalLinksBuilders: MutableList = mutableListOf() - val antSourceLinkDefinition: MutableList = mutableListOf() - - private val defaultExternalDocumentationLinks: List - get() { - val links = mutableListOf() - if (!noJdkLink) - links += DokkaConfiguration.ExternalDocumentationLink.Builder("https://docs.oracle.com/javase/$jdkVersion/docs/api/").build() - - if (!noStdlibLink) - links += DokkaConfiguration.ExternalDocumentationLink.Builder("https://kotlinlang.org/api/latest/jvm/stdlib/").build() - return links - } - - - fun setSamples(ref: Path) { - samplesPath.append(ref) - } - - fun setSamplesRef(ref: Reference) { - samplesPath.createPath().refid = ref - } - - fun setInclude(ref: Path) { - includesPath.append(ref) - } - - fun setClasspath(classpath: Path) { - buildClassPath.append(classpath) - } - - fun createPackageOptions(): AntPackageOptions = AntPackageOptions().apply { perPackageOptions.add(this) } - - fun createSourceRoot(): AntSourceRoot = AntSourceRoot().apply { antSourceRoots.add(this) } - - fun createTarget(): TextProperty = TextProperty().apply { - buildTargets.add(this) - } - - fun setClasspathRef(ref: Reference) { - buildClassPath.createPath().refid = ref - } - - fun setSrc(src: Path) { - sourcePath.append(src) - } - - fun setSrcRef(ref: Reference) { - sourcePath.createPath().refid = ref - } - - fun createSourceLink(): AntSourceLinkDefinition { - val def = AntSourceLinkDefinition() - antSourceLinkDefinition.add(def) - return def - } - - fun createExternalDocumentationLink() = - ExternalDocumentationLink.Builder().apply { buildExternalLinksBuilders.add(this) } - -} - -class AntPackageOptions( - override var prefix: String = "", - override var includeNonPublic: Boolean = false, - override var reportUndocumented: Boolean = true, - override var skipDeprecated: Boolean = false, - override var suppress: Boolean = false) : DokkaConfiguration.PackageOptions - -class DokkaAntTask: Task(), DokkaConfiguration { - - override var format: String = "html" - override var generateIndexPages: Boolean = false - override var outputDir: String = "" - override var impliedPlatforms: List = listOf() - get() = buildImpliedPlatforms.map { it.value }.toList() - private val buildImpliedPlatforms: MutableList = mutableListOf() - - override var cacheRoot: String? = null - override val passesConfigurations: MutableList = mutableListOf() - override var pluginsClasspath: List = mutableListOf() - - fun createPassConfig() = AntPassConfig(this).apply { passesConfigurations.add(this) } - fun createImpliedPlatform(): TextProperty = TextProperty().apply { buildImpliedPlatforms.add(this) } - - - override fun execute() { - for (passConfig in passesConfigurations) { - if (passConfig.sourcePath.list().isEmpty() && passConfig.antSourceRoots.isEmpty()) { - throw BuildException("At least one source path needs to be specified") - } - - if (passConfig.moduleName == "") { - throw BuildException("Module name needs to be specified and not empty") - } - - for (sourceLink in passConfig.antSourceLinkDefinition) { - if (sourceLink.path == null) { - throw BuildException("'path' attribute of a element is required") - } - if (sourceLink.path!!.contains("\\")) { - throw BuildException("'dir' attribute of a - incorrect value, only Unix based path allowed") - } - - if (sourceLink.url == null) { - throw BuildException("'url' attribute of a element is required") - } - } - } - - if (outputDir == "") { - throw BuildException("Output directory needs to be specified and not empty") - } - - val generator = DokkaGenerator(this, AntLogger(this)) - generator.generate() - } -} \ No newline at end of file diff --git a/runners/ant/src/main/resources/dokka-antlib.xml b/runners/ant/src/main/resources/dokka-antlib.xml deleted file mode 100644 index 9c3373d5..00000000 --- a/runners/ant/src/main/resources/dokka-antlib.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/runners/cli/build.gradle.kts b/runners/cli/build.gradle.kts index 8c4955ca..bc09f2cd 100644 --- a/runners/cli/build.gradle.kts +++ b/runners/cli/build.gradle.kts @@ -10,7 +10,6 @@ repositories { dependencies { implementation("org.jetbrains.kotlinx:kotlinx-cli-jvm:0.2.1") - implementation("com.google.code.gson:gson:2.8.5") implementation(project(":core")) implementation(kotlin("stdlib")) } @@ -36,4 +35,4 @@ publishing { } } -configureBintrayPublication("dokkaCli") \ No newline at end of file +configureBintrayPublication("dokkaCli") diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index b0fb45b2..5e5cd6b2 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka -import com.google.gson.Gson import kotlinx.cli.* import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet.* @@ -34,7 +33,7 @@ class GlobalArguments(args: Array) : DokkaConfiguration { override val sourceSets by parser.option( ArgTypeArgument, description = "Single dokka source set", - fullName = "pass" + fullName = "sourceSet" ).multiple() override val pluginsConfiguration by parser.option( @@ -60,7 +59,7 @@ class GlobalArguments(args: Array) : DokkaConfiguration { val globalPackageOptions by parser.option( ArgType.String, - description = "List of package passConfiguration in format \"prefix,-deprecated,-privateApi,+warnUndocumented,+suppress;...\" " + description = "List of package source sets in format \"prefix,-deprecated,-privateApi,+warnUndocumented,+suppress;...\" " ).delimiter(";") val globalLinks by parser.option( @@ -73,9 +72,9 @@ class GlobalArguments(args: Array) : DokkaConfiguration { description = "Mapping between a source directory and a Web site for browsing the code (allows many paths separated by the semicolon `;`)" ).delimiter(";") - val helpPass by parser.option( - ArgTypeHelpPass, - description = "Prints help for single -pass" + val helpSourceSet by parser.option( + ArgTypeHelpSourceSet, + description = "Prints help for single -sourceSet" ) override val modules: List = emptyList() @@ -94,8 +93,8 @@ class GlobalArguments(args: Array) : DokkaConfiguration { globalSrcLink.forEach { if (it.isNotEmpty() && it.contains("=")) - sourceSets.all { pass -> - pass.sourceLinks.cast>() + sourceSets.all { sourceSet -> + sourceSet.sourceLinks.cast>() .add(SourceLinkDefinitionImpl.parseSourceLinkDefinition(it)) } else { @@ -112,9 +111,9 @@ class GlobalArguments(args: Array) : DokkaConfiguration { } } -fun passArguments(args: Array): DokkaConfiguration.DokkaSourceSet { +private fun parseSourceSet(args: Array): DokkaConfiguration.DokkaSourceSet { - val parser = ArgParser("passConfiguration", prefixStyle = ArgParser.OptionPrefixStyle.JVM) + val parser = ArgParser("sourceSet", prefixStyle = ArgParser.OptionPrefixStyle.JVM) val moduleName by parser.option( ArgType.String, @@ -122,16 +121,21 @@ fun passArguments(args: Array): DokkaConfiguration.DokkaSourceSet { fullName = "module" ).required() - val displayName by parser.option( + val moduleDisplayName by parser.option( ArgType.String, - description = "Name of the source set" - ).default("JVM") + description = "Name of the documentation module" + ) - val sourceSetID by parser.option( + val name by parser.option( ArgType.String, - description = "ID of the source set" + description = "Name of the source set" ).default("main") + val displayName by parser.option( + ArgType.String, + description = "Displayed name of the source set" + ).default("JVM") + val classpath by parser.option( ArgType.String, description = "Classpath for symbol resolution (allows many paths separated by the semicolon `;`)" @@ -213,7 +217,7 @@ fun passArguments(args: Array): DokkaConfiguration.DokkaSourceSet { val perPackageOptions by parser.option( ArgType.String, - description = "List of package passConfiguration in format \"prefix,-deprecated,-privateApi,+warnUndocumented,+suppress;...\" " + description = "List of package source set configuration in format \"prefix,-deprecated,-privateApi,+warnUndocumented,+suppress;...\" " ).delimiter(";") val externalDocumentationLinks by parser.option( @@ -230,12 +234,14 @@ fun passArguments(args: Array): DokkaConfiguration.DokkaSourceSet { parser.parse(args) return object : DokkaConfiguration.DokkaSourceSet { - override val moduleName = moduleName + override val moduleDisplayName = moduleDisplayName ?: moduleName override val displayName = displayName - override val sourceSetID = sourceSetID + override val sourceSetID = DokkaSourceSetID(moduleName, name) override val classpath = classpath override val sourceRoots = sourceRoots.map { SourceRootImpl(it.toAbsolutePath()) } - override val dependentSourceSets: List = dependentSourceSets + override val dependentSourceSets: Set = dependentSourceSets + .map { dependentSourceSetName -> DokkaSourceSetID(moduleName, dependentSourceSetName) } + .toSet() override val samples = samples.map { it.toAbsolutePath() } override val includes = includes.map { it.toAbsolutePath() } override val includeNonPublic = includeNonPublic @@ -294,15 +300,15 @@ object ArgTypeSourceLinkDefinition : ArgType(true) { override fun convert(value: kotlin.String, name: kotlin.String): DokkaConfiguration.DokkaSourceSet = - passArguments(value.split(" ").filter { it.isNotBlank() }.toTypedArray()) + parseSourceSet(value.split(" ").filter { it.isNotBlank() }.toTypedArray()) override val description: kotlin.String get() = "" } // Workaround for printing nested parsers help -object ArgTypeHelpPass : ArgType(false) { - override fun convert(value: kotlin.String, name: kotlin.String): Any = Any().also { passArguments(arrayOf("-h")) } +object ArgTypeHelpSourceSet : ArgType(false) { + override fun convert(value: kotlin.String, name: kotlin.String): Any = Any().also { parseSourceSet(arrayOf("-h")) } override val description: kotlin.String get() = "" @@ -345,11 +351,10 @@ fun parseLinks(links: List): List { fun main(args: Array) { val globalArguments = GlobalArguments(args) val configuration = if (globalArguments.json != null) - Gson().fromJson( - Paths.get(globalArguments.json).toFile().readText(), - DokkaConfigurationImpl::class.java + DokkaConfigurationImpl( + Paths.get(checkNotNull(globalArguments.json)).toFile().readText() ) else globalArguments DokkaGenerator(configuration, DokkaConsoleLogger).generate() -} \ No newline at end of file +} diff --git a/runners/gradle-plugin/build.gradle.kts b/runners/gradle-plugin/build.gradle.kts index 71d7e72f..2c25a707 100644 --- a/runners/gradle-plugin/build.gradle.kts +++ b/runners/gradle-plugin/build.gradle.kts @@ -19,6 +19,8 @@ dependencies { compileOnly(gradleKotlinDsl()) testImplementation(gradleApi()) testImplementation(kotlin("test-junit")) + testImplementation("org.jetbrains.kotlin:kotlin-gradle-plugin") + constraints { val kotlin_version: String by project compileOnly("org.jetbrains.kotlin:kotlin-reflect:${kotlin_version}") { diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt index 3bd0b6ab..c9693467 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/ConfigurationExtractor.kt @@ -169,4 +169,4 @@ class ConfigurationExtractor(private val project: Project) { val dependentSourceSets: List, val platform: String ) : Serializable -} \ No newline at end of file +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt index ead0f90a..823206e3 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaCollectorTask.kt @@ -19,7 +19,7 @@ open class DokkaCollectorTask : DefaultTask() { @TaskAction fun collect() { - val passesConfigurations = getProjects(project).filter { it.name in modules }.flatMap { + val sourceSets = getProjects(project).filter { it.name in modules }.flatMap { val tasks = try { it.tasks.withType(DokkaTask::class.java) } catch (e: UnknownTaskException) { @@ -30,11 +30,11 @@ open class DokkaCollectorTask : DefaultTask() { val initial = GradleDokkaConfigurationImpl().apply { outputDir = outputDirectory - cacheRoot = passesConfigurations.first().cacheRoot - format = passesConfigurations.first().format + cacheRoot = sourceSets.first().cacheRoot + format = sourceSets.first().format } - configuration = passesConfigurations.fold(initial) { acc, it: GradleDokkaConfigurationImpl -> + configuration = sourceSets.fold(initial) { acc, it: GradleDokkaConfigurationImpl -> if(acc.format != it.format || acc.cacheRoot != it.cacheRoot) throw IllegalStateException("Dokka task configurations differ on core arguments (format, cacheRoot)") acc.sourceSets = acc.sourceSets + it.sourceSets diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaSourceSetIDFactory.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaSourceSetIDFactory.kt new file mode 100644 index 00000000..3fadb4fd --- /dev/null +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaSourceSetIDFactory.kt @@ -0,0 +1,10 @@ +@file:Suppress("FunctionName") + +package org.jetbrains.dokka.gradle + +import org.gradle.api.Project +import org.jetbrains.dokka.DokkaSourceSetID + +internal fun DokkaSourceSetID(project: Project, sourceSetName: String): DokkaSourceSetID { + return DokkaSourceSetID(moduleName = project.path, sourceSetName = sourceSetName) +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt index e27357c9..aac7e2a0 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaTask.kt @@ -7,11 +7,9 @@ import org.gradle.api.file.FileCollection import org.gradle.api.internal.plugins.DslObject import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.tasks.* -import org.jetbrains.dokka.DokkaBootstrap +import org.jetbrains.dokka.* import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink.Builder import org.jetbrains.dokka.DokkaConfiguration.SourceRoot -import org.jetbrains.dokka.DokkaException -import org.jetbrains.dokka.Platform import org.jetbrains.dokka.ReflectDsl import org.jetbrains.dokka.ReflectDsl.isNotInstance import org.jetbrains.dokka.gradle.ConfigurationExtractor.PlatformData @@ -183,10 +181,7 @@ open class DokkaTask : DefaultTask(), Configurable { val defaultModulesConfiguration = configuredDokkaSourceSets .map { configureDefault(it, globalConfig) }.takeIf { it.isNotEmpty() } ?: listOf( - configureDefault( - configureDokkaSourceSet(GradleDokkaSourceSet("main")), - null - ) + configureDefault(configureDokkaSourceSet(GradleDokkaSourceSet("main", project)), null) ).takeIf { project.isNotMultiplatformProject() } ?: emptyList() if (defaultModulesConfiguration.isEmpty()) { @@ -288,28 +283,25 @@ open class DokkaTask : DefaultTask(), Configurable { protected fun mergeUserConfigurationAndPlatformData( userConfig: GradleDokkaSourceSet, autoConfig: PlatformData - ) = - userConfig.copy().apply { - sourceRoots.addAll(userConfig.sourceRoots.union(autoConfig.sourceRoots.toSourceRoots()).distinct()) - dependentSourceSets.addAll(userConfig.dependentSourceSets.union(autoConfig.dependentSourceSets).distinct()) - classpath = userConfig.classpath.union(autoConfig.classpath.map { it.absolutePath }).distinct() - if (userConfig.platform == null && autoConfig.platform != "") - platform = autoConfig.platform - } + ) = userConfig.copy().apply { + sourceRoots.addAll(userConfig.sourceRoots.union(autoConfig.sourceRoots.toSourceRoots()).distinct()) + dependentSourceSets.addAll(userConfig.dependentSourceSets) + dependentSourceSets.addAll(autoConfig.dependentSourceSets.map { DokkaSourceSetID(project, it) }) + classpath = userConfig.classpath.union(autoConfig.classpath.map { it.absolutePath }).distinct() + if (userConfig.platform == null && autoConfig.platform != "") + platform = autoConfig.platform + } protected fun configureDefault( config: GradleDokkaSourceSet, globalConfig: GradleDokkaSourceSet? ): GradleDokkaSourceSet { - if (config.moduleName.isBlank()) { - config.moduleName = project.name + if (config.moduleDisplayName.isBlank()) { + config.moduleDisplayName = project.name } - if (config.sourceSetID.isBlank()) { - config.sourceSetID = config.moduleName + "/" + config.name - } - config.dependentSourceSets = config.dependentSourceSets.map { config.moduleName + "/" + it }.toMutableList() + if (config.displayName.isBlank()) { - config.displayName = config.sourceSetID.substringBeforeLast("Main", config.platform.toString()) + config.displayName = config.name.substringBeforeLast("Main", config.platform.toString()) } config.classpath = (config.classpath as List).map { it.toString() }.distinct() // Workaround for Groovy's GStringImpl diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt index a28416d6..7b2d05a6 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/configurationImplementations.kt @@ -1,13 +1,19 @@ +@file:Suppress("FunctionName") + package org.jetbrains.dokka.gradle +import com.android.build.gradle.api.AndroidSourceSet import groovy.lang.Closure import org.gradle.api.Action +import org.gradle.api.Project import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Optional import org.gradle.util.ConfigureUtil import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaConfiguration.* import org.jetbrains.dokka.DokkaDefaults +import org.jetbrains.dokka.DokkaSourceSetID import org.jetbrains.dokka.Platform import java.io.File import java.io.Serializable @@ -15,6 +21,8 @@ import java.net.URL import java.util.concurrent.Callable import kotlin.reflect.KMutableProperty import kotlin.reflect.full.memberProperties +import org.gradle.api.tasks.SourceSet as GradleSourceSet +import org.jetbrains.kotlin.gradle.model.SourceSet as KotlinSourceSet class GradleSourceRootImpl : SourceRoot, Serializable { override var path: String = "" @@ -25,64 +33,113 @@ class GradleSourceRootImpl : SourceRoot, Serializable { override fun toString(): String = path } -open class GradleDokkaSourceSet(@Transient val name: String = "") : DokkaSourceSet { +open class GradleDokkaSourceSet constructor( + @Transient val name: String, + @Transient internal val project: Project +) : DokkaSourceSet { + @Input @Optional override var classpath: List = emptyList() + @Input - override var moduleName: String = "" + override var moduleDisplayName: String = "" + @Input override var displayName: String = "" - @Input - override var sourceSetID: String = "" + + @get:Internal + override val sourceSetID: DokkaSourceSetID = DokkaSourceSetID(project, name) + @Input override var sourceRoots: MutableList = mutableListOf() + @Input - override var dependentSourceSets: MutableList = mutableListOf() + override var dependentSourceSets: MutableSet = mutableSetOf() + @Input override var samples: List = emptyList() + @Input override var includes: List = emptyList() + @Input override var includeNonPublic: Boolean = DokkaDefaults.includeNonPublic + @Input override var includeRootPackage: Boolean = DokkaDefaults.includeRootPackage + @Input override var reportUndocumented: Boolean = DokkaDefaults.reportUndocumented + @Input override var skipEmptyPackages: Boolean = DokkaDefaults.skipEmptyPackages + @Input override var skipDeprecated: Boolean = DokkaDefaults.skipDeprecated + @Input override var jdkVersion: Int = DokkaDefaults.jdkVersion + @Input override var sourceLinks: MutableList = mutableListOf() + @Input override var perPackageOptions: MutableList = mutableListOf() + @Input override var externalDocumentationLinks: MutableList = mutableListOf() + @Input @Optional override var languageVersion: String? = null + @Input @Optional override var apiVersion: String? = null + @Input override var noStdlibLink: Boolean = DokkaDefaults.noStdlibLink + @Input override var noJdkLink: Boolean = DokkaDefaults.noJdkLink + @Input var noAndroidSdkLink: Boolean = false + @Input override var suppressedFiles: List = emptyList() + @Input override var analysisPlatform: Platform = DokkaDefaults.analysisPlatform + @Input @Optional var platform: String? = null + @Transient var collectKotlinTasks: (() -> List?)? = null + fun DokkaSourceSetID(sourceSetName: String): DokkaSourceSetID { + return DokkaSourceSetID(project, sourceSetName) + } + + fun dependsOn(sourceSet: GradleSourceSet) { + dependsOn(DokkaSourceSetID(sourceSet.name)) + } + + fun dependsOn(sourceSet: DokkaSourceSet) { + dependsOn(sourceSet.sourceSetID) + } + + fun dependsOn(sourceSetName: String) { + dependsOn(DokkaSourceSetID(sourceSetName)) + } + + fun dependsOn(sourceSetID: DokkaSourceSetID) { + dependentSourceSets.add(sourceSetID) + } + fun kotlinTasks(taskSupplier: Callable>) { collectKotlinTasks = { taskSupplier.call() } } @@ -136,6 +193,18 @@ open class GradleDokkaSourceSet(@Transient val name: String = "") : DokkaSourceS } } +fun GradleDokkaSourceSet.dependsOn(sourceSet: KotlinSourceSet) { + dependsOn(DokkaSourceSetID(sourceSet.name)) +} + +fun GradleDokkaSourceSet.dependsOn(sourceSet: org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet) { + dependsOn(DokkaSourceSetID(sourceSet.name)) +} + +fun GradleDokkaSourceSet.dependsOn(sourceSet: AndroidSourceSet) { + dependsOn(DokkaSourceSetID(sourceSet.name)) +} + class GradleSourceLinkDefinitionImpl : SourceLinkDefinition, Serializable { override var path: String = "" override var url: String = "" @@ -174,16 +243,16 @@ class GradlePackageOptionsImpl : PackageOptions, Serializable { } internal fun GradleDokkaSourceSet.copy(): GradleDokkaSourceSet { - val newObj = GradleDokkaSourceSet(this.name) + val newObj = GradleDokkaSourceSet(this.name, this.project) this::class.memberProperties.forEach { field -> if (field is KMutableProperty<*>) { - val value = field.getter.call(this) - if (value is Collection<*>) { - field.setter.call(newObj, value.toMutableList()) - } else { - field.setter.call(newObj, field.getter.call(this)) + when (val value = field.getter.call(this)) { + is List<*> -> field.setter.call(newObj, value.toMutableList()) + is Set<*> -> field.setter.call(newObj, value.toMutableSet()) + else -> field.setter.call(newObj, field.getter.call(this)) } + } } return newObj -} \ No newline at end of file +} diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt index 92d63a40..a92f5475 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt @@ -53,7 +53,9 @@ open class DokkaPlugin : Plugin { project.tasks.create(DOKKA_TASK_NAME, taskClass) } project.tasks.withType(taskClass) { task -> - task.dokkaSourceSets = project.container(GradleDokkaSourceSet::class.java) + task.dokkaSourceSets = project.container(GradleDokkaSourceSet::class.java) { name -> + GradleDokkaSourceSet(name, project) + } task.dokkaRuntime = runtimeConfiguration task.pluginsClasspathConfiguration = pluginsConfiguration task.outputDirectory = File(project.buildDir, DOKKA_TASK_NAME).absolutePath diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt index 0b80f4a2..da6daeea 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/KotlinDslDokkaTaskConfigurationTest.kt @@ -1,6 +1,9 @@ package org.jetbrains.dokka.gradle +import org.gradle.api.plugins.JavaPluginExtension import org.gradle.testfixtures.ProjectBuilder +import org.jetbrains.dokka.DokkaSourceSetID +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import kotlin.test.Test import kotlin.test.assertEquals @@ -16,4 +19,78 @@ class KotlinDslDokkaTaskConfigurationTest { assertEquals("test", dokkaTask.outputFormat) } } + + @Test + fun `sourceSet dependsOn by String`() { + val project = ProjectBuilder.builder().build() + project.plugins.apply("org.jetbrains.dokka") + + project.dokka { + dokkaSourceSets.run { + val commonMain = create("commonMain") + val jvmMain = create("jvmMain") { + it.dependsOn("commonMain") + } + + assertEquals( + 0, commonMain.dependentSourceSets.size, + "Expected no dependent source set in commonMain" + ) + + assertEquals( + 1, jvmMain.dependentSourceSets.size, + "Expected only one dependent source set in jvmMain" + ) + + assertEquals( + commonMain.sourceSetID, jvmMain.dependentSourceSets.single(), + "Expected jvmMain to depend on commonMain" + ) + + assertEquals( + DokkaSourceSetID(project.path, "commonMain"), commonMain.sourceSetID + ) + } + } + } + + @Test + fun `sourceSet dependsOn by DokkaSourceSet`() { + val project = ProjectBuilder.builder().build() + project.plugins.apply("org.jetbrains.dokka") + + project.dokka { + dokkaSourceSets.run { + val commonMain = create("commonMain") + val jvmMain = create("jvmMain") { + it.dependsOn(commonMain) + } + + assertEquals( + commonMain.sourceSetID, jvmMain.dependentSourceSets.single() + ) + } + } + } + + @Test + fun `sourceSet dependsOn by KotlinSourceSet`() { + val project = ProjectBuilder.builder().build() + project.plugins.apply("org.jetbrains.dokka") + project.plugins.apply("org.jetbrains.kotlin.jvm") + + val kotlin = project.extensions.getByName("kotlin") as KotlinJvmProjectExtension + + project.dokka { + dokkaSourceSets.run { + val special = create("special") { + it.dependsOn(kotlin.sourceSets.getByName("main")) + } + + assertEquals( + DokkaSourceSetID(project, "main"), special.dependentSourceSets.single() + ) + } + } + } } diff --git a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt index 4c10568c..8160ab87 100644 --- a/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt +++ b/runners/maven-plugin/src/main/kotlin/DokkaMojo.kt @@ -90,9 +90,6 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter var sourceRoots: List = emptyList() - @Parameter - var dependentSourceSets: List = emptyList() - @Parameter var samples: List = emptyList() @@ -108,6 +105,9 @@ abstract class AbstractDokkaMojo : AbstractMojo() { @Parameter(required = true, defaultValue = "\${project.artifactId}") var moduleName: String = "" + @Parameter + var moduleDisplayName: String = "" + @Parameter(required = false, defaultValue = "false") var skip: Boolean = false @@ -201,12 +201,12 @@ abstract class AbstractDokkaMojo : AbstractMojo() { } val sourceSet = DokkaSourceSetImpl( - moduleName = moduleName, + moduleDisplayName = moduleDisplayName.takeIf(String::isNotBlank) ?: moduleName, displayName = displayName, - sourceSetID = sourceSetName, + sourceSetID = DokkaSourceSetID(moduleName, sourceSetName), classpath = classpath, sourceRoots = sourceDirectories.map { SourceRootImpl(it) }, - dependentSourceSets = dependentSourceSets, + dependentSourceSets = emptySet(), samples = samples, includes = includes, includeNonPublic = includeNonPublic, @@ -246,7 +246,7 @@ abstract class AbstractDokkaMojo : AbstractMojo() { offlineMode = offlineMode, cacheRoot = cacheRoot, sourceSets = listOf(sourceSet).also { - if (sourceSet.moduleName.isEmpty()) logger.warn("Not specified module name. It can result in unexpected behaviour while including documentation for module") + if (sourceSet.moduleDisplayName.isEmpty()) logger.warn("Not specified module name. It can result in unexpected behaviour while including documentation for module") }, pluginsClasspath = getArtifactByAether("org.jetbrains.dokka", "dokka-base", dokkaVersion) + dokkaPlugins.map { getArtifactByAether(it.groupId, it.artifactId, it.version) }.flatten(), diff --git a/testApi/src/main/kotlin/testApi/context/MockContext.kt b/testApi/src/main/kotlin/testApi/context/MockContext.kt index 07aedf28..97347695 100644 --- a/testApi/src/main/kotlin/testApi/context/MockContext.kt +++ b/testApi/src/main/kotlin/testApi/context/MockContext.kt @@ -1,7 +1,6 @@ package org.jetbrains.dokka.testApi.context import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.plugability.ExtensionPoint @@ -45,4 +44,4 @@ class MockContext( private fun DokkaPlugin.injectContext(context: DokkaContext) { (DokkaPlugin::class.memberProperties.single { it.name == "context" } as KMutableProperty<*>) .setter.call(this, context) -} \ No newline at end of file +} diff --git a/testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt b/testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt index ec2be689..d3127263 100644 --- a/testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt +++ b/testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt @@ -1,7 +1,6 @@ package org.jetbrains.dokka.testApi.testRunner import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.DokkaGenerator import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.utilities.DokkaLogger @@ -43,4 +42,4 @@ internal class DokkaTestGenerator( dokkaGenerator.reportAfterRendering(context) } -} \ No newline at end of file +} diff --git a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt index 057045a8..381fb2af 100644 --- a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt +++ b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt @@ -174,25 +174,26 @@ abstract class AbstractCoreTest { failOnWarning = failOnWarning ) - fun passes(block: Passes.() -> Unit) { - sourceSets.addAll(Passes().apply(block)) + fun sourceSets(block: SourceSetsBuilder.() -> Unit) { + sourceSets.addAll(SourceSetsBuilder().apply(block)) } } @DokkaConfigurationDsl - protected class Passes : ArrayList() { - fun pass(block: DokkaSourceSetBuilder.() -> Unit) = - add(DokkaSourceSetBuilder().apply(block).build()) + protected class SourceSetsBuilder : ArrayList() { + fun sourceSet(block: DokkaSourceSetBuilder.() -> Unit): DokkaSourceSet = + DokkaSourceSetBuilder().apply(block).build().apply(::add) } @DokkaConfigurationDsl protected class DokkaSourceSetBuilder( var moduleName: String = "root", - var sourceSetID: String = "main", + var moduleDisplayName: String? = null, + var name: String = "main", var displayName: String = "JVM", var classpath: List = emptyList(), var sourceRoots: List = emptyList(), - var dependentSourceSets: List = emptyList(), + var dependentSourceSets: Set = emptySet(), var samples: List = emptyList(), var includes: List = emptyList(), var includeNonPublic: Boolean = false, @@ -212,9 +213,9 @@ abstract class AbstractCoreTest { var sourceLinks: List = emptyList() ) { fun build() = DokkaSourceSetImpl( - moduleName = moduleName, + moduleDisplayName = moduleDisplayName ?: moduleName, displayName = displayName, - sourceSetID = sourceSetID, + sourceSetID = DokkaSourceSetID(moduleName, name), classpath = classpath, sourceRoots = sourceRoots.map { SourceRootImpl(it) }, dependentSourceSets = dependentSourceSets, -- cgit