-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f9bb7d
commit 63ef755
Showing
48 changed files
with
478 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } ?: "") | ||
} |
Oops, something went wrong.