From 46d7f6a3f84f643f7bcbf2a2b5c0a01901b4adf2 Mon Sep 17 00:00:00 2001 From: Vadim Mishenev Date: Mon, 13 Dec 2021 14:53:27 +0300 Subject: [PATCH 1/3] Add test to resolve in UltraLightMethod --- .../DefaultPsiToDocumentableTranslatorTest.kt | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt index 27a06b7746..76ce500100 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.base.DokkaBase +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.model.TypeConstructor import org.jetbrains.dokka.model.doc.Text import org.jetbrains.dokka.model.firstMemberOfType -import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Annotations +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,64 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() { } } } + + class OnlyPsiPlugin : DokkaPlugin() { + private val dokkaBase by lazy { plugin() } + + @Suppress("unused") + val psiOverrideDescriptorTranslator by extending { + (dokkaBase.psiToDocumentableTranslator + override dokkaBase.descriptorToDocumentableTranslator) + } + } + + @Test + fun `psi bug`() { + 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 + ) + } + } + } } From 9647cabf92efa938c7d776f1c736f8aa1481f1eb Mon Sep 17 00:00:00 2001 From: vmishenev Date: Mon, 27 Dec 2021 12:45:53 +0300 Subject: [PATCH 2/3] Enable `eagerResolveOfLightClasses` analysis flag --- .../org/jetbrains/dokka/analysis/AnalysisEnvironment.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt index 0d15937464..f5f0058492 100644 --- a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt +++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt @@ -478,7 +478,7 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl projectContext.withModule(descriptor), modulesContent(moduleInfo), this, - LanguageVersionSettingsImpl.DEFAULT, + configuration.languageVersionSettings, CliSealedClassInheritorsProvider, ) @@ -490,7 +490,11 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl val languageVersion = LanguageVersion.fromVersionString(languageVersionString) ?: LanguageVersion.LATEST_STABLE val apiVersion = apiVersionString?.let { ApiVersion.parse(it) } ?: ApiVersion.createByLanguageVersion(languageVersion) - configuration.languageVersionSettings = LanguageVersionSettingsImpl(languageVersion, apiVersion) + configuration.languageVersionSettings = LanguageVersionSettingsImpl( + languageVersion = languageVersion, + apiVersion = apiVersion, + analysisFlags = hashMapOf(org.jetbrains.kotlin.config.AnalysisFlags.eagerResolveOfLightClasses to true) + ) } /** From 0ff1bebd60fec8000a11ba2f7572c4cb40007563 Mon Sep 17 00:00:00 2001 From: vmishenev Date: Mon, 28 Mar 2022 17:55:24 +0300 Subject: [PATCH 3/3] Refactor --- .../org/jetbrains/dokka/analysis/AnalysisEnvironment.kt | 8 +++++--- .../translators/DefaultPsiToDocumentableTranslatorTest.kt | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt index f5f0058492..393a2c6240 100644 --- a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt +++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt @@ -49,6 +49,7 @@ import org.jetbrains.kotlin.idea.klib.KlibLoadingMetadataCache import org.jetbrains.kotlin.idea.klib.getCompatibilityInfo import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.resolve.JsPlatformAnalyzerServices +import org.jetbrains.kotlin.library.KLIB_FILE_EXTENSION import org.jetbrains.kotlin.library.ToolingSingleFileKlibResolveStrategy import org.jetbrains.kotlin.library.resolveSingleFileKlib import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl @@ -75,7 +76,6 @@ import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices import org.jetbrains.kotlin.resolve.konan.platform.NativePlatformAnalyzerServices import java.io.File import org.jetbrains.kotlin.konan.file.File as KFile -import org.jetbrains.kotlin.library.KLIB_FILE_EXTENSION const val JAR_SEPARATOR = "!/" @@ -492,8 +492,10 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl apiVersionString?.let { ApiVersion.parse(it) } ?: ApiVersion.createByLanguageVersion(languageVersion) configuration.languageVersionSettings = LanguageVersionSettingsImpl( languageVersion = languageVersion, - apiVersion = apiVersion, - analysisFlags = hashMapOf(org.jetbrains.kotlin.config.AnalysisFlags.eagerResolveOfLightClasses to true) + apiVersion = apiVersion, analysisFlags = hashMapOf( + // force to resolve light classes (lazily by default) + AnalysisFlags.eagerResolveOfLightClasses to true + ) ) } diff --git a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt index 76ce500100..9f74e2196f 100644 --- a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt +++ b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt @@ -2,11 +2,11 @@ package translators 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.links.DRI -import org.jetbrains.dokka.model.Annotations import org.jetbrains.dokka.plugability.DokkaPlugin import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue @@ -208,8 +208,9 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() { } } + // for Kotlin classes from DefaultPsiToDocumentableTranslator @Test - fun `psi bug`() { + fun `should resolve ultralight class`() { val configurationWithNoJVM = dokkaConfiguration { sourceSets { sourceSet {