From 54c3c87acfb31afc22afc5f20229384f755b677f Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 2 May 2017 15:08:52 +0300 Subject: Refactoring internal communication for gradle --- core/src/main/kotlin/DokkaBootstrapImpl.kt | 42 +++++--------------- core/src/main/kotlin/Generation/DokkaGenerator.kt | 5 +-- .../main/kotlin/Generation/configurationImpl.kt | 46 ++++++++++++++++++++++ .../src/main/kotlin/Kotlin/DocumentationBuilder.kt | 3 +- core/src/main/kotlin/Model/SourceLinks.kt | 2 +- 5 files changed, 59 insertions(+), 39 deletions(-) create mode 100644 core/src/main/kotlin/Generation/configurationImpl.kt (limited to 'core/src/main') diff --git a/core/src/main/kotlin/DokkaBootstrapImpl.kt b/core/src/main/kotlin/DokkaBootstrapImpl.kt index 8b10a5e8..fafa5daa 100644 --- a/core/src/main/kotlin/DokkaBootstrapImpl.kt +++ b/core/src/main/kotlin/DokkaBootstrapImpl.kt @@ -1,14 +1,8 @@ package org.jetbrains.dokka -import java.io.File +import ru.yole.jkid.deserialization.deserialize import java.util.function.BiConsumer -fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinition { - val (path, urlAndLine) = srcLink.split('=') - return SourceLinkDefinition(File(path).absolutePath, - urlAndLine.substringBefore("#"), - urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#" + it }) -} fun parsePerPackageOptions(arg: String): List { if (arg.isBlank()) return emptyList() @@ -25,14 +19,9 @@ fun parsePerPackageOptions(arg: String): List { } } -fun parseSourceRoot(sourceRoot: String): SourceRoot { - val components = sourceRoot.split("::", limit = 2) - return SourceRoot(components.last(), if (components.size == 1) listOf() else components[0].split(',')) -} - class DokkaBootstrapImpl : DokkaBootstrap { - class DokkaProxyLogger(val consumer: BiConsumer) : DokkaLogger { + private class DokkaProxyLogger(val consumer: BiConsumer) : DokkaLogger { override fun info(message: String) { consumer.accept("info", message) } @@ -48,26 +37,14 @@ class DokkaBootstrapImpl : DokkaBootstrap { lateinit var generator: DokkaGenerator - override fun configure(logger: BiConsumer, - moduleName: String, - classpath: List, - sources: List, - samples: List, - includes: List, - outputDir: String, - format: String, - includeNonPublic: Boolean, - includeRootPackage: Boolean, - reportUndocumented: Boolean, - skipEmptyPackages: Boolean, - skipDeprecated: Boolean, - jdkVersion: Int, - generateIndexPages: Boolean, - sourceLinks: List) { + override fun configure(logger: BiConsumer, serializedConfigurationJSON: String) + = configure(DokkaProxyLogger(logger), deserialize(serializedConfigurationJSON)) + + fun configure(logger: DokkaLogger, configuration: DokkaConfiguration) = with(configuration) { generator = DokkaGenerator( - DokkaProxyLogger(logger), + logger, classpath, - sources.map(::parseSourceRoot), + sourceRoots, samples, includes, moduleName, @@ -81,10 +58,9 @@ class DokkaBootstrapImpl : DokkaBootstrap { skipDeprecated, jdkVersion, generateIndexPages, - sourceLinks.map(::parseSourceLinkDefinition) + sourceLinks ) ) - } override fun generate() = generator.generate() diff --git a/core/src/main/kotlin/Generation/DokkaGenerator.kt b/core/src/main/kotlin/Generation/DokkaGenerator.kt index 6b5df7c9..67c641a0 100644 --- a/core/src/main/kotlin/Generation/DokkaGenerator.kt +++ b/core/src/main/kotlin/Generation/DokkaGenerator.kt @@ -7,6 +7,7 @@ import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiFile import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager +import org.jetbrains.dokka.DokkaConfiguration.SourceRoot import org.jetbrains.dokka.Utilities.DokkaAnalysisModule import org.jetbrains.dokka.Utilities.DokkaOutputModule import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation @@ -23,10 +24,6 @@ import org.jetbrains.kotlin.utils.PathUtil import java.io.File import kotlin.system.measureTimeMillis -class SourceRoot(path: String, val defaultPlatforms: List = emptyList()) { - val path: String = File(path).absolutePath -} - class DokkaGenerator(val logger: DokkaLogger, val classpath: List, val sources: List, diff --git a/core/src/main/kotlin/Generation/configurationImpl.kt b/core/src/main/kotlin/Generation/configurationImpl.kt new file mode 100644 index 00000000..6ed0d639 --- /dev/null +++ b/core/src/main/kotlin/Generation/configurationImpl.kt @@ -0,0 +1,46 @@ +package org.jetbrains.dokka + +import org.jetbrains.dokka.DokkaConfiguration.SourceLinkDefinition +import org.jetbrains.dokka.DokkaConfiguration.SourceRoot +import java.io.File + + +data class SourceLinkDefinitionImpl(override val path: String, + override val url: String, + override val lineSuffix: String?) : SourceLinkDefinition { + companion object { + fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinition { + val (path, urlAndLine) = srcLink.split('=') + return SourceLinkDefinitionImpl(File(path).absolutePath, + urlAndLine.substringBefore("#"), + urlAndLine.substringAfter("#", "").let { if (it.isEmpty()) null else "#" + it }) + } + } +} + +class SourceRootImpl(path: String, override val defaultPlatforms: List = emptyList()) : SourceRoot { + override val path: String = File(path).absolutePath + + companion object { + fun parseSourceRoot(sourceRoot: String): SourceRoot { + val components = sourceRoot.split("::", limit = 2) + return SourceRootImpl(components.last(), if (components.size == 1) listOf() else components[0].split(',')) + } + } +} + +data class DokkaConfigurationImpl(override val moduleName: String, + override val classpath: List, + override val sourceRoots: List, + override val samples: List, + override val includes: List, + override val outputDir: String, + override val format: String, + override val includeNonPublic: Boolean, + override val includeRootPackage: Boolean, + override val reportUndocumented: Boolean, + override val skipEmptyPackages: Boolean, + override val skipDeprecated: Boolean, + override val jdkVersion: Int, + override val generateIndexPages: Boolean, + override val sourceLinks: List) : DokkaConfiguration \ No newline at end of file diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index 7c4e4531..aa4eed24 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka import com.google.inject.Inject import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.PsiJavaFile +import org.jetbrains.dokka.DokkaConfiguration.SourceLinkDefinition import org.jetbrains.dokka.Kotlin.DescriptorDocumentationParser import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.* @@ -873,7 +874,7 @@ fun CallableMemberDescriptor.getExtensionClassDescriptor(): ClassifierDescriptor if (extensionReceiver != null) { val type = extensionReceiver.type val receiverClass = type.constructor.declarationDescriptor as? ClassDescriptor - if ((receiverClass as? ClassDescriptor)?.isCompanionObject ?: false) { + if (receiverClass?.isCompanionObject ?: false) { return receiverClass?.containingDeclaration as? ClassifierDescriptor } return receiverClass diff --git a/core/src/main/kotlin/Model/SourceLinks.kt b/core/src/main/kotlin/Model/SourceLinks.kt index 99bb8f60..2c75cfda 100644 --- a/core/src/main/kotlin/Model/SourceLinks.kt +++ b/core/src/main/kotlin/Model/SourceLinks.kt @@ -3,10 +3,10 @@ package org.jetbrains.dokka import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.psi.PsiNameIdentifierOwner +import org.jetbrains.dokka.DokkaConfiguration.SourceLinkDefinition import org.jetbrains.kotlin.psi.psiUtil.startOffset import java.io.File -class SourceLinkDefinition(val path: String, val url: String, val lineSuffix: String?) fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List) { val path = psi?.containingFile?.virtualFile?.path ?: return -- cgit