diff options
-rw-r--r-- | src/Analysis/AnalysisEnvironment.kt | 6 | ||||
-rw-r--r-- | src/Analysis/CompilerAPI.kt | 3 | ||||
-rw-r--r-- | src/Model/DocumentationModule.kt | 14 | ||||
-rw-r--r-- | src/Model/DocumentationNodeBuilder.kt | 6 | ||||
-rw-r--r-- | src/main.kt | 11 | ||||
-rw-r--r-- | test/src/TestAPI.kt | 12 | ||||
-rw-r--r-- | test/src/model/PackageTest.kt | 17 |
7 files changed, 35 insertions, 34 deletions
diff --git a/src/Analysis/AnalysisEnvironment.kt b/src/Analysis/AnalysisEnvironment.kt index 20c1a764..d657ae4a 100644 --- a/src/Analysis/AnalysisEnvironment.kt +++ b/src/Analysis/AnalysisEnvironment.kt @@ -20,14 +20,14 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A body() } - private fun withContext<T>(processor: (JetCoreEnvironment, ModuleDescriptor, BindingContext) -> T): T { + public fun withContext<T>(processor: (JetCoreEnvironment, ModuleDescriptor, BindingContext) -> T): T { val environment = JetCoreEnvironment.createForProduction(this, configuration) val exhaust = environment.analyze(messageCollector) return processor(environment, exhaust.getModuleDescriptor(), exhaust.getBindingContext()) } - public fun withContext<T>(processor: (BindingContext) -> T): T { - return withContext { environment, module, context -> processor(context) } + public fun withContext<T>(processor: (ModuleDescriptor, BindingContext) -> T): T { + return withContext { environment, module, context -> processor(module, context) } } public fun streamFiles<T>(processor: (BindingContext, JetFile) -> T): Stream<T> { diff --git a/src/Analysis/CompilerAPI.kt b/src/Analysis/CompilerAPI.kt index bc0e6e93..b2b9a824 100644 --- a/src/Analysis/CompilerAPI.kt +++ b/src/Analysis/CompilerAPI.kt @@ -53,10 +53,11 @@ fun JetCoreEnvironment.analyze(messageCollector: MessageCollector): AnalyzeExhau fun AnalyzerWithCompilerReport.analyzeAndReport(files: List<JetFile>, analyser: () -> AnalyzeExhaust) = analyzeAndReport(analyser, files) -fun BindingContext.getPackageFragment(file: JetFile) = get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, file) +fun BindingContext.getPackageFragment(file: JetFile) : PackageFragmentDescriptor? = get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, file) fun DeclarationDescriptor.isUserCode() = when (this) { + is PackageViewDescriptor -> false is PackageFragmentDescriptor -> false is PropertyAccessorDescriptor -> !isDefault() is CallableMemberDescriptor -> getKind() == CallableMemberDescriptor.Kind.DECLARATION diff --git a/src/Model/DocumentationModule.kt b/src/Model/DocumentationModule.kt index 1f30268e..6b2773ed 100644 --- a/src/Model/DocumentationModule.kt +++ b/src/Model/DocumentationModule.kt @@ -1,8 +1,8 @@ package org.jetbrains.dokka import org.jetbrains.jet.lang.resolve.BindingContext -import org.jetbrains.jet.lang.psi.JetFile import org.jetbrains.jet.lang.descriptors.* +import org.jetbrains.jet.lang.resolve.name.FqName public class DocumentationModule(val module: ModuleDescriptor) : DocumentationNode(module, "module", DocumentationContent.Empty, DocumentationNode.Kind.Module) { fun merge(other: DocumentationModule): DocumentationModule { @@ -13,15 +13,13 @@ public class DocumentationModule(val module: ModuleDescriptor) : DocumentationNo } } -fun BindingContext.createDocumentationModule(module: ModuleDescriptor, file: JetFile): DocumentationModule { - val packageFragment = getPackageFragment(file) +fun BindingContext.createDocumentationModule(module: ModuleDescriptor, packages: Set<FqName>): DocumentationModule { val documentationModule = DocumentationModule(module) - if (packageFragment == null) throw IllegalArgumentException("File $file should have package fragment") - val visitor = DocumentationNodeBuilder(this) - packageFragment.accept(DocumentationBuildingVisitor(this, visitor), documentationModule) - + for (packageName in packages) { + val pkg = module.getPackage(packageName) + pkg!!.accept(DocumentationBuildingVisitor(this, visitor), documentationModule) + } checkResolveChildren(documentationModule) - return documentationModule } diff --git a/src/Model/DocumentationNodeBuilder.kt b/src/Model/DocumentationNodeBuilder.kt index f974ab11..8d75a45c 100644 --- a/src/Model/DocumentationNodeBuilder.kt +++ b/src/Model/DocumentationNodeBuilder.kt @@ -130,6 +130,12 @@ class DocumentationNodeBuilder(val context: BindingContext) : DeclarationDescrip return node } + override fun visitPackageViewDescriptor(descriptor: PackageViewDescriptor?, data: DocumentationNode?): DocumentationNode? { + val node = DocumentationNode(descriptor!!, descriptor.getFqName().asString(), DocumentationContent.Empty, DocumentationNode.Kind.Package) + reference(data!!, node, DocumentationReference.Kind.Member) + return node + } + override fun visitPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor?, data: DocumentationNode?): DocumentationNode? { val node = DocumentationNode(descriptor!!, descriptor.fqName.asString(), DocumentationContent.Empty, DocumentationNode.Kind.Package) reference(data!!, node, DocumentationReference.Kind.Member) diff --git a/src/main.kt b/src/main.kt index fbbb53d6..56717a80 100644 --- a/src/main.kt +++ b/src/main.kt @@ -35,10 +35,13 @@ public fun main(args: Array<String>) { println() - val documentation = environment.processFiles { context, module, file -> - println("Processing: ${file.getName()}") - context.createDocumentationModule(module, file) - }.reduce {(aggregate, item) -> aggregate.merge(item) } + val documentation = environment.withContext<DocumentationModule> { environment, module, context -> + val packageSet = environment.getSourceFiles().map { file -> + context.getPackageFragment(file)!!.fqName + }.toSet() + + context.createDocumentationModule(module, packageSet) + } val signatureGenerator = KotlinSignatureGenerator() val locationService = FoldersLocationService(arguments.outputDir ?: "out/doc/") diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt index 12c85c77..5ecdf1fb 100644 --- a/test/src/TestAPI.kt +++ b/test/src/TestAPI.kt @@ -27,10 +27,14 @@ public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> addSources(files.toList()) } - val result = environment.processFiles { context, module, file -> - context.createDocumentationModule(module, file) - }.reduce {(aggregate, item) -> aggregate.merge(item) } - verifier(result) + val documentation = environment.withContext<DocumentationModule> { environment, module, context -> + val packageSet = environment.getSourceFiles().map { file -> + context.getPackageFragment(file)!!.fqName + }.toSet() + + context.createDocumentationModule(module, packageSet) + } + verifier(documentation) Disposer.dispose(environment) } diff --git a/test/src/model/PackageTest.kt b/test/src/model/PackageTest.kt index aa4bd088..b855ad7d 100644 --- a/test/src/model/PackageTest.kt +++ b/test/src/model/PackageTest.kt @@ -47,7 +47,7 @@ public class PackageTest { Test fun multipleFiles() { verifyModel("test/data/packages/dottedNamePackage.kt", "test/data/packages/simpleNamePackage.kt") { model -> assertEquals(2, model.members.count()) - with(model.members.elementAt(0)) { + with(model.members.single { it.name == "simple" }) { assertEquals(DocumentationNode.Kind.Package, kind) assertEquals("simple", name) assertEquals(DocumentationContent.Empty, doc) @@ -55,9 +55,8 @@ public class PackageTest { assertTrue(members.none()) assertTrue(links.none()) } - with(model.members.elementAt(1)) { + with(model.members.single { it.name == "dot.name" }) { assertEquals(DocumentationNode.Kind.Package, kind) - assertEquals("dot.name", name) assertEquals(DocumentationContent.Empty, doc) assertTrue(details.none()) assertTrue(members.none()) @@ -68,7 +67,7 @@ public class PackageTest { Test fun multipleFilesSamePackage() { verifyModel("test/data/packages/simpleNamePackage.kt", "test/data/packages/simpleNamePackage2.kt") { model -> - assertEquals(2, model.members.count()) + assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(DocumentationNode.Kind.Package, kind) assertEquals("simple", name) @@ -77,16 +76,6 @@ public class PackageTest { assertTrue(members.none()) assertTrue(links.none()) } - // TODO: Looks like package fragments should be merged into package view in the model - // and here should be single member - with(model.members.elementAt(1)) { - assertEquals(DocumentationNode.Kind.Package, kind) - assertEquals("simple", name) - assertEquals(DocumentationContent.Empty, doc) - assertTrue(details.none()) - assertTrue(members.none()) - assertTrue(links.none()) - } } } }
\ No newline at end of file |