aboutsummaryrefslogtreecommitdiff
path: root/plugins/base
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base')
-rw-r--r--plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt2
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt12
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt9
-rw-r--r--plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt39
-rw-r--r--plugins/base/src/test/kotlin/model/FunctionsTest.kt2
5 files changed, 55 insertions, 9 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt
index a5aa6879..f83eb4d8 100644
--- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt
+++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt
@@ -104,7 +104,7 @@ interface JvmSignatureUtils {
}
is EnumValue -> link(a.enumName, a.enumDri)
is ClassValue -> link(a.className + classExtension, a.classDRI)
- is StringValue -> group(styles = setOf(TextStyle.Breakable)) { text(a.value) }
+ is LiteralValue -> group(styles = setOf(TextStyle.Breakable)) { text(a.text()) }
}
fun PageContentBuilder.DocumentableContentBuilder.annotationsBlockWithIgnored(
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index 8bb8b527..1870b8da 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -69,6 +69,12 @@ import org.jetbrains.kotlin.resolve.constants.AnnotationValue as ConstantsAnnota
import org.jetbrains.kotlin.resolve.constants.ArrayValue as ConstantsArrayValue
import org.jetbrains.kotlin.resolve.constants.EnumValue as ConstantsEnumValue
import org.jetbrains.kotlin.resolve.constants.KClassValue as ConstantsKtClassValue
+import org.jetbrains.kotlin.resolve.constants.DoubleValue as ConstantsDoubleValue
+import org.jetbrains.kotlin.resolve.constants.FloatValue as ConstantsFloatValue
+import org.jetbrains.kotlin.resolve.constants.IntValue as ConstantsIntValue
+import org.jetbrains.kotlin.resolve.constants.LongValue as ConstantsLongValue
+import org.jetbrains.kotlin.resolve.constants.UIntValue as ConstantsUIntValue
+import org.jetbrains.kotlin.resolve.constants.ULongValue as ConstantsULongValue
class DefaultDescriptorToDocumentableTranslator(
context: DokkaContext
@@ -963,6 +969,12 @@ private class DokkaDescriptorVisitor(
)
}
}
+ is ConstantsFloatValue -> FloatValue(value)
+ is ConstantsDoubleValue -> DoubleValue(value)
+ is ConstantsUIntValue -> IntValue(value)
+ is ConstantsULongValue -> LongValue(value)
+ is ConstantsIntValue -> IntValue(value)
+ is ConstantsLongValue -> LongValue(value)
else -> StringValue(unquotedValue(toString()))
}
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index be7b826b..d2fb0271 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -602,6 +602,15 @@ class DefaultPsiToDocumentableTranslator(
val psiClass = ((type as PsiImmediateClassType).parameters.single() as PsiClassReferenceType).resolve()
psiClass?.let { ClassValue(text ?: "", DRI.from(psiClass)) }
}
+ is PsiLiteralExpression -> toValue()
+ else -> StringValue(text ?: "")
+ }
+
+ private fun PsiLiteralExpression.toValue(): AnnotationParameterValue? = when (type) {
+ PsiType.INT -> (value as? Int)?.let { IntValue(it) }
+ PsiType.LONG -> (value as? Long)?.let { LongValue(it) }
+ PsiType.FLOAT -> (value as? Float)?.let { FloatValue(it) }
+ PsiType.DOUBLE -> (value as? Double)?.let { DoubleValue(it) }
else -> StringValue(text ?: "")
}
diff --git a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt
index 0b9e2390..5ea792f0 100644
--- a/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt
+++ b/plugins/base/src/test/kotlin/content/annotations/ContentForAnnotationsTest.kt
@@ -3,9 +3,7 @@ package content.annotations
import matchers.content.*
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.model.Annotations
-import org.jetbrains.dokka.model.StringValue
-import org.jetbrains.dokka.model.dfs
+import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.pages.ContentPage
import org.jetbrains.dokka.pages.ContentText
import org.jetbrains.dokka.pages.MemberPageNode
@@ -196,20 +194,47 @@ class ContentForAnnotationsTest : BaseAbstractTest() {
| }
| class ABC
|}
- |annotation class Reference(val value: Int)
- |
+ |annotation class Reference(val value: Long)
+ |annotation class ReferenceReal(val value: Double)
+ |
|
|@BugReport(
| assignedTo = "me",
| testCase = BugReport.ABC::class,
| status = BugReport.Status.FIXED,
- | ref = Reference(value = 2),
- | reportedBy = [Reference(value = 2), Reference(value = 4)],
+ | ref = Reference(value = 2u),
+ | reportedBy = [Reference(value = 2UL), Reference(value = 4L),
+ | ReferenceReal(value = 4.9), ReferenceReal(value = 2f)],
| showStopper = true
|)
|val ltint: Int = 5
""".trimIndent(), testConfiguration
) {
+ documentablesCreationStage = { modules ->
+
+ fun expectedAnnotationValue(name: String, value: AnnotationParameterValue) = AnnotationValue(Annotations.Annotation(
+ dri = DRI("test", name),
+ params = mapOf("value" to value),
+ scope = Annotations.AnnotationScope.DIRECT,
+ mustBeDocumented = false
+ ))
+ val property = modules.flatMap { it.packages }.flatMap { it.properties }.first()
+ val annotation = property.extra?.get(Annotations)?.let {
+ it.directAnnotations.entries.firstNotNullResult { (_, annotations) -> annotations.firstOrNull() }
+ }
+ val annotationParams = annotation?.params ?: emptyMap()
+
+ assertEquals(expectedAnnotationValue("Reference", IntValue(2)), annotationParams["ref"])
+
+ val reportedByParam = ArrayValue(listOf(
+ expectedAnnotationValue("Reference", LongValue(2)),
+ expectedAnnotationValue("Reference", LongValue(4)),
+ expectedAnnotationValue("ReferenceReal", DoubleValue(4.9)),
+ expectedAnnotationValue("ReferenceReal", FloatValue(2f))
+ ))
+ assertEquals(reportedByParam, annotationParams["reportedBy"])
+ }
+
pagesTransformationStage = { module ->
val page = module.children.single { it.name == "test" } as PackagePageNode
page.content.assertNode {
diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt
index ac9b6d7d..10ff29b4 100644
--- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt
+++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt
@@ -324,7 +324,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
with(this.first()) {
dri.classNames equals "Fancy"
params.entries counts 1
- (params["size"] as StringValue).value equals "1"
+ (params["size"] as IntValue).value equals 1
}
}
}