aboutsummaryrefslogtreecommitdiff
path: root/src/Model/DocumentationResolver.kt
blob: 40968f4fc95391f91e6c2f8ddd0c4c7af73de989 (plain)
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
package org.jetbrains.dokka

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

fun DocumentationNode.resolve() {
    for (item in details + members) {
        val symbolName = item.name
        val symbol: DeclarationDescriptor? = when (item.kind) {
            DocumentationNodeKind.Receiver -> (scope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter()
            DocumentationNodeKind.Parameter -> scope.getLocalVariable(Name.guess(symbolName))
            DocumentationNodeKind.Function -> scope.getFunctions(Name.guess(symbolName)).firstOrNull()
            DocumentationNodeKind.Property -> scope.getProperties(Name.guess(symbolName)).firstOrNull()
            DocumentationNodeKind.Constructor -> scope.getFunctions(Name.guess(symbolName)).firstOrNull()

            DocumentationNodeKind.Package -> {
                // TODO: do not resolve constructors and packages for now
                item.scope.getContainingDeclaration()
            }
            else -> scope.getClassifier(Name.guess(symbolName))
        }

        if (symbol == null)
            throw IllegalStateException("Cannot resolve $item in $this")
    }

    for (reference in allReferences().filterNot { it.kind == DocumentationReferenceKind.Owner }) {
        reference.to.resolve()
    }
}

fun DocumentationModel.resolveAll() {
    resolve()
}