Skip to content

Commit

Permalink
Unify InheritedMember DRI logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
BarkingBad committed Feb 24, 2022
1 parent c72b96b commit 668b707
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,8 @@ private class DokkaDescriptorVisitor(
originalDescriptor: PropertyDescriptor,
parent: DRIWithPlatformInfo
): DProperty {
val (dri, inheritedFrom) = originalDescriptor.createDRI().let {
if (it.second != null) (it.second to it.first) as Pair<DRI, DRI?>
else it
}
val (dri, _) = originalDescriptor.createDRI()
val inheritedFrom = dri.copy(callable = null).takeIf { parent.dri.classNames != dri.classNames }
val descriptor = originalDescriptor.getConcreteDescriptor()
val isExpect = descriptor.isExpect
val isActual = descriptor.isActual
Expand Down Expand Up @@ -471,7 +469,7 @@ private class DokkaDescriptorVisitor(
(descriptor.getAnnotationsWithBackingField() + descriptor.fileLevelAnnotations()).toSourceSetDependent()
.toAnnotations(),
descriptor.getDefaultValue()?.let { DefaultValue(it) },
InheritedMember(inheritedFrom.toSourceSetDependent()),
inheritedFrom?.let { InheritedMember(it.toSourceSetDependent()) },
)
)
)
Expand All @@ -488,10 +486,8 @@ private class DokkaDescriptorVisitor(
originalDescriptor: FunctionDescriptor,
parent: DRIWithPlatformInfo
): DFunction {
val (dri, inheritedFrom) = originalDescriptor.createDRI().let {
if (it.second != null) (it.second to it.first) as Pair<DRI, DRI?>
else it
}
val (dri, _) = originalDescriptor.createDRI()
val inheritedFrom = dri.copy(callable = null).takeIf { parent.dri.classNames != dri.classNames }
val descriptor = originalDescriptor.getConcreteDescriptor()
val isExpect = descriptor.isExpect
val isActual = descriptor.isActual
Expand Down Expand Up @@ -521,7 +517,7 @@ private class DokkaDescriptorVisitor(
sourceSets = setOf(sourceSet),
isExpectActual = (isExpect || isActual),
extra = PropertyContainer.withAll(
InheritedMember(inheritedFrom.toSourceSetDependent()),
inheritedFrom?.let { InheritedMember(it.toSourceSetDependent()) },
descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
(descriptor.getAnnotations() + descriptor.fileLevelAnnotations()).toSourceSetDependent()
.toAnnotations(),
Expand Down Expand Up @@ -601,10 +597,9 @@ private class DokkaDescriptorVisitor(
descriptor: PropertyAccessorDescriptor,
propertyDescriptor: PropertyDescriptor,
parent: DRI,
parentInheritedFrom: DRI? = null
inheritedFrom: DRI? = null
): DFunction {
val dri = parent.copy(callable = Callable.from(descriptor))
val inheritedFrom = parentInheritedFrom?.copy(callable = Callable.from(descriptor))
val isGetter = descriptor is PropertyGetterDescriptor
val isExpect = descriptor.isExpect
val isActual = descriptor.isActual
Expand Down Expand Up @@ -689,7 +684,7 @@ private class DokkaDescriptorVisitor(
extra = PropertyContainer.withAll(
descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
descriptor.getAnnotations().toSourceSetDependent().toAnnotations(),
InheritedMember(inheritedFrom.toSourceSetDependent())
inheritedFrom?.let { InheritedMember(it.toSourceSetDependent()) }
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class DefaultPsiToDocumentableTranslator(
false,
psi.additionalExtras().let {
PropertyContainer.withAll(
InheritedMember(inheritedFrom.toSourceSetDependent()),
inheritedFrom?.let { InheritedMember(it.toSourceSetDependent()) },
it.toSourceSetDependent().toAdditionalModifiers(),
(psi.annotations.toList()
.toListOfAnnotations() + it.toListOfAnnotations()).toSourceSetDependent()
Expand Down Expand Up @@ -635,7 +635,7 @@ class DefaultPsiToDocumentableTranslator(
false,
psi.additionalExtras().let {
PropertyContainer.withAll(
InheritedMember(inheritedFrom.toSourceSetDependent()),
inheritedFrom?.let { InheritedMember(it.toSourceSetDependent()) },
it.toSourceSetDependent().toAdditionalModifiers(),
(psi.annotations.toList().toListOfAnnotations() +
it.toListOfAnnotations() +
Expand Down
3 changes: 2 additions & 1 deletion plugins/base/src/test/kotlin/model/PropertyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,15 @@ class PropertyTest : AbstractModelTest("/src/main/kotlin/property/Test.kt", "pro
) {
with((this / "property").cast<DPackage>()) {
with((this / "Bar" / "property").cast<DProperty>()) {
dri.classNames equals "Bar"
dri.classNames equals "Foo"
name equals "property"
children counts 0
with(getter.assertNotNull("Getter")) {
type.name equals "Int"
}
extra[InheritedMember]?.inheritedFrom?.values?.single()?.run {
classNames equals "Foo"
callable equals null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class DescriptorSuperPropertiesTest : BaseAbstractTest() {
Assertions.assertNull(this.setter)
this.extra[InheritedMember]?.inheritedFrom?.values?.single()?.run {
assertEquals(
DRI(packageName = "test", classNames = "A", callable = Callable("a", params = emptyList())),
DRI(packageName = "test", classNames = "A"),
this
)
}
this.getter.run {
this!!.extra[InheritedMember]?.inheritedFrom?.values?.single()?.run {
assertEquals(
DRI(packageName = "test", classNames = "A", callable = Callable("getA", params = emptyList())),
DRI(packageName = "test", classNames = "A"),
this
)
}
Expand Down Expand Up @@ -94,26 +94,22 @@ class DescriptorSuperPropertiesTest : BaseAbstractTest() {
Assertions.assertNotNull(this.setter)
this.extra[InheritedMember]?.inheritedFrom?.values?.single()?.run {
assertEquals(
DRI(packageName = "test", classNames = "A", callable = Callable("a", params = emptyList())),
DRI(packageName = "test", classNames = "A"),
this
)
}
this.getter.run {
this!!.extra[InheritedMember]?.inheritedFrom?.values?.single()?.run {
assertEquals(
DRI(packageName = "test", classNames = "A", callable = Callable("getA", params = emptyList())),
DRI(packageName = "test", classNames = "A"),
this
)
}
}
this.setter.run {
this!!.extra[InheritedMember]?.inheritedFrom?.values?.single()?.run {
assertEquals(
DRI(packageName = "test", classNames = "A",
callable = Callable("setA",
params = listOf(TypeConstructor("kotlin.Int", emptyList()))
)
),
DRI(packageName = "test", classNames = "A"),
this
)
}
Expand Down Expand Up @@ -157,7 +153,7 @@ class DescriptorSuperPropertiesTest : BaseAbstractTest() {
Assertions.assertNull(this.setter)
this.extra[InheritedMember]?.inheritedFrom?.values?.single()?.run {
assertEquals(
DRI(packageName = "test", classNames = "A", callable = Callable("a", params = emptyList())),
DRI(packageName = "test", classNames = "A"),
this
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class JavadocIndexTest : AbstractJavadocTemplateMapTest() {
AnnotationTarget.ANNOTATION_CLASS::class.java.methods.any { it.name == "describeConstable" }

testIndexPages { indexPages ->
assertEquals(if (hasAdditionalFunction()) 41 else 40, indexPages.sumBy { it.elements.size })
assertEquals(if (hasAdditionalFunction()) 32 else 31, indexPages.sumBy { it.elements.size })
}
}

Expand Down

0 comments on commit 668b707

Please sign in to comment.