diff options
Diffstat (limited to 'src/Kotlin/DocumentationContext.kt')
-rw-r--r-- | src/Kotlin/DocumentationContext.kt | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/Kotlin/DocumentationContext.kt b/src/Kotlin/DocumentationContext.kt new file mode 100644 index 00000000..1491aa2d --- /dev/null +++ b/src/Kotlin/DocumentationContext.kt @@ -0,0 +1,47 @@ +package org.jetbrains.dokka + +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor +import org.jetbrains.jet.lang.resolve.BindingContext +import org.jetbrains.jet.lang.resolve.scopes.JetScope +import org.jetbrains.jet.lang.descriptors.ModuleDescriptor +import org.jetbrains.jet.lang.resolve.name.FqName + +public class DocumentationContext(val bindingContext: BindingContext) { + val descriptorToNode = hashMapOf<DeclarationDescriptor, DocumentationNode>() + val nodeToDescriptor = hashMapOf<DocumentationNode, DeclarationDescriptor>() + + fun register(descriptor: DeclarationDescriptor, node: DocumentationNode) { + descriptorToNode.put(descriptor, node) + nodeToDescriptor.put(node, descriptor) + } + + fun getResolutionScope(node: DocumentationNode): JetScope { + val descriptor = nodeToDescriptor[node] ?: throw IllegalArgumentException("Node is not known to this context") + return bindingContext.getResolutionScope(descriptor) + } + + fun parseDocumentation(descriptor: DeclarationDescriptor): Content { + val docText = bindingContext.getDocumentationElements(descriptor).map { it.extractText() }.join("\n") + val tree = MarkdownProcessor.parse(docText) + println(tree.toTestString()) + val content = tree.toContent() + return content + } +} + +fun BindingContext.createDocumentationModule(name: String, + module: ModuleDescriptor, + packages: Set<FqName>, + options: DocumentationOptions = DocumentationOptions()): DocumentationModule { + val documentationModule = DocumentationModule(name) + val context = DocumentationContext(this) + val visitor = DocumentationNodeBuilder(context) + for (packageName in packages) { + val pkg = module.getPackage(packageName) + pkg!!.accept(DocumentationBuildingVisitor(this, options, visitor), documentationModule) + } + + // TODO: Uncomment for resolve verification + // checkResolveChildren(documentationModule) + return documentationModule +} |