aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/translators
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2020-05-05 11:53:16 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-05-19 09:56:32 +0200
commit430d7d6453a0b63dcabecd54aea915410cd35103 (patch)
treeb9e40e3eaa9f1948590141d7d46491e2f34f2ef9 /plugins/base/src/main/kotlin/translators
parentc1b4669ee227a479516f37ce1b9dff5f2d2bef38 (diff)
downloaddokka-430d7d6453a0b63dcabecd54aea915410cd35103.tar.gz
dokka-430d7d6453a0b63dcabecd54aea915410cd35103.tar.bz2
dokka-430d7d6453a0b63dcabecd54aea915410cd35103.zip
Add a draft version of divergent rendering
Diffstat (limited to 'plugins/base/src/main/kotlin/translators')
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt77
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt166
2 files changed, 200 insertions, 43 deletions
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index 232f6721..51e95160 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -95,20 +95,8 @@ open class DefaultPageCreator(
dri: DRI,
sourceSets: List<SourceSetData>
) = contentBuilder.contentFor(s as Documentable) {
- block("Types", 2, ContentKind.Classlikes, s.classlikes, sourceSets.toSet()) {
- link(it.name ?: "", it.dri, kind = ContentKind.Main)
- sourceSetDependentHint(it.dri, it.sourceSets.toSet(), kind = ContentKind.SourceSetDependantHint) {
- +buildSignature(it)
- contentForBrief(it)
- }
- }
- block("Functions", 2, ContentKind.Functions, s.functions, sourceSets.toSet()) {
- link(it.name, it.dri, kind = ContentKind.Main)
- sourceSetDependentHint(it.dri, it.sourceSets.toSet(), kind = ContentKind.SourceSetDependantHint) {
- +buildSignature(it)
- contentForBrief(it)
- }
- }
+ divergentBlock("Types", s.classlikes, ContentKind.Classlikes)
+ divergentBlock("Functions", s.functions, ContentKind.Functions)
block("Properties", 2, ContentKind.Properties, s.properties, sourceSets.toSet()) {
link(it.name, it.dri, kind = ContentKind.Main)
sourceSetDependentHint(it.dri, it.sourceSets.toSet(), kind = ContentKind.SourceSetDependantHint) {
@@ -125,7 +113,7 @@ open class DefaultPageCreator(
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) {
+ buildGroup(setOf(dri), platforms.toSet(), ContentKind.Inheritors) {
link(
classlike.classNames?.substringBeforeLast(".") ?: classlike.toString()
.also { logger.warn("No class name found for DRI $classlike") }, classlike
@@ -219,6 +207,7 @@ open class DefaultPageCreator(
}
}
}
+
}
}
@@ -334,23 +323,59 @@ open class DefaultPageCreator(
}
}
- protected open fun contentForFunction(f: DFunction) = contentBuilder.contentFor(f) {
- group(kind = ContentKind.Cover) {
- header(1) { text(f.name) }
- sourceSetDependentHint(f.dri, f.sourceSets.toSet()) {
- +buildSignature(f)
+ protected open fun contentForFunction(f: DFunction) = contentForMember(f)
+ protected open fun contentForTypeAlias(t: DTypeAlias) = contentForMember(t)
+ protected open fun contentForMember(d: Documentable) = contentBuilder.contentFor(d) {
+ header(1) { text(d.name.orEmpty()) }
+ divergentGroup(ContentDivergentGroup.GroupID("member")) {
+ instance(setOf(d.dri), d.sourceSets.toSet()) {
+ divergent(kind = ContentKind.Symbol) {
+ +buildSignature(d)
+ }
+ after {
+ +contentForComments(d)
+ }
}
}
- +contentForComments(f)
}
- protected open fun contentForTypeAlias(t: DTypeAlias) = contentBuilder.contentFor(t) {
- group(kind = ContentKind.Cover) {
- header(1) { text(t.name) }
- +buildSignature(t)
+ protected open fun DocumentableContentBuilder.divergentBlock(
+ name: String,
+ collection: Collection<Documentable>,
+ kind: ContentKind
+ ) {
+ if (collection.any()) {
+ header(2) { text(name) }
+ table(kind) {
+ collection.groupBy { it.name }.map { (elementName, elements) -> // This groupBy should probably use LocationProvider
+ buildGroup(elements.map { it.dri }.toSet(), elements.flatMap { it.sourceSets }.toSet()) {
+ link(elementName.orEmpty(), elements.first().dri)
+ divergentGroup(
+ ContentDivergentGroup.GroupID(name),
+ elements.map { it.dri }.toSet(),
+ kind = ContentKind.Symbol
+ ) {
+ elements.map {
+ instance(setOf(it.dri), it.sourceSets.toSet()) {
+ divergent {
+ group(kind = ContentKind.Symbol) {
+ +buildSignature(it)
+ }
+ }
+ after {
+ group(kind = ContentKind.BriefComment) {
+ contentForBrief(it)
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
- +contentForComments(t)
}
+
protected open fun TagWrapper.toHeaderString() = this.javaClass.toGenericString().split('.').last()
}
diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
index 3ed19afa..2f04e2a0 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
@@ -25,6 +25,18 @@ open class PageContentBuilder(
extra: PropertyContainer<ContentNode> = PropertyContainer.empty(),
block: DocumentableContentBuilder.() -> Unit
): ContentGroup =
+ DocumentableContentBuilder(setOf(dri), sourceSets, styles, extra)
+ .apply(block)
+ .build(sourceSets, kind, styles, extra)
+
+ fun contentFor(
+ dri: Set<DRI>,
+ sourceSets: Set<SourceSetData>,
+ kind: Kind = ContentKind.Main,
+ styles: Set<Style> = emptySet(),
+ extra: PropertyContainer<ContentNode> = PropertyContainer.empty(),
+ block: DocumentableContentBuilder.() -> Unit
+ ): ContentGroup =
DocumentableContentBuilder(dri, sourceSets, styles, extra)
.apply(block)
.build(sourceSets, kind, styles, extra)
@@ -37,13 +49,13 @@ open class PageContentBuilder(
sourceSets: Set<SourceSetData> = d.sourceSets.toSet(),
block: DocumentableContentBuilder.() -> Unit = {}
): ContentGroup =
- DocumentableContentBuilder(d.dri, sourceSets, styles, extra)
+ DocumentableContentBuilder(setOf(d.dri), sourceSets, styles, extra)
.apply(block)
.build(sourceSets, kind, styles, extra)
@ContentBuilderMarker
open inner class DocumentableContentBuilder(
- val mainDRI: DRI,
+ val mainDRI: Set<DRI>,
val mainPlatformData: Set<SourceSetData>,
val mainStyles: Set<Style>,
val mainExtra: PropertyContainer<ContentNode>
@@ -57,7 +69,7 @@ open class PageContentBuilder(
extra: PropertyContainer<ContentNode>
) = ContentGroup(
contents.toList(),
- DCI(setOf(mainDRI), kind),
+ DCI(mainDRI, kind),
sourceSets,
styles,
extra
@@ -111,13 +123,12 @@ open class PageContentBuilder(
link(it.classNames ?: "", it)
}
},
- DCI(setOf(mainDRI), kind),
+ DCI(mainDRI, kind),
sourceSets, styles, extra
)
}
fun table(
- dri: DRI = mainDRI,
kind: Kind = ContentKind.Main,
sourceSets: Set<SourceSetData> = mainPlatformData,
styles: Set<Style> = mainStyles,
@@ -127,7 +138,7 @@ open class PageContentBuilder(
contents += ContentTable(
emptyList(),
operation(),
- DCI(setOf(mainDRI), kind),
+ DCI(mainDRI, kind),
sourceSets, styles, extra
)
}
@@ -148,11 +159,11 @@ open class PageContentBuilder(
contents += ContentTable(
emptyList(),
elements.map {
- buildGroup(it.dri, it.sourceSets.toSet(), kind, styles, extra) {
+ buildGroup(setOf(it.dri), it.sourceSets.toSet(), kind, styles, extra) {
operation(it)
}
},
- DCI(setOf(mainDRI), kind),
+ DCI(mainDRI, kind),
sourceSets, styles, extra
)
}
@@ -188,7 +199,7 @@ open class PageContentBuilder(
contents += ContentDRILink(
listOf(createText(text, kind, sourceSets, styles, extra)),
address,
- DCI(setOf(mainDRI), kind),
+ DCI(mainDRI, kind),
sourceSets
)
}
@@ -205,7 +216,7 @@ open class PageContentBuilder(
children = listOf(createText(text, kind, sourceSets, styles, extra)),
address = address,
extra = PropertyContainer.empty(),
- dci = DCI(setOf(mainDRI), kind),
+ dci = DCI(mainDRI, kind),
sourceSets = sourceSets,
style = emptySet()
)
@@ -221,7 +232,7 @@ open class PageContentBuilder(
contents += ContentDRILink(
contentFor(mainDRI, sourceSets, kind, styles, extra, block).children,
address,
- DCI(setOf(mainDRI), kind),
+ DCI(mainDRI, kind),
sourceSets
)
}
@@ -235,14 +246,14 @@ open class PageContentBuilder(
) {
val content = commentsConverter.buildContent(
docTag,
- DCI(setOf(mainDRI), kind),
+ DCI(mainDRI, kind),
sourceSets
)
- contents += ContentGroup(content, DCI(setOf(mainDRI), kind), sourceSets, styles, extra)
+ contents += ContentGroup(content, DCI(mainDRI, kind), sourceSets, styles, extra)
}
fun group(
- dri: DRI = mainDRI,
+ dri: Set<DRI> = mainDRI,
sourceSets: Set<SourceSetData> = mainPlatformData,
kind: Kind = ContentKind.Main,
styles: Set<Style> = mainStyles,
@@ -252,8 +263,23 @@ open class PageContentBuilder(
contents += buildGroup(dri, sourceSets, kind, styles, extra, block)
}
+ fun divergentGroup(
+ groupID: ContentDivergentGroup.GroupID,
+ dri: Set<DRI> = mainDRI,
+ kind: Kind = ContentKind.Main,
+ styles: Set<Style> = mainStyles,
+ extra: PropertyContainer<ContentNode> = mainExtra,
+ implicitlySourceSetHinted: Boolean = true,
+ block: DivergentBuilder.() -> Unit
+ ) {
+ contents +=
+ DivergentBuilder(dri, kind, styles, extra)
+ .apply(block)
+ .build(groupID = groupID, implicitlySourceSetHinted = implicitlySourceSetHinted)
+ }
+
fun buildGroup(
- dri: DRI = mainDRI,
+ dri: Set<DRI> = mainDRI,
sourceSets: Set<SourceSetData> = mainPlatformData,
kind: Kind = ContentKind.Main,
styles: Set<Style> = mainStyles,
@@ -262,7 +288,7 @@ open class PageContentBuilder(
): ContentGroup = contentFor(dri, sourceSets, kind, styles, extra, block)
fun sourceSetDependentHint(
- dri: DRI = mainDRI,
+ dri: Set<DRI> = mainDRI,
sourceSets: Set<SourceSetData> = mainPlatformData,
kind: Kind = ContentKind.Main,
styles: Set<Style> = mainStyles,
@@ -275,6 +301,20 @@ open class PageContentBuilder(
)
}
+ fun sourceSetDependentHint(
+ dri: DRI,
+ platformData: Set<SourceSetData> = mainPlatformData,
+ kind: Kind = ContentKind.Main,
+ styles: Set<Style> = mainStyles,
+ extra: PropertyContainer<ContentNode> = mainExtra,
+ block: DocumentableContentBuilder.() -> Unit
+ ) {
+ contents += PlatformHintedContent(
+ buildGroup(setOf(dri), platformData, kind, styles, extra, block),
+ platformData
+ )
+ }
+
protected fun createText(
text: String,
kind: Kind,
@@ -282,7 +322,7 @@ open class PageContentBuilder(
styles: Set<Style>,
extra: PropertyContainer<ContentNode>
) =
- ContentText(text, DCI(setOf(mainDRI), kind), sourceSets, styles, extra)
+ ContentText(text, DCI(mainDRI, kind), sourceSets, styles, extra)
fun <T> platformText(
value: SourceSetDependent<T>,
@@ -292,4 +332,96 @@ open class PageContentBuilder(
transform(v).takeIf { it.isNotBlank() }?.also { text(it, sourceSets = setOf(p)) }
}
}
+
+ @ContentBuilderMarker
+ open inner class DivergentBuilder(
+ private val mainDRI: Set<DRI>,
+ private val mainKind: Kind,
+ private val mainStyles: Set<Style>,
+ private val mainExtra: PropertyContainer<ContentNode>
+ ) {
+ private val instances: MutableList<ContentDivergentInstance> = mutableListOf()
+ fun instance(
+ dri: Set<DRI>,
+ sourceSets: Set<SourceSetData>, // Having correct PlatformData is crucial here, that's why there's no default
+ kind: Kind = mainKind,
+ styles: Set<Style> = mainStyles,
+ extra: PropertyContainer<ContentNode> = mainExtra,
+ block: DivergentInstanceBuilder.() -> Unit
+ ) {
+ instances += DivergentInstanceBuilder(dri, sourceSets, styles, extra)
+ .apply(block)
+ .build(kind)
+ }
+
+ fun build(
+ groupID: ContentDivergentGroup.GroupID,
+ implicitlySourceSetHinted: Boolean,
+ kind: Kind = mainKind,
+ styles: Set<Style> = mainStyles,
+ extra: PropertyContainer<ContentNode> = mainExtra
+ ) = ContentDivergentGroup(instances.toList(), DCI(mainDRI, kind), styles, extra, groupID, implicitlySourceSetHinted)
+ }
+
+ @ContentBuilderMarker
+ open inner class DivergentInstanceBuilder(
+ private val mainDRI: Set<DRI>,
+ private val mainSourceSets: Set<SourceSetData>,
+ private val mainStyles: Set<Style>,
+ private val mainExtra: PropertyContainer<ContentNode>
+ ) {
+ private var before: ContentNode? = null
+ private var divergent: ContentNode? = null
+ private var after: ContentNode? = null
+
+ fun before(
+ dri: Set<DRI> = mainDRI,
+ sourceSets: Set<SourceSetData> = mainSourceSets,
+ kind: Kind = ContentKind.Main,
+ styles: Set<Style> = mainStyles,
+ extra: PropertyContainer<ContentNode> = mainExtra,
+ block: DocumentableContentBuilder.() -> Unit
+ ) {
+ before = contentFor(dri, sourceSets, kind, styles, extra, block)
+ }
+
+ fun divergent(
+ dri: Set<DRI> = mainDRI,
+ sourceSets: Set<SourceSetData> = mainSourceSets,
+ kind: Kind = ContentKind.Main,
+ styles: Set<Style> = mainStyles,
+ extra: PropertyContainer<ContentNode> = mainExtra,
+ block: DocumentableContentBuilder.() -> Unit
+ ) {
+ divergent = contentFor(dri, sourceSets, kind, styles, extra, block)
+ }
+
+ fun after(
+ dri: Set<DRI> = mainDRI,
+ sourceSets: Set<SourceSetData> = mainSourceSets,
+ kind: Kind = ContentKind.Main,
+ styles: Set<Style> = mainStyles,
+ extra: PropertyContainer<ContentNode> = mainExtra,
+ block: DocumentableContentBuilder.() -> Unit
+ ) {
+ after = contentFor(dri, sourceSets, kind, styles, extra, block)
+ }
+
+
+ fun build(
+ kind: Kind,
+ sourceSets: Set<SourceSetData> = mainSourceSets,
+ styles: Set<Style> = mainStyles,
+ extra: PropertyContainer<ContentNode> = mainExtra
+ ) =
+ ContentDivergentInstance(
+ before,
+ divergent!!,
+ after,
+ DCI(mainDRI, kind),
+ sourceSets,
+ styles,
+ extra
+ )
+ }
} \ No newline at end of file