Skip to content

Commit

Permalink
Set a message collector to the CompilerConfiguration to avoid the Ill…
Browse files Browse the repository at this point in the history
…egalStateException in Java 9+
  • Loading branch information
sciencesakura committed Sep 2, 2020
1 parent 7db39c3 commit 07dd8d6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions kotato/src/main/kotlin/com/github/angrypotato/kotato/Parser.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.github.angrypotato.kotato

import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer
Expand All @@ -13,9 +16,14 @@ import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType

open class Parser(val converter: Converter = Converter) {
protected val proj by lazy {
val configuration = CompilerConfiguration()
configuration.put(
CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false)
)
KotlinCoreEnvironment.createForProduction(
Disposer.newDisposable(),
CompilerConfiguration(),
configuration,
EnvironmentConfigFiles.JVM_CONFIG_FILES
).project
}
Expand All @@ -40,4 +48,4 @@ open class Parser(val converter: Converter = Converter) {
System.setProperty("idea.use.native.fs.for.win", "false")
}
}
}
}

0 comments on commit 07dd8d6

Please sign in to comment.