diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-12 15:14:03 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-12 15:14:03 +0400 |
commit | 52deaf7d9b31a4cc5ed36a280e07fdfeff975362 (patch) | |
tree | 7864aa9cd01a8d7c793246c6d993747577bdab3b /src | |
parent | 9ebe89742ccf29bb7efb6198666bd968397320e0 (diff) | |
download | dokka-52deaf7d9b31a4cc5ed36a280e07fdfeff975362.tar.gz dokka-52deaf7d9b31a4cc5ed36a280e07fdfeff975362.tar.bz2 dokka-52deaf7d9b31a4cc5ed36a280e07fdfeff975362.zip |
Add signature generator classes, refactor classes into files and nested enums.
Diffstat (limited to 'src')
-rw-r--r-- | src/Generation/KotlinSignatureGenerator.kt | 7 | ||||
-rw-r--r-- | src/Generation/SignatureGenerator.kt | 6 | ||||
-rw-r--r-- | src/Model/Diagnostics.kt | 14 | ||||
-rw-r--r-- | src/Model/DocumentationModule.kt | 78 | ||||
-rw-r--r-- | src/Model/DocumentationNode.kt | 63 | ||||
-rw-r--r-- | src/Model/DocumentationNodeBuilder.kt | 82 | ||||
-rw-r--r-- | src/Model/DocumentationReference.kt | 14 | ||||
-rw-r--r-- | src/main.kt | 2 |
8 files changed, 145 insertions, 121 deletions
diff --git a/src/Generation/KotlinSignatureGenerator.kt b/src/Generation/KotlinSignatureGenerator.kt new file mode 100644 index 00000000..fad655b0 --- /dev/null +++ b/src/Generation/KotlinSignatureGenerator.kt @@ -0,0 +1,7 @@ +package org.jetbrains.dokka + +class KotlinSignatureGenerator : SignatureGenerator { + override fun getFunctionSignature(node: DocumentationNode): String { + return node.name + } +}
\ No newline at end of file diff --git a/src/Generation/SignatureGenerator.kt b/src/Generation/SignatureGenerator.kt new file mode 100644 index 00000000..2f603327 --- /dev/null +++ b/src/Generation/SignatureGenerator.kt @@ -0,0 +1,6 @@ +package org.jetbrains.dokka + +trait SignatureGenerator { + fun getFunctionSignature(node: DocumentationNode): String +} + diff --git a/src/Model/Diagnostics.kt b/src/Model/Diagnostics.kt index 723bd59d..470d7973 100644 --- a/src/Model/Diagnostics.kt +++ b/src/Model/Diagnostics.kt @@ -5,18 +5,18 @@ import org.jetbrains.jet.lang.resolve.name.* import org.jetbrains.jet.lang.resolve.BindingContext fun BindingContext.checkResolveChildren(node : DocumentationNode) { - if (node.kind != DocumentationNodeKind.Module && node.kind != DocumentationNodeKind.Package) { + if (node.kind != DocumentationNode.Kind.Module && node.kind != DocumentationNode.Kind.Package) { // TODO: we don't resolve packages and modules for now 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() + DocumentationNode.Kind.Receiver -> (parentScope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter() + DocumentationNode.Kind.Parameter -> parentScope.getLocalVariable(Name.guess(symbolName)) + DocumentationNode.Kind.Function -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull() + DocumentationNode.Kind.Property -> parentScope.getProperties(Name.guess(symbolName)).firstOrNull() + DocumentationNode.Kind.Constructor -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull() else -> parentScope.getClassifier(Name.guess(symbolName)) } @@ -25,7 +25,7 @@ fun BindingContext.checkResolveChildren(node : DocumentationNode) { } } - for (reference in node.allReferences().filterNot { it.kind == DocumentationReferenceKind.Owner }) { + for (reference in node.allReferences().filterNot { it.kind == DocumentationReference.Kind.Owner }) { checkResolveChildren(reference.to) } } diff --git a/src/Model/DocumentationModule.kt b/src/Model/DocumentationModule.kt index 49a54624..25cbb600 100644 --- a/src/Model/DocumentationModule.kt +++ b/src/Model/DocumentationModule.kt @@ -4,71 +4,7 @@ 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 - - Package - Class - Trait - Object - - Constructor - Function - Property - - Parameter - Receiver - TypeParameter - Type - UpperBound - LowerBound - Exception - - Module -} - -public enum class DocumentationReferenceKind { - Owner - Member - Detail - Link - Override -} - -public open class DocumentationNode(val descriptor: DeclarationDescriptor, - val name: String, - val doc: DocumentationContent, - val kind: DocumentationNodeKind) { - - private val references = arrayListOf<DocumentationReference>() - - public val owner: DocumentationNode? - get() = references(DocumentationReferenceKind.Owner).firstOrNull()?.to // TODO: should be singleOrNull, but bugz! - public val details: List<DocumentationNode> - get() = references(DocumentationReferenceKind.Detail).map { it.to } - public val members: List<DocumentationNode> - get() = references(DocumentationReferenceKind.Member).map { it.to } - public val links: List<DocumentationNode> - get() = references(DocumentationReferenceKind.Link).map { it.to } - - // TODO: Should we allow node mutation? Model merge will copy by ref, so references are transparent, which could nice - public fun addReferenceTo(to: DocumentationNode, kind: DocumentationReferenceKind) { - references.add(DocumentationReference(this, to, kind)) - } - - public fun addAllReferencesFrom(other: DocumentationNode) { - references.addAll(other.references) - } - - public fun references(kind: DocumentationReferenceKind): List<DocumentationReference> = references.filter { it.kind == kind } - public fun allReferences(): List<DocumentationReference> = references - - public override fun toString(): String { - return "$kind:$name" - } -} - -public class DocumentationModule(val module: ModuleDescriptor) : DocumentationNode(module, "model", DocumentationContent.Empty, DocumentationNodeKind.Module) { +public class DocumentationModule(val module: ModuleDescriptor) : DocumentationNode(module, "model", DocumentationContent.Empty, DocumentationNode.Kind.Module) { fun merge(other: DocumentationModule): DocumentationModule { val model = DocumentationModule(module) model.addAllReferencesFrom(other) @@ -77,17 +13,15 @@ public class DocumentationModule(val module: ModuleDescriptor) : DocumentationNo } } -public data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: DocumentationReferenceKind) - -fun BindingContext.createDocumentationModel(module: ModuleDescriptor, file: JetFile): DocumentationModule { +fun BindingContext.createDocumentationModule(module: ModuleDescriptor, file: JetFile): DocumentationModule { val packageFragment = getPackageFragment(file) - val model = DocumentationModule(module) + val documentationModule = DocumentationModule(module) if (packageFragment == null) throw IllegalArgumentException("File $file should have package fragment") val visitor = DocumentationNodeBuilder(this) - packageFragment.accept(DocumentationBuildingVisitor(this, visitor), model) + packageFragment.accept(DocumentationBuildingVisitor(this, visitor), documentationModule) - checkResolveChildren(model) + checkResolveChildren(documentationModule) - return model + return documentationModule } diff --git a/src/Model/DocumentationNode.kt b/src/Model/DocumentationNode.kt new file mode 100644 index 00000000..f095e8b0 --- /dev/null +++ b/src/Model/DocumentationNode.kt @@ -0,0 +1,63 @@ +package org.jetbrains.dokka + +import org.jetbrains.jet.lang.descriptors.* + + +public open class DocumentationNode(val descriptor: DeclarationDescriptor, + val name: String, + val doc: DocumentationContent, + val kind: DocumentationNode.Kind) { + + private val references = arrayListOf<DocumentationReference>() + + public val owner: DocumentationNode? + get() = references(DocumentationReference.Kind.Owner).firstOrNull()?.to // TODO: should be singleOrNull, but bugz! + public val details: List<DocumentationNode> + get() = references(DocumentationReference.Kind.Detail).map { it.to } + public val members: List<DocumentationNode> + get() = references(DocumentationReference.Kind.Member).map { it.to } + public val links: List<DocumentationNode> + get() = references(DocumentationReference.Kind.Link).map { it.to } + + // TODO: Should we allow node mutation? Model merge will copy by ref, so references are transparent, which could nice + public fun addReferenceTo(to: DocumentationNode, kind: DocumentationReference.Kind) { + references.add(DocumentationReference(this, to, kind)) + } + + public fun addAllReferencesFrom(other: DocumentationNode) { + references.addAll(other.references) + } + + public fun references(kind: DocumentationReference.Kind): List<DocumentationReference> = references.filter { it.kind == kind } + public fun allReferences(): List<DocumentationReference> = references + + public override fun toString(): String { + return "$kind:$name" + } + + public enum class Kind { + Unknown + + Package + Class + Trait + Object + + Constructor + Function + Property + + Parameter + Receiver + TypeParameter + Type + UpperBound + LowerBound + Exception + + Module + } + +} + + diff --git a/src/Model/DocumentationNodeBuilder.kt b/src/Model/DocumentationNodeBuilder.kt index b079c499..8fa12012 100644 --- a/src/Model/DocumentationNodeBuilder.kt +++ b/src/Model/DocumentationNodeBuilder.kt @@ -10,104 +10,104 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Unknown) - data!!.addReferenceTo(node, DocumentationReferenceKind.Link) - node.addReferenceTo(data, DocumentationReferenceKind.Owner) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.Unknown) + data!!.addReferenceTo(node, DocumentationReference.Kind.Link) + node.addReferenceTo(data, DocumentationReference.Kind.Owner) return node } override fun visitReceiverParameterDescriptor(descriptor: ReceiverParameterDescriptor?, data: DocumentationNode?): DocumentationNode? { - val node = DocumentationNode(descriptor!!, descriptor.getName().asString(), DocumentationContent.Empty, DocumentationNodeKind.Receiver) - data!!.addReferenceTo(node, DocumentationReferenceKind.Detail) + val node = DocumentationNode(descriptor!!, descriptor.getName().asString(), DocumentationContent.Empty, DocumentationNode.Kind.Receiver) + data!!.addReferenceTo(node, DocumentationReference.Kind.Detail) - val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type) - node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail) + val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNode.Kind.Type) + node.addReferenceTo(typeNode, DocumentationReference.Kind.Detail) - node.addReferenceTo(data, DocumentationReferenceKind.Owner) + node.addReferenceTo(data, DocumentationReference.Kind.Owner) return node } override fun visitValueParameterDescriptor(descriptor: ValueParameterDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Parameter) - data!!.addReferenceTo(node, DocumentationReferenceKind.Detail) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.Parameter) + data!!.addReferenceTo(node, DocumentationReference.Kind.Detail) - val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type) - node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail) + val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNode.Kind.Type) + node.addReferenceTo(typeNode, DocumentationReference.Kind.Detail) - node.addReferenceTo(data, DocumentationReferenceKind.Owner) + node.addReferenceTo(data, DocumentationReference.Kind.Owner) return node } override fun visitClassDescriptor(descriptor: ClassDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, when (descriptor.getKind()) { - ClassKind.OBJECT -> DocumentationNodeKind.Object - ClassKind.TRAIT -> DocumentationNodeKind.Trait - else -> DocumentationNodeKind.Class + ClassKind.OBJECT -> DocumentationNode.Kind.Object + ClassKind.TRAIT -> DocumentationNode.Kind.Trait + else -> DocumentationNode.Kind.Class }) - data!!.addReferenceTo(node, DocumentationReferenceKind.Member) - node.addReferenceTo(data, DocumentationReferenceKind.Owner) + data!!.addReferenceTo(node, DocumentationReference.Kind.Member) + node.addReferenceTo(data, DocumentationReference.Kind.Owner) return node } override fun visitFunctionDescriptor(descriptor: FunctionDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Function) - data!!.addReferenceTo(node, DocumentationReferenceKind.Member) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.Function) + data!!.addReferenceTo(node, DocumentationReference.Kind.Member) - val typeNode = DocumentationNode(descriptor, descriptor.getReturnType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type) - node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail) + val typeNode = DocumentationNode(descriptor, descriptor.getReturnType().toString(), DocumentationContent.Empty, DocumentationNode.Kind.Type) + node.addReferenceTo(typeNode, DocumentationReference.Kind.Detail) - node.addReferenceTo(data, DocumentationReferenceKind.Owner) + node.addReferenceTo(data, DocumentationReference.Kind.Owner) return node } override fun visitTypeParameterDescriptor(descriptor: TypeParameterDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.TypeParameter) - data!!.addReferenceTo(node, DocumentationReferenceKind.Detail) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.TypeParameter) + data!!.addReferenceTo(node, DocumentationReference.Kind.Detail) val builtIns = KotlinBuiltIns.getInstance() for (constraint in descriptor.getUpperBounds()) { if (constraint == builtIns.getDefaultBound()) continue - val constraintNode = DocumentationNode(descriptor, constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.UpperBound) - node.addReferenceTo(constraintNode, DocumentationReferenceKind.Detail) + val constraintNode = DocumentationNode(descriptor, constraint.toString(), DocumentationContent.Empty, DocumentationNode.Kind.UpperBound) + node.addReferenceTo(constraintNode, DocumentationReference.Kind.Detail) } for (constraint in descriptor.getLowerBounds()) { if (builtIns.isNothing(constraint)) continue - val constraintNode = DocumentationNode(descriptor, constraint.toString(), DocumentationContent.Empty, DocumentationNodeKind.LowerBound) - node.addReferenceTo(constraintNode, DocumentationReferenceKind.Detail) + val constraintNode = DocumentationNode(descriptor, constraint.toString(), DocumentationContent.Empty, DocumentationNode.Kind.LowerBound) + node.addReferenceTo(constraintNode, DocumentationReference.Kind.Detail) } - node.addReferenceTo(data, DocumentationReferenceKind.Owner) + node.addReferenceTo(data, DocumentationReference.Kind.Owner) return node } override fun visitPropertyDescriptor(descriptor: PropertyDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Property) - data!!.addReferenceTo(node, DocumentationReferenceKind.Member) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.Property) + data!!.addReferenceTo(node, DocumentationReference.Kind.Member) - val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNodeKind.Type) - node.addReferenceTo(typeNode, DocumentationReferenceKind.Detail) + val typeNode = DocumentationNode(descriptor, descriptor.getType().toString(), DocumentationContent.Empty, DocumentationNode.Kind.Type) + node.addReferenceTo(typeNode, DocumentationReference.Kind.Detail) - node.addReferenceTo(data, DocumentationReferenceKind.Owner) + node.addReferenceTo(data, DocumentationReference.Kind.Owner) return node } override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor?, data: DocumentationNode?): DocumentationNode? { val doc = context.getDocumentation(descriptor!!) - val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNodeKind.Constructor) - data!!.addReferenceTo(node, DocumentationReferenceKind.Member) - node.addReferenceTo(data, DocumentationReferenceKind.Owner) + val node = DocumentationNode(descriptor, descriptor.getName().asString(), doc, DocumentationNode.Kind.Constructor) + data!!.addReferenceTo(node, DocumentationReference.Kind.Member) + node.addReferenceTo(data, DocumentationReference.Kind.Owner) return node } override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? { - val node = DocumentationNode(descriptor!!, descriptor.fqName.asString(), DocumentationContent.Empty, DocumentationNodeKind.Package) - data!!.addReferenceTo(node, DocumentationReferenceKind.Member) - node.addReferenceTo(data, DocumentationReferenceKind.Owner) + val node = DocumentationNode(descriptor!!, descriptor.fqName.asString(), DocumentationContent.Empty, DocumentationNode.Kind.Package) + data!!.addReferenceTo(node, DocumentationReference.Kind.Member) + node.addReferenceTo(data, DocumentationReference.Kind.Owner) return node } } diff --git a/src/Model/DocumentationReference.kt b/src/Model/DocumentationReference.kt new file mode 100644 index 00000000..41cca8db --- /dev/null +++ b/src/Model/DocumentationReference.kt @@ -0,0 +1,14 @@ +package org.jetbrains.dokka + +public data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: DocumentationReference.Kind) { + public enum class Kind { + Owner + Member + Detail + Link + Override + } +} + + + diff --git a/src/main.kt b/src/main.kt index 975b2633..95cda7af 100644 --- a/src/main.kt +++ b/src/main.kt @@ -38,7 +38,7 @@ public fun main(args: Array<String>) { val model = environment.processFiles { context, module, file -> println("Processing: ${file.getName()}") - context.createDocumentationModel(module, file) + context.createDocumentationModule(module, file) }.reduce {(aggregate, item) -> aggregate.merge(item) } ConsoleGenerator().generate(model) |