aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/model/aditionalExtras.kt22
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt2
-rw-r--r--plugins/base/src/test/kotlin/enums/EnumsTest.kt6
-rw-r--r--plugins/base/src/test/kotlin/model/ClassesTest.kt173
-rw-r--r--plugins/base/src/test/kotlin/model/FunctionsTest.kt321
-rw-r--r--plugins/base/src/test/kotlin/model/InheritorsTest.kt4
-rw-r--r--plugins/base/src/test/kotlin/model/JavaTest.kt109
-rw-r--r--plugins/base/src/test/kotlin/model/PropertyTest.kt59
-rw-r--r--plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt10
-rw-r--r--plugins/base/src/test/kotlin/utils/TestUtils.kt5
-rw-r--r--plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt2
11 files changed, 431 insertions, 282 deletions
diff --git a/core/src/main/kotlin/model/aditionalExtras.kt b/core/src/main/kotlin/model/aditionalExtras.kt
index b0755759..f7d37111 100644
--- a/core/src/main/kotlin/model/aditionalExtras.kt
+++ b/core/src/main/kotlin/model/aditionalExtras.kt
@@ -5,22 +5,34 @@ import org.jetbrains.dokka.model.properties.ExtraProperty
import org.jetbrains.dokka.model.properties.MergeStrategy
class AdditionalModifiers(val content: Set<ExtraModifiers>) : ExtraProperty<Documentable> {
- object AdditionalKey : ExtraProperty.Key<Documentable, AdditionalModifiers> {
+ companion object : ExtraProperty.Key<Documentable, AdditionalModifiers> {
override fun mergeStrategyFor(
left: AdditionalModifiers,
right: AdditionalModifiers
): MergeStrategy<Documentable> = MergeStrategy.Replace(AdditionalModifiers(left.content + right.content))
}
- override fun equals(other: Any?): Boolean = if (other is AdditionalModifiers) other.content == content else false
+ override fun equals(other: Any?): Boolean =
+ if (other is AdditionalModifiers) other.content == content else false
+
override fun hashCode() = content.hashCode()
- override val key: ExtraProperty.Key<Documentable, *> = AdditionalKey
+ override val key: ExtraProperty.Key<Documentable, *> = AdditionalModifiers
}
class Annotations(val content: List<Annotation>) : ExtraProperty<Documentable> {
- companion object : ExtraProperty.Key<Documentable, Annotations>
+ companion object : ExtraProperty.Key<Documentable, Annotations> {
+ override fun mergeStrategyFor(left: Annotations, right: Annotations): MergeStrategy<Documentable> =
+ MergeStrategy.Replace(Annotations((left.content + right.content).distinct()))
+ }
override val key: ExtraProperty.Key<Documentable, *> = Annotations
- data class Annotation(val dri: DRI, val params: Map<String, String>)
+ data class Annotation(val dri: DRI, val params: Map<String, String>) {
+ override fun equals(other: Any?): Boolean = when(other) {
+ is Annotation -> dri.equals(other.dri)
+ else -> false
+ }
+
+ override fun hashCode(): Int = dri.hashCode()
+ }
} \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index 8e0f1231..44679d8d 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -367,7 +367,7 @@ private class DokkaDescriptorVisitor( // TODO: close this class and make it priv
type = descriptor.type.toBound(),
documentation = descriptor.resolveDescriptorData(platformData),
platformData = listOf(platformData),
- extra = PropertyContainer.withAll(descriptor.additionalExtras())
+ extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations())
)
private fun MemberScope.functions(parent: DRIWithPlatformInfo): List<DFunction> =
diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt
index 55ad0fbc..c9024a72 100644
--- a/plugins/base/src/test/kotlin/enums/EnumsTest.kt
+++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt
@@ -34,9 +34,9 @@ class EnumsTest : AbstractCoreTest() {
pagesGenerationStage = {
val map = it.getClasslikeToMemberMap()
val test = map.filterKeys { it.name == "Test" }.values.firstOrNull()
- assert(test != null) { "Test not found" }
- assert(test!!.any { it.name == "E1" } && test.any { it.name == "E2" }) { "Enum entries missing in parent" }
- assert(map.keys.any { it.name == "E1" } && map.keys.any { it.name == "E2" }) { "Enum entries missing" }
+ assertTrue(test != null) { "Test not found" }
+ assertTrue(test!!.any { it.name == "E1" } && test.any { it.name == "E2" }) { "Enum entries missing in parent" }
+ assertTrue(map.keys.any { it.name == "E1" } && map.keys.any { it.name == "E2" }) { "Enum entries missing" }
}
}
}
diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt
index bd35afc5..336023da 100644
--- a/plugins/base/src/test/kotlin/model/ClassesTest.kt
+++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt
@@ -1,7 +1,6 @@
package model
import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.DFunction
import org.jetbrains.dokka.model.KotlinModifier.*
import org.junit.jupiter.api.Test
import utils.AbstractModelTest
@@ -150,20 +149,14 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
with((this / "classes" / "Klass").cast<DClass>()) {
name equals "Klass"
visibility.values allEquals KotlinVisibility.Public
- with(extra[AdditionalModifiers.AdditionalKey].assertNotNull("Extras")) {
- content.find { it == ExtraModifiers.DATA }.assertNotNull("data modifier")
+ with(extra[AdditionalModifiers].assertNotNull("Extras")) {
+ content counts 1
+ content.first() equals ExtraModifiers.DATA
}
}
}
}
-// @Test fun dataClass() {
-// verifyPackageMember("testdata/classes/dataClass.kt", defaultModelConfig) { cls ->
-// val modifiers = cls.details(NodeKind.Modifier).map { it.name }
-// assertTrue("data" in modifiers)
-// }
-// }
-
@Test
fun sealedClass() {
inlineModelTest(
@@ -178,30 +171,25 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
}
}
-// // TODO modifiers
-// @Test fun annotatedClassWithAnnotationParameters() {
-// checkSourceExistsAndVerifyModel(
-// "testdata/classes/annotatedClassWithAnnotationParameters.kt",
-// defaultModelConfig
-// ) { model ->
-// with(model.members.single().members.single()) {
-// with(deprecation!!) {
-// assertEquals("Deprecated", name)
-// assertEquals(Content.Empty, content)
-// assertEquals(NodeKind.Annotation, kind)
-// assertEquals(1, details.count())
-// with(details[0]) {
-// assertEquals(NodeKind.Parameter, kind)
-// assertEquals(1, details.count())
-// with(details[0]) {
-// assertEquals(NodeKind.Value, kind)
-// assertEquals("\"should no longer be used\"", name)
-// }
-// }
-// }
-// }
-// }
-// }
+ @Test
+ fun annotatedClassWithAnnotationParameters() {
+ inlineModelTest(
+ """
+ |@Deprecated("should no longer be used") class Foo() {}
+ """
+ ) {
+ with((this / "classes" / "Foo").cast<DClass>()) {
+ with(extra[Annotations].assertNotNull("Annotations")) {
+ this.content counts 1
+ with(content.first()) {
+ dri.classNames equals "Deprecated"
+ params.entries counts 1
+ params["message"].assertNotNull("message") equals "should no longer be used"
+ }
+ }
+ }
+ }
+ }
@Test
fun notOpenClass() {
@@ -272,7 +260,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
}
}
- @Test // todo inner class
+ @Test
fun innerClass() {
inlineModelTest(
"""
@@ -284,21 +272,15 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
with((this / "classes" / "C").cast<DClass>()) {
with((this / "D").cast<DClass>()) {
+ with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) {
+ content counts 1
+ content.first() equals ExtraModifiers.INNER
+ }
}
}
}
}
-// // TODO modifiers
-// @Test fun innerClass() {
-// verifyPackageMember("testdata/classes/innerClass.kt", defaultModelConfig) { cls ->
-// val innerClass = cls.members.single { it.name == "D" }
-// val modifiers = innerClass.details(NodeKind.Modifier)
-// assertEquals(3, modifiers.size)
-// assertEquals("inner", modifiers[2].name)
-// }
-// }
-
@Test
fun companionObjectExtension() {
inlineModelTest(
@@ -364,14 +346,29 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
}
}
- // TODO modifiers
-// @Test fun sinceKotlin() {
-// checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model ->
-// with(model.members.single().members.single()) {
-// assertEquals("1.1", sinceKotlin)
-// }
-// }
-// }
+ @Test
+ fun sinceKotlin() {
+ inlineModelTest(
+ """
+ |/**
+ | * Useful
+ | */
+ |@SinceKotlin("1.1")
+ |class C
+ """
+ ) {
+ with((this / "classes" / "C").cast<DClass>()) {
+ with(extra[Annotations].assertNotNull("Annotations")) {
+ this.content counts 1
+ with(content.first()) {
+ dri.classNames equals "SinceKotlin"
+ params.entries counts 1
+ params["version"].assertNotNull("version") equals "1.1"
+ }
+ }
+ }
+ }
+ }
@Test
fun privateCompanionObject() {
@@ -402,7 +399,8 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
}
}
- @Test fun annotatedClass() {
+ @Test
+ fun annotatedClass() {
inlineModelTest(
"""@Suppress("abc") class Foo() {}"""
) {
@@ -417,47 +415,30 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class
}
}
- // TODO annotations
-// @Test fun annotatedClass() {
-// verifyPackageMember("testdata/classes/annotatedClass.kt", ModelConfig(
-// analysisPlatform = analysisPlatform,
-// withKotlinRuntime = true
-// )
-// ) { cls ->
-// Assert.assertEquals(1, cls.annotations.count())
-// with(cls.annotations[0]) {
-// Assert.assertEquals("Strictfp", name)
-// Assert.assertEquals(Content.Empty, content)
-// Assert.assertEquals(NodeKind.Annotation, kind)
-// }
-// }
-// }
-
-
-// TODO annotations
-
-// @Test fun javaAnnotationClass() {
-// checkSourceExistsAndVerifyModel(
-// "testdata/classes/javaAnnotationClass.kt",
-// modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true)
-// ) { model ->
-// with(model.members.single().members.single()) {
-// Assert.assertEquals(1, annotations.count())
-// with(annotations[0]) {
-// Assert.assertEquals("Retention", name)
-// Assert.assertEquals(Content.Empty, content)
-// Assert.assertEquals(NodeKind.Annotation, kind)
-// with(details[0]) {
-// Assert.assertEquals(NodeKind.Parameter, kind)
-// Assert.assertEquals(1, details.count())
-// with(details[0]) {
-// Assert.assertEquals(NodeKind.Value, kind)
-// Assert.assertEquals("RetentionPolicy.SOURCE", name)
-// }
-// }
-// }
-// }
-// }
-// }
+ @Test fun javaAnnotationClass() {
+ inlineModelTest(
+ """
+ |import java.lang.annotation.Retention
+ |import java.lang.annotation.RetentionPolicy
+ |
+ |@Retention(RetentionPolicy.SOURCE)
+ |public annotation class throws()
+ """
+ ) {
+ with((this / "classes" / "throws").cast<DAnnotation>()) {
+ with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) {
+ content counts 1
+ content.first() equals ExtraModifiers.OVERRIDE // ??
+ }
+ with(extra[Annotations].assertNotNull("Annotations")) {
+ content counts 1
+ with(content.first()) {
+ dri.classNames equals "Retention"
+ params["value"].assertNotNull("value") equals "(java/lang/annotation/RetentionPolicy, SOURCE)"
+ }
+ }
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt
index c8b8f2ba..068c2895 100644
--- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt
+++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt
@@ -1,9 +1,11 @@
package model
-import org.jetbrains.dokka.model.DFunction
-import org.jetbrains.dokka.model.DPackage
+import org.jetbrains.dokka.model.*
import org.junit.jupiter.api.Test
-import utils.*
+import utils.AbstractModelTest
+import utils.assertNotNull
+import utils.comments
+import utils.name
class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "function") {
@@ -130,8 +132,6 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
}
}
-// TODO add modifiers - start
-
@Test
fun functionWithNotDocumentedAnnotation() {
inlineModelTest(
@@ -139,20 +139,19 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
|@Suppress("FOO") fun f() {}
"""
) {
- // TODO add annotations
-
with((this / "function" / "f").cast<DFunction>()) {
- assert(false) { "No annotation data" }
+ with(extra[Annotations].assertNotNull("Annotations")) {
+ content counts 1
+ with(content.first()) {
+ dri.classNames equals "Suppress"
+ params.entries counts 1
+ params["names"].assertNotNull("names") equals "[\"FOO\"]"
+ }
+ }
}
}
}
-// @Test fun functionWithNotDocumentedAnnotation() {
-// verifyPackageMember("testdata/functions/functionWithNotDocumentedAnnotation.kt", defaultModelConfig) { func ->
-// assertEquals(0, func.annotations.count())
-// }
-// }
-
@Test
fun inlineFunction() {
inlineModelTest(
@@ -160,21 +159,13 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
|inline fun f(a: () -> String) {}
"""
) {
- // TODO add data about inline
-
with((this / "function" / "f").cast<DFunction>()) {
- assert(false) { "No inline data" }
+ extra[AdditionalModifiers]?.content counts 1
+ extra[AdditionalModifiers]?.content exists ExtraModifiers.INLINE
}
}
}
-// @Test fun inlineFunction() {
-// verifyPackageMember("testdata/functions/inlineFunction.kt", defaultModelConfig) { func ->
-// val modifiers = func.details(NodeKind.Modifier).map { it.name }
-// assertTrue("inline" in modifiers)
-// }
-// }
-
@Test
fun suspendFunction() {
inlineModelTest(
@@ -182,112 +173,167 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
|suspend fun f() {}
"""
) {
- // TODO add data about suspend
+ with((this / "function" / "f").cast<DFunction>()) {
+ extra[AdditionalModifiers]?.content counts 1
+ extra[AdditionalModifiers]?.content exists ExtraModifiers.SUSPEND
+ }
+ }
+ }
+ @Test
+ fun suspendInlineFunctionOrder() {
+ inlineModelTest(
+ """
+ |suspend inline fun f(a: () -> String) {}
+ """
+ ) {
with((this / "function" / "f").cast<DFunction>()) {
- assert(false) { "No suspend data" }
+ extra[AdditionalModifiers]?.content counts 2
+ extra[AdditionalModifiers]?.content exists ExtraModifiers.SUSPEND
+ extra[AdditionalModifiers]?.content exists ExtraModifiers.INLINE
}
}
}
-// @Test fun suspendFunction() {
-// verifyPackageMember("testdata/functions/suspendFunction.kt") { func ->
-// val modifiers = func.details(NodeKind.Modifier).map { it.name }
-// assertTrue("suspend" in modifiers)
-// }
-// }
+ @Test
+ fun inlineSuspendFunctionOrderChanged() {
+ inlineModelTest(
+ """
+ |inline suspend fun f(a: () -> String) {}
+ """
+ ) {
+ with((this / "function" / "f").cast<DFunction>()) {
+ with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) {
+ content counts 2
+ content exists ExtraModifiers.SUSPEND
+ content exists ExtraModifiers.INLINE
+ }
+ }
+ }
+ }
-// @Test fun suspendInlineFunctionOrder() {
-// verifyPackageMember("testdata/functions/suspendInlineFunction.kt") { func ->
-// val modifiers = func.details(NodeKind.Modifier).map { it.name }.filter {
-// it == "suspend" || it == "inline"
-// }
-//
-// assertEquals(listOf("suspend", "inline"), modifiers)
-// }
-// }
-//
-// @Test fun inlineSuspendFunctionOrderChanged() {
-// verifyPackageMember("testdata/functions/inlineSuspendFunction.kt") { func ->
-// val modifiers = func.details(NodeKind.Modifier).map { it.name }.filter {
-// it == "suspend" || it == "inline"
-// }
-//
-// assertEquals(listOf("suspend", "inline"), modifiers)
-// }
-// }
-//
-// @Test fun functionWithAnnotatedParam() {
-// checkSourceExistsAndVerifyModel("testdata/functions/functionWithAnnotatedParam.kt", defaultModelConfig) { model ->
-// with(model.members.single().members.single { it.name == "function" }) {
-// with(details(NodeKind.Parameter).first()) {
-// assertEquals(1, annotations.count())
-// with(annotations[0]) {
-// assertEquals("Fancy", name)
-// assertEquals(Content.Empty, content)
-// assertEquals(NodeKind.Annotation, kind)
-// }
-// }
-// }
-// }
-// }
-//
-// @Test fun functionWithNoinlineParam() {
-// verifyPackageMember("testdata/functions/functionWithNoinlineParam.kt", defaultModelConfig) { func ->
-// with(func.details(NodeKind.Parameter).first()) {
-// val modifiers = details(NodeKind.Modifier).map { it.name }
-// assertTrue("noinline" in modifiers)
-// }
-// }
-// }
-//
-// @Test fun annotatedFunctionWithAnnotationParameters() {
-// checkSourceExistsAndVerifyModel(
-// "testdata/functions/annotatedFunctionWithAnnotationParameters.kt",
-// defaultModelConfig
-// ) { model ->
-// with(model.members.single().members.single { it.name == "f" }) {
-// assertEquals(1, annotations.count())
-// with(annotations[0]) {
-// assertEquals("Fancy", name)
-// assertEquals(Content.Empty, content)
-// assertEquals(NodeKind.Annotation, kind)
-// assertEquals(1, details.count())
-// with(details[0]) {
-// assertEquals(NodeKind.Parameter, kind)
-// assertEquals(1, details.count())
-// with(details[0]) {
-// assertEquals(NodeKind.Value, kind)
-// assertEquals("1", name)
-// }
-// }
-// }
-// }
-// }
-// }
+ @Test
+ fun functionWithAnnotatedParam() {
+ inlineModelTest(
+ """
+ |@Target(AnnotationTarget.VALUE_PARAMETER)
+ |@Retention(AnnotationRetention.SOURCE)
+ |@MustBeDocumented
+ |public annotation class Fancy
+ |
+ |fun function(@Fancy notInlined: () -> Unit) {}
+ """
+ ) {
+ with((this / "function" / "Fancy").cast<DAnnotation>()) {
+ with(extra[Annotations].assertNotNull("Annotations")) {
+ content counts 3
+ with(content.map { it.dri.classNames to it }.toMap()) {
+ with(this["Target"].assertNotNull("Target")) {
+ params["allowedTargets"].assertNotNull("allowedTargets") equals "[AnnotationTarget.VALUE_PARAMETER]"
+ }
+ with(this["Retention"].assertNotNull("Retention")) {
+ params["value"].assertNotNull("value") equals "(kotlin/annotation/AnnotationRetention, SOURCE)"
+ }
+ this["MustBeDocumented"].assertNotNull("MustBeDocumented").params.entries counts 0
+ }
+ }
+
+ }
+ with((this / "function" / "function" / "notInlined").cast<DParameter>()) {
+ with(this.extra[Annotations].assertNotNull("Annotations")) {
+ content counts 1
+ with(content.first()) {
+ dri.classNames equals "Fancy"
+ params.entries counts 0
+ }
+ }
+ }
+ }
+ }
-// TODO add modifiers - end
+ @Test
+ fun functionWithNoinlineParam() {
+ inlineModelTest(
+ """
+ |fun f(noinline notInlined: () -> Unit) {}
+ """
+ ) {
+ with((this / "function" / "f" / "notInlined").cast<DParameter>()) {
+ extra[AdditionalModifiers]?.content counts 1
+ extra[AdditionalModifiers]?.content exists ExtraModifiers.NOINLINE
+ }
+ }
+ }
-// @Test
-// fun functionWithDefaultParameter() {
-// inlineModelTest(
-// """
-// |/src/main/kotlin/function/Test.kt
-// |package function
-// |fun f(x: String = "") {}
-// """
-// ) {
-// // TODO add default value data
-//
-// with(this / "function" / "f" cast Function::class) {
-// parameters.forEach { p ->
-// p.name equals "x"
-// p.type.constructorFqName.assertNotNull("Parameter type: ") equals "kotlin.String"
-// assert(false) { "Add default value data" }
-// }
-// }
-// }
-// }
+ @Test
+ fun annotatedFunctionWithAnnotationParameters() {
+ inlineModelTest(
+ """
+ |@Target(AnnotationTarget.VALUE_PARAMETER)
+ |@Retention(AnnotationRetention.SOURCE)
+ |@MustBeDocumented
+ |public annotation class Fancy(val size: Int)
+ |
+ |@Fancy(1) fun f() {}
+ """
+ ) {
+ with((this / "function" / "Fancy").cast<DAnnotation>()) {
+ constructors counts 1
+ with(constructors.first()) {
+ parameters counts 1
+ with(parameters.first()) {
+ type.name equals "Int"
+ name equals "size"
+ }
+ }
+
+ with(extra[Annotations].assertNotNull("Annotations")) {
+ content counts 3
+ with(content.map { it.dri.classNames to it }.toMap()) {
+ with(this["Target"].assertNotNull("Target")) {
+ params["allowedTargets"].assertNotNull("allowedTargets") equals "[AnnotationTarget.VALUE_PARAMETER]"
+ }
+ with(this["Retention"].assertNotNull("Retention")) {
+ params["value"].assertNotNull("value") equals "(kotlin/annotation/AnnotationRetention, SOURCE)"
+ }
+ this["MustBeDocumented"].assertNotNull("MustBeDocumented").params.entries counts 0
+ }
+ }
+
+ }
+ with((this / "function" / "f").cast<DFunction>()) {
+ with(this.extra[Annotations].assertNotNull("Annotations")) {
+ content counts 1
+ with(content.first()) {
+ dri.classNames equals "Fancy"
+ params.entries counts 1
+ params["size"] equals "1"
+ }
+ }
+ }
+ }
+ }
+
+ @Test
+ fun functionWithDefaultParameter() {
+ inlineModelTest(
+ """
+ |/src/main/kotlin/function/Test.kt
+ |package function
+ |fun f(x: String = "") {}
+ """
+ ) {
+ // TODO add default value data
+
+ with((this / "function" / "f").cast<DFunction>()) {
+ parameters.forEach { p ->
+ p.name equals "x"
+ p.type.name.assertNotNull("Parameter type: ") equals "String"
+ assert(false) { "No default value data" }
+ }
+ }
+ }
+ }
// @Test fun functionWithDefaultParameter() {
// checkSourceExistsAndVerifyModel("testdata/functions/functionWithDefaultParameter.kt", defaultModelConfig) { model ->
@@ -302,14 +348,29 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun
// }
// }
// }
-//
-// @Test fun sinceKotlin() {
-// checkSourceExistsAndVerifyModel("testdata/functions/sinceKotlin.kt", defaultModelConfig) { model ->
-// with(model.members.single().members.single()) {
-// assertEquals("1.1", sinceKotlin)
-// }
-// }
-// }
-//}
+
+ @Test
+ fun sinceKotlin() {
+ inlineModelTest(
+ """
+ |/**
+ | * Quite useful [String]
+ | */
+ |@SinceKotlin("1.1")
+ |fun f(): String = "1.1 rulezz"
+ """
+ ) {
+ with((this / "function" / "f").cast<DFunction>()) {
+ with(extra[Annotations].assertNotNull("Annotations")) {
+ this.content counts 1
+ with(content.first()) {
+ dri.classNames equals "SinceKotlin"
+ params.entries counts 1
+ params["version"].assertNotNull("version") equals "1.1"
+ }
+ }
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/plugins/base/src/test/kotlin/model/InheritorsTest.kt b/plugins/base/src/test/kotlin/model/InheritorsTest.kt
index da128803..e1717fe4 100644
--- a/plugins/base/src/test/kotlin/model/InheritorsTest.kt
+++ b/plugins/base/src/test/kotlin/model/InheritorsTest.kt
@@ -5,8 +5,8 @@ import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.base.transformers.documentables.InheritorsExtractorTransformer
import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo
import org.jetbrains.dokka.model.DInterface
-import org.jetbrains.dokka.model.DPackage
import org.jetbrains.dokka.plugability.DokkaPlugin
+import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import utils.AbstractModelTest
import utils.assertNotNull
@@ -83,7 +83,7 @@ class InheritorsTest : AbstractModelTest("/src/main/kotlin/inheritors/Test.kt",
with(find { it.platformType == Platform.js }.assertNotNull("js key").let { map[it]!! }) {
this counts 2
val classes = listOf("B", "C")
- assert(all{ classes.contains(it.classNames) }){"One of subclasses missing in js"}
+ assertTrue(all { classes.contains(it.classNames) }, "One of subclasses missing in js" )
}
}
diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt
index c6d111a4..a3fcce42 100644
--- a/plugins/base/src/test/kotlin/model/JavaTest.kt
+++ b/plugins/base/src/test/kotlin/model/JavaTest.kt
@@ -1,8 +1,7 @@
package model
+import org.jetbrains.dokka.base.transformers.documentables.InheritorsInfo
import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.DEnum
-import org.jetbrains.dokka.model.DFunction
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import utils.AbstractModelTest
@@ -113,7 +112,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
val sups = listOf("Exception", "Cloneable")
assertTrue(
sups.all { s -> supertypes.map.values.flatten().any { it.classNames == s } })
- "Foo must extend ${sups.joinToString(", ")}"
+ "Foo must extend ${sups.joinToString(", ")}"
}
}
}
@@ -155,7 +154,7 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
"""
) {
with((this / "java" / "Foo").cast<DClass>()) {
- this
+ throw AssertionError("No type parameters data for class")
}
}
}
@@ -286,6 +285,24 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
// }
// }
+ @Test
+ fun staticMethod() {
+ inlineModelTest(
+ """
+ |class C {
+ | public static void foo() {}
+ |}
+ """
+ ) {
+ with((this / "java" / "C" / "foo").cast<DFunction>()) {
+ with(extra[AdditionalModifiers].assertNotNull("AdditionalModifiers")) {
+ content counts 1
+ content.first() equals ExtraModifiers.STATIC
+ }
+ }
+ }
+ }
+
// @Test fun staticMethod() { todo
// verifyJavaPackageMember("testdata/java/staticMethod.java", defaultModelConfig) { cls ->
// val m = cls.members(NodeKind.Function).single { it.name == "foo" }
@@ -304,31 +321,53 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
// assertEquals(1, cls.members(NodeKind.Function).size)
// }
// }
- //
- // @Test fun annotatedAnnotation() {
- // verifyJavaPackageMember("testdata/java/annotatedAnnotation.java", defaultModelConfig) { cls ->
- // assertEquals(1, cls.annotations.size)
- // with(cls.annotations[0]) {
- // assertEquals(1, details.count())
- // with(details[0]) {
- // assertEquals(NodeKind.Parameter, kind)
- // assertEquals(1, details.count())
- // with(details[0]) {
- // assertEquals(NodeKind.Value, kind)
- // assertEquals("[AnnotationTarget.FIELD, AnnotationTarget.CLASS, AnnotationTarget.FILE, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER]", name)
- // }
- // }
- // }
- // }
- // }
- //
+
+ @Test
+ fun annotatedAnnotation() {
+ inlineModelTest(
+ """
+ |import java.lang.annotation.*;
+ |
+ |@Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD})
+ |public @interface Attribute {
+ | String value() default "";
+ |}
+ """
+ ) {
+ with((this / "java" / "Attribute").cast<DAnnotation>()) {
+ with(extra[Annotations].assertNotNull("Annotations")) {
+ content counts 1
+ with(content.first()) {
+ dri.classNames equals "Target"
+ params["value"].assertNotNull("value") equals "PsiArrayInitializerMemberValue:{ElementType.FIELD, ElementType.TYPE, ElementType.METHOD}"
+ }
+ }
+ }
+ }
+ }
+
// @Test fun deprecation() {
// verifyJavaPackageMember("testdata/java/deprecation.java", defaultModelConfig) { cls ->
// val fn = cls.members(NodeKind.Function).single()
// assertEquals("This should no longer be used", fn.deprecation!!.content.toTestString())
// }
// }
- //
+
+ @Test
+ fun javaLangObject() {
+ inlineModelTest(
+ """
+ |class Test {
+ | public Object fn() { return null; }
+ |}
+ """
+ ) {
+ with((this / "java" / "Test" / "fn").cast<DFunction>()) {
+ type.name equals "Any"
+ }
+ }
+ }
+
// @Test fun javaLangObject() {
// verifyJavaPackageMember("testdata/java/javaLangObject.java", defaultModelConfig) { cls ->
// val fn = cls.members(NodeKind.Function).single()
@@ -356,6 +395,30 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") {
}
}
+ @Test
+ fun inheritorLinks() {
+ inlineModelTest(
+ """
+ |public class InheritorLinks {
+ | public static class Foo {}
+ |
+ | public static class Bar extends Foo {}
+ |}
+ """
+ ) {
+ with((this / "java" / "InheritorLinks").cast<DClass>()) {
+ val dri = (this / "Foo").assertNotNull("Foo dri").dri
+ with((this / "Bar").cast<DClass>()) {
+ with(extra[InheritorsInfo].assertNotNull("InheritorsInfo")) {
+ with(value.map.values.flatten().distinct()) {
+ this counts 1
+ first() equals dri
+ }
+ }
+ }
+ }
+ }
+ }
// todo
// @Test fun inheritorLinks() {
diff --git a/plugins/base/src/test/kotlin/model/PropertyTest.kt b/plugins/base/src/test/kotlin/model/PropertyTest.kt
index f391df4e..f6f7f3c0 100644
--- a/plugins/base/src/test/kotlin/model/PropertyTest.kt
+++ b/plugins/base/src/test/kotlin/model/PropertyTest.kt
@@ -1,8 +1,6 @@
package model
-import org.jetbrains.dokka.model.KotlinVisibility
-import org.jetbrains.dokka.model.DPackage
-import org.jetbrains.dokka.model.DProperty
+import org.jetbrains.dokka.model.*
import org.junit.jupiter.api.Test
import utils.AbstractModelTest
import utils.assertNotNull
@@ -140,19 +138,48 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro
}
}
- // todo
-// @Test fun sinceKotlin() {
-// checkSourceExistsAndVerifyModel("testdata/properties/sinceKotlin.kt", defaultModelConfig) { model ->
-// with(model.members.single().members.single()) {
-// assertEquals("1.1", sinceKotlin)
-// }
-// }
-// }
-//}
-//
-//class JSPropertyTest: BasePropertyTest(Platform.js) {}
-//
-//class JVMPropertyTest : BasePropertyTest(Platform.jvm) {
+ @Test
+ fun sinceKotlin() {
+ inlineModelTest(
+ """
+ |/**
+ | * Quite useful [String]
+ | */
+ |@SinceKotlin("1.1")
+ |val prop: String = "1.1 rulezz"
+ """
+ ) {
+ with((this / "property" / "prop").cast<DProperty>()) {
+ with(extra[Annotations].assertNotNull("Annotations")) {
+ this.content counts 1
+ with(content.first()) {
+ dri.classNames equals "SinceKotlin"
+ params.entries counts 1
+ params["version"].assertNotNull("version") equals "1.1"
+ }
+ }
+ }
+ }
+ }
+
+ @Test
+ fun annotatedProperty() {
+ inlineModelTest(
+ """
+ |@Strictfp var property = "test"
+ """
+ ) {
+ with((this / "property" / "property").cast<DProperty>()) {
+ with(extra[Annotations].assertNotNull("Annotations")) {
+ this.content counts 1
+ with(content.first()) {
+ dri.classNames equals "Strictfp"
+ params.entries counts 0
+ }
+ }
+ }
+ }
+ }
// @Test
// fun annotatedProperty() {
// checkSourceExistsAndVerifyModel(
diff --git a/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt b/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt
index 15dc5581..6ef38aa9 100644
--- a/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt
+++ b/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt
@@ -110,13 +110,13 @@ class PageNodeMergerTest : AbstractCoreTest() {
val testT = allChildren.filter { it.name == "testT" }
val test = allChildren.filter { it.name == "test" }
- assert(testT.size == 1) { "There can be only one testT page" }
- assert(testT.first().dri.size == 1) { "testT page should have single DRI, but has ${testT.first().dri.size}" }
+ assertTrue(testT.size == 1) { "There can be only one testT page" }
+ assertTrue(testT.first().dri.size == 1) { "testT page should have single DRI, but has ${testT.first().dri.size}" }
- assert(test.size == 1) { "There can be only one test page" }
- assert(test.first().dri.size == 1) { "test page should have single DRI, but has ${test.first().dri.size}" }
+ assertTrue(test.size == 1) { "There can be only one test page" }
+ assertTrue(test.first().dri.size == 1) { "test page should have single DRI, but has ${test.first().dri.size}" }
- assert(strList.count() == 2) { "Expected 2 warnings, got ${strList.count()}" }
+ assertTrue(strList.count() == 2) { "Expected 2 warnings, got ${strList.count()}" }
}
}
}
diff --git a/plugins/base/src/test/kotlin/utils/TestUtils.kt b/plugins/base/src/test/kotlin/utils/TestUtils.kt
index 68ab7120..8a3053b3 100644
--- a/plugins/base/src/test/kotlin/utils/TestUtils.kt
+++ b/plugins/base/src/test/kotlin/utils/TestUtils.kt
@@ -3,6 +3,7 @@ package utils
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
+import org.junit.jupiter.api.Assertions.assertTrue
import kotlin.collections.orEmpty
@DslMarker
@@ -22,6 +23,10 @@ interface AssertDSL {
infix fun Any?.equals(other: Any?) = this.assertEqual(other)
infix fun Collection<Any>?.allEquals(other: Any?) =
this?.also { c -> c.forEach { it equals other } } ?: run { assert(false) { "Collection is empty" } }
+ infix fun <T> Collection<T>?.exists(e: T) {
+ assertTrue(this.orEmpty().isNotEmpty(), "Collection cannot be null or empty")
+ assertTrue(this!!.any{it == e}, "Collection doesn't contain $e")
+ }
infix fun <T> Collection<T>?.counts(n: Int) = this.orEmpty().assertCount(n)
diff --git a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
index 991ee07d..ce41562b 100644
--- a/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
+++ b/plugins/kotlin-as-java/src/main/kotlin/converters/KotlinToJavaConverter.kt
@@ -259,7 +259,7 @@ internal fun ClassId.toDRI(dri: DRI?): DRI = DRI(
)
private fun PropertyContainer<out Documentable>.mergeAdditionalModifiers(second: Set<ExtraModifiers>) =
- this[AdditionalModifiers.AdditionalKey]?.squash(AdditionalModifiers(second)) ?: AdditionalModifiers(second)
+ this[AdditionalModifiers]?.squash(AdditionalModifiers(second)) ?: AdditionalModifiers(second)
private fun AdditionalModifiers.squash(second: AdditionalModifiers) =
AdditionalModifiers(content + second.content)