aboutsummaryrefslogtreecommitdiff
path: root/src/Model
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-12 03:25:39 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-12 03:25:39 +0400
commitd627d2cfdfebcddd63669734efb82dfc66e7c7fe (patch)
treef0c60789cc4b529b86a6ba028bb2bd8a749d9b4c /src/Model
parent7bc3513935588467d4f848bbe40539664fdbdcf9 (diff)
downloaddokka-d627d2cfdfebcddd63669734efb82dfc66e7c7fe.tar.gz
dokka-d627d2cfdfebcddd63669734efb82dfc66e7c7fe.tar.bz2
dokka-d627d2cfdfebcddd63669734efb82dfc66e7c7fe.zip
Convert string doc to structured DocumentationContent
Diffstat (limited to 'src/Model')
-rw-r--r--src/Model/Diagnostics.kt (renamed from src/Model/DocumentationResolver.kt)4
-rw-r--r--src/Model/DocumentationModel.kt4
-rw-r--r--src/Model/DocumentationNodeBuilder.kt16
-rw-r--r--src/Model/Sections.kt43
4 files changed, 55 insertions, 12 deletions
diff --git a/src/Model/DocumentationResolver.kt b/src/Model/Diagnostics.kt
index b5b6b1a2..78d711a0 100644
--- a/src/Model/DocumentationResolver.kt
+++ b/src/Model/Diagnostics.kt
@@ -1,7 +1,7 @@
package org.jetbrains.dokka
-import org.jetbrains.jet.lang.resolve.name.*
import org.jetbrains.jet.lang.descriptors.*
+import org.jetbrains.jet.lang.resolve.name.*
fun DocumentationNode.checkResolve() {
val parentScope = scope
@@ -31,7 +31,7 @@ fun DocumentationNode.checkResolve() {
}
}
-fun path(node: DocumentationNode) : String {
+fun path(node: DocumentationNode): String {
val owner = node.owner
if (owner != null)
return "$node in ${path(owner)}"
diff --git a/src/Model/DocumentationModel.kt b/src/Model/DocumentationModel.kt
index e24b3c41..55f524b3 100644
--- a/src/Model/DocumentationModel.kt
+++ b/src/Model/DocumentationModel.kt
@@ -36,7 +36,7 @@ public enum class DocumentationReferenceKind {
}
public open class DocumentationNode(val name: String,
- val doc: String,
+ val doc: DocumentationContent,
val kind: DocumentationNodeKind,
val scope: JetScope) {
private val references = arrayListOf<DocumentationReference>()
@@ -67,7 +67,7 @@ public open class DocumentationNode(val name: String,
}
}
-public class DocumentationModel : DocumentationNode("model", "", DocumentationNodeKind.Model, JetScope.EMPTY) {
+public class DocumentationModel : DocumentationNode("model", DocumentationContent.Empty, DocumentationNodeKind.Model, JetScope.EMPTY) {
fun merge(other: DocumentationModel): DocumentationModel {
val model = DocumentationModel()
model.addAllReferencesFrom(other)
diff --git a/src/Model/DocumentationNodeBuilder.kt b/src/Model/DocumentationNodeBuilder.kt
index e3307f50..103e2e89 100644
--- a/src/Model/DocumentationNodeBuilder.kt
+++ b/src/Model/DocumentationNodeBuilder.kt
@@ -17,10 +17,10 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
}
override fun visitReceiverParameterDescriptor(descriptor: ReceiverParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val node = DocumentationNode(descriptor!!.getName().asString(), "", DocumentationNodeKind.Receiver, context.getResolutionScope(descriptor))
+ val node = DocumentationNode(descriptor!!.getName().asString(), DocumentationContent.Empty, DocumentationNodeKind.Receiver, context.getResolutionScope(descriptor))
data!!.addReferenceTo(node, DocumentationReferenceKind.Detail)
- val typeNode = DocumentationNode(descriptor.getType().toString(), "", DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
+ val typeNode = DocumentationNode(descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
@@ -32,7 +32,7 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter, context.getResolutionScope(descriptor))
data!!.addReferenceTo(node, DocumentationReferenceKind.Detail)
- val typeNode = DocumentationNode(descriptor.getType().toString(), "", DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
+ val typeNode = DocumentationNode(descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
@@ -56,7 +56,7 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Function, context.getResolutionScope(descriptor))
data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
- val typeNode = DocumentationNode(descriptor.getReturnType().toString(), "", DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
+ val typeNode = DocumentationNode(descriptor.getReturnType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
@@ -71,13 +71,13 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
for (constraint in descriptor.getUpperBounds()) {
if (constraint == builtIns.getDefaultBound())
continue
- val constraintNode = DocumentationNode(constraint.toString(), "", DocumentationNodeKind.UpperBound, context.getResolutionScope(descriptor))
+ val constraintNode = DocumentationNode(constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.UpperBound, context.getResolutionScope(descriptor))
node.addReferenceTo(constraintNode, DocumentationReferenceKind.Detail)
}
for (constraint in descriptor.getLowerBounds()) {
if (builtIns.isNothing(constraint))
continue
- val constraintNode = DocumentationNode(constraint.toString(), "", DocumentationNodeKind.LowerBound, context.getResolutionScope(descriptor))
+ val constraintNode = DocumentationNode(constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.LowerBound, context.getResolutionScope(descriptor))
node.addReferenceTo(constraintNode, DocumentationReferenceKind.Detail)
}
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
@@ -89,7 +89,7 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Property, context.getResolutionScope(descriptor))
data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
- val typeNode = DocumentationNode(descriptor.getType().toString(), "", DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
+ val typeNode = DocumentationNode(descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor))
node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
@@ -105,7 +105,7 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip
}
override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? {
- val node = DocumentationNode(descriptor!!.fqName.asString(), "", DocumentationNodeKind.Package, context.getResolutionScope(descriptor))
+ val node = DocumentationNode(descriptor!!.fqName.asString(), DocumentationContent.Empty, DocumentationNodeKind.Package, context.getResolutionScope(descriptor))
data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
diff --git a/src/Model/Sections.kt b/src/Model/Sections.kt
new file mode 100644
index 00000000..733c0d2f
--- /dev/null
+++ b/src/Model/Sections.kt
@@ -0,0 +1,43 @@
+package org.jetbrains.dokka
+
+import org.jetbrains.jet.lang.descriptors.*
+import org.jetbrains.jet.lang.resolve.BindingContext
+
+fun BindingContext.getDocumentation(descriptor: DeclarationDescriptor): DocumentationContent {
+ val docText = getDocumentationElements(descriptor).map { it.extractText() }.join("\n")
+ return DocumentationContent(docText, listOf())
+}
+
+class DocumentationContentSection(val label: String, val text: String) {
+
+}
+
+class DocumentationContent(val summary: String, val sections: List<DocumentationContentSection>) {
+
+ override fun equals(other: Any?): Boolean {
+ if (other !is DocumentationContent)
+ return false
+ if (summary != other.summary)
+ return false
+ if (sections.size != other.sections.size)
+ return false
+ for (index in sections.indices)
+ if (sections[index] != other.sections[index])
+ return false
+
+ return true
+ }
+
+ override fun hashCode(): Int {
+ return summary.hashCode() + sections.map { it.hashCode() }.sum()
+ }
+
+ override fun toString(): String {
+ return "$summary | " + sections.joinToString()
+ }
+
+ class object {
+ val Empty = DocumentationContent("", listOf())
+ }
+}
+