1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package superFields
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.InheritedMember
import org.jetbrains.dokka.model.IsVar
import org.jetbrains.dokka.model.isJvmField
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
class PsiSuperFieldsTest : BaseAbstractTest() {
private val commonTestConfiguration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
analysisPlatform = "jvm"
name = "jvm"
}
}
}
@Test
fun `java inheriting java`() {
testInline(
"""
|/src/test/A.java
|package test;
|public class A {
| public int a = 1;
|}
|
|/src/test/B.java
|package test;
|public class B extends A {}
""".trimIndent(),
commonTestConfiguration
) {
documentablesMergingStage = { module ->
val inheritorProperties = module.packages.single().classlikes.single { it.name == "B" }.properties
val property = inheritorProperties.single { it.name == "a" }
val inheritedFrom = property.extra[InheritedMember]?.inheritedFrom?.values?.single()
assertEquals(DRI(packageName = "test", classNames = "A"), inheritedFrom)
}
}
}
@Test
fun `java inheriting kotlin common case`() {
testInline(
"""
|/src/test/A.kt
|package test
|open class A {
| var a: Int = 1
| val b: Int = 2
|}
|
|/src/test/B.java
|package test;
|public class B extends A {}
""".trimIndent(),
commonTestConfiguration
) {
documentablesMergingStage = { module ->
val inheritorProperties = module.packages.single().classlikes.single { it.name == "B" }.properties
inheritorProperties.single { it.name == "a" }.let { mutableProperty ->
assertNotNull(mutableProperty.getter)
assertNotNull(mutableProperty.setter)
val inheritedFrom = mutableProperty.extra[InheritedMember]?.inheritedFrom?.values?.single()
assertEquals(DRI(packageName = "test", classNames = "A"), inheritedFrom)
assertNotNull(mutableProperty.extra[IsVar])
}
inheritorProperties.single { it.name == "b" }.let { immutableProperty ->
assertNotNull(immutableProperty.getter)
assertNull(immutableProperty.setter)
val inheritedFrom = immutableProperty.extra[InheritedMember]?.inheritedFrom?.values?.single()
assertEquals(DRI(packageName = "test", classNames = "A"), inheritedFrom)
assertNull(immutableProperty.extra[IsVar])
}
}
}
}
@Test
fun `java inheriting kotlin with boolean property`() {
testInline(
"""
|/src/test/A.kt
|package test
|open class A {
| var isActive: Boolean = true
|}
|
|/src/test/B.java
|package test;
|public class B extends A {}
""".trimIndent(),
commonTestConfiguration
) {
documentablesMergingStage = { module ->
val inheritorProperties = module.packages.single().classlikes.single { it.name == "B" }.properties
val property = inheritorProperties.single { it.name == "isActive" }
assertNotNull(property.getter)
assertEquals("isActive", property.getter?.name)
assertNotNull(property.setter)
assertEquals("setActive", property.setter?.name)
val inheritedFrom = property.extra[InheritedMember]?.inheritedFrom?.values?.single()
assertEquals(DRI(packageName = "test", classNames = "A"), inheritedFrom)
assertNotNull(property.extra[IsVar])
}
}
}
@Test
fun `java inheriting kotlin with @JvmField should not inherit accessors`() {
testInline(
"""
|/src/test/A.kt
|package test
|open class A {
| @kotlin.jvm.JvmField
| var a: Int = 1
|}
|
|/src/test/B.java
|package test;
|public class B extends A {}
""".trimIndent(),
dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
analysisPlatform = "jvm"
name = "jvm"
classpath += jvmStdlibPath!! // needed for JvmField
}
}
}
) {
documentablesMergingStage = { module ->
val inheritorProperties = module.packages.single().classlikes.single { it.name == "B" }.properties
val property = inheritorProperties.single { it.name == "a" }
assertNull(property.getter)
assertNull(property.setter)
val jvmFieldAnnotation = property.extra[Annotations]?.directAnnotations?.values?.single()?.find {
it.isJvmField()
}
assertNotNull(jvmFieldAnnotation)
val inheritedFrom = property.extra[InheritedMember]?.inheritedFrom?.values?.single()
assertEquals(DRI(packageName = "test", classNames = "A"), inheritedFrom)
assertNotNull(property.extra[IsVar])
}
}
}
}
|