From 046265ea04b645b4f8ff835aa6c3ff9879501aed Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Sat, 12 Jul 2014 01:12:42 +0400 Subject: Add Owner references, cleanup --- src/Model/DocumentationModel.kt | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/Model/DocumentationModel.kt') diff --git a/src/Model/DocumentationModel.kt b/src/Model/DocumentationModel.kt index 77bd8373..06bc3775 100644 --- a/src/Model/DocumentationModel.kt +++ b/src/Model/DocumentationModel.kt @@ -1,5 +1,6 @@ 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 @@ -9,9 +10,11 @@ public enum class DocumentationNodeKind { Package Class Object + Constructor Function Property + Parameter Receiver TypeParameter @@ -19,19 +22,21 @@ public enum class DocumentationNodeKind { LowerBound Exception - Page Model } public enum class DocumentationReferenceKind { + Owner Member Detail - Owner Link Override } -public open class DocumentationNode(val name: String, val doc: String, val kind: DocumentationNodeKind) { +public open class DocumentationNode(val name: String, + val doc: String, + val kind: DocumentationNodeKind, + val scope: JetScope) { private val references = arrayListOf() public val owner: DocumentationNode @@ -54,12 +59,12 @@ public open class DocumentationNode(val name: String, val doc: String, val kind: public fun references(kind: DocumentationReferenceKind): List = references.filter { it.kind == kind } - public override fun toString() : String { + public override fun toString(): String { return "$kind $name" } } -public class DocumentationModel : DocumentationNode("model", "", DocumentationNodeKind.Model) { +public class DocumentationModel : DocumentationNode("model", "", DocumentationNodeKind.Model, JetScope.EMPTY) { fun merge(other: DocumentationModel): DocumentationModel { val model = DocumentationModel() model.addAllReferencesFrom(other) @@ -72,3 +77,14 @@ public class DocumentationModel : DocumentationNode("model", "", DocumentationNo } public data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: DocumentationReferenceKind) + +fun BindingContext.createDocumentationModel(file: JetFile): DocumentationModel { + val model = DocumentationModel() + val packageFragment = getPackageFragment(file) + if (packageFragment == null) throw IllegalArgumentException("File $file should have package fragment") + + val visitor = DocumentationNodeBuilder(this) + packageFragment.accept(DocumentationBuildingVisitor(this, visitor), model) + + return model +} -- cgit