aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Diagnostics.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Diagnostics.kt')
-rw-r--r--src/Model/Diagnostics.kt40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Model/Diagnostics.kt b/src/Model/Diagnostics.kt
new file mode 100644
index 00000000..78d711a0
--- /dev/null
+++ b/src/Model/Diagnostics.kt
@@ -0,0 +1,40 @@
+package org.jetbrains.dokka
+
+import org.jetbrains.jet.lang.descriptors.*
+import org.jetbrains.jet.lang.resolve.name.*
+
+fun DocumentationNode.checkResolve() {
+ val parentScope = scope
+
+ for (item in details + members) {
+ val symbolName = item.name
+ val symbol: DeclarationDescriptor? = when (item.kind) {
+ DocumentationNodeKind.Receiver -> (parentScope.getContainingDeclaration() as FunctionDescriptor).getReceiverParameter()
+ DocumentationNodeKind.Parameter -> parentScope.getLocalVariable(Name.guess(symbolName))
+ DocumentationNodeKind.Function -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull()
+ DocumentationNodeKind.Property -> parentScope.getProperties(Name.guess(symbolName)).firstOrNull()
+ DocumentationNodeKind.Constructor -> parentScope.getFunctions(Name.guess(symbolName)).firstOrNull()
+
+ DocumentationNodeKind.Package -> {
+ // TODO: do not resolve constructors and packages for now
+ item.scope.getContainingDeclaration()
+ }
+ else -> parentScope.getClassifier(Name.guess(symbolName))
+ }
+
+ if (symbol == null)
+ println("WARNING: Cannot resolve $item in ${path(this)}")
+ }
+
+ for (reference in allReferences().filterNot { it.kind == DocumentationReferenceKind.Owner }) {
+ reference.to.checkResolve()
+ }
+}
+
+fun path(node: DocumentationNode): String {
+ val owner = node.owner
+ if (owner != null)
+ return "$node in ${path(owner)}"
+ else
+ return "$node"
+} \ No newline at end of file