diff options
Diffstat (limited to 'src/Kotlin/DocumentationBuilder.kt')
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index bea2f6fa..6c0b7b03 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.TypedCompileTimeConstant import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.resolve.source.PsiSourceElement import org.jetbrains.kotlin.resolve.source.getPsi @@ -685,7 +686,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.build() + val valueNode = it.second.value.toDocumentationNode() if (valueNode != null) { val paramNode = DocumentationNode(it.first.getName().asString(), Content.Empty, DocumentationNode.Kind.Parameter) paramNode.append(valueNode, DocumentationReference.Kind.Detail) @@ -695,15 +696,18 @@ class DocumentationBuilder(val resolutionFacade: ResolutionFacade, return node } - fun CompileTimeConstant<out Any?>.build(): DocumentationNode? { - val value = getValue() - val valueString = when(value) { - is String -> - "\"" + StringUtil.escapeStringCharacters(value) + "\"" - is EnumEntrySyntheticClassDescriptor -> - value.getContainingDeclaration().getName().asString() + "." + value.getName() - else -> value?.toString() - } - return if (valueString != null) DocumentationNode(valueString, Content.Empty, DocumentationNode.Kind.Value) else null + fun CompileTimeConstant<Any?>.build(): DocumentationNode? { + val value: Any? = if (this is TypedCompileTimeConstant) getValue(type) else null + return value.toDocumentationNode() + } + + 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 } } |