aboutsummaryrefslogtreecommitdiff
path: root/plugins/kotlin-as-java/src/test
diff options
context:
space:
mode:
authorowengray-google <owengray@google.com>2022-04-08 11:53:52 -0400
committerGitHub <noreply@github.com>2022-04-08 18:53:52 +0300
commit13746f4afacd72576515dd94ba1167546418421f (patch)
treeb6fbb6b0fae435c3940a4d06bba8822f76a7e5bb /plugins/kotlin-as-java/src/test
parentc81b39f966ce15f38afc8bea60f800fed9ea2473 (diff)
downloaddokka-13746f4afacd72576515dd94ba1167546418421f.tar.gz
dokka-13746f4afacd72576515dd94ba1167546418421f.tar.bz2
dokka-13746f4afacd72576515dd94ba1167546418421f.zip
Rework AnnotationTarget to be stricter (#2414)
Diffstat (limited to 'plugins/kotlin-as-java/src/test')
-rw-r--r--plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt52
1 files changed, 52 insertions, 0 deletions
diff --git a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt
index b9627f9b..0235b9d1 100644
--- a/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt
+++ b/plugins/kotlin-as-java/src/test/kotlin/KotlinAsJavaPluginTest.kt
@@ -4,10 +4,14 @@ import matchers.content.*
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.jdk
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.model.Annotations
+import org.jetbrains.dokka.model.GenericTypeConstructor
import org.jetbrains.dokka.model.dfs
import org.jetbrains.dokka.pages.*
import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.junit.Assert
+import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import signatures.Parameter
import signatures.Parameters
@@ -534,6 +538,54 @@ class KotlinAsJavaPluginTest : BaseAbstractTest() {
}
}
}
+
+ /**
+ * Kotlin Int becomes java int. Java int cannot be annotated in source, but Kotlin Int can be.
+ * This is paired with DefaultDescriptorToDocumentableTranslatorTest.`Java primitive annotations work`()
+ *
+ * This test currently does not do anything because Kotlin.Int currently becomes java.lang.Integer not primitive int
+ */
+ @Test
+ fun `Java primitive annotations work`() {
+ val writerPlugin = TestOutputWriterPlugin()
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ externalDocumentationLinks = listOf(
+ DokkaConfiguration.ExternalDocumentationLink.jdk(8),
+ stdlibExternalDocumentationLink
+ )
+ }
+ }
+ }
+ testInline(
+ """
+ |/src/main/kotlin/kotlinAsJavaPlugin/Test.kt
+ |package kotlinAsJavaPlugin
+ |@MustBeDocumented
+ |@Target(AnnotationTarget.TYPE)
+ |annotation class Hello()
+ |fun bar(): @Hello() Int
+ """.trimMargin(),
+ configuration,
+ pluginOverrides = listOf(writerPlugin),
+ cleanupOutput = true
+ ) {
+ documentablesTransformationStage = { module ->
+ val type = module.packages.single()
+ .classlikes.first { it.name == "TestKt" }
+ .functions.single()
+ .type as GenericTypeConstructor
+ Assertions.assertEquals(
+ Annotations.Annotation(DRI("kotlinAsJavaPlugin", "Hello"), emptyMap()),
+ type.extra[Annotations]?.directAnnotations?.values?.single()?.single()
+ )
+ // A bug; the GenericTypeConstructor cast should fail and this should be a PrimitiveJavaType
+ Assertions.assertEquals("java.lang/Integer///PointingToDeclaration/", type.dri.toString())
+ }
+ }
+ }
}
private val ContentNode.mainContents: List<ContentNode>