aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/AnalysisEnvironment.kt (renamed from src/DokkaContext.kt)31
-rw-r--r--src/CompilerAPI.kt11
-rw-r--r--src/main.kt37
3 files changed, 46 insertions, 33 deletions
diff --git a/src/DokkaContext.kt b/src/AnalysisEnvironment.kt
index 5154c237..13316419 100644
--- a/src/DokkaContext.kt
+++ b/src/AnalysisEnvironment.kt
@@ -12,30 +12,33 @@ 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()
+public class AnalysisEnvironment(val messageCollector: MessageCollector, body: AnalysisEnvironment.()->Unit = {}) : Disposable {
+ val configuration = CompilerConfiguration();
- ;
{
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
+ body()
}
- private fun analyze<T>(analyser: (JetCoreEnvironment, BindingContext) -> T) {
+ private fun processContext<T>(processor: (JetCoreEnvironment, BindingContext) -> T): T {
val environment = JetCoreEnvironment.createForProduction(this, configuration)
val result = environment.analyze(messageCollector)
- analyser(environment, result)
+ return processor(environment, result)
}
- public fun analyze<T>(analyser: (BindingContext) -> T) {
- analyze { environment, context ->
- analyser(context)
+ 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 analyzeFiles<T>(analyser: (BindingContext, JetFile) -> T) {
- analyze { environment, context ->
- for (file in environment.getSourceFiles())
- analyser(context, file)
+ public fun processFiles<T>(processor: (BindingContext, JetFile) -> T): List<T> {
+ return processContext { environment, context ->
+ environment.getSourceFiles().map { file -> processor(context, file) }
}
}
@@ -46,6 +49,10 @@ public class DokkaContext(val messageCollector: MessageCollector) : Disposable {
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>) {
diff --git a/src/CompilerAPI.kt b/src/CompilerAPI.kt
index b68c0354..756cd915 100644
--- a/src/CompilerAPI.kt
+++ b/src/CompilerAPI.kt
@@ -13,13 +13,6 @@ import org.jetbrains.jet.lang.resolve.*
import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.analyzer.*
-private fun getClasspath(paths: KotlinPaths): MutableList<File> {
- val classpath = arrayListOf<File>()
- classpath.addAll(PathUtil.getJdkClassesRoots())
- classpath.add(paths.getRuntimePath())
- return classpath
-}
-
private fun getAnnotationsPath(paths: KotlinPaths, arguments: K2JVMCompilerArguments): MutableList<File> {
val annotationsPath = arrayListOf<File>()
annotationsPath.add(paths.getJdkAnnotationsPath())
@@ -55,4 +48,6 @@ private fun JetCoreEnvironment.analyze(messageCollector: MessageCollector): Bind
return exhaust!!.getBindingContext()
}
-fun AnalyzerWithCompilerReport.analyzeAndReport(files: List<JetFile>, analyser: () -> AnalyzeExhaust) = analyzeAndReport(analyser, files) \ No newline at end of file
+fun AnalyzerWithCompilerReport.analyzeAndReport(files: List<JetFile>, analyser: () -> AnalyzeExhaust) = analyzeAndReport(analyser, files)
+
+fun BindingContext.getPackageFragment(file: JetFile) = get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, file)
diff --git a/src/main.kt b/src/main.kt
index 7669af82..8b550999 100644
--- a/src/main.kt
+++ b/src/main.kt
@@ -1,38 +1,49 @@
package com.jetbrains.dokka
-import org.jetbrains.jet.cli.common.arguments.*
import com.sampullara.cli.*
import com.intellij.openapi.util.*
import org.jetbrains.jet.cli.common.messages.*
import org.jetbrains.jet.utils.*
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetFile
+import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
public fun main(args: Array<String>) {
- val dokka = DokkaContext(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR)
- dokka.addClasspath(getClasspath(PathUtil.getKotlinPathsForCompiler()))
- val arguments = K2JVMCompilerArguments()
- val sources: List<String> = Args.parse(arguments, args) ?: listOf()
- dokka.addSources(sources)
+ val compilerArguments = K2JVMCompilerArguments()
+ val sources: List<String> = Args.parse(compilerArguments, args) ?: listOf()
+
+ val environment = AnalysisEnvironment(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR) {
+ addClasspath(PathUtil.getJdkClassesRoots())
+ addClasspath(PathUtil.getKotlinPathsForCompiler().getRuntimePath())
+
+ addSources(sources)
+ }
println("Dokka is preparing sources and libraries...")
- println("Sources: ${dokka.sources.join()}")
- println("Classpath: ${dokka.classpath.joinToString()}")
+ println("Sources: ${environment.sources.join()}")
+ println("Classpath: ${environment.classpath.joinToString()}")
println()
- dokka.analyzeFiles { context, file ->
+ val results = environment.processFiles { context, file ->
println("Processing: ${file.getName()}")
println()
- analyseFile(context, file)
+ context.analyseFile(file)
}
- Disposer.dispose(dokka)
+ println()
+ println("Results:")
+ results.forEach {
+ println(it)
+ }
+
+ Disposer.dispose(environment)
}
-fun analyseFile(context: BindingContext, file: JetFile) {
- val packageFragment = context.get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, file)
+
+fun BindingContext.analyseFile(file: JetFile) {
+ val packageFragment = getPackageFragment(file)
if (packageFragment == null) {
println("PackageFragment is null")
return