[Analysis API] TestModuleKind: introduce moduleKind util
^KT-64468
This commit is contained in:
committed by
Space Team
parent
43a3f7db5f
commit
d1cb9ab060
+8
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.analysis.test.framework.project.structure
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.KtModuleWithFiles
|
||||
import org.jetbrains.kotlin.analysis.test.framework.AnalysisApiTestDirectives
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.moduleKind
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestService
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
@@ -26,17 +26,10 @@ private val TestServices.ktModuleFactory: KtModuleFactory by TestServices.testSe
|
||||
* By default, the [KtModuleFactory] registered with these [TestServices] is returned. It may be overruled by the
|
||||
* [MODULE_KIND][org.jetbrains.kotlin.analysis.test.framework.AnalysisApiTestDirectives.MODULE_KIND] directive for a specific test module.
|
||||
*/
|
||||
fun TestServices.getKtModuleFactoryForTestModule(testModule: TestModule): KtModuleFactory {
|
||||
val explicitKinds = testModule.directives[AnalysisApiTestDirectives.MODULE_KIND]
|
||||
if (explicitKinds.size > 1) {
|
||||
throw IllegalArgumentException("A test module may only specify one `${AnalysisApiTestDirectives.MODULE_KIND.name}`.")
|
||||
}
|
||||
|
||||
return when (explicitKinds.singleOrNull()) {
|
||||
TestModuleKind.Source -> KtSourceModuleFactory
|
||||
TestModuleKind.LibraryBinary -> KtLibraryBinaryModuleFactory
|
||||
TestModuleKind.LibrarySource -> KtLibrarySourceModuleFactory
|
||||
TestModuleKind.ScriptSource -> KtScriptModuleFactory
|
||||
else -> ktModuleFactory
|
||||
}
|
||||
fun TestServices.getKtModuleFactoryForTestModule(testModule: TestModule): KtModuleFactory = when (testModule.moduleKind) {
|
||||
TestModuleKind.Source -> KtSourceModuleFactory
|
||||
TestModuleKind.LibraryBinary -> KtLibraryBinaryModuleFactory
|
||||
TestModuleKind.LibrarySource -> KtLibrarySourceModuleFactory
|
||||
TestModuleKind.ScriptSource -> KtScriptModuleFactory
|
||||
else -> ktModuleFactory
|
||||
}
|
||||
|
||||
+7
@@ -5,6 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.test.framework.test.configurators
|
||||
|
||||
import org.jetbrains.kotlin.analysis.test.framework.AnalysisApiTestDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.singleOrZeroValue
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
|
||||
/**
|
||||
* In an Analysis API test configuration, the [TestModuleKind] determines the kind of the default
|
||||
* [KtModule][org.jetbrains.kotlin.analysis.project.structure.KtModule]s used in the test. This essentially defines the context in which a
|
||||
@@ -35,3 +39,6 @@ enum class TestModuleKind(val suffix: String) {
|
||||
*/
|
||||
ScriptSource("ScriptSource"),
|
||||
}
|
||||
|
||||
val TestModule.moduleKind: TestModuleKind?
|
||||
get() = directives.singleOrZeroValue(AnalysisApiTestDirectives.MODULE_KIND)
|
||||
|
||||
Reference in New Issue
Block a user