diff options
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 24 | ||||
-rw-r--r-- | src/Kotlin/KotlinLanguageService.kt (renamed from src/Languages/KotlinLanguageService.kt) | 96 | ||||
-rw-r--r-- | src/main.kt | 9 |
3 files changed, 70 insertions, 59 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index d8162c44..adb2b4c6 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -15,6 +15,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName public data class DocumentationOptions(val includeNonPublic: Boolean = false) class DocumentationBuilder(val context: BindingContext, val options: DocumentationOptions) { + val visibleToDocumentation = setOf(Visibilities.INTERNAL, Visibilities.PROTECTED, Visibilities.PUBLIC) val descriptorToNode = hashMapOf<DeclarationDescriptor, DocumentationNode>() val nodeToDescriptor = hashMapOf<DocumentationNode, DeclarationDescriptor>() val links = hashMapOf<DocumentationNode, DeclarationDescriptor>() @@ -104,8 +105,6 @@ class DocumentationBuilder(val context: BindingContext, val options: Documentati node.appendProjection(typeArgument) } - val visibleToDocumentation = setOf(Visibilities.INTERNAL, Visibilities.PROTECTED, Visibilities.PUBLIC) - fun DocumentationNode.appendChild(descriptor: DeclarationDescriptor, kind: DocumentationReference.Kind) { // do not include generated code if (descriptor is CallableMemberDescriptor && descriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) @@ -122,15 +121,19 @@ class DocumentationBuilder(val context: BindingContext, val options: Documentati descriptors.forEach { descriptor -> appendChild(descriptor, kind) } } + fun DocumentationNode.appendFile(sourceFile : JetFile) { + val fragment = context.getPackageFragment(sourceFile)!! + val packageNode = packages.getOrPut(fragment.fqName) { + val packageNode = DocumentationNode(fragment.fqName.asString(), Content.Empty, Kind.Package) + append(packageNode, DocumentationReference.Kind.Member) + packageNode + } + packageNode.appendChildren(fragment.getMemberScope().getAllDescriptors(), DocumentationReference.Kind.Member) + } + fun DocumentationNode.appendFiles(sourceFiles : List<JetFile>) { for (sourceFile in sourceFiles) { - val fragment = context.getPackageFragment(sourceFile)!! - val packageNode = packages.getOrPut(fragment.fqName) { - val packageNode = DocumentationNode(fragment.fqName.asString(), Content.Empty, Kind.Package) - append(packageNode, DocumentationReference.Kind.Member) - packageNode - } - packageNode.appendChildren(fragment.getMemberScope().getAllDescriptors(), DocumentationReference.Kind.Member) + appendFile(sourceFile) } } @@ -172,7 +175,6 @@ class DocumentationBuilder(val context: BindingContext, val options: Documentati return node } - fun ConstructorDescriptor.build(): DocumentationNode { val node = DocumentationNode(this, Kind.Constructor) node.appendChildren(getValueParameters(), DocumentationReference.Kind.Detail) @@ -244,7 +246,7 @@ class DocumentationBuilder(val context: BindingContext, val options: Documentati } fun ReceiverParameterDescriptor.build(): DocumentationNode { - val node = DocumentationNode(this, Kind.Receiver) + val node = DocumentationNode(getName().asString(), Content.Empty, Kind.Receiver) node.appendType(getType()) return node } diff --git a/src/Languages/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index f806dd19..80467914 100644 --- a/src/Languages/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -1,29 +1,35 @@ package org.jetbrains.dokka -import org.jetbrains.dokka.DocumentationNode.* +import org.jetbrains.dokka.symbol +import org.jetbrains.dokka.text +import org.jetbrains.dokka.identifier +import org.jetbrains.dokka.link +import org.jetbrains.dokka.keyword +import org.jetbrains.dokka.LanguageService +import org.jetbrains.dokka.DocumentationNode +import org.jetbrains.dokka.ContentNode +import org.jetbrains.dokka +import org.jetbrains.dokka.ContentText -/** - * Implements [LanguageService] and provides rendering of symbols in Kotlin language - */ class KotlinLanguageService : LanguageService { override fun render(node: DocumentationNode): ContentNode { - return content { + return dokka.content { when (node.kind) { - Kind.Package -> renderPackage(node) - Kind.Class, - Kind.Interface, - Kind.Enum, - Kind.EnumItem, - Kind.Object -> renderClass(node) - - Kind.TypeParameter -> renderTypeParameter(node) - Kind.Type, - Kind.UpperBound -> renderType(node) - - Kind.Modifier -> renderModifier(node) - Kind.Constructor, - Kind.Function -> renderFunction(node) - Kind.Property -> renderProperty(node) + DocumentationNode.Kind.Package -> renderPackage(node) + DocumentationNode.Kind.Class, + DocumentationNode.Kind.Interface, + DocumentationNode.Kind.Enum, + DocumentationNode.Kind.EnumItem, + DocumentationNode.Kind.Object -> renderClass(node) + + DocumentationNode.Kind.TypeParameter -> renderTypeParameter(node) + DocumentationNode.Kind.Type, + DocumentationNode.Kind.UpperBound -> renderType(node) + + DocumentationNode.Kind.Modifier -> renderModifier(node) + DocumentationNode.Kind.Constructor, + DocumentationNode.Kind.Function -> renderFunction(node) + DocumentationNode.Kind.Property -> renderProperty(node) else -> ContentText("${node.kind}: ${node.name}") } } @@ -31,7 +37,7 @@ class KotlinLanguageService : LanguageService { override fun renderName(node: DocumentationNode): String { return when (node.kind) { - Kind.Constructor -> node.owner!!.name + DocumentationNode.Kind.Constructor -> node.owner!!.name else -> node.name } } @@ -63,7 +69,7 @@ class KotlinLanguageService : LanguageService { } private fun ContentNode.renderType(node: DocumentationNode) { - val typeArguments = node.details(Kind.Type) + val typeArguments = node.details(DocumentationNode.Kind.Type) if (node.name == "Function${typeArguments.count() - 1}") { // lambda symbol("(") @@ -111,7 +117,7 @@ class KotlinLanguageService : LanguageService { } private fun ContentNode.renderTypeParameter(node: DocumentationNode) { - val constraints = node.details(Kind.UpperBound) + val constraints = node.details(DocumentationNode.Kind.UpperBound) identifier(node.name) if (constraints.any()) { symbol(" : ") @@ -124,12 +130,12 @@ class KotlinLanguageService : LanguageService { private fun ContentNode.renderParameter(node: DocumentationNode) { identifier(node.name) symbol(": ") - val parameterType = node.detail(Kind.Type) + val parameterType = node.detail(DocumentationNode.Kind.Type) renderType(parameterType) } private fun ContentNode.renderTypeParametersForNode(node: DocumentationNode) { - val typeParameters = node.details(Kind.TypeParameter) + val typeParameters = node.details(DocumentationNode.Kind.TypeParameter) if (typeParameters.any()) { symbol("<") renderList(typeParameters) { @@ -140,7 +146,7 @@ class KotlinLanguageService : LanguageService { } private fun ContentNode.renderSupertypesForNode(node: DocumentationNode) { - val supertypes = node.details(Kind.Supertype) + val supertypes = node.details(DocumentationNode.Kind.Supertype) if (supertypes.any()) { symbol(" : ") renderList(supertypes) { @@ -150,9 +156,9 @@ class KotlinLanguageService : LanguageService { } private fun ContentNode.renderModifiersForNode(node: DocumentationNode) { - val modifiers = node.details(Kind.Modifier) + val modifiers = node.details(DocumentationNode.Kind.Modifier) for (it in modifiers) { - if (node.kind == Kind.Interface && it.name == "abstract") + if (node.kind == org.jetbrains.dokka.DocumentationNode.Kind.Interface && it.name == "abstract") continue renderModifier(it) text(" ") @@ -162,11 +168,11 @@ class KotlinLanguageService : LanguageService { private fun ContentNode.renderClass(node: DocumentationNode) { renderModifiersForNode(node) when (node.kind) { - Kind.Class -> keyword("class ") - Kind.Interface -> keyword("trait ") - Kind.Enum -> keyword("enum class ") - Kind.EnumItem -> keyword("enum val ") - Kind.Object -> keyword("object ") + DocumentationNode.Kind.Class -> keyword("class ") + DocumentationNode.Kind.Interface -> keyword("trait ") + DocumentationNode.Kind.Enum -> keyword("enum class ") + DocumentationNode.Kind.EnumItem -> keyword("enum val ") + DocumentationNode.Kind.Object -> keyword("object ") else -> throw IllegalArgumentException("Node $node is not a class-like object") } @@ -178,46 +184,46 @@ class KotlinLanguageService : LanguageService { private fun ContentNode.renderFunction(node: DocumentationNode) { renderModifiersForNode(node) when (node.kind) { - Kind.Constructor -> identifier(node.owner!!.name) - Kind.Function -> keyword("fun ") + DocumentationNode.Kind.Constructor -> identifier(node.owner!!.name) + DocumentationNode.Kind.Function -> keyword("fun ") else -> throw IllegalArgumentException("Node $node is not a function-like object") } renderTypeParametersForNode(node) - val receiver = node.details(Kind.Receiver).singleOrNull() + val receiver = node.details(DocumentationNode.Kind.Receiver).singleOrNull() if (receiver != null) { - renderType(receiver.detail(Kind.Type)) + renderType(receiver.detail(DocumentationNode.Kind.Type)) symbol(".") } - if (node.kind != Kind.Constructor) + if (node.kind != org.jetbrains.dokka.DocumentationNode.Kind.Constructor) identifier(node.name) symbol("(") - renderList(node.details(Kind.Parameter)) { + renderList(node.details(DocumentationNode.Kind.Parameter)) { renderParameter(it) } symbol(")") - if (node.kind != Kind.Constructor) { + if (node.kind != org.jetbrains.dokka.DocumentationNode.Kind.Constructor) { symbol(": ") - renderType(node.detail(Kind.Type)) + renderType(node.detail(DocumentationNode.Kind.Type)) } } private fun ContentNode.renderProperty(node: DocumentationNode) { renderModifiersForNode(node) when (node.kind) { - Kind.Property -> keyword("val ") + DocumentationNode.Kind.Property -> keyword("val ") else -> throw IllegalArgumentException("Node $node is not a property") } renderTypeParametersForNode(node) - val receiver = node.details(Kind.Receiver).singleOrNull() + val receiver = node.details(DocumentationNode.Kind.Receiver).singleOrNull() if (receiver != null) { - renderType(receiver.detail(Kind.Type)) + renderType(receiver.detail(DocumentationNode.Kind.Type)) symbol(".") } identifier(node.name) symbol(": ") - renderType(node.detail(Kind.Type)) + renderType(node.detail(DocumentationNode.Kind.Type)) } }
\ No newline at end of file diff --git a/src/main.kt b/src/main.kt index 923b2ea8..742d3815 100644 --- a/src/main.kt +++ b/src/main.kt @@ -6,8 +6,6 @@ import org.jetbrains.jet.cli.common.messages.* import org.jetbrains.jet.cli.common.arguments.* import org.jetbrains.jet.utils.PathUtil import java.io.File -import org.jetbrains.jet.lang.resolve.name.FqName -import org.jetbrains.dokka.DocumentationNode.Kind class DokkaArguments { Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)") @@ -53,12 +51,17 @@ public fun main(args: Array<String>) { val startAnalyse = System.currentTimeMillis() val documentation = environment.withContext { environment, module, context -> + println("building documentation ... ") val documentationModule = DocumentationModule("test") val options = DocumentationOptions() val documentationBuilder = DocumentationBuilder(context, options) with(documentationBuilder) { - documentationModule.appendFiles(environment.getSourceFiles()) + for (sourceFile in environment.getSourceFiles()) { + println(sourceFile.getName()) + documentationModule.appendFile(sourceFile) + } } + print("... resolving links ... ") documentationBuilder.resolveReferences(documentationModule) documentationModule } |