diff options
author | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-11 21:43:38 +0400 |
---|---|---|
committer | Ilya Ryzhenkov <orangy@jetbrains.com> | 2014-07-11 21:43:38 +0400 |
commit | a8e59d7af41ca05b68e2d916552cecbbacbf3e92 (patch) | |
tree | 34c95981c8d08fa28706ad1c8d2ccef91e2776ad /src/Analysis/CommentsAPI.kt | |
parent | 197a6e486d16d2e3689e900b45c65ef8d598f3b7 (diff) | |
download | dokka-a8e59d7af41ca05b68e2d916552cecbbacbf3e92.tar.gz dokka-a8e59d7af41ca05b68e2d916552cecbbacbf3e92.tar.bz2 dokka-a8e59d7af41ca05b68e2d916552cecbbacbf3e92.zip |
Add tests for comment extraction, support one-line and mutliple joined doc-comments.
Start primitive ConsoleGenerator to dump model.
Diffstat (limited to 'src/Analysis/CommentsAPI.kt')
-rw-r--r-- | src/Analysis/CommentsAPI.kt | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/Analysis/CommentsAPI.kt b/src/Analysis/CommentsAPI.kt index a32ee734..03b1911c 100644 --- a/src/Analysis/CommentsAPI.kt +++ b/src/Analysis/CommentsAPI.kt @@ -5,12 +5,21 @@ import org.jetbrains.jet.lang.resolve.* import org.jetbrains.jet.kdoc.psi.api.* import org.jetbrains.jet.lang.psi.* -fun BindingContext.getDocumentation(descriptor: DeclarationDescriptor): KDoc? { +fun BindingContext.getDocumentation(descriptor: DeclarationDescriptor): String { + return getDocumentationElements(descriptor).map { it.extractText() }.join("\n") +} + +fun BindingContext.getDocumentationElements(descriptor: DeclarationDescriptor): List<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? + return psiElement.previousSiblings() // go backwards + .takeWhile { it !is JetDeclaration } // till previous declaration + .filter { it is KDoc } // get KDocs + .map { it as KDoc } // cast + .toList() + .reverse() // make reversed list } fun KDoc?.extractText(): String { @@ -21,10 +30,14 @@ fun KDoc?.extractText(): String { return "" val lines = text.replace("\r", "").split("\n") return lines.map { - it.dropWhile { java.lang.Character.isWhitespace(it) } + val comment = it.trim() .dropWhile { it == '/' } .dropWhile { it == '*' } .dropWhile { it == '/' } - .dropWhile { java.lang.Character.isWhitespace(it) } + .trim() + if (comment.endsWith("*/")) + comment.substring(0, comment.length - 2).trim() + else + comment }.filter { it.any() }.join("\n") }
\ No newline at end of file |