aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/translators
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/test/kotlin/translators')
-rw-r--r--plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt106
-rw-r--r--plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt81
2 files changed, 145 insertions, 42 deletions
diff --git a/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt
index 79e9f548..a9466f29 100644
--- a/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt
+++ b/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt
@@ -11,6 +11,7 @@ import org.junit.Assert
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
+import kotlin.test.assertNotNull
class DefaultDescriptorToDocumentableTranslatorTest : BaseAbstractTest() {
val configuration = dokkaConfiguration {
@@ -22,6 +23,16 @@ class DefaultDescriptorToDocumentableTranslatorTest : BaseAbstractTest() {
}
}
+ @Suppress("DEPRECATION") // for includeNonPublic
+ val javaConfiguration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/main/java")
+ includeNonPublic = true
+ }
+ }
+ }
+
@Test
fun `data class kdocs over generated methods`() {
testInline(
@@ -154,33 +165,6 @@ class DefaultDescriptorToDocumentableTranslatorTest : BaseAbstractTest() {
}
}
- private sealed class TestSuite {
- abstract val propertyName: String
-
- data class PropertyDoesntExist(
- override val propertyName: String
- ) : TestSuite()
-
-
- data class PropertyExists(
- override val propertyName: String,
- val modifier: KotlinModifier,
- val visibility: KotlinVisibility,
- val additionalModifiers: Set<ExtraModifiers.KotlinOnlyModifiers>
- ) : TestSuite()
-
- data class FunctionDoesntExist(
- override val propertyName: String,
- ) : TestSuite()
-
- data class FunctionExists(
- override val propertyName: String,
- val modifier: KotlinModifier,
- val visibility: KotlinVisibility,
- val additionalModifiers: Set<ExtraModifiers.KotlinOnlyModifiers>
- ) : TestSuite()
- }
-
private fun runTestSuitesAgainstGivenClasses(classlikes: List<DClasslike>, testSuites: List<List<TestSuite>>) {
classlikes.zip(testSuites).forEach { (classlike, testSuites) ->
testSuites.forEach { testSuite ->
@@ -669,16 +653,6 @@ class DefaultDescriptorToDocumentableTranslatorTest : BaseAbstractTest() {
}
}
- @Suppress("DEPRECATION") // for includeNonPublic
- 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`() {
@@ -730,4 +704,62 @@ class DefaultDescriptorToDocumentableTranslatorTest : BaseAbstractTest() {
}
}
}
+
+ @Test
+ fun `should preserve regular functions that look like accessors, but are not accessors`() {
+ testInline(
+ """
+ |/src/main/kotlin/A.kt
+ |package test
+ |class A {
+ | private var v: Int = 0
+ |
+ | // not accessors because declared separately, just functions
+ | fun setV(new: Int) { v = new }
+ | fun getV(): Int = v
+ |}
+ """.trimIndent(),
+ configuration
+ ) {
+ documentablesMergingStage = { module ->
+ val testClass = module.packages.single().classlikes.single { it.name == "A" }
+ val setterLookalike = testClass.functions.firstOrNull { it.name == "setV" }
+ assertNotNull(setterLookalike) {
+ "Expected regular function not found, wrongly categorized as setter?"
+ }
+
+ val getterLookalike = testClass.functions.firstOrNull { it.name == "getV" }
+ assertNotNull(getterLookalike) {
+ "Expected regular function not found, wrongly categorized as getter?"
+ }
+ }
+ }
+ }
+}
+
+private sealed class TestSuite {
+ abstract val propertyName: String
+
+ data class PropertyDoesntExist(
+ override val propertyName: String
+ ) : TestSuite()
+
+
+ data class PropertyExists(
+ override val propertyName: String,
+ val modifier: KotlinModifier,
+ val visibility: KotlinVisibility,
+ val additionalModifiers: Set<ExtraModifiers.KotlinOnlyModifiers>
+ ) : TestSuite()
+
+ data class FunctionDoesntExist(
+ override val propertyName: String,
+ ) : TestSuite()
+
+ data class FunctionExists(
+ override val propertyName: String,
+ val modifier: KotlinModifier,
+ val visibility: KotlinVisibility,
+ val additionalModifiers: Set<ExtraModifiers.KotlinOnlyModifiers>
+ ) : TestSuite()
}
diff --git a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt
index 1213727d..25d6b22e 100644
--- a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt
+++ b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt
@@ -1,15 +1,14 @@
package translators
+import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.base.DokkaBase
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.TypeConstructor
+import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.doc.Text
-import org.jetbrains.dokka.model.firstMemberOfType
import org.jetbrains.dokka.plugability.DokkaPlugin
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Assertions.assertTrue
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import utils.assertNotNull
@@ -259,4 +258,76 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() {
}
}
}
+
+ @Test
+ fun `should preserve regular functions that look like accessors, but are not accessors`() {
+ testInline(
+ """
+ |/src/main/java/test/A.java
+ |package test;
+ |public class A {
+ | public int a = 1;
+ | public void setA() { } // no arg
+ | public String getA() { return "s"; } // wrong return type
+ |}
+ """.trimIndent(),
+ configuration
+ ) {
+ documentablesMergingStage = { module ->
+ val testClass = module.packages.single().classlikes.single { it.name == "A" }
+
+ val setterLookalike = testClass.functions.firstOrNull { it.name == "setA" }
+ assertNotNull(setterLookalike) {
+ "Expected regular function not found, wrongly categorized as setter?"
+ }
+
+ val getterLookalike = testClass.functions.firstOrNull { it.name == "getA" }
+ assertNotNull(getterLookalike) {
+ "Expected regular function not found, wrongly categorized as getter?"
+ }
+ }
+ }
+ }
+
+ @Test
+ fun `should not associate accessors with field because field is public api`() {
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ documentedVisibilities = setOf(
+ DokkaConfiguration.Visibility.PUBLIC,
+ DokkaConfiguration.Visibility.PROTECTED
+ )
+ }
+ }
+ }
+
+ testInline(
+ """
+ |/src/test/A.java
+ |package test;
+ |public class A {
+ | protected int a = 1;
+ | public int getA() { return a; }
+ | public void setA(int a) { this.a = a; }
+ |}
+ """.trimIndent(),
+ configuration
+ ) {
+ documentablesMergingStage = { module ->
+ val testedClass = module.packages.single().classlikes.single { it.name == "A" }
+
+ val property = testedClass.properties.single { it.name == "a" }
+ assertEquals(JavaVisibility.Protected, property.visibility.values.single())
+ assertNull(property.getter)
+ assertNull(property.setter)
+
+ assertEquals(2, testedClass.functions.size)
+
+ assertEquals("getA", testedClass.functions[0].name)
+ assertEquals("setA", testedClass.functions[1].name)
+ }
+ }
+ }
}