Minor, extract CompilerConfiguration.messageCollector to extension property
This commit is contained in:
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
|||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.common.getLibraryFromHome
|
import org.jetbrains.kotlin.cli.common.getLibraryFromHome
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
|
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
|
||||||
import org.jetbrains.kotlin.cli.jvm.config.JvmModulePathRoot
|
import org.jetbrains.kotlin.cli.jvm.config.JvmModulePathRoot
|
||||||
@@ -19,9 +20,6 @@ import org.jetbrains.kotlin.utils.PathUtil
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArguments) {
|
fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArguments) {
|
||||||
|
|
||||||
val messageCollector = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
|
||||||
|
|
||||||
put(JVMConfigurationKeys.INCLUDE_RUNTIME, arguments.includeRuntime)
|
put(JVMConfigurationKeys.INCLUDE_RUNTIME, arguments.includeRuntime)
|
||||||
|
|
||||||
putIfNotNull(JVMConfigurationKeys.FRIEND_PATHS, arguments.friendPaths?.asList())
|
putIfNotNull(JVMConfigurationKeys.FRIEND_PATHS, arguments.friendPaths?.asList())
|
||||||
@@ -71,9 +69,6 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun CompilerConfiguration.configureJdkHome(arguments: K2JVMCompilerArguments): Boolean {
|
fun CompilerConfiguration.configureJdkHome(arguments: K2JVMCompilerArguments): Boolean {
|
||||||
|
|
||||||
val messageCollector = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
|
||||||
|
|
||||||
if (arguments.noJdk) {
|
if (arguments.noJdk) {
|
||||||
put(JVMConfigurationKeys.NO_JDK, true)
|
put(JVMConfigurationKeys.NO_JDK, true)
|
||||||
|
|
||||||
@@ -84,7 +79,7 @@ fun CompilerConfiguration.configureJdkHome(arguments: K2JVMCompilerArguments): B
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.jdkHome != null) {
|
if (arguments.jdkHome != null) {
|
||||||
val jdkHome = File(arguments.jdkHome)
|
val jdkHome = File(arguments.jdkHome!!)
|
||||||
if (!jdkHome.exists()) {
|
if (!jdkHome.exists()) {
|
||||||
messageCollector.report(ERROR, "JDK home directory does not exist: $jdkHome")
|
messageCollector.report(ERROR, "JDK home directory does not exist: $jdkHome")
|
||||||
return false
|
return false
|
||||||
@@ -114,7 +109,6 @@ fun CompilerConfiguration.configureExplicitContentRoots(arguments: K2JVMCompiler
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun CompilerConfiguration.configureStandardLibs(paths: KotlinPaths?, arguments: K2JVMCompilerArguments) {
|
fun CompilerConfiguration.configureStandardLibs(paths: KotlinPaths?, arguments: K2JVMCompilerArguments) {
|
||||||
val messageCollector = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
|
||||||
val isModularJava = isModularJava()
|
val isModularJava = isModularJava()
|
||||||
|
|
||||||
fun addRoot(moduleName: String, libraryName: String, getLibrary: (KotlinPaths) -> File, noLibraryArgument: String) {
|
fun addRoot(moduleName: String, libraryName: String, getLibrary: (KotlinPaths) -> File, noLibraryArgument: String) {
|
||||||
@@ -176,7 +170,7 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
|||||||
val abiStability = JvmAbiStability.fromStringOrNull(arguments.abiStability)
|
val abiStability = JvmAbiStability.fromStringOrNull(arguments.abiStability)
|
||||||
if (arguments.abiStability != null) {
|
if (arguments.abiStability != null) {
|
||||||
if (abiStability == null) {
|
if (abiStability == null) {
|
||||||
getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
messageCollector.report(
|
||||||
ERROR,
|
ERROR,
|
||||||
"Unknown ABI stability mode: ${arguments.abiStability}, supported modes: ${JvmAbiStability.values().map { it.description }}"
|
"Unknown ABI stability mode: ${arguments.abiStability}, supported modes: ${JvmAbiStability.values().map { it.description }}"
|
||||||
)
|
)
|
||||||
@@ -201,43 +195,34 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
|||||||
put(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS, arguments.noUnifiedNullChecks)
|
put(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS, arguments.noUnifiedNullChecks)
|
||||||
|
|
||||||
if (!JVMConstructorCallNormalizationMode.isSupportedValue(arguments.constructorCallNormalizationMode)) {
|
if (!JVMConstructorCallNormalizationMode.isSupportedValue(arguments.constructorCallNormalizationMode)) {
|
||||||
getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
messageCollector.report(
|
||||||
ERROR,
|
ERROR,
|
||||||
"Unknown constructor call normalization mode: ${arguments.constructorCallNormalizationMode}, " +
|
"Unknown constructor call normalization mode: ${arguments.constructorCallNormalizationMode}, " +
|
||||||
"supported modes: ${JVMConstructorCallNormalizationMode.values().map { it.description }}"
|
"supported modes: ${JVMConstructorCallNormalizationMode.values().map { it.description }}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val constructorCallNormalizationMode =
|
val constructorCallNormalizationMode = JVMConstructorCallNormalizationMode.fromStringOrNull(arguments.constructorCallNormalizationMode)
|
||||||
JVMConstructorCallNormalizationMode.fromStringOrNull(arguments.constructorCallNormalizationMode)
|
|
||||||
if (constructorCallNormalizationMode != null) {
|
if (constructorCallNormalizationMode != null) {
|
||||||
put(
|
put(JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE, constructorCallNormalizationMode)
|
||||||
JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE,
|
|
||||||
constructorCallNormalizationMode
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val assertionsMode =
|
val assertionsMode =
|
||||||
JVMAssertionsMode.fromStringOrNull(arguments.assertionsMode)
|
JVMAssertionsMode.fromStringOrNull(arguments.assertionsMode)
|
||||||
if (assertionsMode == null) {
|
if (assertionsMode == null) {
|
||||||
getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
messageCollector.report(
|
||||||
ERROR,
|
ERROR,
|
||||||
"Unknown assertions mode: ${arguments.assertionsMode}, " +
|
"Unknown assertions mode: ${arguments.assertionsMode}, supported modes: ${JVMAssertionsMode.values().map { it.description }}"
|
||||||
"supported modes: ${JVMAssertionsMode.values().map { it.description }}"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
put(
|
put(JVMConfigurationKeys.ASSERTIONS_MODE, assertionsMode ?: JVMAssertionsMode.DEFAULT)
|
||||||
JVMConfigurationKeys.ASSERTIONS_MODE,
|
|
||||||
assertionsMode ?: JVMAssertionsMode.DEFAULT
|
|
||||||
)
|
|
||||||
|
|
||||||
put(JVMConfigurationKeys.USE_TYPE_TABLE, arguments.useTypeTable)
|
put(JVMConfigurationKeys.USE_TYPE_TABLE, arguments.useTypeTable)
|
||||||
put(JVMConfigurationKeys.SKIP_RUNTIME_VERSION_CHECK, arguments.skipRuntimeVersionCheck)
|
put(JVMConfigurationKeys.SKIP_RUNTIME_VERSION_CHECK, arguments.skipRuntimeVersionCheck)
|
||||||
put(JVMConfigurationKeys.USE_PSI_CLASS_FILES_READING, arguments.useOldClassFilesReading)
|
put(JVMConfigurationKeys.USE_PSI_CLASS_FILES_READING, arguments.useOldClassFilesReading)
|
||||||
|
|
||||||
if (arguments.useOldClassFilesReading) {
|
if (arguments.useOldClassFilesReading) {
|
||||||
getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
messageCollector.report(INFO, "Using the old java class files reading implementation")
|
||||||
.report(INFO, "Using the old java class files reading implementation")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
put(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE, arguments.allowKotlinPackage)
|
put(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE, arguments.allowKotlinPackage)
|
||||||
@@ -247,8 +232,7 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
|||||||
put(JVMConfigurationKeys.ENABLE_JVM_PREVIEW, arguments.enableJvmPreview)
|
put(JVMConfigurationKeys.ENABLE_JVM_PREVIEW, arguments.enableJvmPreview)
|
||||||
|
|
||||||
if (arguments.enableJvmPreview) {
|
if (arguments.enableJvmPreview) {
|
||||||
getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
messageCollector.report(INFO, "Using preview Java language features")
|
||||||
.report(INFO, "Using preview Java language features")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
arguments.declarationsOutputPath?.let { put(JVMConfigurationKeys.DECLARATIONS_JSON_PATH, it) }
|
arguments.declarationsOutputPath?.let { put(JVMConfigurationKeys.DECLARATIONS_JSON_PATH, it) }
|
||||||
@@ -261,3 +245,6 @@ fun CompilerConfiguration.configureKlibPaths(arguments: K2JVMCompilerArguments)
|
|||||||
?.filterNot { it.isEmpty() }
|
?.filterNot { it.isEmpty() }
|
||||||
?.let { put(JVMConfigurationKeys.KLIB_PATHS, it) }
|
?.let { put(JVMConfigurationKeys.KLIB_PATHS, it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val CompilerConfiguration.messageCollector: MessageCollector
|
||||||
|
get() = getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||||
|
|||||||
Reference in New Issue
Block a user