aboutsummaryrefslogtreecommitdiff
path: root/src/Model
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-12 01:12:42 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-12 01:12:42 +0400
commit046265ea04b645b4f8ff835aa6c3ff9879501aed (patch)
tree27856cad58e73c95978c16e264beed806047b9e7 /src/Model
parent2f4e56d77ac72c3f47cd2799094b1b987b0d9522 (diff)
downloaddokka-046265ea04b645b4f8ff835aa6c3ff9879501aed.tar.gz
dokka-046265ea04b645b4f8ff835aa6c3ff9879501aed.tar.bz2
dokka-046265ea04b645b4f8ff835aa6c3ff9879501aed.zip
Add Owner references, cleanup
Diffstat (limited to 'src/Model')
-rw-r--r--src/Model/DocumentationBuildingVisitor.kt26
-rw-r--r--src/Model/DocumentationModel.kt26
-rw-r--r--src/Model/DocumentationNodeBuilder.kt (renamed from src/Model/DocumentationBuilder.kt)70
-rw-r--r--src/Model/DocumentationResolver.kt16
4 files changed, 73 insertions, 65 deletions
diff --git a/src/Model/DocumentationBuildingVisitor.kt b/src/Model/DocumentationBuildingVisitor.kt
index 81a6474c..b078f753 100644
--- a/src/Model/DocumentationBuildingVisitor.kt
+++ b/src/Model/DocumentationBuildingVisitor.kt
@@ -28,19 +28,19 @@ class DocumentationBuildingVisitor(val context: BindingContext, private val work
visitChildren(descriptor.getTypeParameters(), node)
visitChild(descriptor.getReceiverParameter(), node)
visitChildren(descriptor.getValueParameters(), node)
- return node.resolve(context.getResolutionScope(descriptor))
+ return node.resolve()
}
public override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = createDocumentation(descriptor!!, data!!)
visitChildren(descriptor.getMemberScope().getAllDescriptors(), node)
- return node.resolve(context.getResolutionScope(descriptor))
+ return node.resolve()
}
public override fun visitPackageViewDescriptor(descriptor: PackageViewDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = createDocumentation(descriptor!!, data!!)
visitChildren(descriptor.getMemberScope().getAllDescriptors(), node)
- return node.resolve(context.getResolutionScope(descriptor))
+ return node.resolve()
}
public override fun visitVariableDescriptor(descriptor: VariableDescriptor?, data: DocumentationNode?): DocumentationNode? {
@@ -57,12 +57,12 @@ class DocumentationBuildingVisitor(val context: BindingContext, private val work
public override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = processCallable(descriptor!!, data!!)
- return node.resolve(context.getResolutionScope(descriptor))
+ return node.resolve()
}
public override fun visitTypeParameterDescriptor(descriptor: TypeParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = createDocumentation(descriptor!!, data!!)
- return node.resolve(context.getResolutionScope(descriptor))
+ return node.resolve()
}
public override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? {
@@ -77,43 +77,43 @@ class DocumentationBuildingVisitor(val context: BindingContext, private val work
it !is CallableMemberDescriptor || it.isUserCode()
}
visitChildren(members, node)
- return node.resolve(context.getResolutionScope(descriptor))
+ return node.resolve()
}
public override fun visitModuleDeclaration(descriptor: ModuleDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = createDocumentation(descriptor!!, data!!)
visitChild(descriptor.getPackage(FqName.ROOT), node)
- return node.resolve(context.getResolutionScope(descriptor))
+ return node.resolve()
}
public override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = visitFunctionDescriptor(descriptor!!, data)
- return node?.resolve(context.getResolutionScope(descriptor))
+ return node?.resolve()
}
public override fun visitScriptDescriptor(scriptDescriptor: ScriptDescriptor?, data: DocumentationNode?): DocumentationNode? {
val classDescriptor = scriptDescriptor!!.getClassDescriptor()
val node = visitClassDescriptor(classDescriptor, data)
- return node?.resolve(context.getResolutionScope(classDescriptor))
+ return node?.resolve()
}
public override fun visitValueParameterDescriptor(descriptor: ValueParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = visitVariableDescriptor(descriptor!!, data)
- return node?.resolve(context.getResolutionScope(descriptor))
+ return node?.resolve()
}
public override fun visitPropertyGetterDescriptor(descriptor: PropertyGetterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = visitFunctionDescriptor(descriptor!!, data)
- return node?.resolve(context.getResolutionScope(descriptor))
+ return node?.resolve()
}
public override fun visitPropertySetterDescriptor(descriptor: PropertySetterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = visitFunctionDescriptor(descriptor!!, data)
- return node?.resolve(context.getResolutionScope(descriptor))
+ return node?.resolve()
}
public override fun visitReceiverParameterDescriptor(descriptor: ReceiverParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val node = createDocumentation(descriptor!!, data!!)
- return node.resolve(context.getResolutionScope(descriptor))
+ return node.resolve()
}
}
diff --git a/src/Model/DocumentationModel.kt b/src/Model/DocumentationModel.kt
index 77bd8373..06bc3775 100644
--- a/src/Model/DocumentationModel.kt
+++ b/src/Model/DocumentationModel.kt
@@ -1,5 +1,6 @@
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
@@ -9,9 +10,11 @@ public enum class DocumentationNodeKind {
Package
Class
Object
+
Constructor
Function
Property
+
Parameter
Receiver
TypeParameter
@@ -19,19 +22,21 @@ public enum class DocumentationNodeKind {
LowerBound
Exception
- Page
Model
}
public enum class DocumentationReferenceKind {
+ Owner
Member
Detail
- Owner
Link
Override
}
-public open class DocumentationNode(val name: String, val doc: String, val kind: DocumentationNodeKind) {
+public open class DocumentationNode(val name: String,
+ val doc: String,
+ val kind: DocumentationNodeKind,
+ val scope: JetScope) {
private val references = arrayListOf<DocumentationReference>()
public val owner: DocumentationNode
@@ -54,12 +59,12 @@ public open class DocumentationNode(val name: String, val doc: String, val kind:
public fun references(kind: DocumentationReferenceKind): List<DocumentationReference> = references.filter { it.kind == kind }
- public override fun toString() : String {
+ public override fun toString(): String {
return "$kind $name"
}
}
-public class DocumentationModel : DocumentationNode("model", "", DocumentationNodeKind.Model) {
+public class DocumentationModel : DocumentationNode("model", "", DocumentationNodeKind.Model, JetScope.EMPTY) {
fun merge(other: DocumentationModel): DocumentationModel {
val model = DocumentationModel()
model.addAllReferencesFrom(other)
@@ -72,3 +77,14 @@ public class DocumentationModel : DocumentationNode("model", "", DocumentationNo
}
public data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: DocumentationReferenceKind)
+
+fun BindingContext.createDocumentationModel(file: JetFile): DocumentationModel {
+ val model = DocumentationModel()
+ val packageFragment = getPackageFragment(file)
+ if (packageFragment == null) throw IllegalArgumentException("File $file should have package fragment")
+
+ val visitor = DocumentationNodeBuilder(this)
+ packageFragment.accept(DocumentationBuildingVisitor(this, visitor), model)
+
+ return model
+}
diff --git a/src/Model/DocumentationBuilder.kt b/src/Model/DocumentationNodeBuilder.kt
index 353e839e..1c451465 100644
--- a/src/Model/DocumentationBuilder.kt
+++ b/src/Model/DocumentationNodeBuilder.kt
@@ -6,95 +6,91 @@ import org.jetbrains.jet.lang.descriptors.*
import org.jetbrains.jet.lang.descriptors.impl.*
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
-fun BindingContext.createDocumentationModel(file: JetFile): DocumentationModel {
- val model = DocumentationModel()
- val packageFragment = getPackageFragment(file)
- if (packageFragment == null) throw IllegalArgumentException("File $file should have package fragment")
-
- val visitor = DocumentationBuilderVisitor(this)
- packageFragment.accept(DocumentationBuildingVisitor(this, visitor), model)
-
- return model
-}
-
-class DocumentationBuilderVisitor(val context: BindingContext) : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() {
+class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode, DocumentationNode>() {
override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Unknown)
- data?.addReferenceTo(node, DocumentationReferenceKind.Member)
+ val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Unknown, context.getResolutionScope(descriptor))
+ 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(), "", DocumentationNodeKind.Receiver)
- data?.addReferenceTo(node, DocumentationReferenceKind.Detail)
+ val node = DocumentationNode(descriptor!!.getName().asString(), "", DocumentationNodeKind.Receiver, context.getResolutionScope(descriptor))
+ data!!.addReferenceTo(node, DocumentationReferenceKind.Detail)
+ node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
}
override fun visitValueParameterDescriptor(descriptor: ValueParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter)
- data?.addReferenceTo(node, DocumentationReferenceKind.Detail)
+ val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter, context.getResolutionScope(descriptor))
+ data!!.addReferenceTo(node, DocumentationReferenceKind.Detail)
+ node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
}
override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc,
- when (descriptor.getKind()) {
- ClassKind.OBJECT -> DocumentationNodeKind.Object
- else -> DocumentationNodeKind.Class
- }
- )
- data?.addReferenceTo(node, DocumentationReferenceKind.Member)
+ val node = DocumentationNode(descriptor.getName().asString(), doc, when (descriptor.getKind()) {
+ ClassKind.OBJECT -> DocumentationNodeKind.Object
+ else -> DocumentationNodeKind.Class
+ }, context.getResolutionScope(descriptor))
+ data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
+ node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
}
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Function)
- data?.addReferenceTo(node, DocumentationReferenceKind.Member)
+ val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Function, context.getResolutionScope(descriptor))
+ data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
+ node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
}
override fun visitTypeParameterDescriptor(descriptor: TypeParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.TypeParameter)
- data?.addReferenceTo(node, DocumentationReferenceKind.Detail)
+ val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.TypeParameter, context.getResolutionScope(descriptor))
+ data!!.addReferenceTo(node, DocumentationReferenceKind.Detail)
val builtIns = KotlinBuiltIns.getInstance()
for (constraint in descriptor.getUpperBounds()) {
if (constraint == builtIns.getDefaultBound())
continue
- val constraintNode = DocumentationNode(constraint.toString(), "", DocumentationNodeKind.UpperBound)
+ val constraintNode = DocumentationNode(constraint.toString(), "", 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)
+ val constraintNode = DocumentationNode(constraint.toString(), "", DocumentationNodeKind.LowerBound, context.getResolutionScope(descriptor))
node.addReferenceTo(constraintNode, DocumentationReferenceKind.Detail)
}
+ node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
}
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Property)
- data?.addReferenceTo(node, DocumentationReferenceKind.Member)
+ val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Property, context.getResolutionScope(descriptor))
+ data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
+ node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
}
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? {
val doc = context.getDocumentation(descriptor!!)
- val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Constructor)
- data?.addReferenceTo(node, DocumentationReferenceKind.Member)
+ val node = DocumentationNode(descriptor.getName().asString(), doc, DocumentationNodeKind.Constructor, context.getResolutionScope(descriptor))
+ 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(), "", DocumentationNodeKind.Package)
- data?.addReferenceTo(node, DocumentationReferenceKind.Member)
+ val node = DocumentationNode(descriptor!!.fqName.asString(), "", DocumentationNodeKind.Package, context.getResolutionScope(descriptor))
+ data!!.addReferenceTo(node, DocumentationReferenceKind.Member)
+ node.addReferenceTo(data, DocumentationReferenceKind.Owner)
return node
}
}
diff --git a/src/Model/DocumentationResolver.kt b/src/Model/DocumentationResolver.kt
index 1d470867..dee68f49 100644
--- a/src/Model/DocumentationResolver.kt
+++ b/src/Model/DocumentationResolver.kt
@@ -2,20 +2,15 @@ package org.jetbrains.dokka
import org.jetbrains.jet.lang.resolve.scopes.*
import org.jetbrains.jet.lang.resolve.name.*
-import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
-
+import org.jetbrains.jet.lang.descriptors.*
fun DocumentationNode.resolve(): DocumentationNode {
- return this
-}
-
-fun DocumentationNode.resolve(scope: JetScope): DocumentationNode {
for (detail in details) {
- val symbol = when (detail.kind) {
+ val symbol: DeclarationDescriptor? = when (detail.kind) {
DocumentationNodeKind.Receiver -> (scope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter()
DocumentationNodeKind.Parameter -> scope.getLocalVariable(Name.guess(detail.name))
- DocumentationNodeKind.Function -> scope.getFunctions(Name.guess(detail.name)).single()
- DocumentationNodeKind.Property -> scope.getProperties(Name.guess(detail.name)).single()
+ 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))
}
@@ -24,4 +19,5 @@ fun DocumentationNode.resolve(scope: JetScope): DocumentationNode {
throw IllegalStateException("Cannot resolve node $this detail $detail")
}
return this
-} \ No newline at end of file
+}
+