aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Mashkov <sergey.mashkov@jetbrains.com>2015-07-24 16:39:02 +0300
committerSergey Mashkov <sergey.mashkov@jetbrains.com>2015-07-24 16:39:02 +0300
commitd874444314ba60427a21d01585a7e632fc6d4bb0 (patch)
treefb87d7ebe8353936df43018045b5aa4611566289
parent891cdbbe19580ee2379e3b7cfe269109bf897d84 (diff)
downloaddokka-d874444314ba60427a21d01585a7e632fc6d4bb0.tar.gz
dokka-d874444314ba60427a21d01585a7e632fc6d4bb0.tar.bz2
dokka-d874444314ba60427a21d01585a7e632fc6d4bb0.zip
Rework toDocumentationNode function to use ConstantValue<*> instead of any?
-rw-r--r--src/Kotlin/DocumentationBuilder.kt27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt
index 6c0b7b03..eda69841 100644
--- a/src/Kotlin/DocumentationBuilder.kt
+++ b/src/Kotlin/DocumentationBuilder.kt
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.JetParameter
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
+import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
@@ -686,7 +687,7 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade,
val node = DocumentationNode(annotationClass.getName().asString(), Content.Empty, DocumentationNode.Kind.Annotation)
val arguments = getAllValueArguments().toList().sortBy { it.first.getIndex() }
arguments.forEach {
- val valueNode = it.second.value.toDocumentationNode()
+ val valueNode = it.second.toDocumentationNode()
if (valueNode != null) {
val paramNode = DocumentationNode(it.first.getName().asString(), Content.Empty, DocumentationNode.Kind.Parameter)
paramNode.append(valueNode, DocumentationReference.Kind.Detail)
@@ -696,18 +697,20 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade,
return node
}
- fun CompileTimeConstant<Any?>.build(): DocumentationNode? {
- val value: Any? = if (this is TypedCompileTimeConstant) getValue(type) else null
- return value.toDocumentationNode()
+ fun CompileTimeConstant<Any?>.build(): DocumentationNode? = when (this) {
+ is TypedCompileTimeConstant -> constantValue.toDocumentationNode()
+ else -> null
}
- private fun Any?.toDocumentationNode(): DocumentationNode? = when (this) {
- is String ->
- "\"" + StringUtil.escapeStringCharacters(this) + "\""
- is EnumEntrySyntheticClassDescriptor ->
- getContainingDeclaration().getName().asString() + "." + getName()
- else -> this?.toString()
- }.let { valueString ->
- if (valueString != null) DocumentationNode(valueString, Content.Empty, DocumentationNode.Kind.Value) else null
+ fun ConstantValue<*>.toDocumentationNode(): DocumentationNode? = value?.let { value ->
+ when (value) {
+ is String ->
+ "\"" + StringUtil.escapeStringCharacters(value) + "\""
+ is EnumEntrySyntheticClassDescriptor ->
+ value.containingDeclaration.name.asString() + "." + value.name.asString()
+ else -> value.toString()
+ }.let { valueString ->
+ DocumentationNode(valueString, Content.Empty, DocumentationNode.Kind.Value)
+ }
}
}