aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Diagnostics.kt
blob: 470d797371f75a9fbbaed25cc526f2fb520bebf4 (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
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 BindingContext.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.descriptor)
        for (item in node.details + node.members) {
            val symbolName = item.name
            val symbol: DeclarationDescriptor? = when (item.kind) {
                DocumentationNode.Kind.Receiver -> (parentScope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter()
                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"
}