aboutsummaryrefslogtreecommitdiff
path: root/src/Model/DocumentationResolver.kt
blob: dee68f494571afe34d2f4ee0cd2659c4e4d9ecb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package org.jetbrains.dokka

import org.jetbrains.jet.lang.resolve.scopes.*
import org.jetbrains.jet.lang.resolve.name.*
import org.jetbrains.jet.lang.descriptors.*

fun DocumentationNode.resolve(): DocumentationNode {
    for (detail in details) {
        val symbol: DeclarationDescriptor? = when (detail.kind) {
            DocumentationNodeKind.Receiver -> (scope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter()
            DocumentationNodeKind.Parameter -> scope.getLocalVariable(Name.guess(detail.name))
            DocumentationNodeKind.Function -> scope.getFunctions(Name.guess(detail.name)).firstOrNull()
            DocumentationNodeKind.Property -> scope.getProperties(Name.guess(detail.name)).firstOrNull()
            DocumentationNodeKind.TypeParameter -> scope.getClassifier(Name.guess(detail.name))
            else -> scope.getClassifier(Name.guess(detail.name))
        }

        if (symbol == null)
            throw IllegalStateException("Cannot resolve node $this detail $detail")
    }
    return this
}