Skip to content

Commit

Permalink
[K2] fix DRI.callable.name of constructor to be just class name in ne…
Browse files Browse the repository at this point in the history
…sted classes (#3564)
  • Loading branch information
whyoleg authored Apr 15, 2024
1 parent 7fc9244 commit f7a42ee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal fun KtAnalysisSession.getDRIFromConstructor(symbol: KtConstructorSymbol
(symbol.containingClassIdIfNonLocal
?: throw IllegalStateException("Can not get class Id due to it is local")).createDRI().copy(
callable = Callable(
name = symbol.containingClassIdIfNonLocal?.relativeClassName?.asString() ?: "",
name = symbol.containingClassIdIfNonLocal?.shortClassName?.asString() ?: "",
params = symbol.valueParameters.map { getTypeReferenceFrom(it.returnType) })
)

Expand Down
45 changes: 45 additions & 0 deletions dokka-subprojects/plugin-base/src/test/kotlin/basic/DRITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,49 @@ class DRITest : BaseAbstractTest() {
}
}
}

@Test
fun `nested classes constructor should have callable name equal to class name`() = testInline(
"""
|/src/main/kotlin/Test.kt
|class Parent { class Nested { class DoubleNested } }
""".trimMargin(),
dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}
) {
documentablesMergingStage = { module ->
fun findConstructorDriOfClass(className: String) =
(module.dfs { it.name == className } as? DClass)?.constructors?.singleOrNull()?.dri

assertEquals(
findConstructorDriOfClass("Parent"),
DRI(
packageName = "",
classNames = "Parent",
callable = Callable("Parent", null, emptyList())
)
)
assertEquals(
findConstructorDriOfClass("Nested"),
DRI(
packageName = "",
classNames = "Parent.Nested",
callable = Callable("Nested", null, emptyList())
)
)
assertEquals(
findConstructorDriOfClass("DoubleNested"),
DRI(
packageName = "",
classNames = "Parent.Nested.DoubleNested",
callable = Callable("DoubleNested", null, emptyList())
)
)
}
}
}

0 comments on commit f7a42ee

Please sign in to comment.