From 044e1b86602662c78bb2ed12b9d645ab10b23429 Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Fri, 11 Jul 2014 17:11:35 +0400 Subject: Setup test framework and empty DocumentationModel to kickstart test development. --- src/AnalysesEnvironment.kt | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/AnalysesEnvironment.kt (limited to 'src/AnalysesEnvironment.kt') diff --git a/src/AnalysesEnvironment.kt b/src/AnalysesEnvironment.kt new file mode 100644 index 00000000..3eae33ca --- /dev/null +++ b/src/AnalysesEnvironment.kt @@ -0,0 +1,71 @@ +package com.jetbrains.dokka + +import com.intellij.openapi.* +import org.jetbrains.jet.cli.common.messages.* +import org.jetbrains.jet.cli.common.* +import org.jetbrains.jet.cli.jvm.compiler.* +import java.io.* +import org.jetbrains.jet.cli.jvm.* +import org.jetbrains.jet.config.* +import com.intellij.openapi.util.* +import org.jetbrains.jet.lang.resolve.* +import org.jetbrains.jet.lang.psi.* +import kotlin.platform.* + +public class AnalysesEnvironment(val messageCollector: MessageCollector, body: AnalysesEnvironment.() -> Unit = {}) : Disposable { + val configuration = CompilerConfiguration(); + + { + configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector) + body() + } + + private fun withContext(processor: (JetCoreEnvironment, BindingContext) -> T): T { + val environment = JetCoreEnvironment.createForProduction(this, configuration) + val result = environment.analyze(messageCollector) + return processor(environment, result) + } + + public fun withContext(processor: (BindingContext) -> T): T { + return withContext { environment, context -> processor(context) } + } + + public fun streamFiles(processor: (BindingContext, JetFile) -> T): Stream { + return withContext { environment, context -> + environment.getSourceFiles().stream().map { file -> processor(context, file) } + } + } + + public fun processFiles(processor: (BindingContext, JetFile) -> T): List { + return withContext { environment, context -> + environment.getSourceFiles().map { file -> processor(context, file) } + } + } + + public fun processFilesFlat(processor: (BindingContext, JetFile) -> List): List { + return withContext { environment, context -> + environment.getSourceFiles().flatMap { file -> processor(context, file) } + } + } + + public val classpath: List + get() = configuration.get(JVMConfigurationKeys.CLASSPATH_KEY) ?: listOf() + + public fun addClasspath(list: List) { + configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, list) + } + + public fun addClasspath(file: File) { + configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, file) + } + + public val sources: List + get() = configuration.get(CommonConfigurationKeys.SOURCE_ROOTS_KEY) ?: listOf() + public fun addSources(list: List) { + configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, list) + } + + public override fun dispose() { + Disposer.dispose(this) + } +} \ No newline at end of file -- cgit