From 992bf22a5e2209e8305ce86255518c4dd918894d Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Sat, 12 Jul 2014 01:49:53 +0400 Subject: Resolve all the referenced node, except owners. --- src/Model/DocumentationModel.kt | 3 +++ src/Model/DocumentationResolver.kt | 33 ++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'src/Model') diff --git a/src/Model/DocumentationModel.kt b/src/Model/DocumentationModel.kt index 90fe40e4..c5dd6603 100644 --- a/src/Model/DocumentationModel.kt +++ b/src/Model/DocumentationModel.kt @@ -59,6 +59,7 @@ public open class DocumentationNode(val name: String, } public fun references(kind: DocumentationReferenceKind): List = references.filter { it.kind == kind } + public fun allReferences(): List = references public override fun toString(): String { return "$kind $name" @@ -87,5 +88,7 @@ fun BindingContext.createDocumentationModel(file: JetFile): DocumentationModel { val visitor = DocumentationNodeBuilder(this) packageFragment.accept(DocumentationBuildingVisitor(this, visitor), model) + model.resolveAll() + return model } diff --git a/src/Model/DocumentationResolver.kt b/src/Model/DocumentationResolver.kt index dee68f49..40968f4f 100644 --- a/src/Model/DocumentationResolver.kt +++ b/src/Model/DocumentationResolver.kt @@ -1,23 +1,34 @@ package org.jetbrains.dokka -import org.jetbrains.jet.lang.resolve.scopes.* import org.jetbrains.jet.lang.resolve.name.* import org.jetbrains.jet.lang.descriptors.* -fun DocumentationNode.resolve(): DocumentationNode { - for (detail in details) { - val symbol: DeclarationDescriptor? = when (detail.kind) { +fun DocumentationNode.resolve() { + for (item in details + members) { + val symbolName = item.name + val symbol: DeclarationDescriptor? = when (item.kind) { DocumentationNodeKind.Receiver -> (scope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter() - DocumentationNodeKind.Parameter -> scope.getLocalVariable(Name.guess(detail.name)) - DocumentationNodeKind.Function -> scope.getFunctions(Name.guess(detail.name)).firstOrNull() - DocumentationNodeKind.Property -> scope.getProperties(Name.guess(detail.name)).firstOrNull() - DocumentationNodeKind.TypeParameter -> scope.getClassifier(Name.guess(detail.name)) - else -> scope.getClassifier(Name.guess(detail.name)) + DocumentationNodeKind.Parameter -> scope.getLocalVariable(Name.guess(symbolName)) + DocumentationNodeKind.Function -> scope.getFunctions(Name.guess(symbolName)).firstOrNull() + DocumentationNodeKind.Property -> scope.getProperties(Name.guess(symbolName)).firstOrNull() + DocumentationNodeKind.Constructor -> scope.getFunctions(Name.guess(symbolName)).firstOrNull() + + DocumentationNodeKind.Package -> { + // TODO: do not resolve constructors and packages for now + item.scope.getContainingDeclaration() + } + else -> scope.getClassifier(Name.guess(symbolName)) } if (symbol == null) - throw IllegalStateException("Cannot resolve node $this detail $detail") + throw IllegalStateException("Cannot resolve $item in $this") + } + + for (reference in allReferences().filterNot { it.kind == DocumentationReferenceKind.Owner }) { + reference.to.resolve() } - return this } +fun DocumentationModel.resolveAll() { + resolve() +} \ No newline at end of file -- cgit