diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-12 03:25:39 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-12 03:25:39 +0400 |
commit | d627d2cfdfebcddd63669734efb82dfc66e7c7fe (patch) | |
tree | f0c60789cc4b529b86a6ba028bb2bd8a749d9b4c /src | |
parent | 7bc3513935588467d4f848bbe40539664fdbdcf9 (diff) | |
download | dokka-d627d2cfdfebcddd63669734efb82dfc66e7c7fe.tar.gz dokka-d627d2cfdfebcddd63669734efb82dfc66e7c7fe.tar.bz2 dokka-d627d2cfdfebcddd63669734efb82dfc66e7c7fe.zip |
Convert string doc to structured DocumentationContent
Diffstat (limited to 'src')
-rw-r--r-- | src/Analysis/CommentsAPI.kt | 4 | ||||
-rw-r--r-- | src/Generation/ConsoleGenerator.kt | 2 | ||||
-rw-r--r-- | src/Model/Diagnostics.kt (renamed from src/Model/DocumentationResolver.kt) | 4 | ||||
-rw-r--r-- | src/Model/DocumentationModel.kt | 4 | ||||
-rw-r--r-- | src/Model/DocumentationNodeBuilder.kt | 16 | ||||
-rw-r--r-- | src/Model/Sections.kt | 43 |
6 files changed, 56 insertions, 17 deletions
diff --git a/src/Analysis/CommentsAPI.kt b/src/Analysis/CommentsAPI.kt index 6bdc3716..c8a2ed3c 100644 --- a/src/Analysis/CommentsAPI.kt +++ b/src/Analysis/CommentsAPI.kt @@ -5,10 +5,6 @@ import org.jetbrains.jet.lang.resolve.* import org.jetbrains.jet.kdoc.psi.api.* import org.jetbrains.jet.lang.psi.* -fun BindingContext.getDocumentation(descriptor: DeclarationDescriptor): String { - return getDocumentationElements(descriptor).map { it.extractText() }.join("\n") -} - fun BindingContext.getDocumentationElements(descriptor: DeclarationDescriptor): List<KDoc> { val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) if (psiElement == null) diff --git a/src/Generation/ConsoleGenerator.kt b/src/Generation/ConsoleGenerator.kt index 90bd53be..3ba42099 100644 --- a/src/Generation/ConsoleGenerator.kt +++ b/src/Generation/ConsoleGenerator.kt @@ -12,7 +12,7 @@ public class ConsoleGenerator() { public fun generateHeader(node: DocumentationNode, indent: String = "") { println("$indent${node.kind}: ${node.name}") - println("$indent\"${node.doc.replace("\n", "\n$indent")}\"") + println("$indent\"${node.doc.summary.replace("\n", "\n$indent")}\"") println() } 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()) + } +} + |