From edb0d90fbc44f611d806a06a12f1d8280e274b8e Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 24 Feb 2017 10:51:22 +0100 Subject: Process all declarations with the same primary platform in a single pass; allow to provide default platforms based on declaration descriptor --- core/src/main/kotlin/Generation/DokkaGenerator.kt | 24 +++++++++++++----- .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 29 ++++++++++++---------- core/src/main/kotlin/Utilities/DokkaModules.kt | 5 ++-- 3 files changed, 36 insertions(+), 22 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index ed189b68..2c1cdb03 100644 --- a/core/src/main/kotlin/Generation/DokkaGenerator.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -16,13 +16,16 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.config.JVMConfigurationKeys +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer import org.jetbrains.kotlin.resolve.TopDownAnalysisMode import org.jetbrains.kotlin.utils.PathUtil import java.io.File import kotlin.system.measureTimeMillis -class SourceRoot(val path: String, val defaultPlatforms: List = emptyList()) +class SourceRoot(path: String, val defaultPlatforms: List = emptyList()) { + val path: String = File(path).absolutePath +} class DokkaGenerator(val logger: DokkaLogger, val classpath: List, @@ -35,9 +38,9 @@ class DokkaGenerator(val logger: DokkaLogger, private val documentationModule = DocumentationModule(moduleName) fun generate() { - val sourcesGroupedByPlatform = sources.groupBy { it.defaultPlatforms } - for ((platforms, roots) in sourcesGroupedByPlatform) { - appendSourceModule(platforms, roots.map { it.path }) + val sourcesGroupedByPlatform = sources.groupBy { it.defaultPlatforms[0] } + for ((platform, roots) in sourcesGroupedByPlatform) { + appendSourceModule(platform, roots.map { it.path }) } documentationModule.prepareForGeneration(options) @@ -49,7 +52,7 @@ class DokkaGenerator(val logger: DokkaLogger, logger.info("done in ${timeBuild / 1000} secs") } - private fun appendSourceModule(defaultPlatforms: List, sourcePaths: List) { + private fun appendSourceModule(defaultPlatform: String, sourcePaths: List) { val environment = createAnalysisEnvironment(sourcePaths) logger.info("Module: $moduleName") @@ -60,8 +63,17 @@ class DokkaGenerator(val logger: DokkaLogger, logger.info("Analysing sources and libraries... ") val startAnalyse = System.currentTimeMillis() + val defaultPlatformsProvider = object : DefaultPlatformsProvider { + override fun getDefaultPlatforms(descriptor: DeclarationDescriptor): List { + val containingFilePath = descriptor.sourcePsi()?.containingFile?.virtualFile?.canonicalPath + ?.let { File(it).absolutePath } + val sourceRoot = containingFilePath?.let { path -> sources.find { path.startsWith(it.path) } } + return sourceRoot?.defaultPlatforms ?: listOf(defaultPlatform) + } + } + val injector = Guice.createInjector( - DokkaAnalysisModule(environment, options, defaultPlatforms, documentationModule.nodeRefGraph, logger)) + DokkaAnalysisModule(environment, options, defaultPlatformsProvider, documentationModule.nodeRefGraph, logger)) buildDocumentationModule(injector, documentationModule, { isNotSample(it) }, includes) diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 70c3565f..10b5c598 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -4,7 +4,6 @@ import com.google.inject.Inject import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.PsiJavaFile import org.jetbrains.dokka.Kotlin.DescriptorDocumentationParser -import org.jetbrains.dokka.Utilities.defaultPlatformsName import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotated @@ -60,6 +59,10 @@ interface PackageDocumentationBuilder { allFqNames: Collection) } +interface DefaultPlatformsProvider { + fun getDefaultPlatforms(descriptor: DeclarationDescriptor): List +} + class DocumentationBuilder @Inject constructor(val resolutionFacade: DokkaResolutionFacade, val descriptorDocumentationParser: DescriptorDocumentationParser, @@ -68,7 +71,7 @@ class DocumentationBuilder val platformNodeRegistry: PlatformNodeRegistry, val logger: DokkaLogger, val linkResolver: DeclarationLinkResolver, - @GuiceNamed(defaultPlatformsName) val defaultPlatforms: List) { + val defaultPlatformsProvider: DefaultPlatformsProvider) { 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") @@ -241,8 +244,8 @@ class DocumentationBuilder } } - fun DocumentationNode.appenDefaultPlatforms() { - for (platform in defaultPlatforms) { + fun DocumentationNode.appendDefaultPlatforms(descriptor: DeclarationDescriptor) { + for (platform in defaultPlatformsProvider.getDefaultPlatforms(descriptor)) { append(platformNodeRegistry[platform], RefKind.Platform) } } @@ -273,7 +276,7 @@ class DocumentationBuilder val existingNode = refGraph.lookup(descriptor.signature()) if (existingNode != null) { - existingNode.updatePlatforms() + existingNode.updatePlatforms(descriptor) if (descriptor is ClassDescriptor) { val membersToDocument = descriptor.collectMembersToDocument() @@ -284,7 +287,7 @@ class DocumentationBuilder else { val existingMemberNode = refGraph.lookup(memberDescriptor.signature()) if (existingMemberNode != null) { - existingMemberNode.updatePlatforms() + existingMemberNode.updatePlatforms(memberDescriptor) } else { existingNode.appendClassMember(memberDescriptor, inheritedLinkKind, extraModifier) @@ -298,8 +301,8 @@ class DocumentationBuilder } } - private fun DocumentationNode.updatePlatforms() { - for (platform in defaultPlatforms - platforms) { + private fun DocumentationNode.updatePlatforms(descriptor: DeclarationDescriptor) { + for (platform in defaultPlatformsProvider.getDefaultPlatforms(descriptor) - platforms) { append(platformNodeRegistry[platform], RefKind.Platform) } } @@ -438,7 +441,7 @@ class DocumentationBuilder node.appendType(underlyingType, NodeKind.TypeAliasUnderlyingType) node.appendSourceLink(source) - node.appenDefaultPlatforms() + node.appendDefaultPlatforms(this) register(this, node) return node @@ -467,7 +470,7 @@ class DocumentationBuilder node.appendAnnotations(this) node.appendModifiers(this) node.appendSourceLink(source) - node.appenDefaultPlatforms() + node.appendDefaultPlatforms(this) register(this, node) return node } @@ -516,7 +519,7 @@ class DocumentationBuilder fun ConstructorDescriptor.build(): DocumentationNode { val node = nodeForDescriptor(this, NodeKind.Constructor) node.appendInPageChildren(valueParameters, RefKind.Detail) - node.appenDefaultPlatforms() + node.appendDefaultPlatforms(this) register(this, node) return node } @@ -545,7 +548,7 @@ class DocumentationBuilder node.appendModifiers(this) node.appendSourceLink(source) node.appendSignature(this) - node.appenDefaultPlatforms() + node.appendDefaultPlatforms(this) overriddenDescriptors.forEach { addOverrideLink(it, this) @@ -592,7 +595,7 @@ class DocumentationBuilder overriddenDescriptors.forEach { addOverrideLink(it, this) } - node.appenDefaultPlatforms() + node.appendDefaultPlatforms(this) register(this, node) return node diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt index 1f382f8c..5982d7dd 100644 --- a/core/src/main/kotlin/Utilities/DokkaModules.kt +++ b/core/src/main/kotlin/Utilities/DokkaModules.kt @@ -11,12 +11,11 @@ import org.jetbrains.dokka.Samples.SampleProcessingService import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import java.io.File -const val defaultPlatformsName = "defaultPlatforms" const val impliedPlatformsName = "impliedPlatforms" class DokkaAnalysisModule(val environment: AnalysisEnvironment, val options: DocumentationOptions, - val defaultPlatforms: List, + val defaultPlatformsProvider: DefaultPlatformsProvider, val nodeReferenceGraph: NodeReferenceGraph, val logger: DokkaLogger) : Module { override fun configure(binder: Binder) { @@ -36,7 +35,7 @@ class DokkaAnalysisModule(val environment: AnalysisEnvironment, binder.bind().toInstance(options) binder.bind().toInstance(logger) - binder.bind(StringListType).annotatedWith(Names.named(defaultPlatformsName)).toInstance(defaultPlatforms) + binder.bind().toInstance(defaultPlatformsProvider) binder.bind().toInstance(nodeReferenceGraph) } -- cgit