Skip to content

Commit

Permalink
Finish the merge of master
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev committed Oct 30, 2023
1 parent 1f9bb7d commit 63ef755
Show file tree
Hide file tree
Showing 48 changed files with 478 additions and 112 deletions.
20 changes: 20 additions & 0 deletions dokka-subprojects/analysis-kotlin-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,30 @@ import dokkabuild.overridePublicationArtifactId
plugins {
id("dokkabuild.kotlin-jvm")
id("dokkabuild.publish-jvm")
`java-test-fixtures`
}

overridePublicationArtifactId("analysis-kotlin-api")

dependencies {
compileOnly(projects.dokkaCore)

testFixturesApi(projects.dokkaCore)

testImplementation(kotlin("test"))
testImplementation(projects.analysisKotlinDescriptors)
}

disableTestFixturesPublishing()

/**
* Test fixtures are automatically published by default, which at this moment in time is unwanted
* as the test api is unstable and is internal to the Dokka project, so it shouldn't be used outside of it.
*
* @see https://docs.gradle.org/current/userguide/java_testing.html#ex-disable-publishing-of-test-fixtures-variants
*/
fun disableTestFixturesPublishing() {
val javaComponent = components["java"] as AdhocComponentWithVariants
javaComponent.withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
javaComponent.withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.dokka.analysis.kotlin.symbols.services

import com.intellij.psi.PsiClass
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.analysis.java.util.from
import org.jetbrains.dokka.analysis.java.util.PsiDocumentableSource
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.analysis.kotlin.internal.InheritanceBuilder
import org.jetbrains.dokka.analysis.kotlin.internal.InheritanceNode
import org.jetbrains.dokka.analysis.kotlin.internal.InternalKotlinAnalysisPlugin
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle

/**
* This is copy-pasted from org.jetbrains.dokka.analysis.kotlin.descriptors.compiler.impl.DescriptorInheritanceBuilder and adapted for symbols
*/
internal class SymbolInheritanceBuilder(context: DokkaContext) : InheritanceBuilder {
private val symbolFullClassHierarchyBuilder =
context.plugin<InternalKotlinAnalysisPlugin>().querySingle { fullClassHierarchyBuilder }

override fun build(documentables: Map<DRI, Documentable>): List<InheritanceNode> {

// this statement is copy-pasted from the version for Descriptors
val psiInheritanceTree =
documentables.flatMap { (_, v) -> (v as? WithSources)?.sources?.values.orEmpty() }
.filterIsInstance<PsiDocumentableSource>().mapNotNull { it.psi as? PsiClass }
.flatMap(::gatherPsiClasses)
.flatMap { entry -> entry.second.map { it to entry.first } }
.let {
it + it.map { it.second to null }
}
.groupBy({ it.first }) { it.second }
.map { it.key to it.value.filterNotNull().distinct() }
.map { (k, v) ->
InheritanceNode(
DRI.from(k),
v.map { InheritanceNode(DRI.from(it)) },
k.supers.filter { it.isInterface }.map { DRI.from(it) },
k.isInterface
)

}

// copy-pasted from stdlib 1.5
fun <T, R : Any> Iterable<T>.firstNotNullOfOrNull(transform: (T) -> R?): R? {
for (element in this) {
val result = transform(element)
if (result != null) {
return result
}
}
return null
}

val jvmSourceSet =
documentables.values.firstNotNullOfOrNull { it.sourceSets.find { it.analysisPlatform == Platform.jvm } }
if (jvmSourceSet == null)
return psiInheritanceTree

val typeConstructorsMap =
(symbolFullClassHierarchyBuilder as? SymbolFullClassHierarchyBuilder)?.collectKotlinSupertypesWithKind(
documentables.values,
jvmSourceSet
)
?: throw IllegalStateException("Unexpected symbolFullClassHierarchyBuildertype") // TODO: https://github.com/Kotlin/dokka/issues/3225 Unify FullClassHierarchyBuilder and InheritanceBuilder into one builder

fun ClassKind.isInterface() = this == KotlinClassKindTypes.INTERFACE || this == JavaClassKindTypes.INTERFACE
val symbolsInheritanceTree = typeConstructorsMap.map { (dri, superclasses) ->
InheritanceNode(
dri,
superclasses.superclasses.map { InheritanceNode(it.typeConstructor.dri) },
superclasses.superclasses.filter { it.kind.isInterface() }.map { it.typeConstructor.dri },
isInterface = superclasses.typeConstructorWithKind.kind.isInterface()
)
}

return psiInheritanceTree + symbolsInheritanceTree
}

private fun gatherPsiClasses(psi: PsiClass): List<Pair<PsiClass, List<PsiClass>>> = psi.supers.toList().let { l ->
listOf(psi to l) + l.flatMap { gatherPsiClasses(it) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package org.jetbrains.dokka.analysis.kotlin.symbols.services

import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.PointingToDeclaration
import org.jetbrains.dokka.analysis.kotlin.internal.KotlinToJavaService
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap // or import kotlin.reflect.jvm.internal.impl.builtins.jvm.JavaToKotlinClassMap see https://github.com/Kotlin/dokka/issues/3226
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName

/**
* This is copy-pasted from org.jetbrains.dokka.analysis.kotlin.descriptors.compiler.impl.DescriptorKotlinToJavaMapper
*/
internal class SymbolKotlinToJavaMapper : KotlinToJavaService {

override fun findAsJava(kotlinDri: DRI): DRI? {
return kotlinDri.partialFqName().mapToJava()?.toDRI(kotlinDri)
}

private fun DRI.partialFqName() = packageName?.let { "$it." } + classNames

private fun String.mapToJava(): ClassId? =
JavaToKotlinClassMap.mapKotlinToJava(FqName(this).toUnsafe())

private fun ClassId.toDRI(dri: DRI?): DRI = DRI(
packageName = packageFqName.asString(),
classNames = classNames(),
callable = dri?.callable,//?.asJava(), TODO: check this
extra = null,
target = PointingToDeclaration
)

private fun ClassId.classNames(): String =
shortClassName.identifier + (outerClassId?.classNames()?.let { ".$it" } ?: "")
}
Loading

0 comments on commit 63ef755

Please sign in to comment.