aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 17:11:35 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 17:11:35 +0400
commit044e1b86602662c78bb2ed12b9d645ab10b23429 (patch)
tree91ca7ece2011b71fa10d0b184ccfa234fbe3130d
parent9fec3e15c94969f98596ac04130af6e2d9368a89 (diff)
downloaddokka-044e1b86602662c78bb2ed12b9d645ab10b23429.tar.gz
dokka-044e1b86602662c78bb2ed12b9d645ab10b23429.tar.bz2
dokka-044e1b86602662c78bb2ed12b9d645ab10b23429.zip
Setup test framework and empty DocumentationModel to kickstart test development.
-rw-r--r--src/AnalysesEnvironment.kt (renamed from src/AnalysisEnvironment.kt)40
-rw-r--r--src/CommentsAPI.kt2
-rw-r--r--src/DocumentationModel.kt14
-rw-r--r--src/main.kt9
-rw-r--r--test/data/function.kt (renamed from test/data/discovery.kt)0
-rw-r--r--test/playground.kt16
-rw-r--r--test/src/DiscoveryTest.kt12
-rw-r--r--test/src/TestAPI.kt36
8 files changed, 104 insertions, 25 deletions
diff --git a/src/AnalysisEnvironment.kt b/src/AnalysesEnvironment.kt
index 13316419..3eae33ca 100644
--- a/src/AnalysisEnvironment.kt
+++ b/src/AnalysesEnvironment.kt
@@ -1,18 +1,18 @@
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
+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 AnalysisEnvironment(val messageCollector: MessageCollector, body: AnalysisEnvironment.()->Unit = {}) : Disposable {
+public class AnalysesEnvironment(val messageCollector: MessageCollector, body: AnalysesEnvironment.() -> Unit = {}) : Disposable {
val configuration = CompilerConfiguration();
{
@@ -20,28 +20,34 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A
body()
}
- private fun processContext<T>(processor: (JetCoreEnvironment, BindingContext) -> T): T {
+ private fun withContext<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 withContext<T>(processor: (BindingContext) -> T): T {
+ return withContext { environment, context -> processor(context) }
}
public fun streamFiles<T>(processor: (BindingContext, JetFile) -> T): Stream<T> {
- return processContext { environment, context ->
+ return withContext { environment, context ->
environment.getSourceFiles().stream().map { file -> processor(context, file) }
}
}
public fun processFiles<T>(processor: (BindingContext, JetFile) -> T): List<T> {
- return processContext { environment, context ->
+ return withContext { environment, context ->
environment.getSourceFiles().map { file -> processor(context, file) }
}
}
+ public fun processFilesFlat<T>(processor: (BindingContext, JetFile) -> List<T>): List<T> {
+ return withContext { environment, context ->
+ environment.getSourceFiles().flatMap { file -> processor(context, file) }
+ }
+ }
+
public val classpath: List<File>
get() = configuration.get(JVMConfigurationKeys.CLASSPATH_KEY) ?: listOf()
diff --git a/src/CommentsAPI.kt b/src/CommentsAPI.kt
index 4bfb19e6..21ba1067 100644
--- a/src/CommentsAPI.kt
+++ b/src/CommentsAPI.kt
@@ -6,7 +6,7 @@ import org.jetbrains.jet.lang.resolve.*
import org.jetbrains.jet.kdoc.psi.api.*
import org.jetbrains.jet.lang.psi.JetDeclaration
-fun BindingContext.getComments(descriptor: DeclarationDescriptor): KDoc? {
+fun BindingContext.getDocumentation(descriptor: DeclarationDescriptor): KDoc? {
val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)
if (psiElement == null) throw IllegalArgumentException("$descriptor doesn't have connection to source code, is it synthetic?")
diff --git a/src/DocumentationModel.kt b/src/DocumentationModel.kt
new file mode 100644
index 00000000..6da18d42
--- /dev/null
+++ b/src/DocumentationModel.kt
@@ -0,0 +1,14 @@
+package com.jetbrains.dokka
+
+import com.intellij.psi.PsiFile
+import org.jetbrains.jet.lang.resolve.BindingContext
+
+public class DocumentationModel {
+ fun merge(other: DocumentationModel): DocumentationModel {
+ return DocumentationModel()
+ }
+}
+
+fun BindingContext.createDocumentation(file: PsiFile): DocumentationModel {
+ return DocumentationModel()
+} \ No newline at end of file
diff --git a/src/main.kt b/src/main.kt
index 3083ba90..04415070 100644
--- a/src/main.kt
+++ b/src/main.kt
@@ -13,10 +13,11 @@ public fun main(args: Array<String>) {
val compilerArguments = K2JVMCompilerArguments()
val sources: List<String> = Args.parse(compilerArguments, args) ?: listOf()
- val environment = AnalysisEnvironment(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR) {
+ val environment = AnalysesEnvironment(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR) {
+/*
addClasspath(PathUtil.getJdkClassesRoots())
addClasspath(PathUtil.getKotlinPathsForCompiler().getRuntimePath())
-
+*/
addSources(sources)
}
@@ -52,9 +53,9 @@ fun BindingContext.analyseFile(file: JetFile) {
println("Package: ${packageFragment}")
for (descriptor in packageFragment.getMemberScope().getAllDescriptors()) {
println("Member: ${descriptor}")
- val doc = getComments(descriptor)
+ val doc = getDocumentation(descriptor)
if (doc != null) {
- println("Comment: ${doc.getText()}")
+ println("Comment:\n${doc.getText()}")
}
println()
}
diff --git a/test/data/discovery.kt b/test/data/function.kt
index e69de29b..e69de29b 100644
--- a/test/data/discovery.kt
+++ b/test/data/function.kt
diff --git a/test/playground.kt b/test/playground.kt
index 80992fbd..5bc5207a 100644
--- a/test/playground.kt
+++ b/test/playground.kt
@@ -6,10 +6,10 @@ fun topLevelFunction() {
val topLevelConstantValue = "Hello"
-val topLevelValue : String
+val topLevelValue: String
get() = "Bye bye"
-var topLevelVariable : String
+var topLevelVariable: String
get() = "Modify me!"
set(value) {
}
@@ -23,6 +23,18 @@ class Class {
}
+/**
+ * This is a class with constructor and space after doc
+ */
+
+class ClassWithConstructor(val name: String)
+
+/**
+ * This is data class with constructor and comment after doc
+ */
+// irrelevant comment
+data class DataClass(val name: String, val age: Int) {}
+
object Object {
fun objectFunction() {
}
diff --git a/test/src/DiscoveryTest.kt b/test/src/DiscoveryTest.kt
index 71a8aa4f..690f0404 100644
--- a/test/src/DiscoveryTest.kt
+++ b/test/src/DiscoveryTest.kt
@@ -1,2 +1,12 @@
-public class DiscoveryTest {
+package com.jetbrains.dokka.tests
+
+import org.junit.Test
+
+
+public class FunctionTest {
+ Test fun function() {
+ verifyFiles("test/data/function.kt") {
+
+ }
+ }
} \ No newline at end of file
diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt
new file mode 100644
index 00000000..80dc47d5
--- /dev/null
+++ b/test/src/TestAPI.kt
@@ -0,0 +1,36 @@
+package com.jetbrains.dokka.tests
+
+import org.jetbrains.jet.cli.common.messages.*
+import com.intellij.openapi.util.*
+import com.jetbrains.dokka.*
+import kotlin.test.fail
+
+public fun verifyFiles(vararg files: String, verifier: (DocumentationModel) -> Unit) {
+ val messageCollector = object : MessageCollector {
+ override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
+ when (severity) {
+ CompilerMessageSeverity.WARNING,
+ CompilerMessageSeverity.LOGGING,
+ CompilerMessageSeverity.OUTPUT,
+ CompilerMessageSeverity.INFO,
+ CompilerMessageSeverity.ERROR -> {
+ println("$severity: $message at $location")
+ }
+ CompilerMessageSeverity.EXCEPTION -> {
+ fail("$severity: $message at $location")
+ }
+ }
+ }
+ }
+
+ val environment = AnalysesEnvironment(messageCollector) {
+ addSources(files.toList())
+ }
+
+ val result = environment.processFiles { context, file ->
+ context.createDocumentation(file)
+ }.fold(DocumentationModel()) {(aggregate, item) -> aggregate.merge(item) }
+ verifier(result)
+ Disposer.dispose(environment)
+}
+