diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/DokkaBootstrapImpl.kt | 7 | ||||
-rw-r--r-- | core/src/main/kotlin/Generation/DokkaGenerator.kt | 21 | ||||
-rw-r--r-- | core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 17 | ||||
-rw-r--r-- | core/src/main/kotlin/Utilities/DokkaModules.kt | 6 | ||||
-rw-r--r-- | core/src/test/kotlin/TestAPI.kt | 35 | ||||
-rw-r--r-- | core/src/test/kotlin/format/MarkdownFormatTest.kt | 15 |
6 files changed, 76 insertions, 25 deletions
diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index eb2b2a65..59139263 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -10,6 +10,11 @@ fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinition { urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#" + it }) } +fun parseSourceRoot(sourceRoot: String): SourceRoot { + val components = sourceRoot.split("::", limit = 2) + return SourceRoot(components.first(), components.getOrNull(1)?.split(',').orEmpty()) +} + class DokkaBootstrapImpl : DokkaBootstrap { class DokkaProxyLogger(val consumer: BiConsumer<String, String>) : DokkaLogger { @@ -46,7 +51,7 @@ class DokkaBootstrapImpl : DokkaBootstrap { generator = DokkaGenerator( DokkaProxyLogger(logger), classpath, - sources, + sources.map(::parseSourceRoot), samples, includes, moduleName, diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index aaf0deff..95066eec 100644 --- a/core/src/main/kotlin/Generation/DokkaGenerator.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -22,9 +22,11 @@ import org.jetbrains.kotlin.utils.PathUtil import java.io.File import kotlin.system.measureTimeMillis +class SourceRoot(val path: String, val implicitPlatforms: List<String> = emptyList()) + class DokkaGenerator(val logger: DokkaLogger, val classpath: List<String>, - val sources: List<String>, + val sources: List<SourceRoot>, val samples: List<String>, val includes: List<String>, val moduleName: String, @@ -33,7 +35,10 @@ class DokkaGenerator(val logger: DokkaLogger, private val documentationModule = DocumentationModule(moduleName) fun generate() { - appendSourceModule() + val sourcesGroupedByPlatform = sources.groupBy { it.implicitPlatforms } + for ((platforms, roots) in sourcesGroupedByPlatform) { + appendSourceModule(platforms, roots.map { it.path }) + } val timeBuild = measureTimeMillis { logger.info("Generating pages... ") @@ -43,18 +48,18 @@ class DokkaGenerator(val logger: DokkaLogger, logger.info("done in ${timeBuild / 1000} secs") } - private fun appendSourceModule() { - val environment = createAnalysisEnvironment() + private fun appendSourceModule(implicitPlatforms: List<String>, sourcePaths: List<String>) { + val environment = createAnalysisEnvironment(sourcePaths) logger.info("Module: $moduleName") logger.info("Output: ${File(options.outputDir)}") - logger.info("Sources: ${environment.sources.joinToString()}") + logger.info("Sources: ${sourcePaths.joinToString()}") logger.info("Classpath: ${environment.classpath.joinToString()}") logger.info("Analysing sources and libraries... ") val startAnalyse = System.currentTimeMillis() - val injector = Guice.createInjector(DokkaAnalysisModule(environment, options, logger)) + val injector = Guice.createInjector(DokkaAnalysisModule(environment, options, implicitPlatforms, logger)) buildDocumentationModule(injector, documentationModule, { isSample(it) }, includes) @@ -64,7 +69,7 @@ class DokkaGenerator(val logger: DokkaLogger, Disposer.dispose(environment) } - fun createAnalysisEnvironment(): AnalysisEnvironment { + fun createAnalysisEnvironment(sourcePaths: List<String>): AnalysisEnvironment { val environment = AnalysisEnvironment(DokkaMessageCollector(logger)) environment.apply { @@ -74,7 +79,7 @@ class DokkaGenerator(val logger: DokkaLogger, addClasspath(File(element)) } - addSources(this@DokkaGenerator.sources) + addSources(sourcePaths) addSources(this@DokkaGenerator.samples) } diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index bcbdf5f4..e165a2b5 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf import org.jetbrains.kotlin.types.typeUtil.supertypes +import com.google.inject.name.Named as GuiceNamed data class DocumentationOptions(val outputDir: String, val outputFormat: String, @@ -57,6 +58,8 @@ interface PackageDocumentationBuilder { allFqNames: Collection<FqName>) } +const val implicitPlatformName = "implicitPlatform" + class DocumentationBuilder @Inject constructor(val resolutionFacade: DokkaResolutionFacade, val descriptorDocumentationParser: DescriptorDocumentationParser, @@ -64,7 +67,8 @@ class DocumentationBuilder val refGraph: NodeReferenceGraph, val platformNodeRegistry: PlatformNodeRegistry, val logger: DokkaLogger, - val linkResolver: DeclarationLinkResolver) { + val linkResolver: DeclarationLinkResolver, + @GuiceNamed(implicitPlatformName) val implicitPlatforms: List<String>) { val boringBuiltinClasses = setOf( "kotlin.Unit", "kotlin.Byte", "kotlin.Short", "kotlin.Int", "kotlin.Long", "kotlin.Char", "kotlin.Boolean", "kotlin.Float", "kotlin.Double", "kotlin.String", "kotlin.Array", "kotlin.Any") @@ -237,6 +241,12 @@ class DocumentationBuilder } } + fun DocumentationNode.appendImplicitPlatforms() { + for (platform in implicitPlatforms) { + append(platformNodeRegistry[platform], RefKind.Platform) + } + } + fun DocumentationNode.isDeprecation() = name == "Deprecated" || name == "deprecated" fun DocumentationNode.isSinceKotlin() = name == "SinceKotlin" && kind == NodeKind.Annotation @@ -412,6 +422,7 @@ class DocumentationBuilder node.appendType(underlyingType, NodeKind.TypeAliasUnderlyingType) node.appendSourceLink(source) + node.appendImplicitPlatforms() register(this, node) return node @@ -453,6 +464,7 @@ class DocumentationBuilder node.appendAnnotations(this) node.appendModifiers(this) node.appendSourceLink(source) + node.appendImplicitPlatforms() register(this, node) return node } @@ -469,6 +481,7 @@ class DocumentationBuilder fun ConstructorDescriptor.build(): DocumentationNode { val node = nodeForDescriptor(this, NodeKind.Constructor) node.appendInPageChildren(valueParameters, RefKind.Detail) + node.appendImplicitPlatforms() register(this, node) return node } @@ -497,6 +510,7 @@ class DocumentationBuilder node.appendModifiers(this) node.appendSourceLink(source) node.appendSignature(this) + node.appendImplicitPlatforms() overriddenDescriptors.forEach { addOverrideLink(it, this) @@ -543,6 +557,7 @@ class DocumentationBuilder overriddenDescriptors.forEach { addOverrideLink(it, this) } + node.appendImplicitPlatforms() register(this, node) return node diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt index 69facaa0..3352a846 100644 --- a/core/src/main/kotlin/Utilities/DokkaModules.kt +++ b/core/src/main/kotlin/Utilities/DokkaModules.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.Utilities import com.google.inject.Binder import com.google.inject.Module import com.google.inject.Provider +import com.google.inject.TypeLiteral import com.google.inject.name.Names import org.jetbrains.dokka.* import org.jetbrains.dokka.Formats.FormatDescriptor @@ -12,6 +13,7 @@ import java.io.File class DokkaAnalysisModule(val environment: AnalysisEnvironment, val options: DocumentationOptions, + val implicitPlatforms: List<String>, val logger: DokkaLogger) : Module { override fun configure(binder: Binder) { val descriptor = ServiceLocator.lookup<FormatDescriptor>("format", options.outputFormat) @@ -29,9 +31,13 @@ class DokkaAnalysisModule(val environment: AnalysisEnvironment, binder.bind<DocumentationOptions>().toInstance(options) binder.bind<DokkaLogger>().toInstance(logger) + + binder.bind(StringListType).annotatedWith(Names.named(implicitPlatformName)).toInstance(implicitPlatforms) } } +object StringListType : TypeLiteral<@JvmSuppressWildcards List<String>>() + class DokkaOutputModule(val options: DocumentationOptions, val logger: DokkaLogger) : Module { override fun configure(binder: Binder) { diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index 61eab562..b3085008 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -22,6 +22,22 @@ fun verifyModel(vararg roots: ContentRoot, format: String = "html", includeNonPublic: Boolean = true, verifier: (DocumentationModule) -> Unit) { + val documentation = DocumentationModule("test") + appendDocumentation(documentation, *roots, + withJdk = withJdk, + withKotlinRuntime = withKotlinRuntime, + format = format, + includeNonPublic = includeNonPublic) + verifier(documentation) +} + +fun appendDocumentation(documentation: DocumentationModule, + vararg roots: ContentRoot, + withJdk: Boolean = false, + withKotlinRuntime: Boolean = false, + format: String = "html", + includeNonPublic: Boolean = true, + implicitPlatforms: List<String> = emptyList()) { val messageCollector = object : MessageCollector { override fun clear() { @@ -65,10 +81,8 @@ fun verifyModel(vararg roots: ContentRoot, skipEmptyPackages = false, sourceLinks = listOf<SourceLinkDefinition>(), generateIndexPages = false) - val injector = Guice.createInjector(DokkaAnalysisModule(environment, options, DokkaConsoleLogger)) - val documentation = DocumentationModule("test") + val injector = Guice.createInjector(DokkaAnalysisModule(environment, options, implicitPlatforms, DokkaConsoleLogger)) buildDocumentationModule(injector, documentation) - verifier(documentation) Disposer.dispose(environment) } @@ -129,19 +143,18 @@ fun verifyOutput(roots: Array<ContentRoot>, format: String = "html", outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { verifyModel(*roots, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, format = format) { - verifyModelOutput(it, outputExtension, outputGenerator, roots.first().path) + verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator) } } -private fun verifyModelOutput(it: DocumentationModule, - outputExtension: String, - outputGenerator: (DocumentationModule, StringBuilder) -> Unit, - sourcePath: String) { +fun verifyModelOutput(it: DocumentationModule, + outputExtension: String, + sourcePath: String, + outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { val output = StringBuilder() outputGenerator(it, output) val ext = outputExtension.removePrefix(".") - val path = sourcePath - val expectedFileContent = File(path.replaceAfterLast(".", ext, path + "." + ext)).readText() + val expectedFileContent = File(sourcePath.replaceAfterLast(".", ext, sourcePath + "." + ext)).readText() val expectedOutput = if (ext.equals("html", true)) expectedFileContent.lines().joinToString(separator = "\n", transform = String::trim) @@ -164,7 +177,7 @@ fun verifyJavaOutput(path: String, withKotlinRuntime: Boolean = false, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { verifyJavaModel(path, withKotlinRuntime) { model -> - verifyModelOutput(model, outputExtension, outputGenerator, path) + verifyModelOutput(model, outputExtension, path, outputGenerator) } } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 4dd01a20..967bc5e4 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -1,9 +1,6 @@ package org.jetbrains.dokka.tests -import org.jetbrains.dokka.DocumentationModule -import org.jetbrains.dokka.DocumentationNode -import org.jetbrains.dokka.KotlinLanguageService -import org.jetbrains.dokka.MarkdownFormatService +import org.jetbrains.dokka.* import org.junit.Test class MarkdownFormatTest { @@ -245,6 +242,16 @@ class MarkdownFormatTest { verifyMarkdownPackage("sinceKotlin") } + @Test fun multiplePlatforms() { + val module = DocumentationModule("test") + val sourcePath = "testdata/format/multiplatform/foo.kt" + appendDocumentation(module, contentRootFromPath(sourcePath), implicitPlatforms = listOf("JVM")) + appendDocumentation(module, contentRootFromPath("testdata/format/multiplatform/bar.kt"), implicitPlatforms = listOf("JS")) + verifyModelOutput(module, ".package.md", sourcePath) { model, output -> + markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + } + } + private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) { verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output -> markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) |