aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/build.gradle.kts7
-rw-r--r--core/dependencies/build.gradle.kts40
-rw-r--r--core/src/main/kotlin/DokkaGenerator.kt83
-rw-r--r--core/src/main/kotlin/links/DRI.kt132
-rw-r--r--core/src/main/kotlin/model/Documentable.kt12
-rw-r--r--core/src/main/kotlin/model/properties/PropertyContainer.kt4
-rw-r--r--core/src/main/kotlin/plugability/DokkaContext.kt7
-rw-r--r--core/src/main/kotlin/plugability/DokkaPlugin.kt6
-rw-r--r--core/src/main/kotlin/utilities/cast.kt5
-rw-r--r--integration-tests/gradle-integration-tests/build.gradle.kts2
-rw-r--r--kotlin-analysis/build.gradle.kts27
-rw-r--r--kotlin-analysis/dependencies/build.gradle.kts (renamed from coreDependencies/build.gradle.kts)28
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt (renamed from core/src/main/kotlin/analysis/AnalysisEnvironment.kt)21
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CallableFactory.kt31
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CoreKotlinCacheService.kt (renamed from core/src/main/kotlin/analysis/CoreKotlinCacheService.kt)2
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CoreProjectFileIndex.kt (renamed from core/src/main/kotlin/analysis/CoreProjectFileIndex.kt)54
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRIFactory.kt38
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRITargetFactory.kt44
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/Documentable.kt14
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/EnvironmentAndFacade.kt59
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/JavaResolveExtension.kt (renamed from core/src/main/kotlin/analysis/JavaResolveExtension.kt)0
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/KotlinAnalysis.kt46
-rw-r--r--kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/TypeReferenceFactory.kt51
-rw-r--r--plugins/base/build.gradle.kts1
-rw-r--r--plugins/base/src/main/kotlin/DokkaBase.kt21
-rw-r--r--plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt2
-rw-r--r--plugins/base/src/main/kotlin/parsers/HtmlParser.kt (renamed from core/src/main/kotlin/parsers/HtmlParser.kt)4
-rw-r--r--plugins/base/src/main/kotlin/parsers/MarkdownParser.kt (renamed from core/src/main/kotlin/parsers/MarkdownParser.kt)5
-rw-r--r--plugins/base/src/main/kotlin/parsers/Parser.kt (renamed from core/src/main/kotlin/parsers/Parser.kt)2
-rw-r--r--plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt (renamed from core/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt)2
-rw-r--r--plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt (renamed from core/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt)2
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt20
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/ReportUndocumentedTransformer.kt1
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt41
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt4
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt13
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt23
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt1
-rw-r--r--plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt6
-rw-r--r--plugins/build.gradle.kts3
-rw-r--r--plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt3
-rw-r--r--plugins/javadoc/src/test/kotlin/javadoc/JavadocTest.kt2
-rw-r--r--runners/cli/build.gradle.kts1
-rw-r--r--runners/cli/src/main/kotlin/cli/main.kt2
-rw-r--r--runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt6
-rw-r--r--settings.gradle.kts6
-rw-r--r--test-tools/build.gradle.kts1
-rw-r--r--testApi/build.gradle.kts2
-rw-r--r--testApi/src/main/kotlin/testApi/context/MockContext.kt4
-rw-r--r--testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt11
-rw-r--r--testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt3
51 files changed, 527 insertions, 378 deletions
diff --git a/core/build.gradle.kts b/core/build.gradle.kts
index 1d61e410..fc62b73d 100644
--- a/core/build.gradle.kts
+++ b/core/build.gradle.kts
@@ -6,12 +6,9 @@ plugins {
}
dependencies {
- api(project(":coreDependencies", configuration = "shadow"))
+ api(project("dependencies", configuration = "shadow"))
- val kotlin_version: String by project
- api("org.jetbrains.kotlin:kotlin-compiler:$kotlin_version")
- implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
- implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version")
+ implementation(kotlin("reflect"))
implementation("com.google.code.gson:gson:2.8.5")
implementation("org.jsoup:jsoup:1.12.1")
diff --git a/core/dependencies/build.gradle.kts b/core/dependencies/build.gradle.kts
new file mode 100644
index 00000000..a26d109e
--- /dev/null
+++ b/core/dependencies/build.gradle.kts
@@ -0,0 +1,40 @@
+import org.jetbrains.configureBintrayPublication
+
+plugins {
+ id("com.github.johnrengelman.shadow")
+ `maven-publish`
+ id("com.jfrog.bintray")
+}
+
+repositories {
+ maven(url = "https://kotlin.bintray.com/kotlin-plugin")
+}
+
+dependencies {
+ // TODO (see https://github.com/Kotlin/dokka/issues/1009)
+ implementation(kotlin("stdlib"))
+ implementation(kotlin("reflect"))
+
+ implementation("org.jetbrains:markdown:0.1.41") {
+ because("it's published only on bintray")
+ }
+}
+
+tasks {
+ shadowJar {
+ val dokka_version: String by project
+ archiveFileName.set("dokka-dependencies-$dokka_version.jar")
+ archiveClassifier.set("")
+ }
+}
+
+publishing {
+ publications {
+ register<MavenPublication>("dokkaCoreDependencies") {
+ artifactId = "dokka-core-dependencies"
+ project.shadow.component(this)
+ }
+ }
+}
+
+configureBintrayPublication("dokkaCoreDependencies")
diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt
index b2e572d4..b88c6223 100644
--- a/core/src/main/kotlin/DokkaGenerator.kt
+++ b/core/src/main/kotlin/DokkaGenerator.kt
@@ -1,7 +1,5 @@
package org.jetbrains.dokka
-import org.jetbrains.dokka.analysis.AnalysisEnvironment
-import org.jetbrains.dokka.analysis.DokkaResolutionFacade
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.model.SourceSetCache
import org.jetbrains.dokka.model.SourceSetData
@@ -9,13 +7,7 @@ import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.utilities.DokkaLogger
-import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
-import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
-import org.jetbrains.kotlin.cli.common.messages.MessageCollector
-import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
-import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
-import org.jetbrains.kotlin.utils.PathUtil
-import java.io.File
+
/**
* DokkaGenerator is the main entry point for generating documentation
@@ -26,15 +18,13 @@ class DokkaGenerator(
private val logger: DokkaLogger
) {
fun generate() = timed {
- report("Setting up analysis environments")
val sourceSetsCache = SourceSetCache()
- val sourceSets: Map<SourceSetData, EnvironmentAndFacade> = setUpAnalysis(configuration, sourceSetsCache)
report("Initializing plugins")
- val context = initializePlugins(configuration, logger, sourceSets, sourceSetsCache)
+ val context = initializePlugins(configuration, logger, sourceSetsCache)
report("Creating documentation models")
- val modulesFromPlatforms = createDocumentationModels(sourceSets, context)
+ val modulesFromPlatforms = createDocumentationModels(context, sourceSetsCache)
report("Transforming documentation model before merging")
val transformedDocumentationBeforeMerge = transformDocumentationModelBeforeMerge(modulesFromPlatforms, context)
@@ -59,9 +49,8 @@ class DokkaGenerator(
fun generateAllModulesPage() = timed {
val sourceSetsCache = SourceSetCache()
- val sourceSets = emptyMap<SourceSetData, EnvironmentAndFacade>()
report("Initializing plugins")
- val context = initializePlugins(configuration, logger, sourceSets, sourceSetsCache)
+ val context = initializePlugins(configuration, logger, sourceSetsCache)
report("Creating all modules page")
val pages = createAllModulePage(context)
@@ -73,26 +62,20 @@ class DokkaGenerator(
render(transformedPages, context)
}.dump("\n\n === TIME MEASUREMENT ===\n")
- fun setUpAnalysis(
- configuration: DokkaConfiguration,
- sourceSetsCache: SourceSetCache
- ): Map<SourceSetData, EnvironmentAndFacade> =
- configuration.passesConfigurations.map {
- sourceSetsCache.getSourceSet(it) to createEnvironmentAndFacade(configuration, it)
- }.toMap()
fun initializePlugins(
configuration: DokkaConfiguration,
logger: DokkaLogger,
- sourceSets: Map<SourceSetData, EnvironmentAndFacade>,
sourceSetsCache: SourceSetCache,
pluginOverrides: List<DokkaPlugin> = emptyList()
- ) = DokkaContext.create(configuration, logger, sourceSets, sourceSetsCache, pluginOverrides)
+ ) = DokkaContext.create(configuration, logger, sourceSetsCache, pluginOverrides)
fun createDocumentationModels(
- platforms: Map<SourceSetData, EnvironmentAndFacade>,
- context: DokkaContext
- ) = platforms.flatMap { (pdata, _) -> translateSources(pdata, context) }
+ context: DokkaContext,
+ sourceSetsCache: SourceSetCache
+ ) = context.configuration.passesConfigurations
+ .map { passConfiguration -> sourceSetsCache.getSourceSet(passConfiguration) }
+ .flatMap { passConfiguration -> translateSources(passConfiguration, context) }
fun transformDocumentationModelBeforeMerge(
modulesFromPlatforms: List<DModule>,
@@ -150,56 +133,10 @@ class DokkaGenerator(
}
}
- private fun createEnvironmentAndFacade(
- configuration: DokkaConfiguration,
- pass: DokkaConfiguration.PassConfiguration
- ): EnvironmentAndFacade =
- AnalysisEnvironment(DokkaMessageCollector(logger), pass.analysisPlatform).run {
- if (analysisPlatform == Platform.jvm) {
- addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre())
- }
- pass.classpath.forEach { addClasspath(File(it)) }
-
- addSources(
- (pass.sourceRoots + configuration.passesConfigurations.filter { it.sourceSetID in pass.dependentSourceSets }
- .flatMap { it.sourceRoots })
- .map { it.path }
- )
-
- loadLanguageVersionSettings(pass.languageVersion, pass.apiVersion)
-
- val environment = createCoreEnvironment()
- val (facade, _) = createResolutionFacade(environment)
- EnvironmentAndFacade(environment, facade)
- }
-
private fun translateSources(platformData: SourceSetData, context: DokkaContext) =
context[CoreExtensions.sourceToDocumentableTranslator].map {
it.invoke(platformData, context)
}
-
- class DokkaMessageCollector(private val logger: DokkaLogger) : MessageCollector {
- override fun clear() {
- seenErrors = false
- }
-
- private var seenErrors = false
-
- override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
- if (severity == CompilerMessageSeverity.ERROR) {
- seenErrors = true
- }
- logger.info(MessageRenderer.PLAIN_FULL_PATHS.render(severity, message, location))
- }
-
- override fun hasErrors() = seenErrors
- }
-}
-
-// It is not data class due to ill-defined equals
-class EnvironmentAndFacade(val environment: KotlinCoreEnvironment, val facade: DokkaResolutionFacade) {
- operator fun component1() = environment
- operator fun component2() = facade
}
private class Timer(startTime: Long, private val logger: DokkaLogger?) {
diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt
index 9cc51fb7..3f6d886f 100644
--- a/core/src/main/kotlin/links/DRI.kt
+++ b/core/src/main/kotlin/links/DRI.kt
@@ -1,15 +1,5 @@
package org.jetbrains.dokka.links
-import com.intellij.psi.*
-import org.jetbrains.kotlin.descriptors.*
-import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
-import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
-import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
-import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
-import org.jetbrains.kotlin.types.KotlinType
-import org.jetbrains.kotlin.types.TypeProjection
-import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
-
/**
* [DRI] stands for DokkaResourceIdentifier
*/
@@ -21,33 +11,10 @@ data class DRI(
val extra: String? = null
) {
override fun toString(): String =
- "${packageName.orEmpty()}/${classNames.orEmpty()}/${callable?.name.orEmpty()}/${callable?.signature().orEmpty()}/$target/${extra.orEmpty()}"
+ "${packageName.orEmpty()}/${classNames.orEmpty()}/${callable?.name.orEmpty()}/${callable?.signature()
+ .orEmpty()}/$target/${extra.orEmpty()}"
companion object {
- fun from(descriptor: DeclarationDescriptor) = descriptor.parentsWithSelf.run {
- val callable = firstIsInstanceOrNull<CallableDescriptor>()
- DRI(
- firstIsInstanceOrNull<PackageFragmentDescriptor>()?.fqName?.asString(),
- (filterIsInstance<ClassDescriptor>() + filterIsInstance<TypeAliasDescriptor>()).toList()
- .takeIf { it.isNotEmpty() }
- ?.asReversed()
- ?.joinToString(separator = ".") { it.name.asString() },
- callable?.let { Callable.from(it) },
- DriTarget.from(descriptor)
- )
- }
-
- fun from(psi: PsiElement) = psi.parentsWithSelf.run {
- val psiMethod = firstIsInstanceOrNull<PsiMethod>()
- val psiField = firstIsInstanceOrNull<PsiField>()
- val classes = filterIsInstance<PsiClass>().toList()
- DRI(
- classes.lastOrNull()?.qualifiedName?.substringBeforeLast('.', ""),
- classes.toList().takeIf { it.isNotEmpty() }?.asReversed()?.mapNotNull { it.name }?.joinToString("."),
- psiMethod?.let { Callable.from(it) } ?: psiField?.let { Callable.from(it) } ,
- DriTarget.from(psi)
- )
- }
val topLevel = DRI()
}
}
@@ -78,71 +45,11 @@ data class Callable(
) {
fun signature() = "${receiver?.toString().orEmpty()}#${params.joinToString("#")}"
- companion object {
- fun from(descriptor: CallableDescriptor) = with(descriptor) {
- Callable(
- name.asString(),
- extensionReceiverParameter?.let { TypeReference.from(it) },
- valueParameters.mapNotNull { TypeReference.from(it) }
- )
- }
-
- fun from(psi: PsiMethod) = with(psi) {
- Callable(
- name,
- null,
- parameterList.parameters.map { param -> JavaClassReference(param.type.canonicalText) })
- }
-
- fun from(psi: PsiField): Callable {
- return Callable(
- name = psi.name,
- receiver = null,
- params = emptyList()
- )
- }
- }
+ companion object
}
sealed class TypeReference {
- companion object {
- fun from(d: ReceiverParameterDescriptor): TypeReference? =
- when (d.value) {
- is ExtensionReceiver -> fromPossiblyNullable(d.type)
- else -> run {
- println("Unknown value type for $d")
- null
- }
- }
-
- fun from(d: ValueParameterDescriptor): TypeReference? =
- fromPossiblyNullable(d.type)
-
- fun from(p: PsiClass) = TypeReference
-
- private fun fromPossiblyNullable(t: KotlinType, self: KotlinType? = null): TypeReference =
- from(t, self).let { if (t.isMarkedNullable) Nullable(it) else it }
-
- private fun from(t: KotlinType, self: KotlinType? = null): TypeReference =
- if (self is KotlinType && self.constructor == t.constructor && self.arguments == t.arguments)
- SelfType
- else when (val d = t.constructor.declarationDescriptor) {
- is TypeParameterDescriptor -> TypeParam(
- d.upperBounds.map { fromPossiblyNullable(it, self ?: t) }
- )
- else -> TypeConstructor(
- t.constructorName.orEmpty(),
- t.arguments.map { fromProjection(it, self) }
- )
- }
-
- private fun fromProjection(t: TypeProjection, r: KotlinType? = null): TypeReference =
- if (t.isStarProjection) {
- StarProjection
- } else {
- fromPossiblyNullable(t.type, r)
- }
- }
+ companion object
}
data class JavaClassReference(val name: String) : TypeReference() {
@@ -171,39 +78,10 @@ object StarProjection : TypeReference() {
override fun toString() = "*"
}
-private val KotlinType.constructorName
- get() = constructor.declarationDescriptor?.fqNameSafe?.asString()
-
sealed class DriTarget {
override fun toString(): String = this.javaClass.simpleName
- companion object {
- fun from(descriptor: DeclarationDescriptor): DriTarget = descriptor.parentsWithSelf.run {
- return when (descriptor) {
- is TypeParameterDescriptor -> PointingToGenericParameters(descriptor.index)
- else -> {
- val callable = firstIsInstanceOrNull<CallableDescriptor>()
- val params =
- callable?.let { listOfNotNull(it.extensionReceiverParameter) + it.valueParameters }.orEmpty()
- val parameterDescriptor = firstIsInstanceOrNull<ParameterDescriptor>()
-
- parameterDescriptor?.let { PointingToCallableParameters(params.indexOf(it)) }
- ?: PointingToDeclaration
- }
- }
- }
-
- fun from(psi: PsiElement): DriTarget = psi.parentsWithSelf.run {
- return when (psi) {
- is PsiTypeParameter -> PointingToGenericParameters(psi.index)
- else -> firstIsInstanceOrNull<PsiParameter>()?.let {
- val callable = firstIsInstanceOrNull<PsiMethod>()
- val params = (callable?.parameterList?.parameters).orEmpty()
- PointingToCallableParameters(params.indexOf(it))
- } ?: PointingToDeclaration
- }
- }
- }
+ companion object
}
data class PointingToGenericParameters(val parameterIndex: Int) : DriTarget() {
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt
index 90958210..768bddc5 100644
--- a/core/src/main/kotlin/model/Documentable.kt
+++ b/core/src/main/kotlin/model/Documentable.kt
@@ -1,12 +1,10 @@
package org.jetbrains.dokka.model
-import com.intellij.psi.PsiNamedElement
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.doc.DocumentationNode
import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.model.properties.WithExtraProperties
-import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
-import org.jetbrains.kotlin.load.kotlin.toSourceElement
+
abstract class Documentable {
abstract val name: String?
@@ -406,11 +404,3 @@ fun <T> SourceSetDependent<T>?.orEmpty(): SourceSetDependent<T> = this ?: emptyM
interface DocumentableSource {
val path: String
}
-
-class DescriptorDocumentableSource(val descriptor: DeclarationDescriptor) : DocumentableSource {
- override val path = descriptor.toSourceElement.containingFile.toString()
-}
-
-class PsiDocumentableSource(val psi: PsiNamedElement) : DocumentableSource {
- override val path = psi.containingFile.virtualFile.path
-} \ No newline at end of file
diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt
index 107bede5..e1e0250e 100644
--- a/core/src/main/kotlin/model/properties/PropertyContainer.kt
+++ b/core/src/main/kotlin/model/properties/PropertyContainer.kt
@@ -1,7 +1,5 @@
package org.jetbrains.dokka.model.properties
-import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
-
class PropertyContainer<C : Any> internal constructor(
@PublishedApi internal val map: Map<ExtraProperty.Key<C, *>, ExtraProperty<C>>
) {
@@ -45,7 +43,7 @@ fun <C> C.mergeExtras(left: C, right: C): C where C : Any, C : WithExtraProperti
(l.key as ExtraProperty.Key<C, ExtraProperty<C>>).mergeStrategyFor(l, r)
}
- strategies.firstIsInstanceOrNull<MergeStrategy.Fail>()?.error?.invoke()
+ strategies.filterIsInstance<MergeStrategy.Fail>().firstOrNull()?.error?.invoke()
val replaces: List<ExtraProperty<C>> =
strategies.filterIsInstance<MergeStrategy.Replace<C>>().map { it.newProperty }
diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt
index 692803dd..a2ff26c7 100644
--- a/core/src/main/kotlin/plugability/DokkaContext.kt
+++ b/core/src/main/kotlin/plugability/DokkaContext.kt
@@ -1,9 +1,7 @@
package org.jetbrains.dokka.plugability
import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.dokka.EnvironmentAndFacade
import org.jetbrains.dokka.model.SourceSetCache
-import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.utilities.DokkaLogger
import java.io.File
import java.net.URLClassLoader
@@ -23,7 +21,6 @@ interface DokkaContext {
val sourceSetCache: SourceSetCache
val logger: DokkaLogger
val configuration: DokkaConfiguration
- val platforms: Map<SourceSetData, EnvironmentAndFacade>
val unusedPoints: Collection<ExtensionPoint<*>>
@@ -31,11 +28,10 @@ interface DokkaContext {
fun create(
configuration: DokkaConfiguration,
logger: DokkaLogger,
- sourceSets: Map<SourceSetData, EnvironmentAndFacade>,
sourceSetsCache: SourceSetCache,
pluginOverrides: List<DokkaPlugin>
): DokkaContext =
- DokkaContextConfigurationImpl(logger, configuration, sourceSets, sourceSetsCache).apply {
+ DokkaContextConfigurationImpl(logger, configuration, sourceSetsCache).apply {
// File(it.path) is a workaround for an incorrect filesystem in a File instance returned by Gradle.
configuration.pluginsClasspath.map { File(it.path).toURI().toURL() }
.toTypedArray()
@@ -59,7 +55,6 @@ interface DokkaContextConfiguration {
private class DokkaContextConfigurationImpl(
override val logger: DokkaLogger,
override val configuration: DokkaConfiguration,
- override val platforms: Map<SourceSetData, EnvironmentAndFacade>,
override val sourceSetCache: SourceSetCache
) : DokkaContext, DokkaContextConfiguration {
private val plugins = mutableMapOf<KClass<*>, DokkaPlugin>()
diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt
index 24f417d8..fe472b12 100644
--- a/core/src/main/kotlin/plugability/DokkaPlugin.kt
+++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt
@@ -2,7 +2,6 @@ package org.jetbrains.dokka.plugability
import com.google.gson.Gson
import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.kotlin.utils.addToStdlib.cast
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
import kotlin.reflect.KProperty1
@@ -60,8 +59,9 @@ interface ConfigurableBlock
inline fun <reified P : DokkaPlugin, reified T : ConfigurableBlock> Configurable.pluginConfiguration(block: T.() -> Unit) {
val instance = T::class.createInstance().apply(block)
- pluginsConfiguration.cast<MutableMap<String, String>>()[P::class.qualifiedName!!] =
- Gson().toJson(instance, T::class.java)
+
+ val mutablePluginsConfiguration = pluginsConfiguration as MutableMap<String, String>
+ mutablePluginsConfiguration[P::class.qualifiedName!!] = Gson().toJson(instance, T::class.java)
}
inline fun <reified P : DokkaPlugin, reified E : Any> P.query(extension: P.() -> ExtensionPoint<E>): List<E> =
diff --git a/core/src/main/kotlin/utilities/cast.kt b/core/src/main/kotlin/utilities/cast.kt
new file mode 100644
index 00000000..d4a8d73d
--- /dev/null
+++ b/core/src/main/kotlin/utilities/cast.kt
@@ -0,0 +1,5 @@
+package org.jetbrains.dokka.utilities
+
+inline fun <reified T> Any.cast(): T {
+ return this as T
+}
diff --git a/integration-tests/gradle-integration-tests/build.gradle.kts b/integration-tests/gradle-integration-tests/build.gradle.kts
index 7fc945b5..7cb96738 100644
--- a/integration-tests/gradle-integration-tests/build.gradle.kts
+++ b/integration-tests/gradle-integration-tests/build.gradle.kts
@@ -14,7 +14,7 @@ dependencies {
testImplementation(gradleTestKit())
dokkaPlugin(project(path = ":runners:gradle-plugin"))
- dokkaCore(project(path = ":coreDependencies", configuration = "shadow"))
+ dokkaCore(project(path = ":core:dependencies", configuration = "shadow"))
dokkaCore(project(path = ":core"))
kotlinGradle("org.jetbrains.kotlin:kotlin-gradle-plugin")
}
diff --git a/kotlin-analysis/build.gradle.kts b/kotlin-analysis/build.gradle.kts
new file mode 100644
index 00000000..67480f82
--- /dev/null
+++ b/kotlin-analysis/build.gradle.kts
@@ -0,0 +1,27 @@
+import org.jetbrains.configureBintrayPublication
+
+plugins {
+ id("com.github.johnrengelman.shadow")
+ `maven-publish`
+ id("com.jfrog.bintray")
+}
+
+dependencies {
+ compileOnly(project(":core"))
+
+ val kotlin_version: String by project
+ api("org.jetbrains.kotlin:kotlin-compiler:$kotlin_version")
+
+ api(project(":kotlin-analysis:dependencies", configuration = "shadow"))
+}
+
+publishing {
+ publications {
+ register<MavenPublication>("analysis") {
+ artifactId = "dokka-analysis"
+ from(components["java"])
+ }
+ }
+}
+
+configureBintrayPublication("analysis")
diff --git a/coreDependencies/build.gradle.kts b/kotlin-analysis/dependencies/build.gradle.kts
index 9af82d9f..5bba6422 100644
--- a/coreDependencies/build.gradle.kts
+++ b/kotlin-analysis/dependencies/build.gradle.kts
@@ -1,44 +1,45 @@
import org.jetbrains.configureBintrayPublication
+
plugins {
id("com.github.johnrengelman.shadow")
`maven-publish`
id("com.jfrog.bintray")
}
-val intellijCore: Configuration by configurations.creating
-
repositories {
maven(url = "https://www.jetbrains.com/intellij-repository/snapshots")
maven(url = "https://www.jetbrains.com/intellij-repository/releases")
maven(url = "https://kotlin.bintray.com/kotlin-plugin")
}
+val intellijCore: Configuration by configurations.creating
+
fun intellijCoreAnalysis() = zipTree(intellijCore.singleFile).matching {
include("intellij-core-analysis.jar")
}
dependencies {
- val idea_version: String by project
- intellijCore("com.jetbrains.intellij.idea:intellij-core:$idea_version")
val kotlin_plugin_version: String by project
- implementation(intellijCoreAnalysis())
- implementation("org.jetbrains.kotlin:kotlin-plugin-ij193:$kotlin_plugin_version") {
+ api("org.jetbrains.kotlin:ide-common-ij193:$kotlin_plugin_version")
+ api("org.jetbrains.kotlin:kotlin-plugin-ij193:$kotlin_plugin_version") {
//TODO: parametrize ij version after 1.3.70
isTransitive = false
}
+
+ val idea_version: String by project
+ intellijCore("com.jetbrains.intellij.idea:intellij-core:$idea_version")
+ implementation(intellijCoreAnalysis())
+
implementation("org.jetbrains:markdown:0.1.41") {
because("it's published only on bintray")
}
- implementation("org.jetbrains.kotlin:ide-common-ij193:$kotlin_plugin_version")
- implementation(kotlin("stdlib-jdk8"))
- implementation(kotlin("reflect"))
}
tasks {
shadowJar {
val dokka_version: String by project
- archiveFileName.set("dokka-dependencies-$dokka_version.jar")
+ archiveFileName.set("dokka-kotlin-analysis-dependencies-$dokka_version.jar")
archiveClassifier.set("")
exclude("colorScheme/**")
@@ -53,13 +54,14 @@ tasks {
}
}
+
publishing {
publications {
- register<MavenPublication>("dokkaCoreDependencies") {
- artifactId = "dokka-core-dependencies"
+ register<MavenPublication>("kotlin-analysis-dependencies") {
+ artifactId = "kotlin-analysis-dependencies"
project.shadow.component(this)
}
}
}
-configureBintrayPublication("dokkaCoreDependencies")
+configureBintrayPublication("kotlin-analysis-dependencies")
diff --git a/core/src/main/kotlin/analysis/AnalysisEnvironment.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt
index 33451dd6..7836bde9 100644
--- a/core/src/main/kotlin/analysis/AnalysisEnvironment.kt
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/AnalysisEnvironment.kt
@@ -153,7 +153,7 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl
)
registerExtensionPoint(
- IdePlatformKindResolution.Companion,
+ IdePlatformKindResolution,
listOf(
CommonPlatformKindResolution(),
JvmPlatformKindResolution(),
@@ -253,10 +253,21 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl
resolverForProject.resolverForModule(library) // Required before module to initialize library properly
val resolverForModule = resolverForProject.resolverForModule(module)
val libraryResolutionFacade =
- DokkaResolutionFacade(environment.project, libraryModuleDescriptor, resolverForLibrary)
- val created = DokkaResolutionFacade(environment.project, moduleDescriptor, resolverForModule)
+ DokkaResolutionFacade(
+ environment.project,
+ libraryModuleDescriptor,
+ resolverForLibrary
+ )
+ val created =
+ DokkaResolutionFacade(
+ environment.project,
+ moduleDescriptor,
+ resolverForModule
+ )
val projectComponentManager = environment.project as MockComponentManager
- projectComponentManager.registerService(KotlinCacheService::class.java, CoreKotlinCacheService(created))
+ projectComponentManager.registerService(KotlinCacheService::class.java,
+ CoreKotlinCacheService(created)
+ )
return created to libraryResolutionFacade
}
@@ -399,7 +410,7 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl
val javaRoots = classpath
.mapNotNull {
val rootFile = when (it.extension) {
- "jar" -> StandardFileSystems.jar().findFileByPath("${it.absolutePath}${JAR_SEPARATOR}")
+ "jar" -> StandardFileSystems.jar().findFileByPath("${it.absolutePath}$JAR_SEPARATOR")
else -> StandardFileSystems.local().findFileByPath(it.absolutePath)
}
rootFile?.let { JavaRoot(it, JavaRoot.RootType.BINARY) }
diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CallableFactory.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CallableFactory.kt
new file mode 100644
index 00000000..ebfe20a5
--- /dev/null
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CallableFactory.kt
@@ -0,0 +1,31 @@
+package org.jetbrains.dokka.analysis
+
+import com.intellij.psi.PsiField
+import com.intellij.psi.PsiMethod
+import org.jetbrains.dokka.links.Callable
+import org.jetbrains.dokka.links.JavaClassReference
+import org.jetbrains.dokka.links.TypeReference
+import org.jetbrains.kotlin.descriptors.CallableDescriptor
+
+fun Callable.Companion.from(descriptor: CallableDescriptor) = with(descriptor) {
+ Callable(
+ name.asString(),
+ extensionReceiverParameter?.let { TypeReference.from(it) },
+ valueParameters.mapNotNull { TypeReference.from(it) }
+ )
+}
+
+fun Callable.Companion.from(psi: PsiMethod) = with(psi) {
+ Callable(
+ name,
+ null,
+ parameterList.parameters.map { param -> JavaClassReference(param.type.canonicalText) })
+}
+
+fun Callable.Companion.from(psi: PsiField): Callable {
+ return Callable(
+ name = psi.name,
+ receiver = null,
+ params = emptyList()
+ )
+}
diff --git a/core/src/main/kotlin/analysis/CoreKotlinCacheService.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CoreKotlinCacheService.kt
index bcf91225..68415875 100644
--- a/core/src/main/kotlin/analysis/CoreKotlinCacheService.kt
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CoreKotlinCacheService.kt
@@ -1,6 +1,7 @@
package org.jetbrains.dokka.analysis
import com.intellij.psi.PsiFile
+import org.jetbrains.dokka.analysis.DokkaResolutionFacade
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
@@ -39,4 +40,3 @@ class CoreKotlinCacheService(private val resolutionFacade: DokkaResolutionFacade
}
}
-
diff --git a/core/src/main/kotlin/analysis/CoreProjectFileIndex.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CoreProjectFileIndex.kt
index 45138e39..d0e0bb4f 100644
--- a/core/src/main/kotlin/analysis/CoreProjectFileIndex.kt
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/CoreProjectFileIndex.kt
@@ -53,14 +53,6 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
throw UnsupportedOperationException()
}
- override fun getOptionValue(p0: String): String? {
- throw UnsupportedOperationException()
- }
-
- override fun clearOption(p0: String) {
- throw UnsupportedOperationException()
- }
-
override fun getName(): String = "<Dokka module>"
override fun getModuleWithLibrariesScope(): GlobalSearchScope {
@@ -71,18 +63,6 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
throw UnsupportedOperationException()
}
- override fun getModuleContentScope(): GlobalSearchScope {
- throw UnsupportedOperationException()
- }
-
- override fun isLoaded(): Boolean {
- throw UnsupportedOperationException()
- }
-
- override fun setOption(p0: String, p1: String?) {
- throw UnsupportedOperationException()
- }
-
override fun getModuleWithDependenciesScope(): GlobalSearchScope {
throw UnsupportedOperationException()
}
@@ -91,16 +71,6 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
throw UnsupportedOperationException()
}
- override fun getProject(): Project = this@CoreProjectFileIndex.project
-
- override fun getModuleContentWithDependenciesScope(): GlobalSearchScope {
- throw UnsupportedOperationException()
- }
-
- override fun getModuleFilePath(): String {
- throw UnsupportedOperationException()
- }
-
override fun getModuleTestsWithDependentsScope(): GlobalSearchScope {
throw UnsupportedOperationException()
}
@@ -109,30 +79,14 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
throw UnsupportedOperationException()
}
- override fun getModuleScope(p0: Boolean): GlobalSearchScope {
- throw UnsupportedOperationException()
- }
-
override fun getModuleRuntimeScope(p0: Boolean): GlobalSearchScope {
throw UnsupportedOperationException()
}
- override fun getModuleFile(): VirtualFile? {
- throw UnsupportedOperationException()
- }
-
override fun <T : Any?> getExtensions(p0: ExtensionPointName<T>): Array<out T> {
throw UnsupportedOperationException()
}
- override fun getComponent(p0: String): BaseComponent? {
- throw UnsupportedOperationException()
- }
-
- override fun <T : Any?> getComponent(p0: Class<T>, p1: T): T {
- throw UnsupportedOperationException()
- }
-
override fun <T : Any?> getComponent(interfaceClass: Class<T>): T? {
if (interfaceClass == ModuleRootManager::class.java) {
return moduleRootManager as T
@@ -144,18 +98,10 @@ class CoreProjectFileIndex(private val project: Project, contentRoots: List<Cont
throw UnsupportedOperationException()
}
- override fun <T : Any?> getComponents(p0: Class<T>): Array<out T> {
- throw UnsupportedOperationException()
- }
-
override fun getPicoContainer(): PicoContainer {
throw UnsupportedOperationException()
}
- override fun hasComponent(p0: Class<*>): Boolean {
- throw UnsupportedOperationException()
- }
-
override fun getMessageBus(): MessageBus {
throw UnsupportedOperationException()
}
diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRIFactory.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRIFactory.kt
new file mode 100644
index 00000000..513817f3
--- /dev/null
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRIFactory.kt
@@ -0,0 +1,38 @@
+package org.jetbrains.dokka.analysis
+
+import com.intellij.psi.PsiClass
+import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiField
+import com.intellij.psi.PsiMethod
+import org.jetbrains.dokka.links.Callable
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.links.DriTarget
+import org.jetbrains.kotlin.descriptors.*
+import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
+import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
+import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
+
+fun DRI.Companion.from(descriptor: DeclarationDescriptor) = descriptor.parentsWithSelf.run {
+ val callable = firstIsInstanceOrNull<CallableDescriptor>()
+ DRI(
+ firstIsInstanceOrNull<PackageFragmentDescriptor>()?.fqName?.asString(),
+ (filterIsInstance<ClassDescriptor>() + filterIsInstance<TypeAliasDescriptor>()).toList()
+ .takeIf { it.isNotEmpty() }
+ ?.asReversed()
+ ?.joinToString(separator = ".") { it.name.asString() },
+ callable?.let { Callable.from(it) },
+ DriTarget.from(descriptor)
+ )
+}
+
+fun DRI.Companion.from(psi: PsiElement) = psi.parentsWithSelf.run {
+ val psiMethod = firstIsInstanceOrNull<PsiMethod>()
+ val psiField = firstIsInstanceOrNull<PsiField>()
+ val classes = filterIsInstance<PsiClass>().toList()
+ DRI(
+ classes.lastOrNull()?.qualifiedName?.substringBeforeLast('.', ""),
+ classes.toList().takeIf { it.isNotEmpty() }?.asReversed()?.mapNotNull { it.name }?.joinToString("."),
+ psiMethod?.let { Callable.from(it) } ?: psiField?.let { Callable.from(it) },
+ DriTarget.from(psi)
+ )
+}
diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRITargetFactory.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRITargetFactory.kt
new file mode 100644
index 00000000..031a5a32
--- /dev/null
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRITargetFactory.kt
@@ -0,0 +1,44 @@
+package org.jetbrains.dokka.analysis
+
+import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiMethod
+import com.intellij.psi.PsiParameter
+import com.intellij.psi.PsiTypeParameter
+import org.jetbrains.dokka.links.DriTarget
+import org.jetbrains.dokka.links.PointingToCallableParameters
+import org.jetbrains.dokka.links.PointingToDeclaration
+import org.jetbrains.dokka.links.PointingToGenericParameters
+import org.jetbrains.kotlin.descriptors.CallableDescriptor
+import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
+import org.jetbrains.kotlin.descriptors.ParameterDescriptor
+import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
+import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
+import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
+import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
+
+fun DriTarget.Companion.from(descriptor: DeclarationDescriptor): DriTarget = descriptor.parentsWithSelf.run {
+ return when (descriptor) {
+ is TypeParameterDescriptor -> PointingToGenericParameters(descriptor.index)
+ else -> {
+ val callable = firstIsInstanceOrNull<CallableDescriptor>()
+ val params =
+ callable?.let { listOfNotNull(it.extensionReceiverParameter) + it.valueParameters }.orEmpty()
+ val parameterDescriptor = firstIsInstanceOrNull<ParameterDescriptor>()
+
+ parameterDescriptor?.let { PointingToCallableParameters(params.indexOf(it)) }
+ ?: PointingToDeclaration
+ }
+ }
+}
+
+
+fun DriTarget.Companion.from(psi: PsiElement): DriTarget = psi.parentsWithSelf.run {
+ return when (psi) {
+ is PsiTypeParameter -> PointingToGenericParameters(psi.index)
+ else -> firstIsInstanceOrNull<PsiParameter>()?.let {
+ val callable = firstIsInstanceOrNull<PsiMethod>()
+ val params = (callable?.parameterList?.parameters).orEmpty()
+ PointingToCallableParameters(params.indexOf(it))
+ } ?: PointingToDeclaration
+ }
+}
diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/Documentable.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/Documentable.kt
new file mode 100644
index 00000000..0c55fed4
--- /dev/null
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/Documentable.kt
@@ -0,0 +1,14 @@
+package org.jetbrains.dokka.analysis
+
+import com.intellij.psi.PsiNamedElement
+import org.jetbrains.dokka.model.DocumentableSource
+import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
+import org.jetbrains.kotlin.load.kotlin.toSourceElement
+
+class DescriptorDocumentableSource(val descriptor: DeclarationDescriptor) : DocumentableSource {
+ override val path = descriptor.toSourceElement.containingFile.toString()
+}
+
+class PsiDocumentableSource(val psi: PsiNamedElement) : DocumentableSource {
+ override val path = psi.containingFile.virtualFile.path
+}
diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/EnvironmentAndFacade.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/EnvironmentAndFacade.kt
new file mode 100644
index 00000000..9d15123a
--- /dev/null
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/EnvironmentAndFacade.kt
@@ -0,0 +1,59 @@
+package org.jetbrains.dokka.analysis
+
+import org.jetbrains.dokka.DokkaConfiguration
+import org.jetbrains.dokka.Platform
+import org.jetbrains.dokka.utilities.DokkaLogger
+import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
+import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
+import org.jetbrains.kotlin.cli.common.messages.MessageCollector
+import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
+import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
+import org.jetbrains.kotlin.utils.PathUtil
+import java.io.File
+
+internal fun createEnvironmentAndFacade(
+ logger: DokkaLogger,
+ configuration: DokkaConfiguration,
+ pass: DokkaConfiguration.PassConfiguration
+): EnvironmentAndFacade =
+ AnalysisEnvironment(DokkaMessageCollector(logger), pass.analysisPlatform).run {
+ if (analysisPlatform == Platform.jvm) {
+ addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre())
+ }
+ pass.classpath.forEach { addClasspath(File(it)) }
+
+ addSources(
+ (pass.sourceRoots + configuration.passesConfigurations.filter { it.sourceSetID in pass.dependentSourceSets }
+ .flatMap { it.sourceRoots })
+ .map { it.path }
+ )
+
+ loadLanguageVersionSettings(pass.languageVersion, pass.apiVersion)
+
+ val environment = createCoreEnvironment()
+ val (facade, _) = createResolutionFacade(environment)
+ EnvironmentAndFacade(environment, facade)
+ }
+
+class DokkaMessageCollector(private val logger: DokkaLogger) : MessageCollector {
+ override fun clear() {
+ seenErrors = false
+ }
+
+ private var seenErrors = false
+
+ override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) {
+ if (severity == CompilerMessageSeverity.ERROR) {
+ seenErrors = true
+ }
+ logger.info(MessageRenderer.PLAIN_FULL_PATHS.render(severity, message, location))
+ }
+
+ override fun hasErrors() = seenErrors
+}
+
+// It is not data class due to ill-defined equals
+class EnvironmentAndFacade(val environment: KotlinCoreEnvironment, val facade: DokkaResolutionFacade) {
+ operator fun component1() = environment
+ operator fun component2() = facade
+}
diff --git a/core/src/main/kotlin/analysis/JavaResolveExtension.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/JavaResolveExtension.kt
index ab6bec9c..ab6bec9c 100644
--- a/core/src/main/kotlin/analysis/JavaResolveExtension.kt
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/JavaResolveExtension.kt
diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/KotlinAnalysis.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/KotlinAnalysis.kt
new file mode 100644
index 00000000..cd07b2a3
--- /dev/null
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/KotlinAnalysis.kt
@@ -0,0 +1,46 @@
+@file:Suppress("FunctionName")
+
+package org.jetbrains.dokka.analysis
+
+import org.jetbrains.dokka.DokkaConfiguration
+import org.jetbrains.dokka.model.SourceSetCache
+import org.jetbrains.dokka.model.SourceSetData
+import org.jetbrains.dokka.model.SourceSetDependent
+import org.jetbrains.dokka.plugability.DokkaContext
+
+fun KotlinAnalysis(context: DokkaContext): KotlinAnalysis {
+ val environments = context.configuration.passesConfigurations
+ .associate { passConfiguration ->
+ context.sourceSetCache.getSourceSet(passConfiguration) to createEnvironmentAndFacade(
+ logger = context.logger,
+ configuration = context.configuration,
+ pass = passConfiguration
+ )
+ }
+
+ return KotlinAnalysisImpl(context.sourceSetCache, environments)
+}
+
+interface KotlinAnalysis : SourceSetDependent<EnvironmentAndFacade> {
+ override fun get(key: SourceSetData): EnvironmentAndFacade
+ operator fun get(sourceSetID: String): EnvironmentAndFacade
+ operator fun get(passConfiguration: DokkaConfiguration.PassConfiguration): EnvironmentAndFacade
+}
+
+internal class KotlinAnalysisImpl(
+ private val sourceSetCache: SourceSetCache,
+ private val environments: SourceSetDependent<EnvironmentAndFacade>
+) : KotlinAnalysis, SourceSetDependent<EnvironmentAndFacade> by environments {
+
+ override fun get(key: SourceSetData): EnvironmentAndFacade {
+ return environments[key] ?: throw IllegalStateException("Missing EnvironmentAndFacade for sourceSet $key")
+ }
+
+ override fun get(sourceSetID: String): EnvironmentAndFacade {
+ return environments.entries.first { (sourceSet, _) -> sourceSet.sourceSetID == sourceSetID }.value
+ }
+
+ override fun get(passConfiguration: DokkaConfiguration.PassConfiguration): EnvironmentAndFacade {
+ return get(sourceSetCache.getSourceSet(passConfiguration))
+ }
+}
diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/TypeReferenceFactory.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/TypeReferenceFactory.kt
new file mode 100644
index 00000000..e07672d4
--- /dev/null
+++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/TypeReferenceFactory.kt
@@ -0,0 +1,51 @@
+package org.jetbrains.dokka.analysis
+
+import com.intellij.psi.PsiClass
+import org.jetbrains.dokka.links.*
+import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
+import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
+import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
+import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
+import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
+import org.jetbrains.kotlin.types.KotlinType
+import org.jetbrains.kotlin.types.TypeProjection
+
+fun TypeReference.Companion.from(d: ReceiverParameterDescriptor): TypeReference? =
+ when (d.value) {
+ is ExtensionReceiver -> fromPossiblyNullable(d.type)
+ else -> run {
+ println("Unknown value type for $d")
+ null
+ }
+ }
+
+fun TypeReference.Companion.from(d: ValueParameterDescriptor): TypeReference? =
+ fromPossiblyNullable(d.type)
+
+fun TypeReference.Companion.from(p: PsiClass) = TypeReference
+
+private fun TypeReference.Companion.fromPossiblyNullable(t: KotlinType, self: KotlinType? = null): TypeReference =
+ from(t, self).let { if (t.isMarkedNullable) Nullable(it) else it }
+
+private fun TypeReference.Companion.from(t: KotlinType, self: KotlinType? = null): TypeReference =
+ if (self is KotlinType && self.constructor == t.constructor && self.arguments == t.arguments)
+ SelfType
+ else when (val d = t.constructor.declarationDescriptor) {
+ is TypeParameterDescriptor -> TypeParam(
+ d.upperBounds.map { fromPossiblyNullable(it, self ?: t) }
+ )
+ else -> TypeConstructor(
+ t.constructorName.orEmpty(),
+ t.arguments.map { fromProjection(it, self) }
+ )
+ }
+
+private fun TypeReference.Companion.fromProjection(t: TypeProjection, r: KotlinType? = null): TypeReference =
+ if (t.isStarProjection) {
+ StarProjection
+ } else {
+ fromPossiblyNullable(t.type, r)
+ }
+
+private val KotlinType.constructorName
+ get() = constructor.declarationDescriptor?.fqNameSafe?.asString()
diff --git a/plugins/base/build.gradle.kts b/plugins/base/build.gradle.kts
index 24a7f593..97d6a646 100644
--- a/plugins/base/build.gradle.kts
+++ b/plugins/base/build.gradle.kts
@@ -5,6 +5,7 @@ plugins {
}
dependencies {
+ api(project(":kotlin-analysis"))
implementation("org.jsoup:jsoup:1.12.1")
implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.10")
testImplementation(project(":test-tools"))
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt
index cf4ad88f..f1b0d969 100644
--- a/plugins/base/src/main/kotlin/DokkaBase.kt
+++ b/plugins/base/src/main/kotlin/DokkaBase.kt
@@ -1,6 +1,9 @@
+@file:Suppress("unused")
+
package org.jetbrains.dokka.base
import org.jetbrains.dokka.CoreExtensions
+import org.jetbrains.dokka.analysis.KotlinAnalysis
import org.jetbrains.dokka.base.allModulePage.MultimodulePageCreator
import org.jetbrains.dokka.base.renderers.*
import org.jetbrains.dokka.base.renderers.html.*
@@ -37,13 +40,19 @@ class DokkaBase : DokkaPlugin() {
val externalLocationProviderFactory by extensionPoint<ExternalLocationProviderFactory>()
val outputWriter by extensionPoint<OutputWriter>()
val htmlPreprocessors by extensionPoint<PageTransformer>()
+ val kotlinAnalysis by extensionPoint<KotlinAnalysis>()
+
val descriptorToDocumentableTranslator by extending {
- CoreExtensions.sourceToDocumentableTranslator with DefaultDescriptorToDocumentableTranslator
+ CoreExtensions.sourceToDocumentableTranslator providing { ctx ->
+ DefaultDescriptorToDocumentableTranslator(ctx.single(kotlinAnalysis))
+ }
}
val psiToDocumentableTranslator by extending {
- CoreExtensions.sourceToDocumentableTranslator with DefaultPsiToDocumentableTranslator
+ CoreExtensions.sourceToDocumentableTranslator providing { ctx ->
+ DefaultPsiToDocumentableTranslator(ctx.single(kotlinAnalysis))
+ }
}
val documentableMerger by extending(isFallback = true) {
@@ -69,7 +78,9 @@ class DokkaBase : DokkaPlugin() {
}
val modulesAndPackagesDocumentation by extending(isFallback = true) {
- CoreExtensions.preMergeDocumentableTransformer providing ::ModuleAndPackageDocumentationTransformer
+ CoreExtensions.preMergeDocumentableTransformer providing { ctx ->
+ ModuleAndPackageDocumentationTransformer(ctx, ctx.single(kotlinAnalysis))
+ }
}
val kotlinSignatureProvider by extending(isFallback = true) {
@@ -124,6 +135,10 @@ class DokkaBase : DokkaPlugin() {
CoreExtensions.renderer providing ::HtmlRenderer applyIf { format == "html" }
}
+ val defaultKotlinAnalysis by extending(isFallback = true) {
+ kotlinAnalysis providing { ctx -> KotlinAnalysis(ctx) }
+ }
+
val locationProvider by extending(isFallback = true) {
locationProviderFactory providing ::DefaultLocationProviderFactory
}
diff --git a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt b/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
index ea1d8510..cdaa0274 100644
--- a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
+++ b/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
@@ -9,7 +9,7 @@ import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.model.doc.DocumentationNode
import org.jetbrains.dokka.model.doc.P
import org.jetbrains.dokka.pages.*
-import org.jetbrains.dokka.parsers.MarkdownParser
+import org.jetbrains.dokka.base.parsers.MarkdownParser
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.transformers.pages.PageCreator
diff --git a/core/src/main/kotlin/parsers/HtmlParser.kt b/plugins/base/src/main/kotlin/parsers/HtmlParser.kt
index a0652b95..ece3cf24 100644
--- a/core/src/main/kotlin/parsers/HtmlParser.kt
+++ b/plugins/base/src/main/kotlin/parsers/HtmlParser.kt
@@ -1,7 +1,7 @@
-package org.jetbrains.dokka.parsers
+package org.jetbrains.dokka.base.parsers
import org.jetbrains.dokka.model.doc.*
-import org.jetbrains.dokka.parsers.factories.DocTagsFromStringFactory
+import org.jetbrains.dokka.base.parsers.factories.DocTagsFromStringFactory
import org.jsoup.Jsoup
import org.jsoup.nodes.Node
import org.jsoup.select.NodeFilter
diff --git a/core/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
index 07e1fcc3..6075ef73 100644
--- a/core/src/main/kotlin/parsers/MarkdownParser.kt
+++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
@@ -1,4 +1,4 @@
-package org.jetbrains.dokka.parsers
+package org.jetbrains.dokka.base.parsers
import com.intellij.psi.PsiElement
import org.jetbrains.dokka.model.doc.*
@@ -12,8 +12,9 @@ import org.intellij.markdown.flavours.gfm.GFMElementTypes
import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor
import org.intellij.markdown.flavours.gfm.GFMTokenTypes
import org.jetbrains.dokka.analysis.DokkaResolutionFacade
+import org.jetbrains.dokka.analysis.from
import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.parsers.factories.DocTagsFromIElementFactory
+import org.jetbrains.dokka.base.parsers.factories.DocTagsFromIElementFactory
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
diff --git a/core/src/main/kotlin/parsers/Parser.kt b/plugins/base/src/main/kotlin/parsers/Parser.kt
index 05adc4d5..1dd0c34a 100644
--- a/core/src/main/kotlin/parsers/Parser.kt
+++ b/plugins/base/src/main/kotlin/parsers/Parser.kt
@@ -1,4 +1,4 @@
-package org.jetbrains.dokka.parsers
+package org.jetbrains.dokka.base.parsers
import org.jetbrains.dokka.model.doc.*
diff --git a/core/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt
index dda6c627..e81eb513 100644
--- a/core/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt
+++ b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt
@@ -1,4 +1,4 @@
-package org.jetbrains.dokka.parsers.factories
+package org.jetbrains.dokka.base.parsers.factories
import org.jetbrains.dokka.model.doc.*
import org.intellij.markdown.IElementType
diff --git a/core/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt
index 3425f52e..de7c3cad 100644
--- a/core/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt
+++ b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt
@@ -1,4 +1,4 @@
-package org.jetbrains.dokka.parsers.factories
+package org.jetbrains.dokka.base.parsers.factories
import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.links.DRI
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt
index 2aab6018..63232793 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt
@@ -1,10 +1,13 @@
package org.jetbrains.dokka.base.transformers.documentables
+import org.jetbrains.dokka.analysis.EnvironmentAndFacade
+import org.jetbrains.dokka.analysis.KotlinAnalysis
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.model.doc.DocumentationNode
import org.jetbrains.dokka.model.sourceSet
-import org.jetbrains.dokka.parsers.MarkdownParser
+import org.jetbrains.dokka.base.parsers.MarkdownParser
+import org.jetbrains.dokka.model.SourceSetDependent
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
import org.jetbrains.kotlin.name.FqName
@@ -12,9 +15,12 @@ import java.nio.file.Files
import java.nio.file.Paths
-internal class ModuleAndPackageDocumentationTransformer(val context: DokkaContext) : PreMergeDocumentableTransformer {
+internal class ModuleAndPackageDocumentationTransformer(
+ private val context: DokkaContext,
+ private val kotlinAnalysis: KotlinAnalysis
+) : PreMergeDocumentableTransformer {
- override fun invoke(original: List<DModule>): List<DModule> {
+ override fun invoke(modules: List<DModule>): List<DModule> {
val modulesAndPackagesDocumentation =
context.configuration.passesConfigurations
@@ -47,13 +53,12 @@ internal class ModuleAndPackageDocumentationTransformer(val context: DokkaContex
}
}.toMap()
- return original.map { module ->
+ return modules.map { module ->
val moduleDocumentation =
module.sourceSets.mapNotNull { pd ->
val doc = modulesAndPackagesDocumentation[Pair(module.name, pd)]
- val facade = context.platforms[pd]?.facade
- ?: return@mapNotNull null.also { context.logger.warn("Could not find platform data for ${pd.moduleName}/${pd.sourceSetID}") }
+ val facade = kotlinAnalysis[pd].facade
try {
doc?.get("Module")?.get(module.name)?.run {
pd to MarkdownParser(
@@ -71,8 +76,7 @@ internal class ModuleAndPackageDocumentationTransformer(val context: DokkaContex
val packagesDocumentation = module.packages.map {
it.name to it.sourceSets.mapNotNull { pd ->
val doc = modulesAndPackagesDocumentation[Pair(module.name, pd)]
- val facade = context.platforms[pd]?.facade
- ?: return@mapNotNull null.also { context.logger.warn("Could not find platform data for ${pd.moduleName}/${pd.sourceSetID}") }
+ val facade = kotlinAnalysis[pd].facade
val descriptor = facade.moduleDescriptor.getPackage(FqName(it.name.let { if(it == "[JS root]") "" else it }))
doc?.get("Package")?.get(it.name)?.run {
pd to MarkdownParser(
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ReportUndocumentedTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ReportUndocumentedTransformer.kt
index 7d475571..0b47345d 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/ReportUndocumentedTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/ReportUndocumentedTransformer.kt
@@ -2,6 +2,7 @@ package org.jetbrains.dokka.base.transformers.documentables
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.DokkaConfiguration.PassConfiguration
+import org.jetbrains.dokka.analysis.DescriptorDocumentableSource
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
diff --git a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt
index 57655a9d..0d133a65 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt
@@ -1,11 +1,11 @@
package org.jetbrains.dokka.base.transformers.pages.samples
import com.intellij.psi.PsiElement
-import org.jetbrains.dokka.DokkaGenerator
-import org.jetbrains.dokka.EnvironmentAndFacade
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.analysis.AnalysisEnvironment
+import org.jetbrains.dokka.analysis.DokkaMessageCollector
import org.jetbrains.dokka.analysis.DokkaResolutionFacade
+import org.jetbrains.dokka.analysis.EnvironmentAndFacade
import org.jetbrains.dokka.base.renderers.platforms
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.SourceSetData
@@ -41,7 +41,7 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer {
}
private fun setUpAnalysis(context: DokkaContext) = context.configuration.passesConfigurations.map {
- context.sourceSet(it) to AnalysisEnvironment(DokkaGenerator.DokkaMessageCollector(context.logger), it.analysisPlatform).run {
+ context.sourceSet(it) to AnalysisEnvironment(DokkaMessageCollector(context.logger), it.analysisPlatform).run {
if (analysisPlatform == Platform.jvm) {
addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre())
}
@@ -57,11 +57,16 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer {
}
}.toMap()
- private fun ContentNode.addSample(contentPage: ContentPage, platform: SourceSetData, fqName: String, analysis: Map<SourceSetData, EnvironmentAndFacade>): ContentNode {
- val facade = analysis[platform]?.facade ?:
- return this.also { context.logger.warn("Cannot resolve facade for platform ${platform.moduleName}")}
- val psiElement = fqNameToPsiElement(facade, fqName) ?:
- return this.also { context.logger.warn("Cannot find PsiElement corresponding to $fqName") }
+ private fun ContentNode.addSample(
+ contentPage: ContentPage,
+ platform: SourceSetData,
+ fqName: String,
+ analysis: Map<SourceSetData, EnvironmentAndFacade>
+ ): ContentNode {
+ val facade = analysis[platform]?.facade
+ ?: return this.also { context.logger.warn("Cannot resolve facade for platform ${platform.moduleName}") }
+ val psiElement = fqNameToPsiElement(facade, fqName)
+ ?: return this.also { context.logger.warn("Cannot find PsiElement corresponding to $fqName") }
val imports = processImports(psiElement) // TODO: Process somehow imports. Maybe just attach them at the top of each body
val body = processBody(psiElement)
val node = contentCode(contentPage.platforms(), contentPage.dri, body, "kotlin")
@@ -70,10 +75,14 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer {
}
private fun ContentNode.dfs(fqName: String, node: ContentCode): ContentNode {
- return when(this) {
+ return when (this) {
is ContentHeader -> copy(children.map { it.dfs(fqName, node) })
is ContentDivergentGroup -> copy(children.map { it.dfs(fqName, node) } as List<ContentDivergentInstance>)
- is ContentDivergentInstance -> copy(before.let { it?.dfs(fqName, node) }, divergent.let { it.dfs(fqName, node) }, after.let { it?.dfs(fqName, node) })
+ is ContentDivergentInstance -> copy(
+ before.let { it?.dfs(fqName, node) },
+ divergent.dfs(fqName, node),
+ after.let { it?.dfs(fqName, node) }
+ )
is ContentCode -> copy(children.map { it.dfs(fqName, node) })
is ContentDRILink -> copy(children.map { it.dfs(fqName, node) })
is ContentResolvedLink -> copy(children.map { it.dfs(fqName, node) })
@@ -90,10 +99,14 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer {
private fun fqNameToPsiElement(resolutionFacade: DokkaResolutionFacade, functionName: String): PsiElement? {
val packageName = functionName.takeWhile { it != '.' }
- val descriptor = resolutionFacade.resolveSession.getPackageFragment(FqName(packageName)) ?:
- return null.also { context.logger.warn("Cannot find descriptor for package $packageName") }
- val symbol = resolveKDocSampleLink(BindingContext.EMPTY, resolutionFacade, descriptor, functionName.split(".")).firstOrNull() ?:
- return null.also { context.logger.warn("Unresolved function $functionName in @sample") }
+ val descriptor = resolutionFacade.resolveSession.getPackageFragment(FqName(packageName))
+ ?: return null.also { context.logger.warn("Cannot find descriptor for package $packageName") }
+ val symbol = resolveKDocSampleLink(
+ BindingContext.EMPTY,
+ resolutionFacade,
+ descriptor,
+ functionName.split(".")
+ ).firstOrNull() ?: return null.also { context.logger.warn("Unresolved function $functionName in @sample") }
return DescriptorToSourceUtils.descriptorToDeclaration(symbol)
}
diff --git a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
index 8113d277..7603c80b 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
@@ -3,11 +3,11 @@ package org.jetbrains.dokka.base.transformers.pages.sourcelinks
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiDocumentManager
import org.jetbrains.dokka.DokkaConfiguration
+import org.jetbrains.dokka.analysis.DescriptorDocumentableSource
+import org.jetbrains.dokka.analysis.PsiDocumentableSource
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
-import org.jetbrains.dokka.model.DescriptorDocumentableSource
import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.model.DocumentableSource
-import org.jetbrains.dokka.model.PsiDocumentableSource
import org.jetbrains.dokka.model.WithExpectActual
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index 49d8ae0f..cefea4ec 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -1,6 +1,6 @@
package org.jetbrains.dokka.base.translators.descriptors
-import org.jetbrains.dokka.analysis.DokkaResolutionFacade
+import org.jetbrains.dokka.analysis.*
import org.jetbrains.dokka.links.*
import org.jetbrains.dokka.links.Callable
import org.jetbrains.dokka.model.*
@@ -8,7 +8,7 @@ import org.jetbrains.dokka.model.Nullable
import org.jetbrains.dokka.model.TypeConstructor
import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.model.properties.PropertyContainer
-import org.jetbrains.dokka.parsers.MarkdownParser
+import org.jetbrains.dokka.base.parsers.MarkdownParser
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.sources.SourceToDocumentableTranslator
import org.jetbrains.dokka.utilities.DokkaLogger
@@ -52,18 +52,19 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue as ConstantsEnumValue
import org.jetbrains.kotlin.resolve.constants.KClassValue as ConstantsKtClassValue
import kotlin.IllegalArgumentException
-object DefaultDescriptorToDocumentableTranslator : SourceToDocumentableTranslator {
+class DefaultDescriptorToDocumentableTranslator(
+ private val kotlinAnalysis: KotlinAnalysis
+) : SourceToDocumentableTranslator {
override fun invoke(sourceSet: SourceSetData, context: DokkaContext): DModule {
-
- val (environment, facade) = context.platforms.getValue(sourceSet)
+ val (environment, facade) = kotlinAnalysis[sourceSet]
val packageFragments = environment.getSourceFiles().asSequence()
.map { it.packageFqName }
.distinct()
.mapNotNull { facade.resolveSession.getPackageFragment(it) }
.toList()
- return DokkaDescriptorVisitor(sourceSet, context.platforms.getValue(sourceSet).facade, context.logger).run {
+ return DokkaDescriptorVisitor(sourceSet, kotlinAnalysis[sourceSet].facade, context.logger).run {
packageFragments.mapNotNull { it.safeAs<PackageFragmentDescriptor>() }.map {
visitPackageFragmentDescriptor(
it,
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index a5117b09..e71d936a 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -7,6 +7,10 @@ import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.*
import com.intellij.psi.impl.source.PsiClassReferenceType
import com.intellij.psi.impl.source.PsiImmediateClassType
+import org.jetbrains.dokka.analysis.KotlinAnalysis
+import org.jetbrains.dokka.analysis.PsiDocumentableSource
+import org.jetbrains.dokka.analysis.from
+import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.nextTarget
import org.jetbrains.dokka.links.withClass
@@ -17,6 +21,7 @@ import org.jetbrains.dokka.model.doc.Param
import org.jetbrains.dokka.model.doc.Text
import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.transformers.sources.SourceToDocumentableTranslator
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation
@@ -33,15 +38,17 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.io.File
-object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
+class DefaultPsiToDocumentableTranslator(
+ private val kotlinAnalysis: KotlinAnalysis
+) : SourceToDocumentableTranslator {
- override fun invoke(sourceSetData: SourceSetData, context: DokkaContext): DModule {
+ override fun invoke(sourceSet: SourceSetData, context: DokkaContext): DModule {
fun isFileInSourceRoots(file: File): Boolean {
- return sourceSetData.sourceRoots.any { root -> file.path.startsWith(File(root.path).absolutePath) }
+ return sourceSet.sourceRoots.any { root -> file.path.startsWith(File(root.path).absolutePath) }
}
- val (environment, _) = context.platforms.getValue(sourceSetData)
+ val (environment, _) = kotlinAnalysis[sourceSet]
val sourceRoots = environment.configuration.get(CLIConfigurationKeys.CONTENT_ROOTS)
?.filterIsInstance<JavaSourceRoot>()
@@ -59,11 +66,11 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
val docParser =
DokkaPsiParser(
- sourceSetData,
+ sourceSet,
context.logger
)
return DModule(
- sourceSetData.moduleName,
+ sourceSet.moduleName,
psiFiles.mapNotNull { it.safeAs<PsiJavaFile>() }.groupBy { it.packageName }.map { (packageName, psiFiles) ->
val dri = DRI(packageName = packageName)
DPackage(
@@ -76,12 +83,12 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator {
emptyList(),
emptyMap(),
null,
- setOf(sourceSetData)
+ setOf(sourceSet)
)
},
emptyMap(),
null,
- setOf(sourceSetData)
+ setOf(sourceSet)
)
}
diff --git a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
index d8130974..7119ba68 100644
--- a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
@@ -6,6 +6,7 @@ import com.intellij.psi.impl.source.tree.JavaDocElementType
import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.javadoc.*
import com.intellij.psi.util.PsiTreeUtil
+import org.jetbrains.dokka.analysis.from
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.model.doc.Deprecated
diff --git a/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt b/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt
index 2c805110..d548b75b 100644
--- a/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt
+++ b/plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt
@@ -28,7 +28,7 @@ class FailOnWarningTest : AbstractCoreTest() {
|package sample
""".trimIndent(), configuration
) {
- analysisSetupStage = {
+ pluginsSetupStage = {
logger.warn("Warning!")
}
}
@@ -53,7 +53,7 @@ class FailOnWarningTest : AbstractCoreTest() {
|package sample
""".trimIndent(), configuration
) {
- analysisSetupStage = {
+ pluginsSetupStage = {
logger.error("Error!")
}
}
@@ -102,7 +102,7 @@ class FailOnWarningTest : AbstractCoreTest() {
|package sample
""".trimIndent(), configuration
) {
- analysisSetupStage = {
+ pluginsSetupStage = {
logger.warn("Error!")
logger.error("Error!")
}
diff --git a/plugins/build.gradle.kts b/plugins/build.gradle.kts
index d681cf2a..bb3b1a3d 100644
--- a/plugins/build.gradle.kts
+++ b/plugins/build.gradle.kts
@@ -6,8 +6,9 @@ subprojects {
dependencies {
compileOnly(project(":core"))
-// compileOnly(project(":coreDependencies", configuration = "shadow")) // uncomment if IntelliJ does not recognize pacakges from IntelliJ
implementation(kotlin("stdlib-jdk8"))
+ implementation(kotlin("stdlib"))
+ implementation(kotlin("reflect"))
testImplementation(project(":testApi"))
testImplementation("org.junit.jupiter:junit-jupiter:5.6.0")
diff --git a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt
index c148a440..becacd26 100644
--- a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt
+++ b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt
@@ -2,6 +2,9 @@ package javadoc.pages
import com.intellij.psi.PsiClass
import org.jetbrains.dokka.Platform
+import org.jetbrains.dokka.analysis.DescriptorDocumentableSource
+import org.jetbrains.dokka.analysis.PsiDocumentableSource
+import org.jetbrains.dokka.analysis.from
import org.jetbrains.dokka.base.renderers.platforms
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
diff --git a/plugins/javadoc/src/test/kotlin/javadoc/JavadocTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/JavadocTest.kt
index 45e97945..905cb61b 100644
--- a/plugins/javadoc/src/test/kotlin/javadoc/JavadocTest.kt
+++ b/plugins/javadoc/src/test/kotlin/javadoc/JavadocTest.kt
@@ -66,4 +66,4 @@ class JavadocTest : AbstractCoreTest() {
// }
// }
// }
-} \ No newline at end of file
+}
diff --git a/runners/cli/build.gradle.kts b/runners/cli/build.gradle.kts
index 6c3a4d7d..8c4955ca 100644
--- a/runners/cli/build.gradle.kts
+++ b/runners/cli/build.gradle.kts
@@ -12,6 +12,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-cli-jvm:0.2.1")
implementation("com.google.code.gson:gson:2.8.5")
implementation(project(":core"))
+ implementation(kotlin("stdlib"))
}
diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt
index f0df08e0..80971ae2 100644
--- a/runners/cli/src/main/kotlin/cli/main.kt
+++ b/runners/cli/src/main/kotlin/cli/main.kt
@@ -5,7 +5,7 @@ import kotlinx.cli.*
import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink
import org.jetbrains.dokka.DokkaConfiguration.PassConfiguration.*
import org.jetbrains.dokka.utilities.DokkaConsoleLogger
-import org.jetbrains.kotlin.utils.addToStdlib.cast
+import org.jetbrains.dokka.utilities.cast
import java.io.*
import java.net.MalformedURLException
import java.net.URL
diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt
index b7961b6e..41d6e67a 100644
--- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt
+++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/main.kt
@@ -3,6 +3,7 @@ package org.jetbrains.dokka.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
+import org.gradle.api.attributes.Usage
import org.gradle.util.GradleVersion
import java.io.File
import java.io.InputStream
@@ -20,9 +21,8 @@ open class DokkaPlugin : Plugin<Project> {
val pluginsConfiguration = project.configurations.create("dokkaPlugins").apply {
dependencies.add(project.dependencies.create("org.jetbrains.dokka:dokka-base:${DokkaVersion.version}"))
attributes.attribute(
- org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE,
- project.objects.named(org.gradle.api.attributes.Usage::class.java, "java-runtime")
- )
+ Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime")
+ )
isCanBeConsumed = false
}
addDokkaTasks(project, dokkaRuntimeConfiguration, pluginsConfiguration, DokkaTask::class.java)
diff --git a/settings.gradle.kts b/settings.gradle.kts
index c813518d..bb91edc6 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -1,13 +1,15 @@
rootProject.name = "dokka"
include("core")
+include("core:dependencies")
include("plugins:base:search-component")
-include("coreDependencies")
include("testApi")
include("test-tools")
include("runners:gradle-plugin")
include("runners:cli")
include("runners:maven-plugin")
+include("kotlin-analysis")
+include("kotlin-analysis:dependencies")
include("plugins:base")
include("plugins:base:frontend")
include("plugins:mathjax")
@@ -27,7 +29,7 @@ pluginManagement {
}
repositories {
- maven(url="https://dl.bintray.com/kotlin/kotlin-dev/")
+ maven(url = "https://dl.bintray.com/kotlin/kotlin-dev/")
mavenLocal()
mavenCentral()
jcenter()
diff --git a/test-tools/build.gradle.kts b/test-tools/build.gradle.kts
index 7fd8a879..a61787a8 100644
--- a/test-tools/build.gradle.kts
+++ b/test-tools/build.gradle.kts
@@ -1,5 +1,6 @@
dependencies {
implementation(project(":testApi"))
implementation(kotlin("stdlib-jdk8"))
+ implementation(kotlin("reflect"))
implementation("com.willowtreeapps.assertk:assertk-jvm:0.22")
} \ No newline at end of file
diff --git a/testApi/build.gradle.kts b/testApi/build.gradle.kts
index 43c984b5..c8b510a1 100644
--- a/testApi/build.gradle.kts
+++ b/testApi/build.gradle.kts
@@ -7,8 +7,10 @@ plugins {
dependencies {
api(project(":core"))
+ implementation(project(":kotlin-analysis"))
implementation("junit:junit:4.13") // TODO: remove dependency to junit
implementation(kotlin("stdlib"))
+ implementation(kotlin("reflect"))
}
val sourceJar by tasks.registering(Jar::class) {
diff --git a/testApi/src/main/kotlin/testApi/context/MockContext.kt b/testApi/src/main/kotlin/testApi/context/MockContext.kt
index 11520280..e3da5f68 100644
--- a/testApi/src/main/kotlin/testApi/context/MockContext.kt
+++ b/testApi/src/main/kotlin/testApi/context/MockContext.kt
@@ -1,7 +1,6 @@
package org.jetbrains.dokka.testApi.context
import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.dokka.EnvironmentAndFacade
import org.jetbrains.dokka.model.SourceSetCache
import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.plugability.DokkaContext
@@ -16,7 +15,6 @@ import kotlin.reflect.full.memberProperties
class MockContext(
vararg extensions: Pair<ExtensionPoint<*>, (DokkaContext) -> Any>,
private val testConfiguration: DokkaConfiguration? = null,
- private val testSourceSets: Map<SourceSetData, EnvironmentAndFacade>? = null,
private val unusedExtensionPoints: List<ExtensionPoint<*>>? = null,
override val sourceSetCache: SourceSetCache
) : DokkaContext {
@@ -41,8 +39,6 @@ class MockContext(
override val configuration: DokkaConfiguration
get() = testConfiguration ?: throw IllegalStateException("This mock context doesn't provide configuration")
- override val platforms: Map<SourceSetData, EnvironmentAndFacade>
- get() = testSourceSets ?: throw IllegalStateException("This mock context doesn't provide platforms data")
override val unusedPoints: Collection<ExtensionPoint<*>>
get() = unusedExtensionPoints
?: throw IllegalStateException("This mock context doesn't provide unused extension points")
diff --git a/testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt b/testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt
index 2ca8523b..7248a4cb 100644
--- a/testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt
+++ b/testApi/src/main/kotlin/testApi/testRunner/DokkaTestGenerator.kt
@@ -2,7 +2,6 @@ package org.jetbrains.dokka.testApi.testRunner
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.DokkaGenerator
-import org.jetbrains.dokka.EnvironmentAndFacade
import org.jetbrains.dokka.model.SourceSetCache
import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.plugability.DokkaPlugin
@@ -19,17 +18,11 @@ internal class DokkaTestGenerator(
val dokkaGenerator = DokkaGenerator(configuration, logger)
val sourceSetsCache = SourceSetCache()
- val platforms: Map<SourceSetData, EnvironmentAndFacade> = dokkaGenerator.setUpAnalysis(
- configuration,
- sourceSetsCache
- )
- analysisSetupStage(platforms)
-
val context =
- dokkaGenerator.initializePlugins(configuration, logger, platforms, sourceSetsCache, pluginOverrides)
+ dokkaGenerator.initializePlugins(configuration, logger, sourceSetsCache, pluginOverrides)
pluginsSetupStage(context)
- val modulesFromPlatforms = dokkaGenerator.createDocumentationModels(platforms, context)
+ val modulesFromPlatforms = dokkaGenerator.createDocumentationModels(context, sourceSetsCache)
documentablesCreationStage(modulesFromPlatforms)
val filteredModules = dokkaGenerator.transformDocumentationModelBeforeMerge(modulesFromPlatforms, context)
diff --git a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt
index 9df20138..88595f85 100644
--- a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt
+++ b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt
@@ -106,7 +106,6 @@ abstract class AbstractCoreTest {
}
protected class TestBuilder {
- var analysisSetupStage: (Map<SourceSetData, EnvironmentAndFacade>) -> Unit = {}
var pluginsSetupStage: (DokkaContext) -> Unit = {}
var documentablesCreationStage: (List<DModule>) -> Unit = {}
var documentablesFirstTransformationStep: (List<DModule>) -> Unit = {}
@@ -118,7 +117,6 @@ abstract class AbstractCoreTest {
@PublishedApi
internal fun build() = TestMethods(
- analysisSetupStage,
pluginsSetupStage,
documentablesCreationStage,
documentablesFirstTransformationStep,
@@ -240,7 +238,6 @@ abstract class AbstractCoreTest {
}
data class TestMethods(
- val analysisSetupStage: (Map<SourceSetData, EnvironmentAndFacade>) -> Unit,
val pluginsSetupStage: (DokkaContext) -> Unit,
val documentablesCreationStage: (List<DModule>) -> Unit,
val documentablesFirstTransformationStep: (List<DModule>) -> Unit,