aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Analysis/AnalysisEnvironment.kt21
-rw-r--r--src/Analysis/CompilerAPI.kt4
-rw-r--r--src/Model/Diagnostics.kt39
-rw-r--r--src/Model/DocumentationModule.kt (renamed from src/Model/DocumentationModel.kt)23
-rw-r--r--src/Model/DocumentationNodeBuilder.kt32
-rw-r--r--src/main.kt6
-rw-r--r--test/src/TestAPI.kt8
7 files changed, 70 insertions, 63 deletions
diff --git a/src/Analysis/AnalysisEnvironment.kt b/src/Analysis/AnalysisEnvironment.kt
index 346367ee..20c1a764 100644
--- a/src/Analysis/AnalysisEnvironment.kt
+++ b/src/Analysis/AnalysisEnvironment.kt
@@ -10,6 +10,7 @@ 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();
@@ -19,30 +20,36 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A
body()
}
- private fun withContext<T>(processor: (JetCoreEnvironment, BindingContext) -> T): T {
+ private fun withContext<T>(processor: (JetCoreEnvironment, ModuleDescriptor, BindingContext) -> T): T {
val environment = JetCoreEnvironment.createForProduction(this, configuration)
- val result = environment.analyze(messageCollector)
- return processor(environment, result)
+ val exhaust = environment.analyze(messageCollector)
+ return processor(environment, exhaust.getModuleDescriptor(), exhaust.getBindingContext())
}
public fun withContext<T>(processor: (BindingContext) -> T): T {
- return withContext { environment, context -> processor(context) }
+ return withContext { environment, module, context -> processor(context) }
}
public fun streamFiles<T>(processor: (BindingContext, JetFile) -> T): Stream<T> {
- return withContext { environment, context ->
+ return withContext { environment, module, context ->
environment.getSourceFiles().stream().map { file -> processor(context, file) }
}
}
public fun processFiles<T>(processor: (BindingContext, JetFile) -> T): List<T> {
- return withContext { environment, context ->
+ return withContext { environment, module, context ->
environment.getSourceFiles().map { file -> processor(context, file) }
}
}
+ public fun processFiles<T>(processor: (BindingContext, ModuleDescriptor, JetFile) -> T): List<T> {
+ return withContext { environment, module, context ->
+ environment.getSourceFiles().map { file -> processor(context, module, file) }
+ }
+ }
+
public fun processFilesFlat<T>(processor: (BindingContext, JetFile) -> List<T>): List<T> {
- return withContext { environment, context ->
+ return withContext { environment, module, context ->
environment.getSourceFiles().flatMap { file -> processor(context, file) }
}
}
diff --git a/src/Analysis/CompilerAPI.kt b/src/Analysis/CompilerAPI.kt
index 8c58428c..a9dc3b0c 100644
--- a/src/Analysis/CompilerAPI.kt
+++ b/src/Analysis/CompilerAPI.kt
@@ -28,7 +28,7 @@ private fun getAnnotationsPath(paths: KotlinPaths, arguments: K2JVMCompilerArgum
return annotationsPath
}
-fun JetCoreEnvironment.analyze(messageCollector: MessageCollector): BindingContext {
+fun JetCoreEnvironment.analyze(messageCollector: MessageCollector): AnalyzeExhaust {
val project = getProject()
val sourceFiles = getSourceFiles()
@@ -48,7 +48,7 @@ fun JetCoreEnvironment.analyze(messageCollector: MessageCollector): BindingConte
val exhaust = analyzerWithCompilerReport.getAnalyzeExhaust()
assert(exhaust != null) { "AnalyzeExhaust should be non-null, compiling: " + sourceFiles }
- return exhaust!!.getBindingContext()
+ return exhaust!!
}
fun AnalyzerWithCompilerReport.analyzeAndReport(files: List<JetFile>, analyser: () -> AnalyzeExhaust) = analyzeAndReport(analyser, files)
diff --git a/src/Model/Diagnostics.kt b/src/Model/Diagnostics.kt
index 78d711a0..723bd59d 100644
--- a/src/Model/Diagnostics.kt
+++ b/src/Model/Diagnostics.kt
@@ -2,32 +2,31 @@ package org.jetbrains.dokka
import org.jetbrains.jet.lang.descriptors.*
import org.jetbrains.jet.lang.resolve.name.*
+import org.jetbrains.jet.lang.resolve.BindingContext
-fun DocumentationNode.checkResolve() {
- val parentScope = scope
+fun BindingContext.checkResolveChildren(node : DocumentationNode) {
+ if (node.kind != DocumentationNodeKind.Module && node.kind != DocumentationNodeKind.Package) {
+ // TODO: we don't resolve packages and modules for now
- for (item in details + members) {
- val symbolName = item.name
- val symbol: DeclarationDescriptor? = when (item.kind) {
- DocumentationNodeKind.Receiver -> (parentScope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter()
- DocumentationNodeKind.Parameter -> parentScope.getLocalVariable(Name.guess(symbolName))
- DocumentationNodeKind.Function -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull()
- DocumentationNodeKind.Property -> parentScope.getProperties(Name.guess(symbolName)).firstOrNull()
- DocumentationNodeKind.Constructor -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull()
-
- DocumentationNodeKind.Package -> {
- // TODO: do not resolve constructors and packages for now
- item.scope.getContainingDeclaration()
+ val parentScope = getResolutionScope(node.descriptor)
+ for (item in node.details + node.members) {
+ val symbolName = item.name
+ val symbol: DeclarationDescriptor? = when (item.kind) {
+ DocumentationNodeKind.Receiver -> (parentScope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter()
+ DocumentationNodeKind.Parameter -> parentScope.getLocalVariable(Name.guess(symbolName))
+ DocumentationNodeKind.Function -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull()
+ DocumentationNodeKind.Property -> parentScope.getProperties(Name.guess(symbolName)).firstOrNull()
+ DocumentationNodeKind.Constructor -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull()
+ else -> parentScope.getClassifier(Name.guess(symbolName))
}
- else -> parentScope.getClassifier(Name.guess(symbolName))
- }
- if (symbol == null)
- println("WARNING: Cannot resolve $item in ${path(this)}")
+ if (symbol == null)
+ println("WARNING: Cannot resolve $item in ${path(node)}")
+ }
}
- for (reference in allReferences().filterNot { it.kind == DocumentationReferenceKind.Owner }) {
- reference.to.checkResolve()
+ for (reference in node.allReferences().filterNot { it.kind == DocumentationReferenceKind.Owner }) {
+ checkResolveChildren(reference.to)
}
}
diff --git a/src/Model/DocumentationModel.kt b/src/Model/DocumentationModule.kt
index 55f524b3..f468228f 100644
--- a/src/Model/DocumentationModel.kt
+++ b/src/Model/DocumentationModule.kt
@@ -1,8 +1,8 @@
package org.jetbrains.dokka
-import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.psi.JetFile
+import org.jetbrains.jet.lang.descriptors.*
public enum class DocumentationNodeKind {
Unknown
@@ -24,7 +24,7 @@ public enum class DocumentationNodeKind {
LowerBound
Exception
- Model
+ Module
}
public enum class DocumentationReferenceKind {
@@ -35,10 +35,11 @@ public enum class DocumentationReferenceKind {
Override
}
-public open class DocumentationNode(val name: String,
+public open class DocumentationNode(val descriptor: DeclarationDescriptor,
+ val name: String,
val doc: DocumentationContent,
- val kind: DocumentationNodeKind,
- val scope: JetScope) {
+ val kind: DocumentationNodeKind) {
+
private val references = arrayListOf<DocumentationReference>()
public val owner: DocumentationNode?
@@ -67,9 +68,9 @@ public open class DocumentationNode(val name: String,
}
}
-public class DocumentationModel : DocumentationNode("model", DocumentationContent.Empty, DocumentationNodeKind.Model, JetScope.EMPTY) {
- fun merge(other: DocumentationModel): DocumentationModel {
- val model = DocumentationModel()
+public class DocumentationModule(val module: ModuleDescriptor) : DocumentationNode(module, "model", DocumentationContent.Empty, DocumentationNodeKind.Module) {
+ fun merge(other: DocumentationModule): DocumentationModule {
+ val model = DocumentationModule(module)
model.addAllReferencesFrom(other)
model.addAllReferencesFrom(this)
return model
@@ -81,15 +82,15 @@ public class DocumentationModel : DocumentationNode("model", DocumentationConten
public data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: DocumentationReferenceKind)
-fun BindingContext.createDocumentationModel(file: JetFile): DocumentationModel {
- val model = DocumentationModel()
+fun BindingContext.createDocumentationModel(module: ModuleDescriptor, file: JetFile): DocumentationModule {
val packageFragment = getPackageFragment(file)
+ val model = DocumentationModule(module)
if (packageFragment == null) throw IllegalArgumentException("File $file should have package fragment")
val visitor = DocumentationNodeBuilder(this)
packageFragment.accept(DocumentationBuildingVisitor(this, visitor), model)
- model.checkResolve()
+ checkResolveChildren(model)
return model
}
diff --git a/src/Model/DocumentationNodeBuilder.kt b/src/Model/DocumentationNodeBuilder.kt
index 103e2e89..b079c499 100644
--- a/src/Model/DocumentationNodeBuilder.kt
+++ b/src/Model/DocumentationNodeBuilder.kt
@@ -10,17 +10,17 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Unknown, context.getResolutionScope(descriptor))
+ val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Unknown)
data!!.addReferenceTo(node, DocumentationReferenceKind.Link)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
}
override fun visitReceiverParameterDescriptor(descriptor: ReceiverParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val node = DocumentationNode(descriptor!!.getName().asString(), DocumentationContent.Empty, DocumentationNodeKind.Receiver, context.getResolutionScope(descriptor))
+ val node = DocumentationNode(descriptor!!, descriptor.getName().asString(), DocumentationContent.Empty, DocumentationNodeKind.Receiver)
data!!.addReferenceTo(node, DocumentationReferenceKind.Detail)
- val typeNode = DocumentationNode(descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
+ val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type)
node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
@@ -29,10 +29,10 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
override fun visitValueParameterDescriptor(descriptor: ValueParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter, context.getResolutionScope(descriptor))
+ val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter)
data!!.addReferenceTo(node, DocumentationReferenceKind.Detail)
- val typeNode = DocumentationNode(descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
+ val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type)
node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
@@ -41,11 +41,11 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, when (descriptor.getKind()) {
+ val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, when (descriptor.getKind()) {
ClassKind.OBJECT -> DocumentationNodeKind.Object
ClassKind.TRAIT -> DocumentationNodeKind.Trait
else -> DocumentationNodeKind.Class
- }, context.getResolutionScope(descriptor))
+ })
data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
@@ -53,10 +53,10 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Function, context.getResolutionScope(descriptor))
+ val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Function)
data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
- val typeNode = DocumentationNode(descriptor.getReturnType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
+ val typeNode = DocumentationNode(descriptor, descriptor.getReturnType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type)
node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
@@ -65,19 +65,19 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
override fun visitTypeParameterDescriptor(descriptor: TypeParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.TypeParameter, context.getResolutionScope(descriptor))
+ val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.TypeParameter)
data!!.addReferenceTo(node, DocumentationReferenceKind.Detail)
val builtIns = KotlinBuiltIns.getInstance()
for (constraint in descriptor.getUpperBounds()) {
if (constraint == builtIns.getDefaultBound())
continue
- val constraintNode = DocumentationNode(constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.UpperBound, context.getResolutionScope(descriptor))
+ val constraintNode = DocumentationNode(descriptor, constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.UpperBound)
node.addReferenceTo(constraintNode, DocumentationReferenceKind.Detail)
}
for (constraint in descriptor.getLowerBounds()) {
if (builtIns.isNothing(constraint))
continue
- val constraintNode = DocumentationNode(constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.LowerBound, context.getResolutionScope(descriptor))
+ val constraintNode = DocumentationNode(descriptor, constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.LowerBound)
node.addReferenceTo(constraintNode, DocumentationReferenceKind.Detail)
}
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
@@ -86,10 +86,10 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Property, context.getResolutionScope(descriptor))
+ val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Property)
data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
- val typeNode = DocumentationNode(descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
+ val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type)
node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
@@ -98,14 +98,14 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Constructor, context.getResolutionScope(descriptor))
+ val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Constructor)
data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
}
override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val node = DocumentationNode(descriptor!!.fqName.asString(), DocumentationContent.Empty, DocumentationNodeKind.Package, context.getResolutionScope(descriptor))
+ val node = DocumentationNode(descriptor!!, descriptor.fqName.asString(), DocumentationContent.Empty, DocumentationNodeKind.Package)
data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
diff --git a/src/main.kt b/src/main.kt
index e8ef4e2f..975b2633 100644
--- a/src/main.kt
+++ b/src/main.kt
@@ -36,10 +36,10 @@ public fun main(args: Array<String>) {
println()
- val model = environment.processFiles { context, file ->
+ val model = environment.processFiles { context, module, file ->
println("Processing: ${file.getName()}")
- context.createDocumentationModel(file)
- }.fold(DocumentationModel()) {(aggregate, item) -> aggregate.merge(item) }
+ context.createDocumentationModel(module, file)
+ }.reduce {(aggregate, item) -> aggregate.merge(item) }
ConsoleGenerator().generate(model)
diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt
index 282697da..29a64366 100644
--- a/test/src/TestAPI.kt
+++ b/test/src/TestAPI.kt
@@ -5,7 +5,7 @@ import com.intellij.openapi.util.*
import kotlin.test.fail
import org.jetbrains.dokka.*
-public fun verifyModel(vararg files: String, verifier: (DocumentationModel) -> Unit) {
+public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> Unit) {
val messageCollector = object : MessageCollector {
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
when (severity) {
@@ -27,9 +27,9 @@ public fun verifyModel(vararg files: String, verifier: (DocumentationModel) -> U
addSources(files.toList())
}
- val result = environment.processFiles { context, file ->
- context.createDocumentationModel(file)
- }.fold(DocumentationModel()) {(aggregate, item) -> aggregate.merge(item) }
+ val result = environment.processFiles { context, module, file ->
+ context.createDocumentationModel(module, file)
+ }.reduce {(aggregate, item) -> aggregate.merge(item) }
verifier(result)
Disposer.dispose(environment)
}