aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Kotlin/KotlinElementSignatureProvider.kt
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2018-04-24 20:35:42 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2018-07-14 23:44:08 +0300
commita3f16fd75c200020465f79563ca58b2833236865 (patch)
tree03530320492ca7e3d055a9de6efd8319485e78d2 /core/src/main/kotlin/Kotlin/KotlinElementSignatureProvider.kt
parent31a4a3804020130e7caf5826b317aaee5547c0d0 (diff)
downloaddokka-a3f16fd75c200020465f79563ca58b2833236865.tar.gz
dokka-a3f16fd75c200020465f79563ca58b2833236865.tar.bz2
dokka-a3f16fd75c200020465f79563ca58b2833236865.zip
[backport] Stabilize signatures to fix linking from Java to Kotlin
Basically there is 2 ways to get signature, from PSI and from descriptors, and there should be only one way in one session Original: adc09f2
Diffstat (limited to 'core/src/main/kotlin/Kotlin/KotlinElementSignatureProvider.kt')
-rw-r--r--core/src/main/kotlin/Kotlin/KotlinElementSignatureProvider.kt31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/src/main/kotlin/Kotlin/KotlinElementSignatureProvider.kt b/core/src/main/kotlin/Kotlin/KotlinElementSignatureProvider.kt
new file mode 100644
index 00000000..4f788634
--- /dev/null
+++ b/core/src/main/kotlin/Kotlin/KotlinElementSignatureProvider.kt
@@ -0,0 +1,31 @@
+package org.jetbrains.dokka
+
+import com.intellij.psi.PsiElement
+import com.intellij.psi.PsiMember
+import com.intellij.psi.PsiNameIdentifierOwner
+import org.jetbrains.kotlin.asJava.elements.KtLightElement
+import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
+import org.jetbrains.kotlin.resolve.BindingContext
+import javax.inject.Inject
+
+class KotlinElementSignatureProvider @Inject constructor(
+ val resolutionFacade: DokkaResolutionFacade
+) : ElementSignatureProvider {
+ override fun signature(forPsi: PsiElement): String {
+
+ val desc = when (forPsi) {
+ is KtLightElement<*, *> -> return signature(forPsi.kotlinOrigin!!)
+ is PsiMember -> forPsi.getJavaOrKotlinMemberDescriptor(resolutionFacade)
+ else -> resolutionFacade.resolveSession.bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, forPsi]
+ }
+
+ if (desc == null && (forPsi as? PsiNameIdentifierOwner)?.name == "remove") {
+ (forPsi as? PsiMember)?.getJavaOrKotlinMemberDescriptor(resolutionFacade)
+ }
+
+ return desc?.let { signature(it) }
+ ?: run { "no desc for $forPsi in ${(forPsi as? PsiMember)?.containingClass}" }
+ }
+
+ override fun signature(forDesc: DeclarationDescriptor): String = forDesc.signature()
+} \ No newline at end of file