diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CommentsAPI.kt | 17 | ||||
-rw-r--r-- | src/DocumentationBuilder.kt | 25 | ||||
-rw-r--r-- | src/DocumentationModel.kt | 2 |
3 files changed, 39 insertions, 5 deletions
diff --git a/src/CommentsAPI.kt b/src/CommentsAPI.kt index 21ba1067..fd281899 100644 --- a/src/CommentsAPI.kt +++ b/src/CommentsAPI.kt @@ -1,7 +1,6 @@ package com.jetbrains.dokka import org.jetbrains.jet.lang.descriptors.* -import org.jetbrains.jet.lexer.* import org.jetbrains.jet.lang.resolve.* import org.jetbrains.jet.kdoc.psi.api.* import org.jetbrains.jet.lang.psi.JetDeclaration @@ -12,3 +11,19 @@ fun BindingContext.getDocumentation(descriptor: DeclarationDescriptor): KDoc? { return psiElement.previousSiblings().takeWhile { it !is JetDeclaration }.firstOrNull { it is KDoc } as KDoc? } + +fun KDoc?.extractText(): String { + if (this == null) + return "" + val text = getText() + if (text == null) + return "" + val lines = text.replace("\r", "").split("\n") + return lines.map { + it.dropWhile { java.lang.Character.isWhitespace(it) } + .dropWhile { it == '/' } + .dropWhile { it == '*' } + .dropWhile { it == '/' } + .dropWhile { java.lang.Character.isWhitespace(it) } + }.filter { it.any() }.join("\n") +}
\ No newline at end of file diff --git a/src/DocumentationBuilder.kt b/src/DocumentationBuilder.kt index 02db3540..26ed4f80 100644 --- a/src/DocumentationBuilder.kt +++ b/src/DocumentationBuilder.kt @@ -10,23 +10,40 @@ fun BindingContext.createDocumentation(file: JetFile): DocumentationModel { val packageFragment = getPackageFragment(file) if (packageFragment == null) throw IllegalArgumentException("File $file should have package fragment") - val visitor = DocumentationBuilderVisitor() + val visitor = DocumentationBuilderVisitor(this) visitDescriptor(packageFragment, model, visitor) return model } -class DocumentationBuilderVisitor() : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() { +class DocumentationBuilderVisitor(val context : BindingContext) : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() { override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: DocumentationNode?): DocumentationNode? { - val node = DocumentationNode(descriptor!!.getName().asString(), "doc", DocumentationNodeKind.Function) + val doc = context.getDocumentation(descriptor!!).extractText() + val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Unknown) data?.addReferenceTo(node, DocumentationReferenceKind.Member) return node } override fun visitValueParameterDescriptor(descriptor: ValueParameterDescriptor?, data: DocumentationNode?): DocumentationNode? { - val node = DocumentationNode(descriptor!!.getName().asString(), "doc", DocumentationNodeKind.Function) + val doc = context.getDocumentation(descriptor!!).extractText() + val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter) data?.addReferenceTo(node, DocumentationReferenceKind.Detail) return node } + + + override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? { + val doc = context.getDocumentation(descriptor!!).extractText() + val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Function) + data?.addReferenceTo(node, DocumentationReferenceKind.Member) + return node + } + + + override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? { + val node = DocumentationNode(descriptor!!.fqName.asString(), "", DocumentationNodeKind.Package) + data?.addReferenceTo(node, DocumentationReferenceKind.Member) + return node + } } diff --git a/src/DocumentationModel.kt b/src/DocumentationModel.kt index b8ef21b0..feddccde 100644 --- a/src/DocumentationModel.kt +++ b/src/DocumentationModel.kt @@ -4,6 +4,8 @@ import org.jetbrains.jet.lang.resolve.BindingContext import org.jetbrains.jet.lang.psi.JetFile public enum class DocumentationNodeKind { + Unknown + Package Class Function |