From f199671c4d33390a38d7754f65b99d90a50c0c79 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Thu, 19 Jan 2023 18:37:54 +0900 Subject: [PATCH] [LL API] Make 'KtNotUnderContentRootModuleForTest' depend on built-ins --- .../structure/impl/KtModuleProviderImpl.kt | 2 + .../impl/KtNotUnderContentRootModuleImpl.kt | 1 + .../AnalysisApiKtModuleProviderImpl.kt | 2 +- .../KtOutOfContentRootModuleFactory.kt | 53 ------------------- ...sApiFirOutOfContentRootTestConfigurator.kt | 52 +++++++++++++++++- .../analysis/project/structure/KtModule.kt | 5 ++ 6 files changed, 59 insertions(+), 56 deletions(-) delete mode 100644 analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtOutOfContentRootModuleFactory.kt diff --git a/analysis/analysis-api-standalone/src/org/jetbrains/kotlin/analysis/project/structure/impl/KtModuleProviderImpl.kt b/analysis/analysis-api-standalone/src/org/jetbrains/kotlin/analysis/project/structure/impl/KtModuleProviderImpl.kt index 9a48dba8d26..a530b258fd0 100644 --- a/analysis/analysis-api-standalone/src/org/jetbrains/kotlin/analysis/project/structure/impl/KtModuleProviderImpl.kt +++ b/analysis/analysis-api-standalone/src/org/jetbrains/kotlin/analysis/project/structure/impl/KtModuleProviderImpl.kt @@ -24,6 +24,7 @@ internal class KtModuleProviderImpl( ) : ProjectStructureProvider() { private val ktNotUnderContentRootModuleWithoutPsiFile by lazy { KtNotUnderContentRootModuleImpl( + name = "unnamed-outside-content-root", moduleDescription = "Standalone-not-under-content-root-module-without-psi-file", project = project, ) @@ -44,6 +45,7 @@ internal class KtModuleProviderImpl( val containingFileAsVirtualFile = containingFileAsPsiFile.virtualFile ?: return notUnderContentRootModuleCache.getOrPut(containingFileAsPsiFile) { KtNotUnderContentRootModuleImpl( + name = containingFileAsPsiFile.name, moduleDescription = "Standalone-not-under-content-root-module-for-$containingFileAsPsiFile", file = containingFileAsPsiFile, project = project, diff --git a/analysis/analysis-api-standalone/src/org/jetbrains/kotlin/analysis/project/structure/impl/KtNotUnderContentRootModuleImpl.kt b/analysis/analysis-api-standalone/src/org/jetbrains/kotlin/analysis/project/structure/impl/KtNotUnderContentRootModuleImpl.kt index 3ba0f959629..6b2328bef7b 100644 --- a/analysis/analysis-api-standalone/src/org/jetbrains/kotlin/analysis/project/structure/impl/KtNotUnderContentRootModuleImpl.kt +++ b/analysis/analysis-api-standalone/src/org/jetbrains/kotlin/analysis/project/structure/impl/KtNotUnderContentRootModuleImpl.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices internal class KtNotUnderContentRootModuleImpl( + override val name: String, override val directRegularDependencies: List = emptyList(), override val directRefinementDependencies: List = emptyList(), override val directFriendDependencies: List = emptyList(), diff --git a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/AnalysisApiKtModuleProviderImpl.kt b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/AnalysisApiKtModuleProviderImpl.kt index d88141804fd..da61de08bf3 100644 --- a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/AnalysisApiKtModuleProviderImpl.kt +++ b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/AnalysisApiKtModuleProviderImpl.kt @@ -57,7 +57,7 @@ fun List.associateByName(): Map { is KtLibrarySourceModule -> ktModule.libraryName is KtSdkModule -> ktModule.sdkName is KtBuiltinsModule -> "Builtins for ${ktModule.platform}" - is KtNotUnderContentRootModuleForTest -> ktModule.moduleName + is KtNotUnderContentRootModule -> ktModule.name else -> error("Unsupported module type: " + ktModule.javaClass.name) } } diff --git a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtOutOfContentRootModuleFactory.kt b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtOutOfContentRootModuleFactory.kt deleted file mode 100644 index b4ebfba9b28..00000000000 --- a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtOutOfContentRootModuleFactory.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.analysis.test.framework.project.structure - -import com.intellij.openapi.project.Project -import com.intellij.psi.PsiFile -import com.intellij.psi.search.GlobalSearchScope -import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtModuleWithFiles -import org.jetbrains.kotlin.analysis.project.structure.KtModule -import org.jetbrains.kotlin.analysis.project.structure.KtNotUnderContentRootModule -import org.jetbrains.kotlin.platform.TargetPlatform -import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices -import org.jetbrains.kotlin.test.getAnalyzerServices -import org.jetbrains.kotlin.test.model.TestModule -import org.jetbrains.kotlin.test.services.TestServices - -class KtOutOfContentRootModuleFactory : KtModuleFactory { - override fun createModule(testModule: TestModule, testServices: TestServices, project: Project): KtModuleWithFiles { - val psiFiles = TestModuleStructureFactory.createSourcePsiFiles(testModule, testServices, project) - val module = KtNotUnderContentRootModuleForTest(testModule.name, psiFiles.single(), testModule.targetPlatform) - return KtModuleWithFiles(module, psiFiles) - } -} - -internal class KtNotUnderContentRootModuleForTest( - val moduleName: String, - override val file: PsiFile, - override val platform: TargetPlatform -) : KtNotUnderContentRootModule { - override val directRegularDependencies: List - get() = emptyList() - - override val directRefinementDependencies: List - get() = emptyList() - - override val directFriendDependencies: List - get() = emptyList() - - override val contentScope: GlobalSearchScope - get() = GlobalSearchScope.fileScope(file) - - override val analyzerServices: PlatformDependentAnalyzerServices - get() = platform.getAnalyzerServices() - - override val project: Project - get() = file.project - - override val moduleDescription: String - get() = "Not under content root for ${file.virtualFile.path}" -} \ No newline at end of file diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirOutOfContentRootTestConfigurator.kt b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirOutOfContentRootTestConfigurator.kt index 44d4f716f20..0e9f2d237bc 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirOutOfContentRootTestConfigurator.kt +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirOutOfContentRootTestConfigurator.kt @@ -6,13 +6,23 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators import com.intellij.openapi.Disposable +import com.intellij.openapi.project.Project import com.intellij.psi.PsiFile +import com.intellij.psi.search.GlobalSearchScope +import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtModuleWithFiles +import org.jetbrains.kotlin.analysis.low.level.api.fir.project.structure.LLFirBuiltinsSessionFactory +import org.jetbrains.kotlin.analysis.project.structure.KtBuiltinsModule +import org.jetbrains.kotlin.analysis.project.structure.KtModule +import org.jetbrains.kotlin.analysis.project.structure.KtNotUnderContentRootModule import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtModuleFactory -import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtOutOfContentRootModuleFactory +import org.jetbrains.kotlin.analysis.test.framework.project.structure.TestModuleStructureFactory import org.jetbrains.kotlin.analysis.test.framework.utils.SkipTestException +import org.jetbrains.kotlin.platform.TargetPlatform +import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer +import org.jetbrains.kotlin.test.getAnalyzerServices import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.TestServices @@ -45,4 +55,42 @@ object AnalysisApiFirOutOfContentRootTestConfigurator : AnalysisApiFirSourceLike } } -private class SkipWhenOutOfContentRootException : SkipTestException() \ No newline at end of file +private class SkipWhenOutOfContentRootException : SkipTestException() + +private class KtOutOfContentRootModuleFactory : KtModuleFactory { + override fun createModule(testModule: TestModule, testServices: TestServices, project: Project): KtModuleWithFiles { + val psiFiles = TestModuleStructureFactory.createSourcePsiFiles(testModule, testServices, project) + val platform = testModule.targetPlatform + val module = KtNotUnderContentRootModuleForTest(testModule.name, psiFiles.single(), platform) + return KtModuleWithFiles(module, psiFiles) + } +} + +private class KtNotUnderContentRootModuleForTest( + override val name: String, + override val file: PsiFile, + override val platform: TargetPlatform +) : KtNotUnderContentRootModule { + override val directRegularDependencies: List by lazy { + val builtinsModule = LLFirBuiltinsSessionFactory.getInstance(project).getBuiltinsSession(platform).ktModule as KtBuiltinsModule + listOf(builtinsModule) + } + + override val directRefinementDependencies: List + get() = emptyList() + + override val directFriendDependencies: List + get() = emptyList() + + override val contentScope: GlobalSearchScope + get() = GlobalSearchScope.fileScope(file) + + override val analyzerServices: PlatformDependentAnalyzerServices + get() = platform.getAnalyzerServices() + + override val project: Project + get() = file.project + + override val moduleDescription: String + get() = "Not under content root \"${name}\" for ${file.virtualFile.path}" +} \ No newline at end of file diff --git a/analysis/project-structure/src/org/jetbrains/kotlin/analysis/project/structure/KtModule.kt b/analysis/project-structure/src/org/jetbrains/kotlin/analysis/project/structure/KtModule.kt index 3eb75940906..7c014d19d6e 100644 --- a/analysis/project-structure/src/org/jetbrains/kotlin/analysis/project/structure/KtModule.kt +++ b/analysis/project-structure/src/org/jetbrains/kotlin/analysis/project/structure/KtModule.kt @@ -172,6 +172,11 @@ public class KtBuiltinsModule( * A set of sources which lives outside project content root. E.g, testdata files or source files of some other project. */ public interface KtNotUnderContentRootModule : KtModule { + /** + * Human-readable module name. + */ + public val name: String + /** * Module owner file. * A separate module is created for each file outside a content root.