diff --git a/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/configurators/AnalysisApiBaseTestServiceRegistrar.kt b/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/configurators/AnalysisApiBaseTestServiceRegistrar.kt index b82631a989d..a13ca00151c 100644 --- a/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/configurators/AnalysisApiBaseTestServiceRegistrar.kt +++ b/analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/configurators/AnalysisApiBaseTestServiceRegistrar.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 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. */ @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.analysis.decompiler.konan.KlibMetaFileType import org.jetbrains.kotlin.analysis.decompiler.psi.BuiltInDefinitionFile import org.jetbrains.kotlin.analysis.decompiler.psi.KotlinBuiltInFileType import org.jetbrains.kotlin.analysis.decompiler.psi.file.KtClsFile +import org.jetbrains.kotlin.analysis.project.structure.KtBinaryModule import org.jetbrains.kotlin.analysis.providers.* import org.jetbrains.kotlin.analysis.providers.impl.* import org.jetbrains.kotlin.analysis.test.framework.project.structure.ktModuleProvider @@ -66,10 +67,18 @@ object AnalysisApiBaseTestServiceRegistrar : AnalysisApiTestServiceRegistrar() { override fun registerProjectModelServices(project: MockProject, testServices: TestServices) { val moduleStructure = testServices.ktModuleProvider.getModuleStructure() val allSourceKtFiles = moduleStructure.mainModules.flatMap { it.files.filterIsInstance() } + val binaryDependencies = moduleStructure.binaryModules.toMutableSet() + for (mainModule in moduleStructure.mainModules) { + val ktModule = mainModule.ktModule + if (ktModule !is KtBinaryModule) continue + binaryDependencies -= ktModule + } + val roots = StandaloneProjectFactory.getVirtualFilesForLibraryRoots( - moduleStructure.binaryModules.flatMap { binary -> binary.getBinaryRoots() }, + binaryDependencies.flatMap { binary -> binary.getBinaryRoots() }, testServices.environmentManager.getProjectEnvironment() ).distinct() + project.apply { registerService(KotlinAnnotationsResolverFactory::class.java, KotlinStaticAnnotationsResolverFactory(project, allSourceKtFiles)) diff --git a/analysis/analysis-api-standalone/analysis-api-standalone-base/src/org/jetbrains/kotlin/analysis/api/standalone/base/project/structure/StandaloneProjectFactory.kt b/analysis/analysis-api-standalone/analysis-api-standalone-base/src/org/jetbrains/kotlin/analysis/api/standalone/base/project/structure/StandaloneProjectFactory.kt index 0cdb53668df..badf06bd052 100644 --- a/analysis/analysis-api-standalone/analysis-api-standalone-base/src/org/jetbrains/kotlin/analysis/api/standalone/base/project/structure/StandaloneProjectFactory.kt +++ b/analysis/analysis-api-standalone/analysis-api-standalone-base/src/org/jetbrains/kotlin/analysis/api/standalone/base/project/structure/StandaloneProjectFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 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. */ @@ -53,6 +53,7 @@ import org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleResolver import org.jetbrains.kotlin.cli.jvm.modules.CoreJrtFileSystem import org.jetbrains.kotlin.cli.jvm.modules.JavaModuleGraph import org.jetbrains.kotlin.config.* +import org.jetbrains.kotlin.library.KLIB_FILE_EXTENSION import org.jetbrains.kotlin.load.java.structure.impl.source.JavaElementSourceFactory import org.jetbrains.kotlin.load.kotlin.MetadataFinderFactory import org.jetbrains.kotlin.load.kotlin.VirtualFileFinderFactory @@ -374,7 +375,7 @@ object StandaloneProjectFactory { return roots.mapNotNull { path -> val pathString = FileUtil.toSystemIndependentName(path.toAbsolutePath().toString()) when { - pathString.endsWith(JAR_PROTOCOL) -> { + pathString.endsWith(JAR_PROTOCOL) || pathString.endsWith(KLIB_FILE_EXTENSION) -> { environment.environment.jarFileSystem.findFileByPath(pathString + JAR_SEPARATOR) } diff --git a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtLibraryBinaryModuleFactory.kt b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtLibraryBinaryModuleFactory.kt index 62455dd0e60..282831a99de 100644 --- a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtLibraryBinaryModuleFactory.kt +++ b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtLibraryBinaryModuleFactory.kt @@ -1,13 +1,14 @@ /* - * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 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.search.GlobalSearchScope import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtModuleWithFiles +import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.StandaloneProjectFactory +import org.jetbrains.kotlin.analysis.test.framework.services.environmentManager import org.jetbrains.kotlin.analysis.test.framework.services.libraries.compiledLibraryProvider import org.jetbrains.kotlin.analysis.test.framework.services.libraries.testModuleDecompiler import org.jetbrains.kotlin.test.model.TestModule @@ -25,12 +26,15 @@ object KtLibraryBinaryModuleFactory : KtModuleFactory { KtLibraryModuleImpl( testModule.name, testModule.targetPlatform, - GlobalSearchScope.filesScope(project, decompiledFiles.mapTo(mutableSetOf()) { it.virtualFile }), + StandaloneProjectFactory.createSearchScopeByLibraryRoots( + listOf(library), + testServices.environmentManager.getProjectEnvironment(), + ), project, binaryRoots = listOf(library), librarySources = null, ), - decompiledFiles + decompiledFiles, ) } } diff --git a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtLibrarySourceModuleFactory.kt b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtLibrarySourceModuleFactory.kt index aef34810bd7..e00bde9990a 100644 --- a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtLibrarySourceModuleFactory.kt +++ b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtLibrarySourceModuleFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 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. */ @@ -9,9 +9,11 @@ import com.intellij.openapi.project.Project import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.analysis.api.impl.base.util.LibraryUtils import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtModuleWithFiles +import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.StandaloneProjectFactory +import org.jetbrains.kotlin.analysis.test.framework.services.environmentManager +import org.jetbrains.kotlin.analysis.test.framework.services.libraries.compiledLibraryProvider import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.TestServices -import org.jetbrains.kotlin.analysis.test.framework.services.libraries.compiledLibraryProvider import java.nio.file.Path /** @@ -28,15 +30,25 @@ object KtLibrarySourceModuleFactory : KtModuleFactory { librarySourcesJar = librarySourcesJar, testModule = testModule, project = project, + testServices = testServices, ) } } -fun createKtLibrarySourceModule(libraryJar: Path, librarySourcesJar: Path, testModule: TestModule, project: Project): KtModuleWithFiles { +fun createKtLibrarySourceModule( + libraryJar: Path, + librarySourcesJar: Path, + testModule: TestModule, + project: Project, + testServices: TestServices, +): KtModuleWithFiles { val libraryKtModule = KtLibraryModuleImpl( testModule.name, testModule.targetPlatform, - GlobalSearchScope.filesScope(project, LibraryUtils.getAllVirtualFilesFromJar(libraryJar)), + StandaloneProjectFactory.createSearchScopeByLibraryRoots( + listOf(libraryJar), + testServices.environmentManager.getProjectEnvironment(), + ), project, binaryRoots = listOf(libraryJar), librarySources = null, diff --git a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/TestModuleStructureFactory.kt b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/TestModuleStructureFactory.kt index 190d111345e..6b7653ac57e 100644 --- a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/TestModuleStructureFactory.kt +++ b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/TestModuleStructureFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 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. */ @@ -58,6 +58,10 @@ object TestModuleStructureFactory { // Not-under-content-root modules have no external dependencies on purpose } is KtModuleWithModifiableDependencies -> { + if (ktModule is KtBinaryModule) { + binaryModulesBySourceRoots.getOrPut(ktModule.getBinaryRoots().toSet()) { ktModule } + } + addModuleDependencies(testModule, moduleEntriesByName, ktModule) stdlibAndSdkDependencies(ktModule, testModule, project, testServices).forEach { library -> val cachedLibrary = binaryModulesBySourceRoots.getOrPut(library.getBinaryRoots().toSet()) { library } diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirStdlibSourceTestConfigurator.kt b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirStdlibSourceTestConfigurator.kt index 3e20be9a143..5e6eb101f6d 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirStdlibSourceTestConfigurator.kt +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirStdlibSourceTestConfigurator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 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. */ @@ -33,6 +33,7 @@ private object KtStdlibSourceModuleFactory : KtModuleFactory { librarySourcesJar = librarySourcesJar, testModule = testModule, project = project, + testServices = testServices, ) } }