aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/superFields
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/test/kotlin/superFields')
-rw-r--r--plugins/base/src/test/kotlin/superFields/DescriptorSuperPropertiesTest.kt172
-rw-r--r--plugins/base/src/test/kotlin/superFields/PsiSuperFieldsTest.kt31
2 files changed, 152 insertions, 51 deletions
diff --git a/plugins/base/src/test/kotlin/superFields/DescriptorSuperPropertiesTest.kt b/plugins/base/src/test/kotlin/superFields/DescriptorSuperPropertiesTest.kt
index a6dd4350..06ced8c9 100644
--- a/plugins/base/src/test/kotlin/superFields/DescriptorSuperPropertiesTest.kt
+++ b/plugins/base/src/test/kotlin/superFields/DescriptorSuperPropertiesTest.kt
@@ -1,8 +1,10 @@
package superFields
+import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.InheritedMember
+import org.jetbrains.dokka.model.KotlinVisibility
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
@@ -53,6 +55,41 @@ class DescriptorSuperPropertiesTest : BaseAbstractTest() {
}
}
+
+ @Test
+ fun `kotlin inheriting java should ignore setter lookalike for non accessible field`() {
+ testInline(
+ """
+ |/src/test/A.java
+ |package test;
+ |public class A {
+ | private int a = 1;
+ |
+ | public void setA(int a) { this.a = a; }
+ |}
+ |
+ |/src/test/B.kt
+ |package test
+ |class B : A {}
+ """.trimIndent(),
+ commonTestConfiguration
+ ) {
+ documentablesMergingStage = { module ->
+ val testedClass = module.packages.single().classlikes.single { it.name == "B" }
+
+ val property = testedClass.properties.firstOrNull { it.name == "a" }
+ assertNull(property, "Inherited property `a` should not be visible as it's not accessible")
+
+ val setterLookalike = testedClass.functions.firstOrNull { it.name == "setA" }
+ assertNotNull(setterLookalike) {
+ "Expected setA to be a regular function because field `a` is neither var nor val from Kotlin's " +
+ "interop perspective, it's not accessible."
+ }
+ }
+ }
+ }
+
+
@Test
fun `kotlin inheriting java should append getter and setter`() {
testInline(
@@ -130,13 +167,27 @@ class DescriptorSuperPropertiesTest : BaseAbstractTest() {
}
@Test
- fun `kotlin inheriting java should not append anything since field is public`() {
+ fun `kotlin inheriting java should not append anything since field is public api`() {
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "jvm"
+ name = "jvm"
+ documentedVisibilities = setOf(
+ DokkaConfiguration.Visibility.PUBLIC,
+ DokkaConfiguration.Visibility.PROTECTED
+ )
+ }
+ }
+ }
+
testInline(
"""
|/src/test/A.java
|package test;
|public class A {
- | public int a = 1;
+ | protected int a = 1;
| public int getA() { return a; }
| public void setA(int a) { this.a = a; }
|}
@@ -145,14 +196,18 @@ class DescriptorSuperPropertiesTest : BaseAbstractTest() {
|package test
|class B : A {}
""".trimIndent(),
- commonTestConfiguration
+ configuration
) {
documentablesMergingStage = { module ->
- val kotlinProperties = module.packages.single().classlikes.single { it.name == "B" }.properties
- val property = kotlinProperties.single { it.name == "a" }
+ val testedClass = module.packages.single().classlikes.single { it.name == "B" }
+ val property = testedClass.properties.single { it.name == "a" }
assertNull(property.getter)
assertNull(property.setter)
+ assertEquals(2, testedClass.functions.size)
+
+ assertEquals("getA", testedClass.functions[0].name)
+ assertEquals("setA", testedClass.functions[1].name)
val inheritedFrom = property.extra[InheritedMember]?.inheritedFrom?.values?.single()
assertEquals(DRI(packageName = "test", classNames = "A"), inheritedFrom)
@@ -161,31 +216,106 @@ class DescriptorSuperPropertiesTest : BaseAbstractTest() {
}
@Test
- fun `should preserve regular functions that look like accessors, but are not accessors`() {
+ fun `should inherit property visibility from getter`() {
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "jvm"
+ name = "jvm"
+ documentedVisibilities = setOf(
+ DokkaConfiguration.Visibility.PUBLIC,
+ DokkaConfiguration.Visibility.PROTECTED
+ )
+ }
+ }
+ }
+
testInline(
"""
- |/src/test/A.kt
- |package test
- |class A {
- | val v = 0
- | fun setV() { println(10) } // no arg
- | fun getV(): String { return "s" } // wrong return type
+ |/src/test/A.java
+ |package test;
+ |public class A {
+ | private int a = 1;
+ | protected int getA() { return a; }
+ | protected void setA(int a) { this.a = a; }
|}
+ |
+ |/src/test/B.kt
+ |package test
+ |class B : A {}
""".trimIndent(),
- commonTestConfiguration
+ 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 testedClass = module.packages.single().classlikes.single { it.name == "B" }
+ assertEquals(0, testedClass.functions.size)
+
+ val property = testedClass.properties.single { it.name == "a" }
+
+ assertNotNull(property.getter)
+ assertNotNull(property.setter)
+
+ val propertyVisibility = property.visibility.values.single()
+ assertEquals(KotlinVisibility.Protected, propertyVisibility)
- val getterLookalike = testClass.functions.firstOrNull { it.name == "getV" }
- assertNotNull(getterLookalike) {
- "Expected regular function not found, wrongly categorized as getter?"
+ val getterVisibility = property.getter?.visibility?.values?.single()
+ assertEquals(KotlinVisibility.Protected, getterVisibility)
+
+ val setterVisibility = property.setter?.visibility?.values?.single()
+ assertEquals(KotlinVisibility.Protected, setterVisibility)
+
+ val inheritedFrom = property.extra[InheritedMember]?.inheritedFrom?.values?.single()
+ assertEquals(DRI(packageName = "test", classNames = "A"), inheritedFrom)
+ }
+ }
+ }
+
+ @Test // checking for mapping between kotlin and java visibility
+ fun `should resolve inherited java protected field as protected`() {
+ val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ analysisPlatform = "jvm"
+ name = "jvm"
+ documentedVisibilities = setOf(
+ DokkaConfiguration.Visibility.PUBLIC,
+ DokkaConfiguration.Visibility.PROTECTED
+ )
}
}
}
+
+ testInline(
+ """
+ |/src/test/A.java
+ |package test;
+ |public class A {
+ | protected int protectedProperty = 0;
+ |}
+ |
+ |/src/test/B.kt
+ |package test
+ |class B : A {}
+ """.trimIndent(),
+ configuration
+ ) {
+ documentablesMergingStage = { module ->
+ val testedClass = module.packages.single().classlikes.single { it.name == "B" }
+ assertEquals(0, testedClass.functions.size)
+
+ val property = testedClass.properties.single { it.name == "protectedProperty" }
+
+ assertNull(property.getter)
+ assertNull(property.setter)
+
+ val propertyVisibility = property.visibility.values.single()
+ assertEquals(KotlinVisibility.Protected, propertyVisibility)
+
+ val inheritedFrom = property.extra[InheritedMember]?.inheritedFrom?.values?.single()
+ assertEquals(DRI(packageName = "test", classNames = "A"), inheritedFrom)
+ }
+ }
}
}
diff --git a/plugins/base/src/test/kotlin/superFields/PsiSuperFieldsTest.kt b/plugins/base/src/test/kotlin/superFields/PsiSuperFieldsTest.kt
index 025c9b06..8dd74ef2 100644
--- a/plugins/base/src/test/kotlin/superFields/PsiSuperFieldsTest.kt
+++ b/plugins/base/src/test/kotlin/superFields/PsiSuperFieldsTest.kt
@@ -1,5 +1,6 @@
package superFields
+import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.Annotations
@@ -153,34 +154,4 @@ class PsiSuperFieldsTest : BaseAbstractTest() {
}
}
}
-
- @Test
- fun `should preserve regular functions that look like accessors, but are not accessors`() {
- testInline(
- """
- |/src/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(),
- commonTestConfiguration
- ) {
- 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?"
- }
- }
- }
- }
}