aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2017-02-24 10:51:22 +0100
committerDmitry Jemerov <yole@jetbrains.com>2017-02-24 10:51:22 +0100
commitedb0d90fbc44f611d806a06a12f1d8280e274b8e (patch)
tree774f67e64d09eb28203ab9d490c741ed221d51b6 /core
parent5da33851dfd3c7c88f939db2b02e979b0e977f87 (diff)
downloaddokka-edb0d90fbc44f611d806a06a12f1d8280e274b8e.tar.gz
dokka-edb0d90fbc44f611d806a06a12f1d8280e274b8e.tar.bz2
dokka-edb0d90fbc44f611d806a06a12f1d8280e274b8e.zip
Process all declarations with the same primary platform in a single pass; allow to provide default platforms based on declaration descriptor
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/Generation/DokkaGenerator.kt24
-rw-r--r--core/src/main/kotlin/Kotlin/DocumentationBuilder.kt29
-rw-r--r--core/src/main/kotlin/Utilities/DokkaModules.kt5
-rw-r--r--core/src/test/kotlin/TestAPI.kt6
4 files changed, 41 insertions, 23 deletions
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<String> = emptyList())
+class SourceRoot(path: String, val defaultPlatforms: List<String> = emptyList()) {
+ val path: String = File(path).absolutePath
+}
class DokkaGenerator(val logger: DokkaLogger,
val classpath: List<String>,
@@ -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<String>, sourcePaths: List<String>) {
+ private fun appendSourceModule(defaultPlatform: String, sourcePaths: List<String>) {
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<String> {
+ 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<FqName>)
}
+interface DefaultPlatformsProvider {
+ fun getDefaultPlatforms(descriptor: DeclarationDescriptor): List<String>
+}
+
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<String>) {
+ 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<String>,
+ 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<DocumentationOptions>().toInstance(options)
binder.bind<DokkaLogger>().toInstance(logger)
- binder.bind(StringListType).annotatedWith(Names.named(defaultPlatformsName)).toInstance(defaultPlatforms)
+ binder.bind<DefaultPlatformsProvider>().toInstance(defaultPlatformsProvider)
binder.bind<NodeReferenceGraph>().toInstance(nodeReferenceGraph)
}
diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt
index be484279..d2af4830 100644
--- a/core/src/test/kotlin/TestAPI.kt
+++ b/core/src/test/kotlin/TestAPI.kt
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot
import org.jetbrains.kotlin.config.ContentRoot
import org.jetbrains.kotlin.config.KotlinSourceRoot
+import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.junit.Assert
import org.junit.Assert.fail
import java.io.File
@@ -83,8 +84,11 @@ fun appendDocumentation(documentation: DocumentationModule,
}
addRoots(roots.toList())
}
+ val defaultPlatformsProvider = object : DefaultPlatformsProvider {
+ override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = defaultPlatforms
+ }
val injector = Guice.createInjector(
- DokkaAnalysisModule(environment, options, defaultPlatforms, documentation.nodeRefGraph, DokkaConsoleLogger))
+ DokkaAnalysisModule(environment, options, defaultPlatformsProvider, documentation.nodeRefGraph, DokkaConsoleLogger))
buildDocumentationModule(injector, documentation)
Disposer.dispose(environment)
}