diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-12 04:23:51 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-12 04:23:51 +0400 |
commit | a6000809a34735ffe1c40bf07a9e291d3c767eb9 (patch) | |
tree | 9d32fe971859e8cd36cb302be204fcdccefe886d /src/Model | |
parent | a83488aae453f1bf01cfb5507317acf0b9ddfb82 (diff) | |
download | dokka-a6000809a34735ffe1c40bf07a9e291d3c767eb9.tar.gz dokka-a6000809a34735ffe1c40bf07a9e291d3c767eb9.tar.bz2 dokka-a6000809a34735ffe1c40bf07a9e291d3c767eb9.zip |
Store descriptors instead of resolution scopes, rename Model -> Module
Diffstat (limited to 'src/Model')
-rw-r--r-- | src/Model/Diagnostics.kt | 39 | ||||
-rw-r--r-- | src/Model/DocumentationModule.kt (renamed from src/Model/DocumentationModel.kt) | 23 | ||||
-rw-r--r-- | src/Model/DocumentationNodeBuilder.kt | 32 |
3 files changed, 47 insertions, 47 deletions
diff --git a/src/Model/Diagnostics.kt b/src/Model/Diagnostics.kt index 78d711a0..723bd59d 100644 --- a/src/Model/Diagnostics.kt +++ b/src/Model/Diagnostics.kt @@ -2,32 +2,31 @@ package org.jetbrains.dokka import org.jetbrains.jet.lang.descriptors.* import org.jetbrains.jet.lang.resolve.name.* +import org.jetbrains.jet.lang.resolve.BindingContext -fun DocumentationNode.checkResolve() { - val parentScope = scope +fun BindingContext.checkResolveChildren(node : DocumentationNode) { + if (node.kind != DocumentationNodeKind.Module && node.kind != DocumentationNodeKind.Package) { + // TODO: we don't resolve packages and modules for now - for (item in details + members) { - val symbolName = item.name - val symbol: DeclarationDescriptor? = when (item.kind) { - DocumentationNodeKind.Receiver -> (parentScope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter() - DocumentationNodeKind.Parameter -> parentScope.getLocalVariable(Name.guess(symbolName)) - DocumentationNodeKind.Function -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull() - DocumentationNodeKind.Property -> parentScope.getProperties(Name.guess(symbolName)).firstOrNull() - DocumentationNodeKind.Constructor -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull() - - DocumentationNodeKind.Package -> { - // TODO: do not resolve constructors and packages for now - item.scope.getContainingDeclaration() + val parentScope = getResolutionScope(node.descriptor) + for (item in node.details + node.members) { + val symbolName = item.name + val symbol: DeclarationDescriptor? = when (item.kind) { + DocumentationNodeKind.Receiver -> (parentScope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter() + DocumentationNodeKind.Parameter -> parentScope.getLocalVariable(Name.guess(symbolName)) + DocumentationNodeKind.Function -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull() + DocumentationNodeKind.Property -> parentScope.getProperties(Name.guess(symbolName)).firstOrNull() + DocumentationNodeKind.Constructor -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull() + else -> parentScope.getClassifier(Name.guess(symbolName)) } - else -> parentScope.getClassifier(Name.guess(symbolName)) - } - if (symbol == null) - println("WARNING: Cannot resolve $item in ${path(this)}") + if (symbol == null) + println("WARNING: Cannot resolve $item in ${path(node)}") + } } - for (reference in allReferences().filterNot { it.kind == DocumentationReferenceKind.Owner }) { - reference.to.checkResolve() + for (reference in node.allReferences().filterNot { it.kind == DocumentationReferenceKind.Owner }) { + checkResolveChildren(reference.to) } } diff --git a/src/Model/DocumentationModel.kt b/src/Model/DocumentationModule.kt index 55f524b3..f468228f 100644 --- a/src/Model/DocumentationModel.kt +++ b/src/Model/DocumentationModule.kt @@ -1,8 +1,8 @@ package org.jetbrains.dokka -import org.jetbrains.jet.lang.resolve.scopes.JetScope import org.jetbrains.jet.lang.resolve.BindingContext import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.lang.descriptors.* public enum class DocumentationNodeKind { Unknown @@ -24,7 +24,7 @@ public enum class DocumentationNodeKind { LowerBound Exception - Model + Module } public enum class DocumentationReferenceKind { @@ -35,10 +35,11 @@ public enum class DocumentationReferenceKind { Override } -public open class DocumentationNode(val name: String, +public open class DocumentationNode(val descriptor: DeclarationDescriptor, + val name: String, val doc: DocumentationContent, - val kind: DocumentationNodeKind, - val scope: JetScope) { + val kind: DocumentationNodeKind) { + private val references = arrayListOf<DocumentationReference>() public val owner: DocumentationNode? @@ -67,9 +68,9 @@ public open class DocumentationNode(val name: String, } } -public class DocumentationModel : DocumentationNode("model", DocumentationContent.Empty, DocumentationNodeKind.Model, JetScope.EMPTY) { - fun merge(other: DocumentationModel): DocumentationModel { - val model = DocumentationModel() +public class DocumentationModule(val module: ModuleDescriptor) : DocumentationNode(module, "model", DocumentationContent.Empty, DocumentationNodeKind.Module) { + fun merge(other: DocumentationModule): DocumentationModule { + val model = DocumentationModule(module) model.addAllReferencesFrom(other) model.addAllReferencesFrom(this) return model @@ -81,15 +82,15 @@ public class DocumentationModel : DocumentationNode("model", DocumentationConten public data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: DocumentationReferenceKind) -fun BindingContext.createDocumentationModel(file: JetFile): DocumentationModel { - val model = DocumentationModel() +fun BindingContext.createDocumentationModel(module: ModuleDescriptor, file: JetFile): DocumentationModule { val packageFragment = getPackageFragment(file) + val model = DocumentationModule(module) if (packageFragment == null) throw IllegalArgumentException("File $file should have package fragment") val visitor = DocumentationNodeBuilder(this) packageFragment.accept(DocumentationBuildingVisitor(this, visitor), model) - model.checkResolve() + checkResolveChildren(model) return model } diff --git a/src/Model/DocumentationNodeBuilder.kt b/src/Model/DocumentationNodeBuilder.kt index 103e2e89..b079c499 100644 --- a/src/Model/DocumentationNodeBuilder.kt +++ b/src/Model/DocumentationNodeBuilder.kt @@ -10,17 +10,17 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Unknown, context.getResolutionScope(descriptor)) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Unknown) data!!.addReferenceTo(node, DocumentationReferenceKind.Link) node.addReferenceTo(data, DocumentationReferenceKind.Owner) return node } override fun visitReceiverParameterDescriptor(descriptor: ReceiverParameterDescriptor?, data: DocumentationNode?): DocumentationNode? { - val node = DocumentationNode(descriptor!!.getName().asString(), DocumentationContent.Empty, DocumentationNodeKind.Receiver, context.getResolutionScope(descriptor)) + val node = DocumentationNode(descriptor!!, descriptor.getName().asString(), DocumentationContent.Empty, DocumentationNodeKind.Receiver) data!!.addReferenceTo(node, DocumentationReferenceKind.Detail) - val typeNode = DocumentationNode(descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor)) + val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type) node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail) node.addReferenceTo(data, DocumentationReferenceKind.Owner) @@ -29,10 +29,10 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip override fun visitValueParameterDescriptor(descriptor: ValueParameterDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter, context.getResolutionScope(descriptor)) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter) data!!.addReferenceTo(node, DocumentationReferenceKind.Detail) - val typeNode = DocumentationNode(descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor)) + val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type) node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail) node.addReferenceTo(data, DocumentationReferenceKind.Owner) @@ -41,11 +41,11 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor.getName().asString(), doc, when (descriptor.getKind()) { + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, when (descriptor.getKind()) { ClassKind.OBJECT -> DocumentationNodeKind.Object ClassKind.TRAIT -> DocumentationNodeKind.Trait else -> DocumentationNodeKind.Class - }, context.getResolutionScope(descriptor)) + }) data!!.addReferenceTo(node, DocumentationReferenceKind.Member) node.addReferenceTo(data, DocumentationReferenceKind.Owner) return node @@ -53,10 +53,10 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Function, context.getResolutionScope(descriptor)) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Function) data!!.addReferenceTo(node, DocumentationReferenceKind.Member) - val typeNode = DocumentationNode(descriptor.getReturnType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor)) + val typeNode = DocumentationNode(descriptor, descriptor.getReturnType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type) node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail) node.addReferenceTo(data, DocumentationReferenceKind.Owner) @@ -65,19 +65,19 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip override fun visitTypeParameterDescriptor(descriptor: TypeParameterDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.TypeParameter, context.getResolutionScope(descriptor)) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.TypeParameter) data!!.addReferenceTo(node, DocumentationReferenceKind.Detail) val builtIns = KotlinBuiltIns.getInstance() for (constraint in descriptor.getUpperBounds()) { if (constraint == builtIns.getDefaultBound()) continue - val constraintNode = DocumentationNode(constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.UpperBound, context.getResolutionScope(descriptor)) + val constraintNode = DocumentationNode(descriptor, constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.UpperBound) node.addReferenceTo(constraintNode, DocumentationReferenceKind.Detail) } for (constraint in descriptor.getLowerBounds()) { if (builtIns.isNothing(constraint)) continue - val constraintNode = DocumentationNode(constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.LowerBound, context.getResolutionScope(descriptor)) + val constraintNode = DocumentationNode(descriptor, constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.LowerBound) node.addReferenceTo(constraintNode, DocumentationReferenceKind.Detail) } node.addReferenceTo(data, DocumentationReferenceKind.Owner) @@ -86,10 +86,10 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip override fun visitPropertyDescriptor(descriptor: PropertyDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Property, context.getResolutionScope(descriptor)) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Property) data!!.addReferenceTo(node, DocumentationReferenceKind.Member) - val typeNode = DocumentationNode(descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type, context.getResolutionScope(descriptor)) + val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type) node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail) node.addReferenceTo(data, DocumentationReferenceKind.Owner) @@ -98,14 +98,14 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Constructor, context.getResolutionScope(descriptor)) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Constructor) data!!.addReferenceTo(node, DocumentationReferenceKind.Member) node.addReferenceTo(data, DocumentationReferenceKind.Owner) return node } override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? { - val node = DocumentationNode(descriptor!!.fqName.asString(), DocumentationContent.Empty, DocumentationNodeKind.Package, context.getResolutionScope(descriptor)) + val node = DocumentationNode(descriptor!!, descriptor.fqName.asString(), DocumentationContent.Empty, DocumentationNodeKind.Package) data!!.addReferenceTo(node, DocumentationReferenceKind.Member) node.addReferenceTo(data, DocumentationReferenceKind.Owner) return node |