From 57133de2fef1be68d9f05e6c262c31288de6cbcd Mon Sep 17 00:00:00 2001 From: Vadim Mishenev Date: Mon, 28 Mar 2022 18:26:29 +0300 Subject: Bug resolving in ultralightmethod (#2400) --- .../DefaultPsiToDocumentableTranslatorTest.kt | 69 +++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'plugins/base') diff --git a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt index 27a06b77..9f74e219 100644 --- a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt +++ b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt @@ -1,13 +1,17 @@ package translators -import org.jetbrains.dokka.model.doc.Text -import org.jetbrains.dokka.model.firstMemberOfType +import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Annotations +import org.jetbrains.dokka.model.TypeConstructor +import org.jetbrains.dokka.model.doc.Text +import org.jetbrains.dokka.model.firstMemberOfType +import org.jetbrains.dokka.plugability.DokkaPlugin import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test +import utils.assertNotNull class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() { val configuration = dokkaConfiguration { @@ -193,4 +197,65 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() { } } } + + class OnlyPsiPlugin : DokkaPlugin() { + private val dokkaBase by lazy { plugin() } + + @Suppress("unused") + val psiOverrideDescriptorTranslator by extending { + (dokkaBase.psiToDocumentableTranslator + override dokkaBase.descriptorToDocumentableTranslator) + } + } + + // for Kotlin classes from DefaultPsiToDocumentableTranslator + @Test + fun `should resolve ultralight class`() { + val configurationWithNoJVM = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/main/java") + } + } + } + + testInline( + """ + |/src/main/java/example/Test.kt + |package example + | + |open class KotlinSubClass { + | fun kotlinSubclassFunction(bar: String): String { + | return "KotlinSubClass" + | } + |} + | + |/src/main/java/example/JavaLeafClass.java + |package example; + | + |public class JavaLeafClass extends KotlinSubClass { + | public String javaLeafClassFunction(String baz) { + | return "JavaLeafClass"; + | } + |} + """.trimMargin(), + configurationWithNoJVM, + pluginOverrides = listOf(OnlyPsiPlugin()) // suppress a descriptor translator because of psi and descriptor translators work in parallel + ) { + documentablesMergingStage = { module -> + val kotlinSubclassFunction = + module.packages.single().classlikes.find { it.name == "JavaLeafClass" }?.functions?.find { it.name == "kotlinSubclassFunction" } + .assertNotNull("kotlinSubclassFunction ") + + assertEquals( + "String", + (kotlinSubclassFunction.type as? TypeConstructor)?.dri?.classNames + ) + assertEquals( + "String", + (kotlinSubclassFunction.parameters.firstOrNull()?.type as? TypeConstructor)?.dri?.classNames + ) + } + } + } } -- cgit