diff --git a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt index 962841ba56..118d80c6be 100644 --- a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt +++ b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt @@ -8,7 +8,7 @@ import kotlin.test.assertEquals import kotlin.test.asserter // entry point: -fun ContentNode.assertNode(block: ContentMatcherBuilder.() -> Unit) { +public fun ContentNode.assertNode(block: ContentMatcherBuilder.() -> Unit) { val matcher = ContentMatcherBuilder(ContentComposite::class).apply(block).build() try { matcher.tryMatch(this) @@ -20,123 +20,161 @@ fun ContentNode.assertNode(block: ContentMatcherBuilder.() -> // DSL: @DslMarker -annotation class ContentMatchersDsl +public annotation class ContentMatchersDsl @ContentMatchersDsl -class ContentMatcherBuilder @PublishedApi internal constructor(private val kclass: KClass) { +public class ContentMatcherBuilder @PublishedApi internal constructor(private val kclass: KClass) { @PublishedApi - internal val children = mutableListOf() + internal val children: MutableList = mutableListOf() internal val assertions = mutableListOf Unit>() - fun build() = CompositeMatcher(kclass, childrenOrSkip()) { assertions.forEach { it() } } + public fun build(): CompositeMatcher = CompositeMatcher(kclass, childrenOrSkip()) { assertions.forEach { it() } } // part of DSL that cannot be defined as an extension - operator fun String.unaryPlus() { + public operator fun String.unaryPlus() { children += TextMatcher(this) } private fun childrenOrSkip() = if (children.isEmpty() && assertions.isNotEmpty()) listOf(Anything) else children } -fun ContentMatcherBuilder.check(assertion: T.() -> Unit) { +public fun ContentMatcherBuilder.check(assertion: T.() -> Unit) { assertions += assertion } private val ContentComposite.extractedText get() = withDescendants().filterIsInstance().joinToString(separator = "") { it.text } -fun ContentMatcherBuilder.hasExactText(expected: String) { +public fun ContentMatcherBuilder.hasExactText(expected: String) { assertions += { assertEquals(expected, this.extractedText) } } -inline fun ContentMatcherBuilder<*>.composite( +public inline fun ContentMatcherBuilder<*>.composite( block: ContentMatcherBuilder.() -> Unit ) { children += ContentMatcherBuilder(S::class).apply(block).build() } -inline fun ContentMatcherBuilder<*>.node(noinline assertions: S.() -> Unit = {}) { +public inline fun ContentMatcherBuilder<*>.node(noinline assertions: S.() -> Unit = {}) { children += NodeMatcher(S::class, assertions) } -fun ContentMatcherBuilder<*>.skipAllNotMatching() { +public fun ContentMatcherBuilder<*>.skipAllNotMatching() { children += Anything } // Convenience functions: -fun ContentMatcherBuilder<*>.group(block: ContentMatcherBuilder.() -> Unit) = composite(block) +public fun ContentMatcherBuilder<*>.group(block: ContentMatcherBuilder.() -> Unit) { + composite(block) +} -fun ContentMatcherBuilder<*>.tabbedGroup( +public fun ContentMatcherBuilder<*>.tabbedGroup( block: ContentMatcherBuilder.() -> Unit -) = composite { - block() - check { assertContains(this.style, ContentStyle.TabbedContent) } +) { + composite { + block() + check { assertContains(this.style, ContentStyle.TabbedContent) } + } } -fun ContentMatcherBuilder<*>.tab( +public fun ContentMatcherBuilder<*>.tab( tabbedContentType: TabbedContentType, block: ContentMatcherBuilder.() -> Unit -) = composite { - block() - check { - assertEquals(tabbedContentType, this.extra[TabbedContentTypeExtra]?.value) +) { + composite { + block() + check { + assertEquals(tabbedContentType, this.extra[TabbedContentTypeExtra]?.value) + } } } -fun ContentMatcherBuilder<*>.header(expectedLevel: Int? = null, block: ContentMatcherBuilder.() -> Unit) = +public fun ContentMatcherBuilder<*>.header(expectedLevel: Int? = null, block: ContentMatcherBuilder.() -> Unit) { composite { block() check { if (expectedLevel != null) assertEquals(expectedLevel, this.level) } } +} -fun ContentMatcherBuilder<*>.p(block: ContentMatcherBuilder.() -> Unit) = +public fun ContentMatcherBuilder<*>.p(block: ContentMatcherBuilder.() -> Unit) { composite { block() check { assertContains(this.style, TextStyle.Paragraph) } } +} -fun ContentMatcherBuilder<*>.link(block: ContentMatcherBuilder.() -> Unit) = composite(block) +public fun ContentMatcherBuilder<*>.link(block: ContentMatcherBuilder.() -> Unit) { + composite(block) +} -fun ContentMatcherBuilder<*>.table(block: ContentMatcherBuilder.() -> Unit) = composite(block) +public fun ContentMatcherBuilder<*>.table(block: ContentMatcherBuilder.() -> Unit) { + composite(block) +} -fun ContentMatcherBuilder<*>.platformHinted(block: ContentMatcherBuilder.() -> Unit) = +public fun ContentMatcherBuilder<*>.platformHinted(block: ContentMatcherBuilder.() -> Unit) { composite { group(block) } +} -fun ContentMatcherBuilder<*>.list(block: ContentMatcherBuilder.() -> Unit) = composite(block) +public fun ContentMatcherBuilder<*>.list(block: ContentMatcherBuilder.() -> Unit) { + composite(block) +} -fun ContentMatcherBuilder<*>.codeBlock(block: ContentMatcherBuilder.() -> Unit) = composite(block) +public fun ContentMatcherBuilder<*>.codeBlock(block: ContentMatcherBuilder.() -> Unit) { + composite(block) +} -fun ContentMatcherBuilder<*>.codeInline(block: ContentMatcherBuilder.() -> Unit) = composite(block) +public fun ContentMatcherBuilder<*>.codeInline(block: ContentMatcherBuilder.() -> Unit) { + composite(block) +} -fun ContentMatcherBuilder<*>.caption(block: ContentMatcherBuilder.() -> Unit) = composite { - block() - check { assertContains(this.style, ContentStyle.Caption) } +public fun ContentMatcherBuilder<*>.caption(block: ContentMatcherBuilder.() -> Unit) { + composite { + block() + check { assertContains(this.style, ContentStyle.Caption) } + } } -fun ContentMatcherBuilder<*>.br() = node() +public fun ContentMatcherBuilder<*>.br() { + node() +} -fun ContentMatcherBuilder<*>.somewhere(block: ContentMatcherBuilder<*>.() -> Unit) { +public fun ContentMatcherBuilder<*>.somewhere(block: ContentMatcherBuilder<*>.() -> Unit) { skipAllNotMatching() block() skipAllNotMatching() } -fun ContentMatcherBuilder<*>.divergentGroup(block: ContentMatcherBuilder.() -> Unit) = +public fun ContentMatcherBuilder<*>.divergentGroup( + block: ContentMatcherBuilder.() -> Unit +) { composite(block) +} -fun ContentMatcherBuilder.divergentInstance(block: ContentMatcherBuilder.() -> Unit) = +public fun ContentMatcherBuilder.divergentInstance( + block: ContentMatcherBuilder.() -> Unit +) { composite(block) +} -fun ContentMatcherBuilder.before(block: ContentMatcherBuilder.() -> Unit) = +public fun ContentMatcherBuilder.before( + block: ContentMatcherBuilder.() -> Unit +) { composite(block) +} -fun ContentMatcherBuilder.divergent(block: ContentMatcherBuilder.() -> Unit) = +public fun ContentMatcherBuilder.divergent( + block: ContentMatcherBuilder.() -> Unit +) { composite(block) +} -fun ContentMatcherBuilder.after(block: ContentMatcherBuilder.() -> Unit) = +public fun ContentMatcherBuilder.after( + block: ContentMatcherBuilder.() -> Unit +) { composite(block) +} /* * TODO replace with kotlin.test.assertContains after migrating to Kotlin language version 1.5+ diff --git a/subprojects/analysis-java-psi/src/main/kotlin/org/jetbrains/dokka/analysis/java/util/PsiUtil.kt b/subprojects/analysis-java-psi/src/main/kotlin/org/jetbrains/dokka/analysis/java/util/PsiUtil.kt index 9e10bbf47c..30c9541e37 100644 --- a/subprojects/analysis-java-psi/src/main/kotlin/org/jetbrains/dokka/analysis/java/util/PsiUtil.kt +++ b/subprojects/analysis-java-psi/src/main/kotlin/org/jetbrains/dokka/analysis/java/util/PsiUtil.kt @@ -13,7 +13,7 @@ internal val PsiElement.parentsWithSelf: Sequence get() = generateSequence(this) { if (it is PsiFile) null else it.parent } @InternalDokkaApi -fun DRI.Companion.from(psi: PsiElement) = psi.parentsWithSelf.run { +public fun DRI.Companion.from(psi: PsiElement): DRI = psi.parentsWithSelf.run { val psiMethod = firstIsInstanceOrNull() val psiField = firstIsInstanceOrNull() val classes = filterIsInstance().filterNot { it is PsiTypeParameter } diff --git a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/services/KotlinSampleProvider.kt b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/services/KotlinSampleProvider.kt index dc61b35b5e..353bcee742 100644 --- a/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/services/KotlinSampleProvider.kt +++ b/subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/services/KotlinSampleProvider.kt @@ -17,7 +17,9 @@ import org.jetbrains.kotlin.psi.KtBlockExpression import org.jetbrains.kotlin.psi.KtDeclarationWithBody import org.jetbrains.kotlin.psi.KtFile -class KotlinSampleProviderFactory(val context: DokkaContext): SampleProviderFactory { +public class KotlinSampleProviderFactory( + public val context: DokkaContext +): SampleProviderFactory { override fun build(): SampleProvider { return KotlinSampleProvider(context) } @@ -28,7 +30,9 @@ class KotlinSampleProviderFactory(val context: DokkaContext): SampleProviderFact * with [processBody] and [processImports] */ @InternalDokkaApi -open class KotlinSampleProvider(val context: DokkaContext): SampleProvider { +public open class KotlinSampleProvider( + public val context: DokkaContext +): SampleProvider { private val kotlinAnalysis = SamplesKotlinAnalysis( sourceSets = context.configuration.sourceSets, context = context, @@ -82,4 +86,4 @@ open class KotlinSampleProvider(val context: DokkaContext): SampleProvider { override fun close() { kotlinAnalysis.close() } -} \ No newline at end of file +}