diff --git a/translator/.idea/compiler.xml b/translator/.idea/compiler.xml
index 10357ec3d62..051f0070962 100644
--- a/translator/.idea/compiler.xml
+++ b/translator/.idea/compiler.xml
@@ -19,8 +19,8 @@
-
-
+
+
\ No newline at end of file
diff --git a/translator/.idea/misc.xml b/translator/.idea/misc.xml
index 7ca109729dc..8f96fd28783 100644
--- a/translator/.idea/misc.xml
+++ b/translator/.idea/misc.xml
@@ -13,7 +13,7 @@
-
+
\ No newline at end of file
diff --git a/translator/.idea/modules/ast-kotlin_main.iml b/translator/.idea/modules/ast-kotlin_main.iml
index 81e1de0dcdd..d496e553278 100644
--- a/translator/.idea/modules/ast-kotlin_main.iml
+++ b/translator/.idea/modules/ast-kotlin_main.iml
@@ -1,6 +1,6 @@
-
+
diff --git a/translator/.idea/modules/ast-kotlin_test.iml b/translator/.idea/modules/ast-kotlin_test.iml
index 04f30958348..8717ed3e558 100644
--- a/translator/.idea/modules/ast-kotlin_test.iml
+++ b/translator/.idea/modules/ast-kotlin_test.iml
@@ -1,6 +1,6 @@
-
+
diff --git a/translator/build.gradle b/translator/build.gradle
index 658e32d3566..3286ebcc285 100644
--- a/translator/build.gradle
+++ b/translator/build.gradle
@@ -13,8 +13,6 @@ buildscript {
apply plugin: 'java'
apply plugin: 'kotlin'
-sourceCompatibility = 1.5
-
repositories {
mavenCentral()
}
diff --git a/translator/src/main/kotlin/main.kt b/translator/src/main/kotlin/main.kt
index 150924f27eb..a20153dbc5f 100644
--- a/translator/src/main/kotlin/main.kt
+++ b/translator/src/main/kotlin/main.kt
@@ -1,6 +1,6 @@
import com.intellij.openapi.util.Disposer
import org.kotlinnative.translator.FileTranslator
-import org.kotlinnative.translator.TranslationState
+import org.kotlinnative.translator.parseAndAnalyze
fun main(args: Array) {
@@ -10,7 +10,7 @@ fun main(args: Array) {
}
val disposer = Disposer.newDisposable()
- val state = TranslationState(args.asList(), disposer)
+ val state = parseAndAnalyze(args.asList(), disposer)
val files = state.environment.getSourceFiles()
if (files.isEmpty()) {
diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/TranslationState.kt b/translator/src/main/kotlin/org/kotlinnative/translator/TranslationState.kt
index d1249ff98b7..d1445bb0788 100644
--- a/translator/src/main/kotlin/org/kotlinnative/translator/TranslationState.kt
+++ b/translator/src/main/kotlin/org/kotlinnative/translator/TranslationState.kt
@@ -20,65 +20,64 @@ import org.jetbrains.kotlin.utils.PathUtil
import org.kotlinnative.translator.exceptions.TranslationException
import java.util.*
+class TranslationState(val environment: KotlinCoreEnvironment, val bindingContext: BindingContext) {
-class TranslationState(sources: List, disposer: Disposable) {
-
- val environment: KotlinCoreEnvironment
- val bindingContext: BindingContext
var functions = HashMap()
var classes = HashMap()
-
val variableManager = VariableManager()
+}
- init {
- val configuration = CompilerConfiguration()
- val messageCollector = GroupingMessageCollector(object : MessageCollector {
- private var hasError = false
+fun parseAndAnalyze(sources: List, disposer: Disposable): TranslationState {
- override fun hasErrors(): Boolean = hasError
+ val configuration = CompilerConfiguration()
+ val messageCollector = GroupingMessageCollector(object : MessageCollector {
+ private var hasError = false
- override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
- println("[report] $message")
- hasError = severity.isError || hasError
- }
- })
+ override fun hasErrors(): Boolean = hasError
- configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
- configuration.put(JVMConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME)
+ override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
+ println("[report] $message")
+ hasError = severity.isError || hasError
+ }
+ })
- configuration.addKotlinSourceRoots(sources)
+ configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
+ configuration.put(JVMConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME)
- environment = KotlinCoreEnvironment.createForProduction(disposer, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
- bindingContext = analyze(environment)?.bindingContext ?: throw TranslationException()
- }
+ configuration.addKotlinSourceRoots(sources)
- fun analyze(environment: KotlinCoreEnvironment): AnalysisResult? {
- val collector = environment.configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
+ val environment = KotlinCoreEnvironment.createForProduction(disposer, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
+ val bindingContext = analyze(environment)?.bindingContext ?: throw TranslationException()
- val analyzer = AnalyzerWithCompilerReport(collector)
- analyzer.analyzeAndReport(environment.getSourceFiles(), object : AnalyzerWithCompilerReport.Analyzer {
- override fun analyze(): AnalysisResult {
- val sharedTrace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace()
- val moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.project, environment.getModuleName())
+ return TranslationState(environment, bindingContext)
+}
- return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(
- moduleContext,
- environment.getSourceFiles(),
- sharedTrace,
- environment.configuration.get(JVMConfigurationKeys.MODULES),
- environment.configuration.get(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS),
- JvmPackagePartProvider(environment))
- }
+fun analyze(environment: KotlinCoreEnvironment): AnalysisResult? {
+ val collector = environment.configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
- override fun reportEnvironmentErrors() {
- val files = environment.configuration.jvmClasspathRoots
- val runtimes = files.map { it.canonicalFile }.filter { it.name == PathUtil.KOTLIN_JAVA_RUNTIME_JAR && it.exists() }
- collector.report(CompilerMessageSeverity.ERROR, runtimes.joinToString { it.path }, CompilerMessageLocation.NO_LOCATION)
- println(runtimes.joinToString { it.toString() })
- }
- })
+ val analyzer = AnalyzerWithCompilerReport(collector)
+ analyzer.analyzeAndReport(environment.getSourceFiles(), object : AnalyzerWithCompilerReport.Analyzer {
+ override fun analyze(): AnalysisResult {
+ val sharedTrace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace()
+ val moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.project, environment.getModuleName())
- return if (analyzer.hasErrors()) null else analyzer.analysisResult
- }
+ return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(
+ moduleContext,
+ environment.getSourceFiles(),
+ sharedTrace,
+ environment.configuration.get(JVMConfigurationKeys.MODULES),
+ environment.configuration.get(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS),
+ JvmPackagePartProvider(environment))
+ }
+
+ override fun reportEnvironmentErrors() {
+ val files = environment.configuration.jvmClasspathRoots
+ val runtimes = files.map { it.canonicalFile }.filter { it.name == PathUtil.KOTLIN_JAVA_RUNTIME_JAR && it.exists() }
+ collector.report(CompilerMessageSeverity.ERROR, runtimes.joinToString { it.path }, CompilerMessageLocation.NO_LOCATION)
+ println(runtimes.joinToString { it.toString() })
+ }
+ })
+
+ return if (analyzer.hasErrors()) null else analyzer.analysisResult
+}
-}
\ No newline at end of file