diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CommentsAPI.kt | 14 | ||||
-rw-r--r-- | src/PsiAPI.kt | 19 | ||||
-rw-r--r-- | src/main.kt | 5 |
3 files changed, 38 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? +} diff --git a/src/PsiAPI.kt b/src/PsiAPI.kt new file mode 100644 index 00000000..9f43730b --- /dev/null +++ b/src/PsiAPI.kt @@ -0,0 +1,19 @@ +package com.jetbrains.dokka + +import com.intellij.psi.PsiElement +import kotlin.support.AbstractIterator + +fun PsiElement.previousSiblings(): Stream<PsiElement> { + var element: PsiElement? = this + return object : Stream<PsiElement> { + override fun iterator(): Iterator<PsiElement> = object : AbstractIterator<PsiElement>() { + override fun computeNext() { + element = element?.getPrevSibling() + if (element == null) + done() + else + setNext(element!!) + } + } + } +} diff --git a/src/main.kt b/src/main.kt index 8b550999..3083ba90 100644 --- a/src/main.kt +++ b/src/main.kt @@ -52,5 +52,10 @@ fun BindingContext.analyseFile(file: JetFile) { println("Package: ${packageFragment}") for (descriptor in packageFragment.getMemberScope().getAllDescriptors()) { println("Member: ${descriptor}") + val doc = getComments(descriptor) + if (doc != null) { + println("Comment: ${doc.getText()}") + } + println() } } |