aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin
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/base/src/test/kotlin
parentc81b39f966ce15f38afc8bea60f800fed9ea2473 (diff)
downloaddokka-13746f4afacd72576515dd94ba1167546418421f.tar.gz
dokka-13746f4afacd72576515dd94ba1167546418421f.tar.bz2
dokka-13746f4afacd72576515dd94ba1167546418421f.zip
Rework AnnotationTarget to be stricter (#2414)
Diffstat (limited to 'plugins/base/src/test/kotlin')
-rw-r--r--plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt67
1 files changed, 65 insertions, 2 deletions
diff --git a/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt
index 798a3f3b..fd9fcc5d 100644
--- a/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt
+++ b/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt
@@ -1,13 +1,15 @@
package translators
import org.jetbrains.dokka.DokkaConfiguration
+import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
+import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
-import org.junit.jupiter.api.Assertions.*
import org.jetbrains.dokka.model.doc.CodeBlock
import org.jetbrains.dokka.model.doc.P
import org.jetbrains.dokka.model.doc.Text
-import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.junit.Assert
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
class DefaultDescriptorToDocumentableTranslatorTest : BaseAbstractTest() {
@@ -663,4 +665,65 @@ class DefaultDescriptorToDocumentableTranslatorTest : BaseAbstractTest() {
}
}
}
+
+ val javaConfiguration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/main/java")
+ includeNonPublic = true
+ }
+ }
+ }
+
+ @Disabled // The compiler throws away annotations on unresolved types upstream
+ @Test
+ fun `Can annotate unresolved type`() {
+ testInline(
+ """
+ |/src/main/java/sample/FooLibrary.kt
+ |package sample;
+ |@MustBeDocumented
+ |@Target(AnnotationTarget.TYPE)
+ |annotation class Hello()
+ |fun bar(): @Hello() TypeThatDoesntResolve
+ """.trimMargin(),
+ javaConfiguration
+ ) {
+ documentablesMergingStage = { module ->
+ val type = module.packages.single().functions.single().type as GenericTypeConstructor
+ assertEquals(
+ Annotations.Annotation(DRI("sample", "Hello"), emptyMap()),
+ type.extra[Annotations]?.directAnnotations?.values?.single()?.single()
+ )
+ }
+ }
+ }
+
+ /**
+ * Kotlin Int becomes java int. Java int cannot be annotated in source, but Kotlin Int can be.
+ * This is paired with KotlinAsJavaPluginTest.`Java primitive annotations work`()
+ */
+ @Test
+ fun `Java primitive annotations work`() {
+ testInline(
+ """
+ |/src/main/java/sample/FooLibrary.kt
+ |package sample;
+ |@MustBeDocumented
+ |@Target(AnnotationTarget.TYPE)
+ |annotation class Hello()
+ |fun bar(): @Hello() Int
+ """.trimMargin(),
+ javaConfiguration
+ ) {
+ documentablesMergingStage = { module ->
+ val type = module.packages.single().functions.single().type as GenericTypeConstructor
+ assertEquals(
+ Annotations.Annotation(DRI("sample", "Hello"), emptyMap()),
+ type.extra[Annotations]?.directAnnotations?.values?.single()?.single()
+ )
+ assertEquals("kotlin/Int///PointingToDeclaration/", type.dri.toString())
+ }
+ }
+ }
}