diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Formats/FormatDescriptor.kt | 15 | ||||
-rw-r--r-- | src/Formats/StandardFormats.kt | 69 | ||||
-rw-r--r-- | src/Java/JavaPsiDocumentationBuilder.kt | 21 | ||||
-rw-r--r-- | src/Kotlin/DeclarationLinkResolver.kt | 3 | ||||
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 46 | ||||
-rw-r--r-- | src/Model/DocumentationReference.kt | 3 | ||||
-rw-r--r-- | src/Model/PackageDocs.kt | 18 | ||||
-rw-r--r-- | src/Utilities/DokkaModule.kt (renamed from src/Utilities/GuiceModule.kt) | 36 | ||||
-rw-r--r-- | src/Utilities/ServiceLocator.kt | 27 | ||||
-rw-r--r-- | src/main.kt | 50 |
10 files changed, 137 insertions, 151 deletions
diff --git a/src/Formats/FormatDescriptor.kt b/src/Formats/FormatDescriptor.kt index cc12dfb9..0c7ca794 100644 --- a/src/Formats/FormatDescriptor.kt +++ b/src/Formats/FormatDescriptor.kt @@ -1,13 +1,12 @@ package org.jetbrains.dokka.Formats -import org.jetbrains.dokka.FormatService -import org.jetbrains.dokka.Generator -import org.jetbrains.dokka.OutlineFormatService -import org.jetbrains.dokka.PackageDocumentationBuilder +import org.jetbrains.dokka.* +import kotlin.reflect.KClass public interface FormatDescriptor { - val formatServiceClass: Class<out FormatService>? - val outlineServiceClass: Class<out OutlineFormatService>? - val generatorServiceClass: Class<out Generator> - val packageDocumentationBuilderServiceClass: Class<out PackageDocumentationBuilder>? + val formatServiceClass: KClass<out FormatService>? + val outlineServiceClass: KClass<out OutlineFormatService>? + val generatorServiceClass: KClass<out Generator> + val packageDocumentationBuilderClass: KClass<out PackageDocumentationBuilder> + val javaDocumentationBuilderClass: KClass<out JavaDocumentationBuilder> } diff --git a/src/Formats/StandardFormats.kt b/src/Formats/StandardFormats.kt index 12b5d85d..94e1b115 100644 --- a/src/Formats/StandardFormats.kt +++ b/src/Formats/StandardFormats.kt @@ -2,58 +2,37 @@ package org.jetbrains.dokka.Formats import org.jetbrains.dokka.* -class HtmlFormatDescriptor : FormatDescriptor { - override val formatServiceClass: Class<out FormatService> - get() = HtmlFormatService::class.java +abstract class KotlinFormatDescriptorBase : FormatDescriptor { + override val packageDocumentationBuilderClass = KotlinPackageDocumentationBuilder::class + override val javaDocumentationBuilderClass = KotlinJavaDocumentationBuilder::class - override val outlineServiceClass: Class<out OutlineFormatService> - get() = HtmlFormatService::class.java - - override val generatorServiceClass: Class<out Generator> - get() = FileGenerator::class.java - - override val packageDocumentationBuilderServiceClass: Class<out PackageDocumentationBuilder>? - get() = null + override val generatorServiceClass = FileGenerator::class } -class KotlinWebsiteFormatDescriptor : FormatDescriptor { - override val formatServiceClass: Class<out FormatService> - get() = KotlinWebsiteFormatService::class.java - - override val outlineServiceClass: Class<out OutlineFormatService> - get() = YamlOutlineService::class.java - - override val generatorServiceClass: Class<out Generator> - get() = FileGenerator::class.java - - override val packageDocumentationBuilderServiceClass: Class<out PackageDocumentationBuilder>? - get() = null +class HtmlFormatDescriptor : KotlinFormatDescriptorBase() { + override val formatServiceClass = HtmlFormatService::class + override val outlineServiceClass = HtmlFormatService::class } -class JekyllFormatDescriptor : FormatDescriptor { - override val formatServiceClass: Class<out FormatService> - get() = JekyllFormatService::class.java - - override val outlineServiceClass: Class<out OutlineFormatService>? - get() = null - - override val generatorServiceClass: Class<out Generator> - get() = FileGenerator::class.java - - override val packageDocumentationBuilderServiceClass: Class<out PackageDocumentationBuilder>? - get() = null +class HtmlAsJavaFormatDescriptor : FormatDescriptor { + 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 } -class MarkdownFormatDescriptor : FormatDescriptor { - override val formatServiceClass: Class<out FormatService> - get() = MarkdownFormatService::class.java - - override val outlineServiceClass: Class<out OutlineFormatService>? - get() = null +class KotlinWebsiteFormatDescriptor : KotlinFormatDescriptorBase() { + override val formatServiceClass = KotlinWebsiteFormatService::class + override val outlineServiceClass = YamlOutlineService::class +} - override val generatorServiceClass: Class<out Generator> - get() = FileGenerator::class.java +class JekyllFormatDescriptor : KotlinFormatDescriptorBase() { + override val formatServiceClass = JekyllFormatService::class + override val outlineServiceClass = null +} - override val packageDocumentationBuilderServiceClass: Class<out PackageDocumentationBuilder>? - get() = null +class MarkdownFormatDescriptor : KotlinFormatDescriptorBase() { + override val formatServiceClass = MarkdownFormatService::class + override val outlineServiceClass = null } diff --git a/src/Java/JavaPsiDocumentationBuilder.kt b/src/Java/JavaPsiDocumentationBuilder.kt index b1e3167d..44270bc7 100644 --- a/src/Java/JavaPsiDocumentationBuilder.kt +++ b/src/Java/JavaPsiDocumentationBuilder.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka +import com.google.inject.Inject import com.intellij.psi.* import org.jetbrains.dokka.DocumentationNode.Kind @@ -29,9 +30,23 @@ interface JavaDocumentationBuilder { fun appendFile(file: PsiJavaFile, module: DocumentationModule, packageContent: Map<String, Content>) } -class JavaPsiDocumentationBuilder(private val options: DocumentationOptions, - private val refGraph: NodeReferenceGraph, - private val docParser: JavaDocumentationParser = JavadocParser(refGraph)) : JavaDocumentationBuilder { +class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { + private val options: DocumentationOptions + private val refGraph: NodeReferenceGraph + private val docParser: JavaDocumentationParser + + @Inject constructor(options: DocumentationOptions, refGraph: NodeReferenceGraph) { + this.options = options + this.refGraph = refGraph + this.docParser = JavadocParser(refGraph) + } + + constructor(options: DocumentationOptions, refGraph: NodeReferenceGraph, docParser: JavaDocumentationParser) { + this.options = options + this.refGraph = refGraph + this.docParser = docParser + } + override fun appendFile(file: PsiJavaFile, module: DocumentationModule, packageContent: Map<String, Content>) { if (file.classes.all { skipElement(it) }) { return diff --git a/src/Kotlin/DeclarationLinkResolver.kt b/src/Kotlin/DeclarationLinkResolver.kt index cd536768..2569bc71 100644 --- a/src/Kotlin/DeclarationLinkResolver.kt +++ b/src/Kotlin/DeclarationLinkResolver.kt @@ -4,10 +4,9 @@ import com.google.inject.Inject import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink -import org.jetbrains.kotlin.idea.resolve.ResolutionFacade class DeclarationLinkResolver - @Inject constructor(val resolutionFacade: ResolutionFacade, + @Inject constructor(val resolutionFacade: DokkaResolutionFacade, val refGraph: NodeReferenceGraph, val logger: DokkaLogger) { fun resolveContentLink(fromDescriptor: DeclarationDescriptor, href: String): ContentBlock { diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 31c2d3e1..a68f6bb5 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka +import com.google.inject.Inject import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.PsiDocCommentOwner import com.intellij.psi.PsiJavaFile @@ -38,7 +39,9 @@ import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KtType import org.jetbrains.kotlin.types.TypeProjection -public data class DocumentationOptions(val includeNonPublic: Boolean = false, +public data class DocumentationOptions(val outputDir: String, + val outputFormat: String, + val includeNonPublic: Boolean = false, val reportUndocumented: Boolean = true, val skipEmptyPackages: Boolean = true, val skipDeprecated: Boolean = false, @@ -57,11 +60,13 @@ interface PackageDocumentationBuilder { declarations: List<DeclarationDescriptor>) } -class DocumentationBuilder(val resolutionFacade: DokkaResolutionFacade, - val linkResolver: DeclarationLinkResolver, - val options: DocumentationOptions, - val refGraph: NodeReferenceGraph, - val logger: DokkaLogger) : JavaDocumentationBuilder { +class DocumentationBuilder + @Inject constructor(val resolutionFacade: DokkaResolutionFacade, + val linkResolver: DeclarationLinkResolver, + val options: DocumentationOptions, + val refGraph: NodeReferenceGraph, + val logger: DokkaLogger) +{ val visibleToDocumentation = setOf(Visibilities.PROTECTED, Visibilities.PUBLIC) val boringBuiltinClasses = setOf( "kotlin.Unit", "kotlin.Byte", "kotlin.Short", "kotlin.Int", "kotlin.Long", "kotlin.Char", "kotlin.Boolean", @@ -328,7 +333,7 @@ class DocumentationBuilder(val resolutionFacade: DokkaResolutionFacade, return null } - private fun DeclarationDescriptor.isDocumented(): Boolean { + fun DeclarationDescriptor.isDocumented(): Boolean { return (options.includeNonPublic || this !is MemberDescriptor || this.visibility in visibleToDocumentation) && @@ -361,7 +366,7 @@ class DocumentationBuilder(val resolutionFacade: DokkaResolutionFacade, fun DocumentationModule.appendFragments(fragments: Collection<PackageFragmentDescriptor>, packageContent: Map<String, Content>, - packageDocumentationBuilder: PackageDocumentationBuilder = KotlinPackageDocumentationBuilder()) { + packageDocumentationBuilder: PackageDocumentationBuilder) { val allFqNames = fragments.map { it.fqName }.distinct() for (packageName in allFqNames) { @@ -614,14 +619,16 @@ class DocumentationBuilder(val resolutionFacade: DokkaResolutionFacade, DocumentationNode(valueString, Content.Empty, DocumentationNode.Kind.Value) } } +} - inner class KotlinPackageDocumentationBuilder : PackageDocumentationBuilder { - override fun buildPackageDocumentation(documentationBuilder: DocumentationBuilder, - packageName: FqName, - packageNode: DocumentationNode, - declarations: List<DeclarationDescriptor>) { - val externalClassNodes = hashMapOf<FqName, DocumentationNode>() - declarations.forEach { descriptor -> +class KotlinPackageDocumentationBuilder : PackageDocumentationBuilder { + override fun buildPackageDocumentation(documentationBuilder: DocumentationBuilder, + packageName: FqName, + packageNode: DocumentationNode, + declarations: List<DeclarationDescriptor>) { + val externalClassNodes = hashMapOf<FqName, DocumentationNode>() + declarations.forEach { descriptor -> + with(documentationBuilder) { if (descriptor.isDocumented()) { val parent = packageNode.getParentForPackageMember(descriptor, externalClassNodes) parent.appendChild(descriptor, DocumentationReference.Kind.Member) @@ -629,7 +636,12 @@ class DocumentationBuilder(val resolutionFacade: DokkaResolutionFacade, } } } +} +class KotlinJavaDocumentationBuilder + @Inject constructor(val documentationBuilder: DocumentationBuilder, + val logger: DokkaLogger) : JavaDocumentationBuilder +{ override fun appendFile(file: PsiJavaFile, module: DocumentationModule, packageContent: Map<String, Content>) { val packageNode = module.findOrCreatePackageNode(file.packageName, packageContent) @@ -642,7 +654,9 @@ class DocumentationBuilder(val resolutionFacade: DokkaResolutionFacade, logger.warn("Cannot find descriptor for Java class ${it.qualifiedName}") } else { - packageNode.appendChild(descriptor, DocumentationReference.Kind.Member) + with(documentationBuilder) { + packageNode.appendChild(descriptor, DocumentationReference.Kind.Member) + } } } } diff --git a/src/Model/DocumentationReference.kt b/src/Model/DocumentationReference.kt index 79cec2f3..898c92d7 100644 --- a/src/Model/DocumentationReference.kt +++ b/src/Model/DocumentationReference.kt @@ -1,5 +1,7 @@ package org.jetbrains.dokka +import com.google.inject.Singleton + public data class DocumentationReference(val from: DocumentationNode, val to: DocumentationNode, val kind: DocumentationReference.Kind) { public enum class Kind { Owner, @@ -30,6 +32,7 @@ class PendingDocumentationReference(val lazyNodeFrom: () -> DocumentationNode?, } } +@Singleton class NodeReferenceGraph() { private val nodeMap = hashMapOf<String, DocumentationNode>() val references = arrayListOf<PendingDocumentationReference>() diff --git a/src/Model/PackageDocs.kt b/src/Model/PackageDocs.kt index a1cfddf9..044c73d8 100644 --- a/src/Model/PackageDocs.kt +++ b/src/Model/PackageDocs.kt @@ -1,19 +1,23 @@ package org.jetbrains.dokka +import com.google.inject.Inject +import com.google.inject.Singleton import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.MarkdownTokenTypes -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor import java.io.File -public class PackageDocs(val linkResolver: DeclarationLinkResolver?, - val linkResolveContext: DeclarationDescriptor?, - val logger: DokkaLogger) { +@Singleton +public class PackageDocs + @Inject constructor(val linkResolver: DeclarationLinkResolver?, + val logger: DokkaLogger) +{ public val moduleContent: MutableContent = MutableContent() private val _packageContent: MutableMap<String, MutableContent> = hashMapOf() public val packageContent: Map<String, Content> get() = _packageContent - fun parse(fileName: String) { + fun parse(fileName: String, linkResolveContext: LazyPackageDescriptor?) { val file = File(fileName) if (file.exists()) { val text = file.readText() @@ -26,7 +30,7 @@ public class PackageDocs(val linkResolver: DeclarationLinkResolver?, targetContent = findTargetContent(headingText.trimStart()) } } else { - buildContentTo(it, targetContent, { resolveContentLink(it) }) + buildContentTo(it, targetContent, { resolveContentLink(it, linkResolveContext) }) } } } else { @@ -47,7 +51,7 @@ public class PackageDocs(val linkResolver: DeclarationLinkResolver?, private fun findOrCreatePackageContent(packageName: String) = _packageContent.getOrPut(packageName) { -> MutableContent() } - private fun resolveContentLink(href: String): ContentBlock { + private fun resolveContentLink(href: String, linkResolveContext: LazyPackageDescriptor?): ContentBlock { if (linkResolveContext != null && linkResolver != null) { return linkResolver.resolveContentLink(linkResolveContext, href) } diff --git a/src/Utilities/GuiceModule.kt b/src/Utilities/DokkaModule.kt index e852ae19..3b2d26f1 100644 --- a/src/Utilities/GuiceModule.kt +++ b/src/Utilities/DokkaModule.kt @@ -4,15 +4,16 @@ import com.google.inject.Binder import com.google.inject.Module import com.google.inject.Provider import com.google.inject.name.Names -import com.google.inject.util.Providers import org.jetbrains.dokka.* import org.jetbrains.dokka.Formats.FormatDescriptor +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import java.io.File -class GuiceModule(val config: DokkaGenerator) : Module { +class DokkaModule(val environment: AnalysisEnvironment, + val options: DocumentationOptions, + val logger: DokkaLogger) : Module { override fun configure(binder: Binder) { - binder.bind(DokkaGenerator::class.java).toInstance(config) - binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(config.outputDir)) + binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(options.outputDir)) binder.bindNameAnnotated<LocationService, SingleFolderLocationService>("singleFolder") binder.bindNameAnnotated<FileLocationService, SingleFolderLocationService>("singleFolder") @@ -33,23 +34,28 @@ class GuiceModule(val config: DokkaGenerator) : Module { binder.registerCategory<FormatService>("format") binder.registerCategory<Generator>("generator") - val descriptor = ServiceLocator.lookup<FormatDescriptor>("format", config.outputFormat, config) + val descriptor = ServiceLocator.lookup<FormatDescriptor>("format", options.outputFormat) descriptor.outlineServiceClass?.let { clazz -> - binder.bind(OutlineFormatService::class.java).to(clazz) + binder.bind(OutlineFormatService::class.java).to(clazz.java) } descriptor.formatServiceClass?.let { clazz -> - binder.bind(FormatService::class.java).to(clazz) - } - if (descriptor.packageDocumentationBuilderServiceClass != null) { - binder.bind(PackageDocumentationBuilder::class.java).to(descriptor.packageDocumentationBuilderServiceClass) - } else { - binder.bind(PackageDocumentationBuilder::class.java).toProvider(Providers.of(null)) + binder.bind(FormatService::class.java).to(clazz.java) } + binder.bind<PackageDocumentationBuilder>().to(descriptor.packageDocumentationBuilderClass.java) + binder.bind<JavaDocumentationBuilder>().to(descriptor.javaDocumentationBuilderClass.java) - binder.bind(Generator::class.java).to(descriptor.generatorServiceClass) - } + binder.bind<Generator>().to(descriptor.generatorServiceClass.java) + + val coreEnvironment = environment.createCoreEnvironment() + binder.bind<KotlinCoreEnvironment>().toInstance(coreEnvironment) + val dokkaResolutionFacade = environment.createResolutionFacade(coreEnvironment) + binder.bind<DokkaResolutionFacade>().toInstance(dokkaResolutionFacade) + + binder.bind<DocumentationOptions>().toInstance(options) + binder.bind<DokkaLogger>().toInstance(logger) + } } private inline fun <reified T: Any> Binder.registerCategory(category: String) { @@ -63,3 +69,5 @@ private inline fun <reified Base : Any, reified T : Base> Binder.bindNameAnnotat bind(Base::class.java).annotatedWith(Names.named(name)).to(T::class.java) } + +inline fun <reified T: Any> Binder.bind() = bind(T::class.java) diff --git a/src/Utilities/ServiceLocator.kt b/src/Utilities/ServiceLocator.kt index 57d2f47b..92aa9ba4 100644 --- a/src/Utilities/ServiceLocator.kt +++ b/src/Utilities/ServiceLocator.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka.Utilities -import org.jetbrains.dokka.DokkaGenerator import java.io.File import java.util.* import java.util.jar.JarFile @@ -11,12 +10,11 @@ data class ServiceDescriptor(val name: String, val category: String, val descrip class ServiceLookupException(message: String) : Exception(message) public object ServiceLocator { - public fun <T : Any> lookup(clazz: Class<T>, category: String, implementationName: String, conf: DokkaGenerator): T { + public fun <T : Any> lookup(clazz: Class<T>, category: String, implementationName: String): T { val descriptor = lookupDescriptor(category, implementationName) val loadedClass = javaClass.classLoader.loadClass(descriptor.className) val constructor = loadedClass.constructors - .filter { it.parameterTypes.isEmpty() || (it.parameterTypes.size == 1 && conf.javaClass.isInstance(it.parameterTypes[0])) } - .sortedByDescending { it.parameterTypes.size } + .filter { it.parameterTypes.isEmpty() } .firstOrNull() ?: throw ServiceLookupException("Class ${descriptor.className} has no corresponding constructor") val implementationRawType: Any = if (constructor.parameterTypes.isEmpty()) constructor.newInstance() else constructor.newInstance(constructor) @@ -29,19 +27,6 @@ public object ServiceLocator { return implementationRawType as T } - public fun <T> lookupClass(clazz: Class<T>, category: String, implementationName: String): Class<T> = lookupDescriptor(category, implementationName).className.let { className -> - javaClass.classLoader.loadClass(className).let { loaded -> - if (!clazz.isAssignableFrom(loaded)) { - throw ServiceLookupException("Class $className is not a subtype of ${clazz.name}") - } - - @Suppress("UNCHECKED_CAST") - val casted = loaded as Class<T> - - casted - } - } - private fun lookupDescriptor(category: String, implementationName: String): ServiceDescriptor { val properties = javaClass.classLoader.getResourceAsStream("dokka/$category/$implementationName.properties")?.use { stream -> Properties().let { properties -> @@ -81,13 +66,7 @@ public object ServiceLocator { } ?: emptyList() } -public inline fun <reified T : Any> ServiceLocator.lookup(category: String, implementationName: String, conf: DokkaGenerator): T = lookup(T::class.java, category, implementationName, conf) -public inline fun <reified T : Any> ServiceLocator.lookupClass(category: String, implementationName: String): Class<T> = lookupClass(T::class.java, category, implementationName) -public inline fun <reified T : Any> ServiceLocator.lookupOrNull(category: String, implementationName: String, conf: DokkaGenerator): T? = try { - lookup(T::class.java, category, implementationName, conf) -} catch (any: Throwable) { - null -} +public inline fun <reified T : Any> ServiceLocator.lookup(category: String, implementationName: String): T = lookup(T::class.java, category, implementationName) private val ZipEntry.fileName: String get() = name.substringAfterLast("/", name) diff --git a/src/main.kt b/src/main.kt index 633e4659..ef694981 100644 --- a/src/main.kt +++ b/src/main.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka import com.google.inject.Guice +import com.google.inject.Injector import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiFile @@ -8,7 +9,7 @@ import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager import com.sampullara.cli.Args import com.sampullara.cli.Argument -import org.jetbrains.dokka.Utilities.GuiceModule +import org.jetbrains.dokka.Utilities.DokkaModule import org.jetbrains.kotlin.cli.common.arguments.ValueDescription import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity @@ -154,22 +155,18 @@ class DokkaGenerator(val logger: DokkaLogger, logger.info("Analysing sources and libraries... ") val startAnalyse = System.currentTimeMillis() - val options = DocumentationOptions(false, sourceLinks = sourceLinks, skipDeprecated = skipDeprecated) + val options = DocumentationOptions(outputDir, outputFormat, false, sourceLinks = sourceLinks, skipDeprecated = skipDeprecated) - val injector = Guice.createInjector(GuiceModule(this)) - val generator = injector.getInstance(Generator::class.java) + val injector = Guice.createInjector(DokkaModule(environment, options, logger)) - val packageDocumentationBuilder = injector.getInstance(PackageDocumentationBuilder::class.java) - - val documentation = buildDocumentationModule(environment, moduleName, options, includes, { isSample(it) }, - packageDocumentationBuilder, null, logger) + val documentation = buildDocumentationModule(injector, moduleName, { isSample(it) }, includes) val timeAnalyse = System.currentTimeMillis() - startAnalyse logger.info("done in ${timeAnalyse / 1000} secs") val timeBuild = measureTimeMillis { logger.info("Generating pages... ") - generator.buildAll(documentation) + injector.getInstance(Generator::class.java).buildAll(documentation) } logger.info("done in ${timeBuild / 1000} secs") @@ -203,19 +200,15 @@ class DokkaGenerator(val logger: DokkaLogger, } } -fun buildDocumentationModule(environment: AnalysisEnvironment, +fun buildDocumentationModule(injector: Injector, moduleName: String, - options: DocumentationOptions, - includes: List<String> = listOf(), filesToDocumentFilter: (PsiFile) -> Boolean = { file -> true }, - packageDocumentationBuilder: PackageDocumentationBuilder? = null, - javaDocumentationBuilder: JavaDocumentationBuilder? = null, - logger: DokkaLogger): DocumentationModule { - - val coreEnvironment = environment.createCoreEnvironment() - val resolutionFacade = environment.createResolutionFacade(coreEnvironment) + includes: List<String> = listOf()): DocumentationModule { + val coreEnvironment = injector.getInstance(KotlinCoreEnvironment::class.java) val fragmentFiles = coreEnvironment.getSourceFiles().filter(filesToDocumentFilter) + + val resolutionFacade = injector.getInstance(DokkaResolutionFacade::class.java) val analyzer = resolutionFacade.getFrontendService(LazyTopDownAnalyzerForTopLevel::class.java) analyzer.analyzeDeclarations(TopDownAnalysisMode.TopLevelDeclarations, fragmentFiles) @@ -224,30 +217,23 @@ fun buildDocumentationModule(environment: AnalysisEnvironment, .filterNotNull() .distinct() - val refGraph = NodeReferenceGraph() - val linkResolver = DeclarationLinkResolver(resolutionFacade, refGraph, logger) - val documentationBuilder = DocumentationBuilder(resolutionFacade, linkResolver, options, refGraph, logger) - val packageDocs = PackageDocs(linkResolver, fragments.firstOrNull(), logger) + val packageDocs = injector.getInstance(PackageDocs::class.java) for (include in includes) { - packageDocs.parse(include) + packageDocs.parse(include, fragments.firstOrNull()) } val documentationModule = DocumentationModule(moduleName, packageDocs.moduleContent) - with(documentationBuilder) { - if (packageDocumentationBuilder != null) { - documentationModule.appendFragments(fragments, packageDocs.packageContent, packageDocumentationBuilder) - } - else { - documentationModule.appendFragments(fragments, packageDocs.packageContent) - } + with(injector.getInstance(DocumentationBuilder::class.java)) { + documentationModule.appendFragments(fragments, packageDocs.packageContent, + injector.getInstance(PackageDocumentationBuilder::class.java)) } val javaFiles = coreEnvironment.getJavaSourceFiles().filter(filesToDocumentFilter) - with(javaDocumentationBuilder ?: documentationBuilder) { + with(injector.getInstance(JavaDocumentationBuilder::class.java)) { javaFiles.map { appendFile(it, documentationModule, packageDocs.packageContent) } } - refGraph.resolveReferences() + injector.getInstance(NodeReferenceGraph::class.java).resolveReferences() return documentationModule } |