• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.jetbrains.dokka
2 
3 import com.intellij.psi.PsiElement
4 import com.intellij.psi.PsiMember
5 import com.intellij.psi.PsiPackage
6 import org.jetbrains.kotlin.asJava.elements.KtLightElement
7 import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
8 import org.jetbrains.kotlin.name.FqName
9 import org.jetbrains.kotlin.resolve.BindingContext
10 import javax.inject.Inject
11 
12 class KotlinElementSignatureProvider @Inject constructor(
13         val resolutionFacade: DokkaResolutionFacade
14 ) : ElementSignatureProvider {
signaturenull15     override fun signature(forPsi: PsiElement): String {
16         return forPsi.extractDescriptor(resolutionFacade)
17                 ?.let { signature(it) }
18                 ?: run { "no desc for $forPsi in ${(forPsi as? PsiMember)?.containingClass}" }
19     }
20 
signaturenull21     override fun signature(forDesc: DeclarationDescriptor): String = forDesc.signature()
22 }
23 
24 
25 fun PsiElement.extractDescriptor(resolutionFacade: DokkaResolutionFacade): DeclarationDescriptor? {
26     val forPsi = this
27 
28     return when (forPsi) {
29         is KtLightElement<*, *> -> return (forPsi.kotlinOrigin!!).extractDescriptor(resolutionFacade)
30         is PsiPackage -> resolutionFacade.moduleDescriptor.getPackage(FqName(forPsi.qualifiedName))
31         is PsiMember -> forPsi.getJavaOrKotlinMemberDescriptor(resolutionFacade)
32         else -> resolutionFacade.resolveSession.bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, forPsi]
33     }
34 }
35