aboutsummaryrefslogtreecommitdiff
path: root/src/Locations/FoldersLocationService.kt
blob: e85c2c9839e2c3f06901b505cea5e17e8d720b5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package org.jetbrains.dokka

import java.io.File

public fun FoldersLocationService(root: String): FoldersLocationService = FoldersLocationService(File(root), "")
public class FoldersLocationService(val root: File, val extension: String) : FileLocationService {
    override fun withExtension(newExtension: String): FileLocationService {
        return if (extension.isEmpty()) FoldersLocationService(root, newExtension) else this
    }

    override fun location(qualifiedName: List<String>, hasMembers: Boolean): FileLocation {
        return FileLocation(File(root, relativePathToNode(qualifiedName, hasMembers)).appendExtension(extension))
    }
}

fun relativePathToNode(qualifiedName: List<String>, hasMembers: Boolean): String {
    val parts = qualifiedName.map { identifierToFilename(it) }.filterNot { it.isEmpty() }
    return if (!hasMembers) {
        // leaf node, use file in owner's folder
        parts.joinToString("/")
    } else {
        parts.joinToString("/") + (if (parts.none()) "" else "/") + "index"
    }
}