diff options
Diffstat (limited to 'plugins/base/src/main/kotlin/translators')
4 files changed, 260 insertions, 258 deletions
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 128b9bd4..7cc96a24 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -7,7 +7,6 @@ import org.jetbrains.dokka.links.withClass import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.model.properties.PropertyContainer -import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.parsers.MarkdownParser import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.utilities.DokkaLogger @@ -20,6 +19,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies import org.jetbrains.kotlin.idea.kdoc.findKDoc +import org.jetbrains.kotlin.load.kotlin.toSourceElement import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.components.isVararg @@ -37,35 +37,35 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs object DefaultDescriptorToDocumentableTranslator : SourceToDocumentableTranslator { - override fun invoke(platformData: PlatformData, context: DokkaContext): DModule { + override fun invoke(sourceSet: SourceSetData, context: DokkaContext): DModule { - val (environment, facade) = context.platforms.getValue(platformData) + val (environment, facade) = context.platforms.getValue(sourceSet) val packageFragments = environment.getSourceFiles().asSequence() .map { it.packageFqName } .distinct() .mapNotNull { facade.resolveSession.getPackageFragment(it) } .toList() - return DokkaDescriptorVisitor(platformData, context.platforms.getValue(platformData).facade, context.logger).run { + return DokkaDescriptorVisitor(sourceSet, context.platforms.getValue(sourceSet).facade, context.logger).run { packageFragments.mapNotNull { it.safeAs<PackageFragmentDescriptor>() }.map { visitPackageFragmentDescriptor( it, - DRIWithPlatformInfo(DRI.topLevel, PlatformDependent.empty()) + DRIWithPlatformInfo(DRI.topLevel, emptyMap()) ) } - }.let { DModule(platformData.name, it, PlatformDependent.empty(), listOf(platformData)) } + }.let { DModule(sourceSet.moduleName, it, emptyMap(), null, listOf(sourceSet)) } } } data class DRIWithPlatformInfo( val dri: DRI, - val actual: PlatformDependent<DocumentableSource> + val actual: SourceSetDependent<DocumentableSource> ) -fun DRI.withEmptyInfo() = DRIWithPlatformInfo(this, PlatformDependent.empty()) +fun DRI.withEmptyInfo() = DRIWithPlatformInfo(this, emptyMap()) private class DokkaDescriptorVisitor( - private val platformData: PlatformData, + private val sourceSet: SourceSetData, private val resolutionFacade: DokkaResolutionFacade, private val logger: DokkaLogger ) : DeclarationDescriptorVisitorEmptyBodies<Documentable, DRIWithPlatformInfo>() { @@ -73,23 +73,30 @@ private class DokkaDescriptorVisitor( throw IllegalStateException("${javaClass.simpleName} should never enter ${descriptor.javaClass.simpleName}") } + private fun Collection<DeclarationDescriptor>.filterDescriptorsInSourceSet() = filter { + val path = it.toSourceElement.containingFile.toString() + path.isNotBlank() && sourceSet.sourceRoots.any { root -> path.startsWith(root.path) } + } + + private fun <T> T.toSourceSetDependent() = mapOf(sourceSet to this) + override fun visitPackageFragmentDescriptor( descriptor: PackageFragmentDescriptor, parent: DRIWithPlatformInfo ): DPackage { - val name = descriptor.fqName.asString().takeUnless { it.isBlank() } - ?: "[" + platformData.targets.joinToString(" ") + " root]"// TODO: error-prone, find a better way to do it + val name = descriptor.fqName.asString().takeUnless { it.isBlank() } ?: + "[${sourceSet.sourceSetName} root]"// TODO: error-prone, find a better way to do it val driWithPlatform = DRI(packageName = name).withEmptyInfo() val scope = descriptor.getMemberScope() return DPackage( dri = driWithPlatform.dri, - functions = scope.functions(driWithPlatform), - properties = scope.properties(driWithPlatform), - classlikes = scope.classlikes(driWithPlatform), - typealiases = scope.typealiases(driWithPlatform), - documentation = descriptor.resolveDescriptorData(platformData), - platformData = listOf(platformData) + functions = scope.functions(driWithPlatform, true), + properties = scope.properties(driWithPlatform, true), + classlikes = scope.classlikes(driWithPlatform, true), + typealiases = scope.typealiases(driWithPlatform, true), + documentation = descriptor.resolveDescriptorData(), + sourceSets = listOf(sourceSet) ) } @@ -106,7 +113,7 @@ private class DokkaDescriptorVisitor( val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo() val scope = descriptor.unsubstitutedMemberScope val isExpect = descriptor.isExpect - val info = descriptor.resolveClassDescriptionData(if (!isExpect) platformData else null) + val info = descriptor.resolveClassDescriptionData() return DInterface( @@ -116,14 +123,13 @@ private class DokkaDescriptorVisitor( properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), sources = descriptor.createSources(), - visibility = if (isExpect) PlatformDependent.expectFrom(descriptor.visibility.toDokkaVisibility()) - else PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), - supertypes = if (isExpect) PlatformDependent.expectFrom(info.supertypes) - else PlatformDependent.from(platformData, info.supertypes), + expectPresentInSet = sourceSet.takeIf { isExpect }, + visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), + supertypes = info.supertypes.toSourceSetDependent(), documentation = info.docs, generics = descriptor.typeConstructor.parameters.map { it.toTypeParameter() }, companion = descriptor.companion(driWithPlatform), - platformData = listOf(platformData), + sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) ) } @@ -132,7 +138,7 @@ private class DokkaDescriptorVisitor( val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo() val scope = descriptor.unsubstitutedMemberScope val isExpect = descriptor.isExpect - val info = descriptor.resolveClassDescriptionData(if (!isExpect) platformData else null) + val info = descriptor.resolveClassDescriptionData() return DObject( @@ -142,12 +148,11 @@ private class DokkaDescriptorVisitor( properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), sources = descriptor.createSources(), - visibility = if (isExpect) PlatformDependent.expectFrom(descriptor.visibility.toDokkaVisibility()) - else PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), - supertypes = if (isExpect) PlatformDependent.expectFrom(info.supertypes) - else PlatformDependent.from(platformData, info.supertypes), + expectPresentInSet = sourceSet.takeIf { isExpect }, + visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), + supertypes = info.supertypes.toSourceSetDependent(), documentation = info.docs, - platformData = listOf(platformData), + sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) ) } @@ -156,7 +161,7 @@ private class DokkaDescriptorVisitor( val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo() val scope = descriptor.unsubstitutedMemberScope val isExpect = descriptor.isExpect - val info = descriptor.resolveClassDescriptionData(if (!isExpect) platformData else null) + val info = descriptor.resolveClassDescriptionData() return DEnum( dri = driWithPlatform.dri, @@ -167,13 +172,12 @@ private class DokkaDescriptorVisitor( properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), sources = descriptor.createSources(), - visibility = if (isExpect) PlatformDependent.expectFrom(descriptor.visibility.toDokkaVisibility()) - else PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), - supertypes = if (isExpect) PlatformDependent.expectFrom(info.supertypes) - else PlatformDependent.from(platformData, info.supertypes), + expectPresentInSet = sourceSet.takeIf { isExpect }, + visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), + supertypes = info.supertypes.toSourceSetDependent(), documentation = info.docs, companion = descriptor.companion(driWithPlatform), - platformData = listOf(platformData), + sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) ) } @@ -186,11 +190,12 @@ private class DokkaDescriptorVisitor( return DEnumEntry( dri = driWithPlatform.dri, name = descriptor.name.asString(), - documentation = descriptor.resolveDescriptorData(if (!isExpect) platformData else null), + documentation = descriptor.resolveDescriptorData(), classlikes = scope.classlikes(driWithPlatform), functions = scope.functions(driWithPlatform), properties = scope.properties(driWithPlatform), - platformData = listOf(platformData), + sourceSets = listOf(sourceSet), + expectPresentInSet = sourceSet.takeIf { isExpect }, extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) ) } @@ -202,14 +207,15 @@ private class DokkaDescriptorVisitor( return DAnnotation( dri = driWithPlatform.dri, name = descriptor.name.asString(), - documentation = descriptor.resolveDescriptorData(platformData), + documentation = descriptor.resolveDescriptorData(), classlikes = scope.classlikes(driWithPlatform), functions = scope.functions(driWithPlatform), properties = scope.properties(driWithPlatform), - platformData = listOf(platformData), + expectPresentInSet = null, + sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()), companion = descriptor.companionObjectDescriptor?.let { objectDescriptor(it, driWithPlatform) }, - visibility = PlatformDependent(mapOf(platformData to descriptor.visibility.toDokkaVisibility())), + visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), constructors = descriptor.constructors.map { visitConstructorDescriptor(it, driWithPlatform) }, sources = descriptor.createSources() ) @@ -219,7 +225,7 @@ private class DokkaDescriptorVisitor( val driWithPlatform = parent.dri.withClass(descriptor.name.asString()).withEmptyInfo() val scope = descriptor.unsubstitutedMemberScope val isExpect = descriptor.isExpect - val info = descriptor.resolveClassDescriptionData(if (!isExpect) platformData else null) + val info = descriptor.resolveClassDescriptionData() val actual = descriptor.createSources() return DClass( @@ -229,23 +235,21 @@ private class DokkaDescriptorVisitor( visitConstructorDescriptor( it, if (it.isPrimary) DRIWithPlatformInfo(driWithPlatform.dri, actual) - else DRIWithPlatformInfo(driWithPlatform.dri, PlatformDependent.empty()) + else DRIWithPlatformInfo(driWithPlatform.dri, emptyMap()) ) }, functions = scope.functions(driWithPlatform), properties = scope.properties(driWithPlatform), classlikes = scope.classlikes(driWithPlatform), sources = actual, - visibility = if (isExpect) PlatformDependent.expectFrom(descriptor.visibility.toDokkaVisibility()) - else PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), - supertypes = if (isExpect) PlatformDependent.expectFrom(info.supertypes) - else PlatformDependent.from(platformData, info.supertypes), + expectPresentInSet = sourceSet.takeIf { isExpect }, + visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), + supertypes = info.supertypes.toSourceSetDependent(), generics = descriptor.typeConstructor.parameters.map { it.toTypeParameter() }, documentation = info.docs, - modifier = if (isExpect) PlatformDependent.expectFrom(descriptor.modifier()) - else PlatformDependent.from(platformData, descriptor.modifier()), + modifier = descriptor.modifier().toSourceSetDependent(), companion = descriptor.companion(driWithPlatform), - platformData = listOf(platformData), + sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) ) } @@ -268,13 +272,12 @@ private class DokkaDescriptorVisitor( setter = descriptor.accessors.filterIsInstance<PropertySetterDescriptor>().singleOrNull()?.let { visitPropertyAccessorDescriptor(it, descriptor, dri) }, - visibility = if (isExpect) PlatformDependent.expectFrom(descriptor.visibility.toDokkaVisibility()) - else PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), - documentation = descriptor.resolveDescriptorData(if (!isExpect) platformData else null), - modifier = if (isExpect) PlatformDependent.expectFrom(descriptor.modifier()) - else PlatformDependent.from(platformData, descriptor.modifier()), + visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), + documentation = descriptor.resolveDescriptorData(), + modifier = descriptor.modifier().toSourceSetDependent(), type = descriptor.returnType!!.toBound(), - platformData = listOf(platformData), + expectPresentInSet = sourceSet.takeIf { isExpect }, + sourceSets = listOf(sourceSet), generics = descriptor.typeParameters.map { it.toTypeParameter() }, extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) ) @@ -301,15 +304,14 @@ private class DokkaDescriptorVisitor( parameters = descriptor.valueParameters.mapIndexed { index, desc -> parameter(index, desc, DRIWithPlatformInfo(dri, actual)) }, + expectPresentInSet = sourceSet.takeIf { isExpect }, sources = actual, - visibility = if (isExpect) PlatformDependent.expectFrom(descriptor.visibility.toDokkaVisibility()) - else PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), + visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), generics = descriptor.typeParameters.map { it.toTypeParameter() }, - documentation = descriptor.resolveDescriptorData(if (!isExpect) platformData else null), - modifier = if (isExpect) PlatformDependent.expectFrom(descriptor.modifier()) - else PlatformDependent.from(platformData, descriptor.modifier()), + documentation = descriptor.resolveDescriptorData(), + modifier = descriptor.modifier().toSourceSetDependent(), type = descriptor.returnType!!.toBound(), - platformData = listOf(platformData), + sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll( InheritedFunction(isInherited), descriptor.additionalExtras(), descriptor.getAnnotations() @@ -333,41 +335,27 @@ private class DokkaDescriptorVisitor( parameter(index, desc, DRIWithPlatformInfo(dri, actual)) }, sources = actual, - visibility = if (isExpect) PlatformDependent.expectFrom(descriptor.visibility.toDokkaVisibility()) - else PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), - documentation = descriptor.resolveDescriptorData(if (!isExpect) platformData else null).let { + expectPresentInSet = sourceSet.takeIf { isExpect }, + visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), + documentation = descriptor.resolveDescriptorData().let { sourceSetDependent -> if (descriptor.isPrimary) { - it.copy( - map = PlatformDependent.from(it.map.map { - Pair( - it.key, - it.value.copy(children = (it.value.children.find { it is Constructor }?.root?.let { constructor -> - listOf( - Description(constructor) - ) - } ?: emptyList<TagWrapper>()) + it.value.children.filterIsInstance<Param>()) - ) - }), - expect = it.expect?.copy(children = (it.expect?.children?.find { it is Constructor }?.root?.let { constructor -> - listOf( - Description(constructor) - ) - } ?: emptyList<TagWrapper>()) + it.expect!!.children.filterIsInstance<Param>()) - ) + sourceSetDependent.map { entry -> + Pair(entry.key, entry.value.copy(children = (entry.value.children.find { it is Constructor }?.root?.let { constructor -> + listOf( Description(constructor) ) + } ?: emptyList<TagWrapper>()) + entry.value.children.filterIsInstance<Param>())) + }.toMap() } else { - it + sourceSetDependent } }, type = descriptor.returnType.toBound(), - modifier = if (isExpect) PlatformDependent.expectFrom(descriptor.modifier()) - else PlatformDependent.from(platformData, descriptor.modifier()), + modifier = descriptor.modifier().toSourceSetDependent(), generics = descriptor.typeParameters.map { it.toTypeParameter() }, - platformData = listOf(platformData), + sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll<DFunction>(descriptor.additionalExtras(), descriptor.getAnnotations()) .let { - if (descriptor.isPrimary) { - it + PrimaryConstructorExtra - } else it + if(descriptor.isPrimary) { it + PrimaryConstructorExtra } + else it } ) } @@ -379,8 +367,9 @@ private class DokkaDescriptorVisitor( dri = parent.dri.copy(target = 0), name = null, type = descriptor.type.toBound(), - documentation = descriptor.resolveDescriptorData(platformData), - platformData = listOf(platformData) + expectPresentInSet = null, + documentation = descriptor.resolveDescriptorData(), + sourceSets = listOf(sourceSet) ) private fun visitPropertyAccessorDescriptor( @@ -397,8 +386,9 @@ private class DokkaDescriptorVisitor( parent.copy(target = 1), this.name.asString(), type = this.type.toBound(), - documentation = descriptor.resolveDescriptorData(if (!isExpect) platformData else null), - platformData = listOf(platformData), + expectPresentInSet = sourceSet.takeIf { isExpect }, + documentation = descriptor.resolveDescriptorData(), + sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) ) @@ -420,13 +410,12 @@ private class DokkaDescriptorVisitor( name, isConstructor = false, parameters = parameters, - visibility = if (isExpect) PlatformDependent.expectFrom(descriptor.visibility.toDokkaVisibility()) - else PlatformDependent.from(platformData, descriptor.visibility.toDokkaVisibility()), - documentation = descriptor.resolveDescriptorData(if (!isExpect) platformData else null), + visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(), + documentation = descriptor.resolveDescriptorData(), type = descriptor.returnType!!.toBound(), generics = descriptor.typeParameters.map { it.toTypeParameter() }, - modifier = if (isExpect) PlatformDependent.expectFrom(descriptor.modifier()) - else PlatformDependent.from(platformData, descriptor.modifier()), + modifier = descriptor.modifier().toSourceSetDependent(), + expectPresentInSet = sourceSet.takeIf { isExpect }, receiver = descriptor.extensionReceiverParameter?.let { visitReceiverParameterDescriptor( it, @@ -434,7 +423,7 @@ private class DokkaDescriptorVisitor( ) }, sources = descriptor.createSources(), - platformData = listOf(platformData), + sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll(descriptor.additionalExtras(), descriptor.getAnnotations()) ) } @@ -445,11 +434,11 @@ private class DokkaDescriptorVisitor( dri = DRI.from(this), name = name.asString(), type = defaultType.toBound(), - underlyingType = PlatformDependent.from(platformData, underlyingType.toBound()), - visibility = if (isExpect) PlatformDependent.expectFrom(visibility.toDokkaVisibility()) - else PlatformDependent.from(platformData, visibility.toDokkaVisibility()), - documentation = resolveDescriptorData(platformData), - platformData = listOf(platformData) + expectPresentInSet = null, + underlyingType = underlyingType.toBound().toSourceSetDependent(), + visibility = visibility.toDokkaVisibility().toSourceSetDependent(), + documentation = resolveDescriptorData(), + sourceSets = listOf(sourceSet) ) } @@ -458,8 +447,9 @@ private class DokkaDescriptorVisitor( dri = parent.dri.copy(target = index + 1), name = descriptor.name.asString(), type = descriptor.type.toBound(), - documentation = descriptor.resolveDescriptorData(platformData), - platformData = listOf(platformData), + expectPresentInSet = null, + documentation = descriptor.resolveDescriptorData(), + sourceSets = listOf(sourceSet), extra = PropertyContainer.withAll( listOfNotNull( descriptor.additionalExtras(), @@ -468,18 +458,23 @@ private class DokkaDescriptorVisitor( ) ) - private fun MemberScope.functions(parent: DRIWithPlatformInfo): List<DFunction> = - getContributedDescriptors(DescriptorKindFilter.FUNCTIONS) { true } + private fun MemberScope.getContributedDescriptors(kindFilter: DescriptorKindFilter, shouldFilter: Boolean) = + getContributedDescriptors(kindFilter) { true }.let { + if (shouldFilter) it.filterDescriptorsInSourceSet() else it + } + + private fun MemberScope.functions(parent: DRIWithPlatformInfo, packageLevel: Boolean = false): List<DFunction> = + getContributedDescriptors(DescriptorKindFilter.FUNCTIONS, packageLevel) .filterIsInstance<FunctionDescriptor>() .map { visitFunctionDescriptor(it, parent) } - private fun MemberScope.properties(parent: DRIWithPlatformInfo): List<DProperty> = - getContributedDescriptors(DescriptorKindFilter.VALUES) { true } + private fun MemberScope.properties(parent: DRIWithPlatformInfo, packageLevel: Boolean = false): List<DProperty> = + getContributedDescriptors(DescriptorKindFilter.VALUES, packageLevel) .filterIsInstance<PropertyDescriptor>() .map { visitPropertyDescriptor(it, parent) } - private fun MemberScope.classlikes(parent: DRIWithPlatformInfo): List<DClasslike> = - getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS) { true } + private fun MemberScope.classlikes(parent: DRIWithPlatformInfo, packageLevel: Boolean = false): List<DClasslike> = + getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS, packageLevel) .filter { it is ClassDescriptor && it.kind != ClassKind.ENUM_ENTRY } .map { visitClassDescriptor(it as ClassDescriptor, parent) } .mapNotNull { it as? DClasslike } @@ -489,8 +484,8 @@ private class DokkaDescriptorVisitor( .filterIsInstance<PackageFragmentDescriptor>() .map { visitPackageFragmentDescriptor(it, parent) } - private fun MemberScope.typealiases(parent: DRIWithPlatformInfo): List<DTypeAlias> = - getContributedDescriptors(DescriptorKindFilter.TYPE_ALIASES) { true } + private fun MemberScope.typealiases(parent: DRIWithPlatformInfo, packageLevel: Boolean = false): List<DTypeAlias> = + getContributedDescriptors(DescriptorKindFilter.TYPE_ALIASES, packageLevel) .filterIsInstance<TypeAliasDescriptor>() .map { visitTypeAliasDescriptor(it, parent) } @@ -500,19 +495,14 @@ private class DokkaDescriptorVisitor( .filter { it.kind == ClassKind.ENUM_ENTRY } .map { enumEntryDescriptor(it, parent) } - private fun DeclarationDescriptor.resolveDescriptorData(platformData: PlatformData?): PlatformDependent<DocumentationNode> = getDocumentation().let { - if (it.children.isEmpty()) - PlatformDependent.empty() - else if (platformData != null) - PlatformDependent.from(platformData, it) - else - PlatformDependent.expectFrom(it) - } - private fun ClassDescriptor.resolveClassDescriptionData(platformData: PlatformData?): ClassInfo { + private fun DeclarationDescriptor.resolveDescriptorData(): SourceSetDependent<DocumentationNode> = + getDocumentation()?.toSourceSetDependent() ?: emptyMap() + + private fun ClassDescriptor.resolveClassDescriptionData(): ClassInfo { return ClassInfo( (getSuperInterfaces() + getAllSuperclassesWithoutAny()).map { DRI.from(it) }, - resolveDescriptorData(platformData) + resolveDescriptorData() ) } @@ -520,9 +510,10 @@ private class DokkaDescriptorVisitor( DTypeParameter( DRI.from(this), name.identifier, - PlatformDependent.from(platformData, getDocumentation()), + resolveDescriptorData(), + null, upperBounds.map { it.toBound() }, - listOf(platformData), + listOf(sourceSet), extra = PropertyContainer.withAll(additionalExtras()) ) @@ -555,7 +546,7 @@ private class DokkaDescriptorVisitor( private fun DeclarationDescriptor.getDocumentation() = findKDoc().let { MarkdownParser(resolutionFacade, this, logger).parseFromKDocTag(it) - } + }.takeIf { it.children.isNotEmpty() } private fun ClassDescriptor.companion(dri: DRIWithPlatformInfo): DObject? = companionObjectDescriptor?.let { objectDescriptor(it, dri) @@ -569,11 +560,8 @@ private class DokkaDescriptorVisitor( else -> KotlinModifier.Empty } - private fun MemberDescriptor.createSources(): PlatformDependent<DocumentableSource> = if (isExpect()) { - PlatformDependent(emptyMap(), DescriptorDocumentableSource(this)) - } else { - PlatformDependent(mapOf(platformData to DescriptorDocumentableSource(this))) - } + private fun MemberDescriptor.createSources(): SourceSetDependent<DocumentableSource> = + DescriptorDocumentableSource(this).toSourceSetDependent() private fun FunctionDescriptor.additionalExtras() = listOfNotNull( ExtraModifiers.DYNAMIC.takeIf { isDynamic() }, @@ -634,7 +622,7 @@ private class DokkaDescriptorVisitor( private fun ValueParameterDescriptor.getDefaultValue(): String? = (source as? KotlinSourceElement)?.psi?.children?.find { it is KtExpression }?.text - private data class ClassInfo(val supertypes: List<DRI>, val docs: PlatformDependent<DocumentationNode>) + private data class ClassInfo(val supertypes: List<DRI>, val docs: SourceSetDependent<DocumentationNode>) private fun Visibility.toDokkaVisibility(): org.jetbrains.dokka.model.Visibility = when (this) { Visibilities.PUBLIC -> KotlinVisibility.Public diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index 439da560..232f6721 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs import kotlin.reflect.KClass import kotlin.reflect.full.isSubclassOf -private typealias GroupedTags = Map<KClass<out TagWrapper>, List<Pair<PlatformData?, TagWrapper>>> +private typealias GroupedTags = Map<KClass<out TagWrapper>, List<Pair<SourceSetData?, TagWrapper>>> private val specialTags: Set<KClass<out TagWrapper>> = setOf(Property::class, Description::class, Constructor::class, Receiver::class, Param::class, See::class) @@ -68,8 +68,8 @@ open class DefaultPageCreator( header(1) { text(m.name) } } +contentForComments(m) - block("Packages", 2, ContentKind.Packages, m.packages, m.platformData.toSet()) { - link(it.name, it.dri, kind = ContentKind.Main) + block("Packages", 2, ContentKind.Packages, m.packages, m.sourceSets.toSet()) { + link(it.name, it.dri) } // text("Index\n") TODO // text("Link to allpage here") @@ -80,10 +80,10 @@ open class DefaultPageCreator( header(1) { text("Package ${p.name}") } } +contentForComments(p) - +contentForScope(p, p.dri, p.platformData) - block("Type aliases", 2, ContentKind.TypeAliases, p.typealiases, p.platformData.toSet()) { + +contentForScope(p, p.dri, p.sourceSets) + block("Type aliases", 2, ContentKind.TypeAliases, p.typealiases, p.sourceSets.toSet()) { link(it.name, it.dri, kind = ContentKind.Main) - platformDependentHint(it.dri, it.platformData.toSet(), kind = ContentKind.PlatformDependantHint) { + sourceSetDependentHint(it.dri, it.sourceSets.toSet(), kind = ContentKind.SourceSetDependantHint) { +buildSignature(it) contentForBrief(it) } @@ -93,47 +93,47 @@ open class DefaultPageCreator( protected open fun contentForScope( s: WithScope, dri: DRI, - platformData: List<PlatformData> + sourceSets: List<SourceSetData> ) = contentBuilder.contentFor(s as Documentable) { - block("Types", 2, ContentKind.Classlikes, s.classlikes, platformData.toSet()) { + block("Types", 2, ContentKind.Classlikes, s.classlikes, sourceSets.toSet()) { link(it.name ?: "", it.dri, kind = ContentKind.Main) - platformDependentHint(it.dri, it.platformData.toSet(), kind = ContentKind.PlatformDependantHint) { + sourceSetDependentHint(it.dri, it.sourceSets.toSet(), kind = ContentKind.SourceSetDependantHint) { +buildSignature(it) contentForBrief(it) } } - block("Functions", 2, ContentKind.Functions, s.functions, platformData.toSet()) { + block("Functions", 2, ContentKind.Functions, s.functions, sourceSets.toSet()) { link(it.name, it.dri, kind = ContentKind.Main) - platformDependentHint(it.dri, it.platformData.toSet(), kind = ContentKind.PlatformDependantHint) { + sourceSetDependentHint(it.dri, it.sourceSets.toSet(), kind = ContentKind.SourceSetDependantHint) { +buildSignature(it) contentForBrief(it) } } - block("Properties", 2, ContentKind.Properties, s.properties, platformData.toSet()) { + block("Properties", 2, ContentKind.Properties, s.properties, sourceSets.toSet()) { link(it.name, it.dri, kind = ContentKind.Main) - platformDependentHint(it.dri, it.platformData.toSet(), kind = ContentKind.PlatformDependantHint) { + sourceSetDependentHint(it.dri, it.sourceSets.toSet(), kind = ContentKind.SourceSetDependantHint) { +buildSignature(it) contentForBrief(it) } } s.safeAs<WithExtraProperties<Documentable>>()?.let { it.extra[InheritorsInfo] }?.let { inheritors -> - val map = inheritors.value.map.filter { it.value.isNotEmpty() } + val map = inheritors.value.filter { it.value.isNotEmpty() } if (map.values.any()) { header(2) { text("Inheritors") } +ContentTable( emptyList(), map.entries.flatMap { entry -> entry.value.map { Pair(entry.key, it) } } .groupBy({ it.second }, { it.first }).map { (classlike, platforms) -> - buildGroup(dri, platforms.toSet(), ContentKind.Inheritors) { - link( - classlike.classNames?.substringBeforeLast(".") ?: classlike.toString() - .also { logger.warn("No class name found for DRI $classlike") }, classlike - ) - } - }, + buildGroup(dri, platforms.toSet(), ContentKind.Inheritors) { + link( + classlike.classNames?.substringBeforeLast(".") ?: classlike.toString() + .also { logger.warn("No class name found for DRI $classlike") }, classlike + ) + } + }, DCI(setOf(dri), ContentKind.Inheritors), - platformData.toSet(), + sourceSets.toSet(), style = emptySet() ) } @@ -146,13 +146,13 @@ open class DefaultPageCreator( +buildSignature(e) } +contentForComments(e) - +contentForScope(e, e.dri, e.platformData) + +contentForScope(e, e.dri, e.sourceSets) } protected open fun contentForClasslike(c: DClasslike) = contentBuilder.contentFor(c) { group(kind = ContentKind.Cover) { header(1) { text(c.name.orEmpty()) } - platformDependentHint(c.dri, c.platformData.toSet()) { + sourceSetDependentHint(c.dri, c.sourceSets.toSet()) { +buildSignature(c) } } @@ -164,58 +164,57 @@ open class DefaultPageCreator( 2, ContentKind.Constructors, c.constructors.filter { it.extra[PrimaryConstructorExtra] == null }, - c.platformData.toSet() + c.sourceSets.toSet() ) { link(it.name, it.dri, kind = ContentKind.Main) - platformDependentHint(it.dri, it.platformData.toSet(), kind = ContentKind.PlatformDependantHint) { + sourceSetDependentHint(it.dri, it.sourceSets.toSet(), kind = ContentKind.SourceSetDependantHint) { +buildSignature(it) contentForBrief(it) } } } if (c is DEnum) { - block("Entries", 2, ContentKind.Classlikes, c.entries, c.platformData.toSet()) { + block("Entries", 2, ContentKind.Classlikes, c.entries, c.sourceSets.toSet()) { link(it.name, it.dri, kind = ContentKind.Main) - platformDependentHint(it.dri, it.platformData.toSet(), kind = ContentKind.PlatformDependantHint) { + sourceSetDependentHint(it.dri, it.sourceSets.toSet(), kind = ContentKind.SourceSetDependantHint) { +buildSignature(it) contentForBrief(it) } } } - +contentForScope(c, c.dri, c.platformData) + +contentForScope(c, c.dri, c.sourceSets) } @Suppress("UNCHECKED_CAST") - private inline fun <reified T : TagWrapper> GroupedTags.withTypeUnnamed(): PlatformDependent<T> = - (this[T::class] as List<Pair<PlatformData, T>>?) - ?.let { PlatformDependent.from(it) }.orEmpty() + private inline fun <reified T : TagWrapper> GroupedTags.withTypeUnnamed(): SourceSetDependent<T> = + (this[T::class] as List<Pair<SourceSetData, T>>?)?.toMap().orEmpty() @Suppress("UNCHECKED_CAST") - private inline fun <reified T : NamedTagWrapper> GroupedTags.withTypeNamed(): Map<String, PlatformDependent<T>> = - (this[T::class] as List<Pair<PlatformData, T>>?) + private inline fun <reified T : NamedTagWrapper> GroupedTags.withTypeNamed(): Map<String, SourceSetDependent<T>> = + (this[T::class] as List<Pair<SourceSetData, T>>?) ?.groupBy { it.second.name } - ?.mapValues { (_, v) -> PlatformDependent.from(v) } + ?.mapValues { (_, v) -> v.toMap() } .orEmpty() private inline fun <reified T : TagWrapper> GroupedTags.isNotEmptyForTag(): Boolean = - this[T::class]?.isNotEmpty() ?: false + this[T::class]?.isNotEmpty() ?: false protected open fun contentForComments( d: Documentable ): List<ContentNode> { - val tags: GroupedTags = d.documentation.allEntries.flatMap { (pd, doc) -> - doc.children.asSequence().map { pd to it } + val tags: GroupedTags = d.documentation.flatMap { (pd, doc) -> + doc.children.asSequence().map { pd to it }.toList() }.groupBy { it.second::class } - val platforms = d.platformData + val platforms = d.sourceSets fun DocumentableContentBuilder.contentForDescription() { val description = tags.withTypeUnnamed<Description>() if (description.any { it.value.root.children.isNotEmpty() }) { platforms.forEach { platform -> - description.getOrExpect(platform)?.also { - group(platformData = setOf(platform)) { + description[platform]?.also { + group(sourceSets = setOf(platform)) { comment(it.root) } } @@ -232,16 +231,16 @@ open class DefaultPageCreator( } table(kind = ContentKind.Parameters) { platforms.flatMap { platform -> - val receiverRow = receiver.getOrExpect(platform)?.let { - buildGroup(platformData = setOf(platform), kind = ContentKind.Parameters, styles = mainStyles + ContentStyle.KeyValue) { + val receiverRow = receiver[platform]?.let { + buildGroup(sourceSets = setOf(platform), kind = ContentKind.Parameters, styles = mainStyles + ContentStyle.KeyValue) { text("<receiver>") comment(it.root) } } val paramRows = params.mapNotNull { (_, param) -> - param.getOrExpect(platform)?.let { - buildGroup(platformData = setOf(platform), kind = ContentKind.Parameters, styles = mainStyles + ContentStyle.KeyValue) { + param[platform]?.let { + buildGroup(sourceSets = setOf(platform), kind = ContentKind.Parameters, styles = mainStyles + ContentStyle.KeyValue) { text(it.name, kind = ContentKind.Parameters) comment(it.root) } @@ -263,8 +262,8 @@ open class DefaultPageCreator( table(kind = ContentKind.Sample) { platforms.flatMap { platform -> seeAlsoTags.mapNotNull { (_, see) -> - see.getOrExpect(platform)?.let { - buildGroup(platformData = setOf(platform), kind = ContentKind.Comment, styles = mainStyles + ContentStyle.KeyValue) { + see[platform]?.let { + buildGroup(sourceSets = setOf(platform), kind = ContentKind.Comment, styles = mainStyles + ContentStyle.KeyValue) { if (it.address != null) link(it.name, it.address!!, kind = ContentKind.Comment) else text(it.name, kind = ContentKind.Comment) comment(it.root) @@ -282,7 +281,7 @@ open class DefaultPageCreator( platforms.forEach { platformData -> val content = samples.filter { it.value.isEmpty() || platformData in it.value } if (content.isNotEmpty()) { - group(platformData = setOf(platformData)) { + group(sourceSets = setOf(platformData)) { header(4, kind = ContentKind.Comment) { text("Samples") } content.forEach { comment(Text(it.key)) @@ -294,13 +293,13 @@ open class DefaultPageCreator( } fun DocumentableContentBuilder.contentForUnnamedTags() { - val unnamedTags: List<PlatformDependent<TagWrapper>> = + val unnamedTags: List<SourceSetDependent<TagWrapper>> = tags.filterNot { (k, _) -> k.isSubclassOf(NamedTagWrapper::class) || k in specialTags } - .map { (_, v) -> PlatformDependent.from(v) } + .map { (_, v) -> v.mapNotNull { (k,v) -> k?.let { it to v } }.toMap() } platforms.forEach { platform -> unnamedTags.forEach { pdTag -> - pdTag.getOrExpect(platform)?.also { tag -> - group(platformData = setOf(platform)) { + pdTag[platform]?.also { tag -> + group(sourceSets = setOf(platform)) { header(4) { text(tag.toHeaderString()) } comment(tag.root) } @@ -312,7 +311,7 @@ open class DefaultPageCreator( return contentBuilder.contentFor(d) { if (tags.isNotEmpty()) { header(3) { text("Description") } - platformDependentHint(platformData = platforms.toSet()) { + sourceSetDependentHint(sourceSets = platforms.toSet()) { contentForDescription() contentForSamples() contentForParams() @@ -324,11 +323,11 @@ open class DefaultPageCreator( } protected open fun DocumentableContentBuilder.contentForBrief(content: Documentable) { - content.platformData.forEach { platform -> + content.sourceSets.forEach { platform -> val root = content.documentation[platform]?.children?.firstOrNull()?.root root?.let { - group(platformData = setOf(platform), kind = ContentKind.BriefComment) { + group(sourceSets = setOf(platform), kind = ContentKind.BriefComment) { text(it.docTagSummary(), kind = ContentKind.Comment) } } @@ -338,7 +337,7 @@ open class DefaultPageCreator( protected open fun contentForFunction(f: DFunction) = contentBuilder.contentFor(f) { group(kind = ContentKind.Cover) { header(1) { text(f.name) } - platformDependentHint(f.dri, f.platformData.toSet()) { + sourceSetDependentHint(f.dri, f.sourceSets.toSet()) { +buildSignature(f) } } diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index 6cb47b7f..3ed19afa 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -19,46 +19,46 @@ open class PageContentBuilder( ) { fun contentFor( dri: DRI, - platformData: Set<PlatformData>, + sourceSets: Set<SourceSetData>, kind: Kind = ContentKind.Main, styles: Set<Style> = emptySet(), extra: PropertyContainer<ContentNode> = PropertyContainer.empty(), block: DocumentableContentBuilder.() -> Unit ): ContentGroup = - DocumentableContentBuilder(dri, platformData, styles, extra) + DocumentableContentBuilder(dri, sourceSets, styles, extra) .apply(block) - .build(platformData, kind, styles, extra) + .build(sourceSets, kind, styles, extra) fun contentFor( d: Documentable, kind: Kind = ContentKind.Main, styles: Set<Style> = emptySet(), extra: PropertyContainer<ContentNode> = PropertyContainer.empty(), - platformData: Set<PlatformData> = d.platformData.toSet(), + sourceSets: Set<SourceSetData> = d.sourceSets.toSet(), block: DocumentableContentBuilder.() -> Unit = {} ): ContentGroup = - DocumentableContentBuilder(d.dri, platformData, styles, extra) + DocumentableContentBuilder(d.dri, sourceSets, styles, extra) .apply(block) - .build(platformData, kind, styles, extra) + .build(sourceSets, kind, styles, extra) @ContentBuilderMarker open inner class DocumentableContentBuilder( val mainDRI: DRI, - val mainPlatformData: Set<PlatformData>, + val mainPlatformData: Set<SourceSetData>, val mainStyles: Set<Style>, val mainExtra: PropertyContainer<ContentNode> ) { protected val contents = mutableListOf<ContentNode>() fun build( - platformData: Set<PlatformData>, + sourceSets: Set<SourceSetData>, kind: Kind, styles: Set<Style>, extra: PropertyContainer<ContentNode> ) = ContentGroup( contents.toList(), DCI(setOf(mainDRI), kind), - platformData, + sourceSets, styles, extra ) @@ -74,7 +74,7 @@ open class PageContentBuilder( fun header( level: Int, kind: Kind = ContentKind.Main, - platformData: Set<PlatformData> = mainPlatformData, + platformData: Set<SourceSetData> = mainPlatformData, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra, block: DocumentableContentBuilder.() -> Unit @@ -88,11 +88,11 @@ open class PageContentBuilder( fun text( text: String, kind: Kind = ContentKind.Main, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra ) { - contents += createText(text, kind, platformData, styles, extra) + contents += createText(text, kind, sourceSets, styles, extra) } fun buildSignature(d: Documentable) = signatureProvider.signature(d) @@ -100,26 +100,26 @@ open class PageContentBuilder( fun linkTable( elements: List<DRI>, kind: Kind = ContentKind.Main, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra ) { contents += ContentTable( emptyList(), elements.map { - contentFor(it, platformData, kind, styles, extra) { + contentFor(it, sourceSets, kind, styles, extra) { link(it.classNames ?: "", it) } }, DCI(setOf(mainDRI), kind), - platformData, styles, extra + sourceSets, styles, extra ) } fun table( dri: DRI = mainDRI, kind: Kind = ContentKind.Main, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra, operation: DocumentableContentBuilder.() -> List<ContentGroup> @@ -128,7 +128,7 @@ open class PageContentBuilder( emptyList(), operation(), DCI(setOf(mainDRI), kind), - platformData, styles, extra + sourceSets, styles, extra ) } @@ -137,7 +137,7 @@ open class PageContentBuilder( level: Int, kind: Kind = ContentKind.Main, elements: Iterable<T>, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra, renderWhenEmpty: Boolean = false, @@ -148,12 +148,12 @@ open class PageContentBuilder( contents += ContentTable( emptyList(), elements.map { - buildGroup(it.dri, it.platformData.toSet(), kind, styles, extra) { + buildGroup(it.dri, it.sourceSets.toSet(), kind, styles, extra) { operation(it) } }, DCI(setOf(mainDRI), kind), - platformData, styles, extra + sourceSets, styles, extra ) } } @@ -163,17 +163,17 @@ open class PageContentBuilder( prefix: String = "", suffix: String = "", separator: String = ", ", - platformData: Set<PlatformData> = mainPlatformData, // TODO: children should be aware of this platform data + sourceSets: Set<SourceSetData> = mainPlatformData, // TODO: children should be aware of this platform data operation: DocumentableContentBuilder.(T) -> Unit ) { if (elements.isNotEmpty()) { - if (prefix.isNotEmpty()) text(prefix, platformData = platformData) + if (prefix.isNotEmpty()) text(prefix, sourceSets = sourceSets) elements.dropLast(1).forEach { operation(it) - text(separator, platformData = platformData) + text(separator, sourceSets = sourceSets) } operation(elements.last()) - if (suffix.isNotEmpty()) text(suffix, platformData = platformData) + if (suffix.isNotEmpty()) text(suffix, sourceSets = sourceSets) } } @@ -181,15 +181,15 @@ open class PageContentBuilder( text: String, address: DRI, kind: Kind = ContentKind.Main, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra ) { contents += ContentDRILink( - listOf(createText(text, kind, platformData, styles, extra)), + listOf(createText(text, kind, sourceSets, styles, extra)), address, DCI(setOf(mainDRI), kind), - platformData + sourceSets ) } @@ -197,99 +197,99 @@ open class PageContentBuilder( text: String, address: String, kind: Kind = ContentKind.Main, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra ) = ContentResolvedLink( - children = listOf(createText(text, kind, platformData, styles, extra)), + children = listOf(createText(text, kind, sourceSets, styles, extra)), address = address, extra = PropertyContainer.empty(), dci = DCI(setOf(mainDRI), kind), - platforms = platformData, + sourceSets = sourceSets, style = emptySet() ) fun link( address: DRI, kind: Kind = ContentKind.Main, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra, block: DocumentableContentBuilder.() -> Unit ) { contents += ContentDRILink( - contentFor(mainDRI, platformData, kind, styles, extra, block).children, + contentFor(mainDRI, sourceSets, kind, styles, extra, block).children, address, DCI(setOf(mainDRI), kind), - platformData + sourceSets ) } fun comment( docTag: DocTag, kind: Kind = ContentKind.Comment, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra ) { val content = commentsConverter.buildContent( docTag, DCI(setOf(mainDRI), kind), - platformData + sourceSets ) - contents += ContentGroup(content, DCI(setOf(mainDRI), kind), platformData, styles, extra) + contents += ContentGroup(content, DCI(setOf(mainDRI), kind), sourceSets, styles, extra) } fun group( dri: DRI = mainDRI, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, kind: Kind = ContentKind.Main, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra, block: DocumentableContentBuilder.() -> Unit ) { - contents += buildGroup(dri, platformData, kind, styles, extra, block) + contents += buildGroup(dri, sourceSets, kind, styles, extra, block) } fun buildGroup( dri: DRI = mainDRI, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, kind: Kind = ContentKind.Main, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra, block: DocumentableContentBuilder.() -> Unit - ): ContentGroup = contentFor(dri, platformData, kind, styles, extra, block) + ): ContentGroup = contentFor(dri, sourceSets, kind, styles, extra, block) - fun platformDependentHint( + fun sourceSetDependentHint( dri: DRI = mainDRI, - platformData: Set<PlatformData> = mainPlatformData, + sourceSets: Set<SourceSetData> = mainPlatformData, kind: Kind = ContentKind.Main, styles: Set<Style> = mainStyles, extra: PropertyContainer<ContentNode> = mainExtra, block: DocumentableContentBuilder.() -> Unit ) { contents += PlatformHintedContent( - buildGroup(dri, platformData, kind, styles, extra, block), - platformData + buildGroup(dri, sourceSets, kind, styles, extra, block), + sourceSets ) } protected fun createText( text: String, kind: Kind, - platformData: Set<PlatformData>, + sourceSets: Set<SourceSetData>, styles: Set<Style>, extra: PropertyContainer<ContentNode> ) = - ContentText(text, DCI(setOf(mainDRI), kind), platformData, styles, extra) + ContentText(text, DCI(setOf(mainDRI), kind), sourceSets, styles, extra) fun <T> platformText( - value: PlatformDependent<T>, - platforms: Set<PlatformData> = value.keys, + value: SourceSetDependent<T>, + platforms: Set<SourceSetData> = value.keys, transform: (T) -> String ) = value.entries.filter { it.key in platforms }.forEach { (p, v) -> - transform(v).takeIf { it.isNotBlank() }?.also { text(it, platformData = setOf(p)) } + transform(v).takeIf { it.isNotBlank() }?.also { text(it, sourceSets = setOf(p)) } } } }
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index e5fa4bfc..ca8055c8 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -9,7 +9,6 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.withClass import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.properties.PropertyContainer -import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.sources.SourceToDocumentableTranslator import org.jetbrains.dokka.utilities.DokkaLogger @@ -23,16 +22,21 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.psiUtil.getChildOfType import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.utils.addToStdlib.safeAs +import java.io.File object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { - override fun invoke(platformData: PlatformData, context: DokkaContext): DModule { + override fun invoke(sourceSetData: SourceSetData, context: DokkaContext): DModule { - val (environment, _) = context.platforms.getValue(platformData) + fun isFileInSourceRoots(file: File) : Boolean { + return sourceSetData.sourceRoots.any { root -> file.path.startsWith(File(root.path).absolutePath) } + } + + val (environment, _) = context.platforms.getValue(sourceSetData) val sourceRoots = environment.configuration.get(CLIConfigurationKeys.CONTENT_ROOTS) ?.filterIsInstance<JavaSourceRoot>() - ?.map { it.file } + ?.mapNotNull { it.file.takeIf(::isFileInSourceRoots) } ?: listOf() val localFileSystem = VirtualFileManager.getInstance().getFileSystem("file") @@ -46,11 +50,11 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { val docParser = DokkaPsiParser( - platformData, + sourceSetData, context.logger ) return DModule( - platformData.name, + sourceSetData.moduleName, psiFiles.mapNotNull { it.safeAs<PsiJavaFile>() }.groupBy { it.packageName }.map { (packageName, psiFiles) -> val dri = DRI(packageName = packageName) DPackage( @@ -61,17 +65,19 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { psiFile.classes.map { docParser.parseClasslike(it, dri) } }, emptyList(), - PlatformDependent.empty(), - listOf(platformData) + emptyMap(), + null, + listOf(sourceSetData) ) }, - PlatformDependent.empty(), - listOf(platformData) + emptyMap(), + null, + listOf(sourceSetData) ) } class DokkaPsiParser( - private val platformData: PlatformData, + private val sourceSetData: SourceSetData, private val logger: DokkaLogger ) { @@ -104,7 +110,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { } private fun <T> T.toPlatformDependant() = - PlatformDependent(mapOf(platformData to this)) + mapOf(sourceSetData to this) fun parseClasslike(psi: PsiClass, parent: DRI): DClasslike = with(psi) { val dri = parent.withClass(name.toString()) @@ -145,6 +151,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { name.orEmpty(), dri, documentation, + null, source, allFunctions, fields.mapNotNull { parseField(it, accessors[it].orEmpty()) }, @@ -152,7 +159,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { visibility, null, constructors.map { parseFunction(it, true) }, - listOf(platformData), + listOf(sourceSetData), PropertyContainer.empty<DAnnotation>() + annotations.toList().toExtra() ) isEnum -> DEnum( @@ -163,14 +170,16 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { dri.withClass("$name.${entry.name}"), entry.name.orEmpty(), javadocParser.parseDocumentation(entry).toPlatformDependant(), + null, emptyList(), emptyList(), emptyList(), - listOf(platformData), + listOf(sourceSetData), PropertyContainer.empty<DEnumEntry>() + entry.annotations.toList().toExtra() ) }, documentation, + null, source, allFunctions, fields.filter { it !is PsiEnumConstant }.map { parseField(it, accessors[it].orEmpty()) }, @@ -179,13 +188,14 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { null, constructors.map { parseFunction(it, true) }, ancestors, - listOf(platformData), + listOf(sourceSetData), PropertyContainer.empty<DEnum>() + annotations.toList().toExtra() ) isInterface -> DInterface( dri, name.orEmpty(), documentation, + null, source, allFunctions, fields.mapNotNull { parseField(it, accessors[it].orEmpty()) }, @@ -194,7 +204,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { null, mapTypeParameters(dri), ancestors, - listOf(platformData), + listOf(sourceSetData), PropertyContainer.empty<DInterface>() + annotations.toList().toExtra() ) else -> DClass( @@ -210,8 +220,9 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { mapTypeParameters(dri), ancestors, documentation, + null, modifiers, - listOf(platformData), + listOf(sourceSetData), PropertyContainer.empty<DClass>() + annotations.toList().toExtra() ) } @@ -232,18 +243,20 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { dri.copy(target = index + 1), psiParameter.name, javadocParser.parseDocumentation(psiParameter).toPlatformDependant(), + null, getBound(psiParameter.type), - listOf(platformData) + listOf(sourceSetData) ) }, javadocParser.parseDocumentation(psi).toPlatformDependant(), + null, PsiDocumentableSource(psi).toPlatformDependant(), psi.getVisibility().toPlatformDependant(), psi.returnType?.let { getBound(type = it) } ?: Void, psi.mapTypeParameters(dri), null, psi.getModifier().toPlatformDependant(), - listOf(platformData), + listOf(sourceSetData), PropertyContainer.withAll( InheritedFunction(isInherited), psi.annotations.toList().toExtra(), @@ -313,8 +326,9 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { dri.copy(genericTarget = index), type.name.orEmpty(), javadocParser.parseDocumentation(type).toPlatformDependant(), + null, mapBounds(type.bounds), - listOf(platformData) + listOf(sourceSetData) ) } } @@ -349,6 +363,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { dri, psi.name!!, // TODO: Investigate if this is indeed nullable javadocParser.parseDocumentation(psi).toPlatformDependant(), + null, PsiDocumentableSource(psi).toPlatformDependant(), psi.getVisibility().toPlatformDependant(), getBound(psi.type), @@ -356,7 +371,7 @@ object DefaultPsiToDocumentableTranslator : SourceToDocumentableTranslator { accessors.firstOrNull { it.hasParameters() }?.let { parseFunction(it) }, accessors.firstOrNull { it.returnType == psi.type }?.let { parseFunction(it) }, psi.getModifier().toPlatformDependant(), - listOf(platformData), + listOf(sourceSetData), emptyList(), PropertyContainer.empty<DProperty>() + psi.annotations.toList().toExtra() ) |