aboutsummaryrefslogtreecommitdiff
path: root/src/DokkaContext.kt
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 15:28:02 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 15:28:02 +0400
commitbdbdbd8986c0b16da69a4beced3cfd274dfd9086 (patch)
tree67d840925df998309ccd83e1a3252269ab57077b /src/DokkaContext.kt
parent7f6961a9de7d4b42e07b3f1fbd71e3bfb2200f9a (diff)
downloaddokka-bdbdbd8986c0b16da69a4beced3cfd274dfd9086.tar.gz
dokka-bdbdbd8986c0b16da69a4beced3cfd274dfd9086.tar.bz2
dokka-bdbdbd8986c0b16da69a4beced3cfd274dfd9086.zip
Primitive API for analysing JetFile in BindingContext.
Diffstat (limited to 'src/DokkaContext.kt')
-rw-r--r--src/DokkaContext.kt58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/DokkaContext.kt b/src/DokkaContext.kt
new file mode 100644
index 00000000..5154c237
--- /dev/null
+++ b/src/DokkaContext.kt
@@ -0,0 +1,58 @@
+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 DokkaContext(val messageCollector: MessageCollector) : Disposable {
+ val configuration = CompilerConfiguration()
+
+ ;
+ {
+ configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
+ }
+
+ private fun analyze<T>(analyser: (JetCoreEnvironment, BindingContext) -> T) {
+ val environment = JetCoreEnvironment.createForProduction(this, configuration)
+ val result = environment.analyze(messageCollector)
+ analyser(environment, result)
+ }
+
+ public fun analyze<T>(analyser: (BindingContext) -> T) {
+ analyze { environment, context ->
+ analyser(context)
+ }
+ }
+
+ public fun analyzeFiles<T>(analyser: (BindingContext, JetFile) -> T) {
+ analyze { environment, context ->
+ for (file in environment.getSourceFiles())
+ analyser(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 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