package org.jetbrains.dokka import org.jetbrains.jet.cli.common.messages.* import com.intellij.openapi.* import org.jetbrains.jet.cli.jvm.compiler.* import org.jetbrains.jet.lang.resolve.* import org.jetbrains.jet.lang.psi.* import java.io.File import org.jetbrains.jet.config.* import org.jetbrains.jet.cli.common.* import org.jetbrains.jet.cli.jvm.* import com.intellij.openapi.util.* import org.jetbrains.jet.lang.descriptors.ModuleDescriptor public class AnalysisEnvironment(val messageCollector: MessageCollector, body: AnalysisEnvironment.() -> Unit = {}) : Disposable { val configuration = CompilerConfiguration(); { configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector) body() } public fun withContext(processor: (JetCoreEnvironment, ModuleDescriptor, BindingContext) -> T): T { val environment = JetCoreEnvironment.createForProduction(this, configuration) val exhaust = environment.analyze(messageCollector) return processor(environment, exhaust.getModuleDescriptor(), exhaust.getBindingContext()) } public fun withContext(processor: (ModuleDescriptor, BindingContext) -> T): T { return withContext { environment, module, context -> processor(module, context) } } public fun streamFiles(processor: (BindingContext, JetFile) -> T): Stream { return withContext { environment, module, context -> environment.getSourceFiles().stream().map { file -> processor(context, file) } } } public fun processFiles(processor: (BindingContext, JetFile) -> T): List { return withContext { environment, module, context -> environment.getSourceFiles().map { file -> processor(context, file) } } } public fun processFiles(processor: (BindingContext, ModuleDescriptor, JetFile) -> T): List { return withContext { environment, module, context -> environment.getSourceFiles().map { file -> processor(context, module, file) } } } public fun processFilesFlat(processor: (BindingContext, JetFile) -> List): List { return withContext { environment, module, 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) } }