aboutsummaryrefslogtreecommitdiff
path: root/src/CommentsAPI.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/CommentsAPI.kt')
-rw-r--r--src/CommentsAPI.kt14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/CommentsAPI.kt b/src/CommentsAPI.kt
new file mode 100644
index 00000000..4bfb19e6
--- /dev/null
+++ b/src/CommentsAPI.kt
@@ -0,0 +1,14 @@
+package com.jetbrains.dokka
+
+import org.jetbrains.jet.lang.descriptors.*
+import org.jetbrains.jet.lexer.*
+import org.jetbrains.jet.lang.resolve.*
+import org.jetbrains.jet.kdoc.psi.api.*
+import org.jetbrains.jet.lang.psi.JetDeclaration
+
+fun BindingContext.getComments(descriptor: DeclarationDescriptor): KDoc? {
+ val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)
+ if (psiElement == null) throw IllegalArgumentException("$descriptor doesn't have connection to source code, is it synthetic?")
+
+ return psiElement.previousSiblings().takeWhile { it !is JetDeclaration }.firstOrNull { it is KDoc } as KDoc?
+}