-
Notifications
You must be signed in to change notification settings - Fork 391
/
CallableFactory.kt
45 lines (39 loc) · 1.37 KB
/
CallableFactory.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package org.jetbrains.dokka.analysis
import com.intellij.psi.PsiField
import com.intellij.psi.PsiMethod
import org.jetbrains.dokka.links.Callable
import org.jetbrains.dokka.links.JavaClassReference
import org.jetbrains.dokka.links.TypeReference
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
fun Callable.Companion.from(descriptor: CallableDescriptor, name: String? = null) = with(descriptor) {
Callable(
name ?: descriptor.name.asString(),
extensionReceiverParameter?.let { TypeReference.from(it) },
valueParameters.mapNotNull { TypeReference.from(it) }
)
}
fun Callable.Companion.from(descriptor: LazyClassDescriptor) = Callable(
descriptor.name.asString(),
null,
emptyList()
)
fun Callable.Companion.from(descriptor: EnumEntrySyntheticClassDescriptor) = Callable(
descriptor.name.asString(),
null,
emptyList()
)
fun Callable.Companion.from(psi: PsiMethod) = with(psi) {
Callable(
name,
null,
parameterList.parameters.map { param -> JavaClassReference(param.type.canonicalText) })
}
fun Callable.Companion.from(psi: PsiField): Callable {
return Callable(
name = psi.name,
receiver = null,
params = emptyList()
)
}