From c1abcaf32abd4e2d74b9246385b3541096cdb5b9 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Sat, 2 Dec 2017 04:29:07 +0300 Subject: Extract Analysis components out of FormatDescriptor Fight with statically injected HtmlTemplateService --- core/src/main/kotlin/Formats/AnalysisComponents.kt | 45 ++++++++++++++++++++++ core/src/main/kotlin/Formats/FormatDescriptor.kt | 25 ++++-------- .../Formats/KotlinWebsiteHtmlFormatService.kt | 14 ++++--- core/src/main/kotlin/Formats/StandardFormats.kt | 42 ++++++++++---------- core/src/main/kotlin/Utilities/DokkaModules.kt | 5 --- core/src/main/kotlin/javadoc/dokka-adapters.kt | 13 ++----- 6 files changed, 84 insertions(+), 60 deletions(-) create mode 100644 core/src/main/kotlin/Formats/AnalysisComponents.kt diff --git a/core/src/main/kotlin/Formats/AnalysisComponents.kt b/core/src/main/kotlin/Formats/AnalysisComponents.kt new file mode 100644 index 00000000..97e1311e --- /dev/null +++ b/core/src/main/kotlin/Formats/AnalysisComponents.kt @@ -0,0 +1,45 @@ +package org.jetbrains.dokka.Formats + +import com.google.inject.Binder +import org.jetbrains.dokka.* +import org.jetbrains.dokka.Kotlin.KotlinAsJavaDescriptorSignatureProvider +import org.jetbrains.dokka.Kotlin.KotlinDescriptorSignatureProvider +import org.jetbrains.dokka.Model.DescriptorSignatureProvider +import org.jetbrains.dokka.Samples.DefaultSampleProcessingService +import org.jetbrains.dokka.Samples.SampleProcessingService +import org.jetbrains.dokka.Utilities.bind +import org.jetbrains.dokka.Utilities.toType +import kotlin.reflect.KClass + + +interface FormatDescriptorAnalysisComponentProvider : FormatDescriptorAnalysisComponent { + + val packageDocumentationBuilderClass: KClass + val javaDocumentationBuilderClass: KClass + val sampleProcessingService: KClass + val descriptorSignatureProvider: KClass + + + override fun configureAnalysis(binder: Binder): Unit = with(binder) { + bind() toType descriptorSignatureProvider + bind() toType packageDocumentationBuilderClass + bind() toType javaDocumentationBuilderClass + bind() toType sampleProcessingService + } +} + + +object KotlinAsJava: FormatDescriptorAnalysisComponentProvider { + override val packageDocumentationBuilderClass = KotlinAsJavaDocumentationBuilder::class + override val javaDocumentationBuilderClass = JavaPsiDocumentationBuilder::class + override val sampleProcessingService = DefaultSampleProcessingService::class + override val descriptorSignatureProvider = KotlinAsJavaDescriptorSignatureProvider::class +} + + +object KotlinAsKotlin: FormatDescriptorAnalysisComponentProvider { + override val packageDocumentationBuilderClass = KotlinPackageDocumentationBuilder::class + override val javaDocumentationBuilderClass = KotlinJavaDocumentationBuilder::class + override val sampleProcessingService = DefaultSampleProcessingService::class + override val descriptorSignatureProvider = KotlinDescriptorSignatureProvider::class +} \ No newline at end of file diff --git a/core/src/main/kotlin/Formats/FormatDescriptor.kt b/core/src/main/kotlin/Formats/FormatDescriptor.kt index fc0c4417..d3861b82 100644 --- a/core/src/main/kotlin/Formats/FormatDescriptor.kt +++ b/core/src/main/kotlin/Formats/FormatDescriptor.kt @@ -9,33 +9,24 @@ import org.jetbrains.dokka.Utilities.toOptional import org.jetbrains.dokka.Utilities.toType import kotlin.reflect.KClass -interface FormatDescriptor { + +interface FormatDescriptorAnalysisComponent { fun configureAnalysis(binder: Binder) - fun configureOutput(binder: Binder) } -interface FormatDescriptorAnalysisComponentProvider : FormatDescriptor { - - val packageDocumentationBuilderClass: KClass - val javaDocumentationBuilderClass: KClass - val sampleProcessingService: KClass - val descriptorSignatureProvider: KClass +interface FormatDescriptorOutputComponent { + fun configureOutput(binder: Binder) +} +interface FormatDescriptor: FormatDescriptorAnalysisComponent, FormatDescriptorOutputComponent - override fun configureAnalysis(binder: Binder): Unit = with(binder) { - bind() toType descriptorSignatureProvider - bind() toType packageDocumentationBuilderClass - bind() toType javaDocumentationBuilderClass - bind() toType sampleProcessingService - } -} -abstract class FileGeneratorBasedFormatDescriptor : FormatDescriptor, FormatDescriptorAnalysisComponentProvider { +abstract class FileGeneratorBasedFormatDescriptor : FormatDescriptor { override fun configureOutput(binder: Binder): Unit = with(binder) { bind() toOptional (outlineServiceClass) bind() toOptional formatServiceClass - bind() toType generatorServiceClass + bind() toType generatorServiceClass //bind() toType generatorServiceClass bind() toOptional packageListServiceClass } diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt index 8fd53cdd..208756c8 100644 --- a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt +++ b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt @@ -7,7 +7,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty import java.nio.file.Path -private object EmptyHtmlTemplateService : HtmlTemplateService { +object EmptyHtmlTemplateService : HtmlTemplateService { override fun appendFooter(to: StringBuilder) {} override fun appendHeader(to: StringBuilder, title: String?, basePath: Path) {} @@ -20,8 +20,9 @@ open class KotlinWebsiteHtmlOutputBuilder( generator: NodeLocationAwareGenerator, languageService: LanguageService, extension: String, - impliedPlatforms: List -) : HtmlOutputBuilder(to, location, generator, languageService, extension, impliedPlatforms, EmptyHtmlTemplateService) { + impliedPlatforms: List, + templateService: HtmlTemplateService +) : HtmlOutputBuilder(to, location, generator, languageService, extension, impliedPlatforms, templateService) { private var needHardLineBreaks = false private var insideDiv = 0 @@ -173,12 +174,13 @@ open class KotlinWebsiteHtmlOutputBuilder( class KotlinWebsiteHtmlFormatService @Inject constructor( generator: NodeLocationAwareGenerator, signatureGenerator: LanguageService, - @Named(impliedPlatformsName) impliedPlatforms: List -) : HtmlFormatService(generator, signatureGenerator, EmptyHtmlTemplateService, impliedPlatforms) { + @Named(impliedPlatformsName) impliedPlatforms: List, + templateService: HtmlTemplateService +) : HtmlFormatService(generator, signatureGenerator, templateService, impliedPlatforms) { override fun enumerateSupportFiles(callback: (String, String) -> Unit) {} override fun createOutputBuilder(to: StringBuilder, location: Location) = - KotlinWebsiteHtmlOutputBuilder(to, location, generator, languageService, extension, impliedPlatforms) + KotlinWebsiteHtmlOutputBuilder(to, location, generator, languageService, extension, impliedPlatforms, templateService) } diff --git a/core/src/main/kotlin/Formats/StandardFormats.kt b/core/src/main/kotlin/Formats/StandardFormats.kt index 54544ebc..9de667ab 100644 --- a/core/src/main/kotlin/Formats/StandardFormats.kt +++ b/core/src/main/kotlin/Formats/StandardFormats.kt @@ -1,41 +1,34 @@ package org.jetbrains.dokka.Formats +import com.google.inject.Binder +import com.google.inject.Provider import org.jetbrains.dokka.* -import org.jetbrains.dokka.Kotlin.KotlinAsJavaDescriptorSignatureProvider -import org.jetbrains.dokka.Kotlin.KotlinDescriptorSignatureProvider -import org.jetbrains.dokka.Samples.DefaultSampleProcessingService import org.jetbrains.dokka.Samples.KotlinWebsiteSampleProcessingService -import org.jetbrains.dokka.Samples.SampleProcessingService +import org.jetbrains.dokka.Utilities.bind import kotlin.reflect.KClass -abstract class KotlinFormatDescriptorBase : FileGeneratorBasedFormatDescriptor() { - - override val packageDocumentationBuilderClass = KotlinPackageDocumentationBuilder::class - override val javaDocumentationBuilderClass = KotlinJavaDocumentationBuilder::class - +abstract class KotlinFormatDescriptorBase : FileGeneratorBasedFormatDescriptor(), FormatDescriptorAnalysisComponentProvider by KotlinAsKotlin { override val generatorServiceClass = FileGenerator::class override val outlineServiceClass: KClass? = null - override val sampleProcessingService: KClass = DefaultSampleProcessingService::class override val packageListServiceClass: KClass? = DefaultPackageListService::class - override val descriptorSignatureProvider = KotlinDescriptorSignatureProvider::class -} - -class HtmlFormatDescriptor : KotlinFormatDescriptorBase() { - override val formatServiceClass = HtmlFormatService::class - override val outlineServiceClass = HtmlFormatService::class } -class HtmlAsJavaFormatDescriptor : FileGeneratorBasedFormatDescriptor() { +abstract class HtmlFormatDescriptorBase : FileGeneratorBasedFormatDescriptor() { override val formatServiceClass = HtmlFormatService::class override val outlineServiceClass = HtmlFormatService::class override val generatorServiceClass = FileGenerator::class - override val packageDocumentationBuilderClass = KotlinAsJavaDocumentationBuilder::class - override val javaDocumentationBuilderClass = JavaPsiDocumentationBuilder::class - override val sampleProcessingService: KClass = DefaultSampleProcessingService::class - override val packageListServiceClass: KClass? = DefaultPackageListService::class - override val descriptorSignatureProvider = KotlinAsJavaDescriptorSignatureProvider::class + override val packageListServiceClass = DefaultPackageListService::class + + override fun configureOutput(binder: Binder): Unit = with(binder) { + super.configureOutput(binder) + bind().toProvider(Provider { HtmlTemplateService.default("style.css") }) + } } +class HtmlFormatDescriptor : HtmlFormatDescriptorBase(), FormatDescriptorAnalysisComponent by KotlinAsKotlin + +class HtmlAsJavaFormatDescriptor : HtmlFormatDescriptorBase(), FormatDescriptorAnalysisComponent by KotlinAsJava + class KotlinWebsiteFormatDescriptor : KotlinFormatDescriptorBase() { override val formatServiceClass = KotlinWebsiteFormatService::class override val outlineServiceClass = YamlOutlineService::class @@ -51,6 +44,11 @@ class KotlinWebsiteHtmlFormatDescriptor : KotlinFormatDescriptorBase() { override val formatServiceClass = KotlinWebsiteHtmlFormatService::class override val sampleProcessingService = KotlinWebsiteSampleProcessingService::class override val outlineServiceClass = YamlOutlineService::class + + override fun configureOutput(binder: Binder) = with(binder) { + super.configureOutput(binder) + bind().toInstance(EmptyHtmlTemplateService) + } } class JekyllFormatDescriptor : KotlinFormatDescriptorBase() { diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt index 9db08010..a2d720ef 100644 --- a/core/src/main/kotlin/Utilities/DokkaModules.kt +++ b/core/src/main/kotlin/Utilities/DokkaModules.kt @@ -49,11 +49,6 @@ class DokkaOutputModule(val options: DocumentationOptions, val logger: DokkaLogger) : Module { override fun configure(binder: Binder) { binder.bind(LanguageService::class.java).to(KotlinLanguageService::class.java) - - binder.bind(HtmlTemplateService::class.java).toProvider(object : Provider { - override fun get(): HtmlTemplateService = HtmlTemplateService.default("style.css") - }) - binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(options.outputDir)) // binder.bindNameAnnotated("singleFolder") diff --git a/core/src/main/kotlin/javadoc/dokka-adapters.kt b/core/src/main/kotlin/javadoc/dokka-adapters.kt index 84dff8f0..bed211f6 100644 --- a/core/src/main/kotlin/javadoc/dokka-adapters.kt +++ b/core/src/main/kotlin/javadoc/dokka-adapters.kt @@ -5,13 +5,10 @@ import com.google.inject.Inject import com.sun.tools.doclets.formats.html.HtmlDoclet import org.jetbrains.dokka.* import org.jetbrains.dokka.Formats.FormatDescriptor -import org.jetbrains.dokka.Formats.FormatDescriptorAnalysisComponentProvider -import org.jetbrains.dokka.Kotlin.KotlinAsJavaDescriptorSignatureProvider -import org.jetbrains.dokka.Model.DescriptorSignatureProvider -import org.jetbrains.dokka.Samples.DefaultSampleProcessingService +import org.jetbrains.dokka.Formats.FormatDescriptorAnalysisComponent +import org.jetbrains.dokka.Formats.KotlinAsJava import org.jetbrains.dokka.Utilities.bind import org.jetbrains.dokka.Utilities.toType -import kotlin.reflect.KClass class JavadocGenerator @Inject constructor(val options: DocumentationOptions, val logger: DokkaLogger) : Generator { @@ -34,11 +31,7 @@ class JavadocGenerator @Inject constructor(val options: DocumentationOptions, va } } -class JavadocFormatDescriptor : FormatDescriptor, FormatDescriptorAnalysisComponentProvider { - override val packageDocumentationBuilderClass = KotlinAsJavaDocumentationBuilder::class - override val javaDocumentationBuilderClass = JavaPsiDocumentationBuilder::class - override val sampleProcessingService = DefaultSampleProcessingService::class - override val descriptorSignatureProvider = KotlinAsJavaDescriptorSignatureProvider::class +class JavadocFormatDescriptor : FormatDescriptor, FormatDescriptorAnalysisComponent by KotlinAsJava { override fun configureOutput(binder: Binder): Unit = with(binder) { bind() toType JavadocGenerator::class -- cgit