From f822c51af0ca775a260f8aab010c9ccc9be8d52e Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Wed, 22 Jul 2015 20:00:50 +0300 Subject: Upgrade to latest kotlin --- src/Kotlin/DocumentationBuilder.kt | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/Kotlin') 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.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.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 } } -- cgit From d874444314ba60427a21d01585a7e632fc6d4bb0 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Fri, 24 Jul 2015 16:39:02 +0300 Subject: Rework toDocumentationNode function to use ConstantValue<*> instead of any? --- src/Kotlin/DocumentationBuilder.kt | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/Kotlin') 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.build(): DocumentationNode? { - val value: Any? = if (this is TypedCompileTimeConstant) getValue(type) else null - return value.toDocumentationNode() + fun CompileTimeConstant.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) + } } } -- cgit