aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Kotlin
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2016-11-08 20:21:15 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2016-11-14 14:06:29 +0300
commitaf81d5a311125fc30dcf9c14fc9bd9c8680e532b (patch)
treec4e299cddad96b00880a9f31f2969f4f7ed2a964 /core/src/main/kotlin/Kotlin
parentd8be364a89ab7d9f38196ef17d0d4eb1d9659b48 (diff)
downloaddokka-af81d5a311125fc30dcf9c14fc9bd9c8680e532b.tar.gz
dokka-af81d5a311125fc30dcf9c14fc9bd9c8680e532b.tar.bz2
dokka-af81d5a311125fc30dcf9c14fc9bd9c8680e532b.zip
Now all sample blocks in kotlin-website wrapped in <div class="sample" markdown="1">...</div>
And small refactoring
Diffstat (limited to 'core/src/main/kotlin/Kotlin')
-rw-r--r--core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt22
1 files changed, 12 insertions, 10 deletions
diff --git a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt
index 941d071d..2fc268e8 100644
--- a/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt
+++ b/core/src/main/kotlin/Kotlin/DescriptorDocumentationParser.kt
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.kdoc.findKDoc
import org.jetbrains.kotlin.idea.kdoc.getKDocLinkResolutionScope
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
+import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
@@ -60,10 +61,10 @@ class DescriptorDocumentationParser
if (kdoc is KDocSection) {
val tags = kdoc.getTags()
tags.forEach {
- when (it.name) {
- "sample" ->
+ when (it.knownTag) {
+ KDocKnownTag.SAMPLE ->
content.append(functionBody(descriptor, it.getSubjectName()))
- "see" ->
+ KDocKnownTag.SEE ->
content.addTagToSeeAlso(descriptor, it)
else -> {
val section = content.addSection(javadocSectionDisplayName(it.name), it.getSubjectName())
@@ -147,7 +148,7 @@ class DescriptorDocumentationParser
private fun functionBody(descriptor: DeclarationDescriptor, functionName: String?): ContentNode {
if (functionName == null) {
logger.warn("Missing function name in @sample in ${descriptor.signature()}")
- return ContentBlockCode().let() { it.append(ContentText("Missing function name in @sample")); it }
+ return ContentBlockSampleCode().let { it.append(ContentText("//Missing function name in @sample")); it }
}
val scope = getKDocLinkResolutionScope(resolutionFacade, descriptor)
val rootPackage = resolutionFacade.moduleDescriptor.getPackage(FqName.ROOT)
@@ -155,16 +156,16 @@ class DescriptorDocumentationParser
val symbol = resolveInScope(functionName, scope) ?: resolveInScope(functionName, rootScope)
if (symbol == null) {
logger.warn("Unresolved function $functionName in @sample in ${descriptor.signature()}")
- return ContentBlockCode().let() { it.append(ContentText("Unresolved: $functionName")); it }
+ return ContentBlockSampleCode().let { it.append(ContentText("//Unresolved: $functionName")); it }
}
val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(symbol)
if (psiElement == null) {
logger.warn("Can't find source for function $functionName in @sample in ${descriptor.signature()}")
- return ContentBlockCode().let() { it.append(ContentText("Source not found: $functionName")); it }
+ return ContentBlockSampleCode().let { it.append(ContentText("//Source not found: $functionName")); it }
}
val text = when (psiElement) {
- is KtDeclarationWithBody -> ContentBlockCode().let() {
+ is KtDeclarationWithBody -> ContentBlockCode().let {
val bodyExpression = psiElement.bodyExpression
when (bodyExpression) {
is KtBlockExpression -> bodyExpression.text.removeSurrounding("{", "}")
@@ -174,10 +175,10 @@ class DescriptorDocumentationParser
else -> psiElement.text
}
- val lines = text.trimEnd().split("\n".toRegex()).toTypedArray().filterNot { it.length == 0 }
- val indent = lines.map { it.takeWhile { it.isWhitespace() }.count() }.min() ?: 0
+ val lines = text.trimEnd().split("\n".toRegex()).toTypedArray().filterNot(String::isEmpty)
+ val indent = lines.map { it.takeWhile(Char::isWhitespace).count() }.min() ?: 0
val finalText = lines.map { it.drop(indent) }.joinToString("\n")
- return ContentBlockCode("kotlin").let() { it.append(ContentText(finalText)); it }
+ return ContentBlockSampleCode().let { it.append(ContentText(finalText)); it }
}
private fun resolveInScope(functionName: String, scope: ResolutionScope): DeclarationDescriptor? {
@@ -197,6 +198,7 @@ class DescriptorDocumentationParser
symbol = null
break
}
+ @Suppress("IfThenToElvis")
currentScope = if (partSymbol is ClassDescriptor)
partSymbol.defaultType.memberScope
else if (partSymbol is PackageViewDescriptor)