diff options
5 files changed, 13 insertions, 20 deletions
diff --git a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRIFactory.kt b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRIFactory.kt index 217a3b7d..e74f9f6a 100644 --- a/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRIFactory.kt +++ b/kotlin-analysis/src/main/kotlin/org/jetbrains/dokka/analysis/DRIFactory.kt @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull fun DRI.Companion.from(descriptor: DeclarationDescriptor) = descriptor.parentsWithSelf.run { val callable = firstIsInstanceOrNull<CallableDescriptor>() DRI( - firstIsInstanceOrNull<PackageFragmentDescriptor>()?.fqName?.asString(), + firstIsInstanceOrNull<PackageFragmentDescriptor>()?.fqName?.asString() ?: "", (filterIsInstance<ClassDescriptor>() + filterIsInstance<TypeAliasDescriptor>()).toList() .takeIf { it.isNotEmpty() } ?.asReversed() @@ -27,7 +27,7 @@ fun DRI.Companion.from(psi: PsiElement) = psi.parentsWithSelf.run { val psiField = firstIsInstanceOrNull<PsiField>() val classes = filterIsInstance<PsiClass>().filterNot { it is PsiTypeParameter }.toList() // We only want exact PsiClass types, not PsiTypeParameter subtype DRI( - classes.lastOrNull()?.qualifiedName?.substringBeforeLast('.', ""), + classes.lastOrNull()?.qualifiedName?.substringBeforeLast('.', "") ?: "", classes.toList().takeIf { it.isNotEmpty() }?.asReversed()?.mapNotNull { it.name }?.joinToString("."), psiMethod?.let { Callable.from(it) } ?: psiField?.let { Callable.from(it) }, DriTarget.from(psi) diff --git a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt index 096104cc..f25f85a6 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt @@ -89,7 +89,10 @@ open class DokkaLocationProvider( private fun PageNode.parent() = pageGraphRoot.parentMap[this] private val PageNode.pathName: String - get() = if (this is PackagePageNode) name else identifierToFilename(name) + get() = when (this) { + is PackagePageNode -> if (name.isBlank()) "[root]" else name + else -> identifierToFilename(name) + } companion object { internal val reservedFilenames = setOf("index", "con", "aux", "lst", "prn", "nul", "eof", "inp", "out") diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index fccbe716..18b05df4 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -104,7 +104,7 @@ private class DokkaDescriptorVisitor( descriptor: PackageFragmentDescriptor, parent: DRIWithPlatformInfo ): DPackage { - val name = descriptor.fqName.asString().takeUnless { it.isBlank() } ?: fallbackPackageName() + val name = descriptor.fqName.asString().takeUnless { it.isBlank() } ?: "" val driWithPlatform = DRI(packageName = name).withEmptyInfo() val scope = descriptor.getMemberScope() @@ -590,7 +590,7 @@ private class DokkaDescriptorVisitor( private fun TypeParameterDescriptor.toVariantTypeParameter() = DTypeParameter( variantTypeParameter( - TypeParameter(DRI.from(this).withPackageFallbackTo(fallbackPackageName()), name.identifier) + TypeParameter(DRI.from(this), name.identifier) ), resolveDescriptorData(), null, @@ -603,7 +603,7 @@ private class DokkaDescriptorVisitor( is DynamicType -> Dynamic else -> when (val ctor = constructor.declarationDescriptor) { is TypeParameterDescriptor -> TypeParameter( - dri = DRI.from(ctor).withPackageFallbackTo(fallbackPackageName()), + dri = DRI.from(ctor), name = ctor.name.asString() ) else -> TypeConstructor( @@ -776,14 +776,4 @@ private class DokkaDescriptorVisitor( private fun ConstantsEnumValue.fullEnumEntryName() = "${this.enumClassId.relativeClassName.asString()}.${this.enumEntryName.identifier}" - private fun fallbackPackageName(): String = - "[${sourceSet.displayName} root]"// TODO: error-prone, find a better way to do it -} - -private fun DRI.withPackageFallbackTo(fallbackPackage: String): DRI { - return if (packageName.isNullOrBlank()) { - copy(packageName = fallbackPackage) - } else { - this - } } diff --git a/plugins/base/src/test/kotlin/markdown/LinkTest.kt b/plugins/base/src/test/kotlin/markdown/LinkTest.kt index deef1d2d..b84eead4 100644 --- a/plugins/base/src/test/kotlin/markdown/LinkTest.kt +++ b/plugins/base/src/test/kotlin/markdown/LinkTest.kt @@ -73,7 +73,7 @@ class LinkTest : AbstractCoreTest() { val foo = innerClass.children.first { it.name == "foo" } as MemberPageNode val destinationDri = (root.documentable as WithGenerics).generics.first().dri.toString() - assertEquals(destinationDri, "[JVM root]/Outer///PointingToGenericParameters(0)/") + assertEquals(destinationDri, "/Outer///PointingToGenericParameters(0)/") assertNotNull(foo.content.dfs { it is ContentDRILink && it.address.toString() == destinationDri } ) } } diff --git a/plugins/base/src/test/kotlin/model/PackagesTest.kt b/plugins/base/src/test/kotlin/model/PackagesTest.kt index 86222d95..188ee2c6 100644 --- a/plugins/base/src/test/kotlin/model/PackagesTest.kt +++ b/plugins/base/src/test/kotlin/model/PackagesTest.kt @@ -22,8 +22,8 @@ class PackagesTest : AbstractModelTest("/src/main/kotlin/packages/Test.kt", "pac } } ) { - with((this / "[JVM root]").cast<DPackage>()) { - name equals "[JVM root]" + with((this / "").cast<DPackage>()) { + name equals "" children counts 0 } } @@ -131,4 +131,4 @@ class PackagesTest : AbstractModelTest("/src/main/kotlin/packages/Test.kt", "pac // assertEquals(0, model.members.count()) // } // } -}
\ No newline at end of file +} |