aboutsummaryrefslogtreecommitdiff
path: root/src/Model/DocumentationBuildingVisitor.kt
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 20:54:26 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-11 20:54:26 +0400
commit197a6e486d16d2e3689e900b45c65ef8d598f3b7 (patch)
tree5b4443a4406dd0fff9a549e8fc51e61d8f2ef06a /src/Model/DocumentationBuildingVisitor.kt
parent6afd7af76563f373e971256f8c9a7dcf42183fd4 (diff)
downloaddokka-197a6e486d16d2e3689e900b45c65ef8d598f3b7.tar.gz
dokka-197a6e486d16d2e3689e900b45c65ef8d598f3b7.tar.bz2
dokka-197a6e486d16d2e3689e900b45c65ef8d598f3b7.zip
Rename Documentation folder to Model
Diffstat (limited to 'src/Model/DocumentationBuildingVisitor.kt')
-rw-r--r--src/Model/DocumentationBuildingVisitor.kt121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/Model/DocumentationBuildingVisitor.kt b/src/Model/DocumentationBuildingVisitor.kt
new file mode 100644
index 00000000..e7b3fc09
--- /dev/null
+++ b/src/Model/DocumentationBuildingVisitor.kt
@@ -0,0 +1,121 @@
+package org.jetbrains.dokka
+
+import org.jetbrains.jet.lang.descriptors.*
+import org.jetbrains.jet.lang.resolve.name.FqName
+
+class DocumentationBuildingVisitor(private val worker: DeclarationDescriptorVisitor<DocumentationNode, DocumentationNode>)
+: DeclarationDescriptorVisitor<DocumentationNode, DocumentationNode> {
+
+ private fun visitChildren(descriptors: Collection<DeclarationDescriptor>, data: DocumentationNode) {
+ for (descriptor in descriptors) {
+ if (descriptor.isUserCode())
+ descriptor.accept(this, data)
+ }
+ }
+
+ private fun visitChild(descriptor: DeclarationDescriptor?, data: DocumentationNode) {
+ if (descriptor != null && descriptor.isUserCode())
+ descriptor.accept(this, data)
+ }
+
+ private fun createDocumentation(descriptor: DeclarationDescriptor, data: DocumentationNode): DocumentationNode {
+ return descriptor.accept(worker, data)
+ }
+
+ private fun processCallable(descriptor: CallableDescriptor, data: DocumentationNode): DocumentationNode {
+ val node = createDocumentation(descriptor, data)
+ visitChildren(descriptor.getTypeParameters(), node)
+ visitChild(descriptor.getReceiverParameter(), node)
+ visitChildren(descriptor.getValueParameters(), node)
+ return node
+ }
+
+ public override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = createDocumentation(descriptor!!, data!!)
+ visitChildren(descriptor.getMemberScope().getAllDescriptors(), node)
+ return node
+ }
+
+ public override fun visitPackageViewDescriptor(descriptor: PackageViewDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = createDocumentation(descriptor!!, data!!)
+ visitChildren(descriptor.getMemberScope().getAllDescriptors(), node)
+ return node
+ }
+
+ public override fun visitVariableDescriptor(descriptor: VariableDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = processCallable(descriptor!!, data!!)
+ return node
+ }
+
+ public override fun visitPropertyDescriptor(descriptor: PropertyDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = processCallable(descriptor!!, data!!)
+ visitChild(descriptor.getGetter(), node)
+ visitChild(descriptor.getSetter(), node)
+ return node
+ }
+
+ public override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = processCallable(descriptor!!, data!!)
+ return node
+ }
+
+ public override fun visitTypeParameterDescriptor(descriptor: TypeParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = createDocumentation(descriptor!!, data!!)
+ return node
+ }
+
+ public override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = createDocumentation(descriptor!!, data!!)
+ if (descriptor.getKind() != ClassKind.OBJECT) {
+ // do not go inside object for class object and constructors, they are generated
+ visitChildren(descriptor.getTypeConstructor().getParameters(), node)
+ visitChildren(descriptor.getConstructors(), node)
+ visitChild(descriptor.getClassObjectDescriptor(), node)
+ }
+ val members = descriptor.getDefaultType().getMemberScope().getAllDescriptors().filter {
+ it !is CallableMemberDescriptor || it.isUserCode()
+ }
+ visitChildren(members, node)
+ return node
+ }
+
+ public override fun visitModuleDeclaration(descriptor: ModuleDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = createDocumentation(descriptor!!, data!!)
+ visitChild(descriptor.getPackage(FqName.ROOT), node)
+ return node
+ }
+
+ public override fun visitConstructorDescriptor(constructorDescriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = visitFunctionDescriptor(constructorDescriptor, data)
+ return node
+ }
+
+ public override fun visitScriptDescriptor(scriptDescriptor: ScriptDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = visitClassDescriptor(scriptDescriptor!!.getClassDescriptor(), data)
+ return node
+ }
+
+ public override fun visitValueParameterDescriptor(descriptor: ValueParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = visitVariableDescriptor(descriptor, data)
+ return node
+ }
+
+ public override fun visitPropertyGetterDescriptor(descriptor: PropertyGetterDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = visitFunctionDescriptor(descriptor, data)
+ return node
+ }
+
+ public override fun visitPropertySetterDescriptor(descriptor: PropertySetterDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = visitFunctionDescriptor(descriptor, data)
+ return node
+ }
+
+ public override fun visitReceiverParameterDescriptor(descriptor: ReceiverParameterDescriptor?, data: DocumentationNode?): DocumentationNode? {
+ val node = createDocumentation(descriptor!!, data!!)
+ return node
+ }
+}
+
+public fun visitDescriptor(descriptor: DeclarationDescriptor, data: DocumentationNode, visitor: DeclarationDescriptorVisitor<DocumentationNode, DocumentationNode>): DocumentationNode {
+ return descriptor.accept(DocumentationBuildingVisitor(visitor), data)
+}