aboutsummaryrefslogtreecommitdiff
path: root/src/Kotlin/Diagnostics.kt
blob: 5548bc0168711a80890e5d6b80b2074c84c41b29 (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
35
36
37
38
39
40
package org.jetbrains.dokka

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

fun DocumentationContext.checkResolveChildren(node: DocumentationNode) {
    if (node.kind != DocumentationNode.Kind.Module && node.kind != DocumentationNode.Kind.Package) {
        // TODO: we don't resolve packages and modules for now

        val parentScope = getResolutionScope(node)
        for (item in node.details + node.members) {
            val symbolName = item.name
            val symbol: DeclarationDescriptor? = when (item.kind) {
                DocumentationNode.Kind.Modifier -> continue // do not resolve modifiers, they are not names
                DocumentationNode.Kind.Receiver -> continue // what is receiver's name in platform?
                DocumentationNode.Kind.Parameter -> parentScope.getLocalVariable(Name.guess(symbolName))
                DocumentationNode.Kind.Function -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull()
                DocumentationNode.Kind.Property -> parentScope.getProperties(Name.guess(symbolName)).firstOrNull()
                DocumentationNode.Kind.Constructor -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull()
                else -> parentScope.getClassifier(Name.guess(symbolName))
            }

            if (symbol == null)
                println("WARNING: Cannot resolve $item in ${path(node)}")
        }
    }

    for (reference in node.allReferences().filterNot { it.kind == DocumentationReference.Kind.Owner }) {
        checkResolveChildren(reference.to)
    }
}

fun path(node: DocumentationNode): String {
    val owner = node.owner
    if (owner != null)
        return "$node in ${path(owner)}"
    else
        return "$node"
}