|
5 | 5 | package model |
6 | 6 |
|
7 | 7 | import org.jetbrains.dokka.model.* |
| 8 | +import org.jetbrains.dokka.pages.MemberPageNode |
8 | 9 | import utils.AbstractModelTest |
9 | 10 | import utils.assertNotNull |
10 | 11 | import utils.name |
@@ -245,6 +246,104 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro |
245 | 246 | } |
246 | 247 | } |
247 | 248 |
|
| 249 | + /** |
| 250 | + * A nested classlike should inherit a clashing property in the same way as a top-level one, |
| 251 | + * see https://github.com/Kotlin/dokka/issues/4588 |
| 252 | + */ |
| 253 | + @Test |
| 254 | + fun `property inherited from clashing parents should be inherited in a nested classlike too`() { |
| 255 | + inlineModelTest( |
| 256 | + """ |
| 257 | + |interface Schema |
| 258 | + |interface NarrowedSchema : Schema |
| 259 | + | |
| 260 | + |interface Base { |
| 261 | + | /** |
| 262 | + | * base property docs |
| 263 | + | */ |
| 264 | + | val schema: Schema |
| 265 | + |} |
| 266 | + | |
| 267 | + |interface NarrowedBase : Base { |
| 268 | + | override val schema: NarrowedSchema |
| 269 | + |} |
| 270 | + | |
| 271 | + |interface Container { |
| 272 | + | interface Nested : Base, NarrowedBase |
| 273 | + |} |
| 274 | + | |
| 275 | + |interface TopLevel : Base, NarrowedBase |
| 276 | + """ |
| 277 | + ) { |
| 278 | + with((this / "property").cast<DPackage>()) { |
| 279 | + fun DProperty.assertInheritedFromBase() { |
| 280 | + dri.classNames equals "Base" |
| 281 | + dri.callable?.name equals "schema" |
| 282 | + |
| 283 | + val inheritedFrom = extra[InheritedMember]?.inheritedFrom?.values?.single() |
| 284 | + .assertNotNull("inheritedFrom") |
| 285 | + inheritedFrom.classNames equals "Base" |
| 286 | + inheritedFrom.callable equals null |
| 287 | + |
| 288 | + documentation.values.single().children.single().text().trim() equals "base property docs" |
| 289 | + } |
| 290 | + |
| 291 | + (this / "Container" / "Nested" / "schema").cast<DProperty>().assertInheritedFromBase() |
| 292 | + (this / "TopLevel" / "schema").cast<DProperty>().assertInheritedFromBase() |
| 293 | + } |
| 294 | + } |
| 295 | + } |
| 296 | + |
| 297 | + /** |
| 298 | + * An inherited property should not get its own page, see https://github.com/Kotlin/dokka/issues/4588 |
| 299 | + */ |
| 300 | + @Test |
| 301 | + fun `no page should be created for a property inherited by a nested classlike from clashing parents`() { |
| 302 | + testInline( |
| 303 | + """ |
| 304 | + |/src/main/kotlin/property/Test.kt |
| 305 | + |package property |
| 306 | + |interface Schema |
| 307 | + |interface NarrowedSchema : Schema |
| 308 | + | |
| 309 | + |interface Base { |
| 310 | + | val schema: Schema |
| 311 | + |} |
| 312 | + | |
| 313 | + |interface NarrowedBase : Base { |
| 314 | + | override val schema: NarrowedSchema |
| 315 | + |} |
| 316 | + | |
| 317 | + |interface Container { |
| 318 | + | interface Nested : Base, NarrowedBase |
| 319 | + |} |
| 320 | + """.trimMargin(), |
| 321 | + dokkaConfiguration { |
| 322 | + sourceSets { |
| 323 | + sourceSet { |
| 324 | + sourceRoots = listOf("src/") |
| 325 | + classpath = listOfNotNull(jvmStdlibPath) |
| 326 | + } |
| 327 | + } |
| 328 | + } |
| 329 | + ) { |
| 330 | + pagesGenerationStage = { root -> |
| 331 | + val nestedPage = root.dfs { it.name == "Nested" }.assertNotNull("Nested page") |
| 332 | + nestedPage.children.map { it.name } equals emptyList<String>() |
| 333 | + |
| 334 | + val schemaPages = root.withDescendants().filterIsInstance<MemberPageNode>() |
| 335 | + .filter { it.name == "schema" } |
| 336 | + .flatMap { it.dri } |
| 337 | + .map { it.toString() } |
| 338 | + .toList() |
| 339 | + schemaPages equals listOf( |
| 340 | + "property/Base/schema/#/PointingToDeclaration/", |
| 341 | + "property/NarrowedBase/schema/#/PointingToDeclaration/" |
| 342 | + ) |
| 343 | + } |
| 344 | + } |
| 345 | + } |
| 346 | + |
248 | 347 | @Test |
249 | 348 | fun sinceKotlin() { |
250 | 349 | inlineModelTest( |
|
0 commit comments