org.jetbrains.dokka.analysis.DRIFactory.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dokka-analysis Show documentation
Show all versions of dokka-analysis Show documentation
Dokka is an API documentation engine for Kotlin and Java, performing the same function as Javadoc for Java
package org.jetbrains.dokka.analysis
import com.intellij.psi.*
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 parameter = firstIsInstanceOrNull()
val callable = parameter?.containingDeclaration ?: firstIsInstanceOrNull()
DRI(
firstIsInstanceOrNull()?.fqName?.asString() ?: "",
(filterIsInstance() + filterIsInstance()).toList()
.takeIf { it.isNotEmpty() }
?.asReversed()
?.joinToString(separator = ".") { it.name.asString() },
callable?.let { Callable.from(it) },
DriTarget.from(parameter ?: descriptor)
)
}
fun DRI.Companion.from(psi: PsiElement) = psi.parentsWithSelf.run {
val psiMethod = firstIsInstanceOrNull()
val psiField = firstIsInstanceOrNull()
val classes = filterIsInstance().filterNot { it is PsiTypeParameter }
.toList() // We only want exact PsiClass types, not PsiTypeParameter subtype
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)
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy