aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt14
-rw-r--r--plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt23
2 files changed, 32 insertions, 5 deletions
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index f67ee15c..c410104c 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -300,7 +300,7 @@ class DefaultPsiToDocumentableTranslator(
classlikes = classlikes.await(),
visibility = visibility,
companion = null,
- constructors = parseConstructors(),
+ constructors = parseConstructors(dri),
generics = mapTypeParameters(dri),
sourceSets = setOf(sourceSetData),
isExpectActual = false,
@@ -340,7 +340,7 @@ class DefaultPsiToDocumentableTranslator(
classlikes = classlikes.await(),
visibility = visibility,
companion = null,
- constructors = parseConstructors(),
+ constructors = parseConstructors(dri),
supertypes = ancestors,
sourceSets = setOf(sourceSetData),
isExpectActual = false,
@@ -376,7 +376,7 @@ class DefaultPsiToDocumentableTranslator(
else -> DClass(
dri = dri,
name = name.orEmpty(),
- constructors = parseConstructors(),
+ constructors = parseConstructors(dri),
functions = allFunctions.await(),
properties = allFields.await(),
classlikes = classlikes.await(),
@@ -401,13 +401,17 @@ class DefaultPsiToDocumentableTranslator(
}
}
- private fun PsiClass.parseConstructors(): List<DFunction> {
+ /*
+ * Parameter `parentDRI` required for substitute package name:
+ * in the case of synthetic constructor, it will return empty from [DRI.Companion.from].
+ */
+ private fun PsiClass.parseConstructors(parentDRI: DRI): List<DFunction> {
val constructors = when {
isAnnotationType || isInterface -> emptyArray()
isEnum -> this.constructors
else -> this.constructors.takeIf { it.isNotEmpty() } ?: arrayOf(createDefaultConstructor())
}
- return constructors.map { parseFunction(it, true) }
+ return constructors.map { parseFunction(psi = it, isConstructor = true, parentDRI = parentDRI) }
}
/**
diff --git a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt
index 537a4bfc..5ce6bbb6 100644
--- a/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt
+++ b/plugins/base/src/test/kotlin/translators/DefaultPsiToDocumentableTranslatorTest.kt
@@ -827,6 +827,29 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() {
}
}
}
+
+ @Test
+ fun `default constructor should get the package name`() {
+ testInline(
+ """
+ |/src/main/java/org/test/A.java
+ |package org.test;
+ |public class A {
+ |}
+ """.trimIndent(),
+ configuration
+ ) {
+ documentablesMergingStage = { module ->
+ val testedClass = module.findClasslike(packageName = "org.test", "A") as DClass
+
+ assertEquals(1, testedClass.constructors.size, "Expect 1 default constructor")
+
+ val constructorDRI = testedClass.constructors.first().dri
+ assertEquals("org.test", constructorDRI.packageName)
+ assertEquals("A", constructorDRI.classNames)
+ }
+ }
+ }
}
private fun DFunction.visibility() = visibility.values.first()