aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Locations
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2019-10-31 12:10:10 +0100
committerKamil Doległo <kamilok1965@interia.pl>2019-10-31 12:10:10 +0100
commit7c30624e3d0868346823b15b5cea5e29a56357f2 (patch)
tree5cc8175510c907d23f7bdcb5d5617ef03b587965 /core/src/main/kotlin/Locations
parent57830827b9bc13aad7af6ab899f25b278b248ef7 (diff)
downloaddokka-7c30624e3d0868346823b15b5cea5e29a56357f2.tar.gz
dokka-7c30624e3d0868346823b15b5cea5e29a56357f2.tar.bz2
dokka-7c30624e3d0868346823b15b5cea5e29a56357f2.zip
Remove all unnecessary files
Diffstat (limited to 'core/src/main/kotlin/Locations')
-rw-r--r--core/src/main/kotlin/Locations/Location.kt78
1 files changed, 0 insertions, 78 deletions
diff --git a/core/src/main/kotlin/Locations/Location.kt b/core/src/main/kotlin/Locations/Location.kt
deleted file mode 100644
index 2ad6b652..00000000
--- a/core/src/main/kotlin/Locations/Location.kt
+++ /dev/null
@@ -1,78 +0,0 @@
-package org.jetbrains.dokka
-
-import java.io.File
-
-interface Location {
- val path: String get
- fun relativePathTo(other: Location, anchor: String? = null): String
-}
-
-/**
- * Represents locations in the documentation in the form of [path](File).
- *
- * $file: [File] for this location
- * $path: [String] representing path of this location
- */
-data class FileLocation(val file: File) : Location {
- override val path: String
- get() = file.path
-
- override fun relativePathTo(other: Location, anchor: String?): String {
- if (other !is FileLocation) {
- throw IllegalArgumentException("$other is not a FileLocation")
- }
- if (file.path.substringBeforeLast(".") == other.file.path.substringBeforeLast(".") && anchor == null) {
- return "./${file.name}"
- }
- val ownerFolder = file.parentFile!!
- val relativePath = ownerFolder.toPath().relativize(other.file.toPath()).toString().replace(File.separatorChar, '/')
- return if (anchor == null) relativePath else "$relativePath#$anchor"
- }
-}
-
-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"
- }
-}
-
-fun nodeActualQualifier(node: DocumentationNode): List<DocumentationNode> {
- val topLevelPage = node.references(RefKind.TopLevelPage).singleOrNull()?.to
- if (topLevelPage != null) {
- return nodeActualQualifier(topLevelPage)
- }
- return node.owner?.let { nodeActualQualifier(it) }.orEmpty() + node
-}
-
-fun relativePathToNode(node: DocumentationNode): String {
- val qualifier = nodeActualQualifier(node)
- return relativePathToNode(
- qualifier.map { it.name },
- qualifier.last().members.any()
- )
-}
-
-
-private val reservedFilenames = setOf("index", "con", "aux", "lst", "prn", "nul", "eof", "inp", "out")
-
-fun identifierToFilename(path: String): String {
- if (path.isEmpty()) return "--root--"
- val escaped = path.replace('<', '-').replace('>', '-')
- val lowercase = escaped.replace("[A-Z]".toRegex()) { matchResult -> "-" + matchResult.value.toLowerCase() }
- return if (lowercase in reservedFilenames) "--$lowercase--" else lowercase
-}
-
-fun NodeLocationAwareGenerator.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode): String {
- return location(owner).relativePathTo(location(node), null)
-}
-
-fun NodeLocationAwareGenerator.relativePathToRoot(from: Location): File {
- val file = File(from.path).parentFile
- return root.relativeTo(file)
-}
-
-fun File.toUnixString() = toString().replace(File.separatorChar, '/')