Introduce CompilerConfiguration#getNotNull and getBoolean

To reduce boilerplate at call sites
This commit is contained in:
Alexander Udalov
2016-05-23 15:02:07 +03:00
parent 81a0fa5f47
commit 8c0f78db50
10 changed files with 36 additions and 29 deletions
@@ -248,11 +248,9 @@ open class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
}
fun reportPerf(configuration: CompilerConfiguration, message: String) {
if (!configuration.get(CLIConfigurationKeys.REPORT_PERF, false)) {
return
}
if (!configuration.getBoolean(CLIConfigurationKeys.REPORT_PERF)) return
val collector = configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]!!
val collector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
collector.report(CompilerMessageSeverity.INFO, "PERF: " + message, CompilerMessageLocation.NO_LOCATION)
}
@@ -244,8 +244,7 @@ class KotlinCoreEnvironment private constructor(
fun getSourceFiles(): List<KtFile> = sourceFiles
private fun report(severity: CompilerMessageSeverity, message: String) {
val messageCollector = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
?: throw CompileEnvironmentException(message)
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
messageCollector.report(severity, message, CompilerMessageLocation.NO_LOCATION)
}
@@ -417,7 +417,7 @@ object KotlinToJVMBytecodeCompiler {
}
private fun checkKotlinPackageUsage(environment: KotlinCoreEnvironment, files: Collection<KtFile>): Boolean {
if (environment.configuration.get(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE) == true) {
if (environment.configuration.getBoolean(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE)) {
return true
}
val messageCollector = environment.configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
@@ -434,8 +434,7 @@ object KotlinToJVMBytecodeCompiler {
}
private val KotlinCoreEnvironment.messageCollector: MessageCollector
get() = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
?: error("Message collector not specified in compiler configuration")
get() = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
private fun reportRuntimeConflicts(messageCollector: MessageCollector, jvmClasspathRoots: List<File>) {
fun String.removeIdeaVersionSuffix(): String {