aboutsummaryrefslogtreecommitdiff
path: root/src/AnalysisEnvironment.kt
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 15:49:47 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 15:49:47 +0400
commitba96795f4eff615578f72c29a2f29b7111c8de8c (patch)
tree4f27da2a4160d2dc145489683c366c7ad7502d15 /src/AnalysisEnvironment.kt
parentbdbdbd8986c0b16da69a4beced3cfd274dfd9086 (diff)
downloaddokka-ba96795f4eff615578f72c29a2f29b7111c8de8c.tar.gz
dokka-ba96795f4eff615578f72c29a2f29b7111c8de8c.tar.bz2
dokka-ba96795f4eff615578f72c29a2f29b7111c8de8c.zip
Improving API, setting up playground, preparing for processing data.
Diffstat (limited to 'src/AnalysisEnvironment.kt')
-rw-r--r--src/AnalysisEnvironment.kt65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/AnalysisEnvironment.kt b/src/AnalysisEnvironment.kt
new file mode 100644
index 00000000..13316419
--- /dev/null
+++ b/src/AnalysisEnvironment.kt
@@ -0,0 +1,65 @@
+package com.jetbrains.dokka
+
+import com.intellij.openapi.Disposable
+import org.jetbrains.jet.config.CompilerConfiguration
+import org.jetbrains.jet.cli.common.messages.MessageCollector
+import org.jetbrains.jet.cli.common.CLIConfigurationKeys
+import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
+import java.io.File
+import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
+import org.jetbrains.jet.config.CommonConfigurationKeys
+import com.intellij.openapi.util.Disposer
+import org.jetbrains.jet.lang.resolve.BindingContext
+import org.jetbrains.jet.lang.psi.JetFile
+
+public class AnalysisEnvironment(val messageCollector: MessageCollector, body: AnalysisEnvironment.()->Unit = {}) : Disposable {
+ val configuration = CompilerConfiguration();
+
+ {
+ configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
+ body()
+ }
+
+ private fun processContext<T>(processor: (JetCoreEnvironment, BindingContext) -> T): T {
+ val environment = JetCoreEnvironment.createForProduction(this, configuration)
+ val result = environment.analyze(messageCollector)
+ return processor(environment, result)
+ }
+
+ public fun processContext<T>(processor: (BindingContext) -> T): T {
+ return processContext { environment, context -> processor(context) }
+ }
+
+ public fun streamFiles<T>(processor: (BindingContext, JetFile) -> T): Stream<T> {
+ return processContext { environment, context ->
+ environment.getSourceFiles().stream().map { file -> processor(context, file) }
+ }
+ }
+
+ public fun processFiles<T>(processor: (BindingContext, JetFile) -> T): List<T> {
+ return processContext { environment, context ->
+ environment.getSourceFiles().map { file -> processor(context, file) }
+ }
+ }
+
+ public val classpath: List<File>
+ get() = configuration.get(JVMConfigurationKeys.CLASSPATH_KEY) ?: listOf()
+
+ public fun addClasspath(list: List<File>) {
+ configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, list)
+ }
+
+ public fun addClasspath(file: File) {
+ configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, file)
+ }
+
+ public val sources: List<String>
+ get() = configuration.get(CommonConfigurationKeys.SOURCE_ROOTS_KEY) ?: listOf()
+ public fun addSources(list: List<String>) {
+ configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, list)
+ }
+
+ public override fun dispose() {
+ Disposer.dispose(this)
+ }
+} \ No newline at end of file