diff options
-rw-r--r-- | .idea/runConfigurations/Stdlib.xml | 2 | ||||
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 21 | ||||
-rw-r--r-- | src/main.kt | 24 | ||||
-rw-r--r-- | test/src/TestAPI.kt | 9 |
4 files changed, 34 insertions, 22 deletions
diff --git a/.idea/runConfigurations/Stdlib.xml b/.idea/runConfigurations/Stdlib.xml index 2e5be68f..6b39f0e7 100644 --- a/.idea/runConfigurations/Stdlib.xml +++ b/.idea/runConfigurations/Stdlib.xml @@ -2,7 +2,7 @@ <configuration default="false" name="Stdlib" type="JetRunConfigurationType" factoryName="Kotlin"> <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" /> <option name="MAIN_CLASS_NAME" value="org.jetbrains.dokka.DokkaPackage" /> - <option name="VM_PARAMETERS" value="" /> + <option name="VM_PARAMETERS" value="-Xmx2048m -Xms256m" /> <option name="PROGRAM_PARAMETERS" value="../kotlin/libraries/stdlib/src/ -output doc -module stdlib" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index adb2b4c6..5230d882 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -121,19 +121,16 @@ 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 + fun DocumentationNode.appendFragments(fragments: Collection<PackageFragmentDescriptor>) { + val descriptors = hashMapOf<String, List<DeclarationDescriptor>>() + for ((name, parts) in fragments.groupBy { it.fqName }) { + descriptors.put(name.asString(), parts.flatMap { it.getMemberScope().getAllDescriptors() }) } - packageNode.appendChildren(fragment.getMemberScope().getAllDescriptors(), DocumentationReference.Kind.Member) - } - - fun DocumentationNode.appendFiles(sourceFiles : List<JetFile>) { - for (sourceFile in sourceFiles) { - appendFile(sourceFile) + for ((packageName, declarations) in descriptors) { + println(" package $packageName: ${declarations.count()} nodes") + val packageNode = DocumentationNode(packageName, Content.Empty, Kind.Package) + packageNode.appendChildren(declarations, DocumentationReference.Kind.Member) + append(packageNode, DocumentationReference.Kind.Member) } } diff --git a/src/main.kt b/src/main.kt index 742d3815..44d78187 100644 --- a/src/main.kt +++ b/src/main.kt @@ -6,6 +6,7 @@ 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.descriptors.DeclarationDescriptor class DokkaArguments { Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)") @@ -47,21 +48,28 @@ public fun main(args: Array<String>) { println() - print("Analysing sources and libraries... ") + println("Analysing sources and libraries... ") val startAnalyse = System.currentTimeMillis() val documentation = environment.withContext { environment, module, context -> - println("building documentation ... ") - val documentationModule = DocumentationModule("test") + val fragments = environment.getSourceFiles().map { context.getPackageFragment(it) }.filterNotNull().distinct() + val documentationModule = DocumentationModule(arguments.moduleName) val options = DocumentationOptions() val documentationBuilder = DocumentationBuilder(context, options) + with(documentationBuilder) { - for (sourceFile in environment.getSourceFiles()) { - println(sourceFile.getName()) - documentationModule.appendFile(sourceFile) + val descriptors = hashMapOf<String, List<DeclarationDescriptor>>() + for ((name, parts) in fragments.groupBy { it.fqName }) { + descriptors.put(name.asString(), parts.flatMap { it.getMemberScope().getAllDescriptors() }) + } + for ((packageName, declarations) in descriptors) { + println(" package $packageName: ${declarations.count()} nodes") + val packageNode = DocumentationNode(packageName, Content.Empty, DocumentationNode.Kind.Package) + packageNode.appendChildren(declarations, DocumentationReference.Kind.Member) + documentationModule.append(packageNode, DocumentationReference.Kind.Member) } } - print("... resolving links ... ") + documentationBuilder.resolveReferences(documentationModule) documentationModule } @@ -76,7 +84,7 @@ public fun main(args: Array<String>) { val formatter = HtmlFormatService(locationService, signatureGenerator, templateService) val generator = FileGenerator(signatureGenerator, locationService, formatter) - print("Building pages... ") + print("Generating pages... ") generator.buildPage(documentation) generator.buildOutline(documentation) val timeBuild = System.currentTimeMillis() - startBuild diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt index fcff75e9..b885a15f 100644 --- a/test/src/TestAPI.kt +++ b/test/src/TestAPI.kt @@ -4,6 +4,7 @@ import org.jetbrains.jet.cli.common.messages.* import com.intellij.openapi.util.* import kotlin.test.fail import org.jetbrains.dokka.* +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> Unit) { val messageCollector = object : MessageCollector { @@ -30,10 +31,16 @@ public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> val options = DocumentationOptions(includeNonPublic = true) val documentation = environment.withContext { environment, module, context -> + val fragments = environment.getSourceFiles().map { context.getPackageFragment(it) }.filterNotNull().distinct() + val descriptors = hashMapOf<String, List<DeclarationDescriptor>>() + for ((name, parts) in fragments.groupBy { it.fqName }) { + descriptors.put(name.asString(), parts.flatMap { it.getMemberScope().getAllDescriptors() }) + } + val documentationModule = DocumentationModule("test") val documentationBuilder = DocumentationBuilder(context, options) with(documentationBuilder) { - documentationModule.appendFiles(environment.getSourceFiles()) + documentationModule.appendFragments(fragments) } documentationBuilder.resolveReferences(documentationModule) documentationModule |