diff options
Diffstat (limited to 'src/Locations')
-rw-r--r-- | src/Locations/FoldersLocationService.kt | 8 | ||||
-rw-r--r-- | src/Locations/LocationService.kt | 4 | ||||
-rw-r--r-- | src/Locations/SingleFolderLocationService.kt | 9 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/Locations/FoldersLocationService.kt b/src/Locations/FoldersLocationService.kt index 8a0cf6be..89b34ed1 100644 --- a/src/Locations/FoldersLocationService.kt +++ b/src/Locations/FoldersLocationService.kt @@ -5,14 +5,16 @@ import com.google.inject.name.Named import java.io.File public fun FoldersLocationService(root: String): FoldersLocationService = FoldersLocationService(File(root), "") -public class FoldersLocationService @Inject constructor(@Named("outputDir") val root: File, val extension: String) : FileLocationService { +public class FoldersLocationService @Inject constructor(@Named("outputDir") val rootFile: File, val extension: String) : FileLocationService { + override val root: Location + get() = FileLocation(rootFile) override fun withExtension(newExtension: String): FileLocationService { - return if (extension.isEmpty()) FoldersLocationService(root, newExtension) else this + return if (extension.isEmpty()) FoldersLocationService(rootFile, newExtension) else this } override fun location(qualifiedName: List<String>, hasMembers: Boolean): FileLocation { - return FileLocation(File(root, relativePathToNode(qualifiedName, hasMembers)).appendExtension(extension)) + return FileLocation(File(rootFile, relativePathToNode(qualifiedName, hasMembers)).appendExtension(extension)) } } diff --git a/src/Locations/LocationService.kt b/src/Locations/LocationService.kt index 4f587361..80bc0236 100644 --- a/src/Locations/LocationService.kt +++ b/src/Locations/LocationService.kt @@ -27,7 +27,7 @@ public data class FileLocation(val file: File): Location { return "." } val ownerFolder = file.parentFile!! - val relativePath = ownerFolder.getRelativePath(other.file).path + val relativePath = ownerFolder.toPath().relativize(other.file.toPath()).toString() return if (anchor == null) relativePath else relativePath + "#" + anchor } } @@ -51,6 +51,8 @@ public interface LocationService { * @param hasMembers if true, the node for which the location is calculated has member nodes. */ fun location(qualifiedName: List<String>, hasMembers: Boolean): Location + + val root: Location } diff --git a/src/Locations/SingleFolderLocationService.kt b/src/Locations/SingleFolderLocationService.kt index 049636c0..e313ac28 100644 --- a/src/Locations/SingleFolderLocationService.kt +++ b/src/Locations/SingleFolderLocationService.kt @@ -5,12 +5,15 @@ import com.google.inject.name.Named import java.io.File public fun SingleFolderLocationService(root: String): SingleFolderLocationService = SingleFolderLocationService(File(root), "") -public class SingleFolderLocationService @Inject constructor(@Named("outputDir") val root: File, val extension: String) : FileLocationService { +public class SingleFolderLocationService @Inject constructor(@Named("outputDir") val rootFile: File, val extension: String) : FileLocationService { override fun withExtension(newExtension: String): FileLocationService = - SingleFolderLocationService(root, newExtension) + SingleFolderLocationService(rootFile, newExtension) override fun location(qualifiedName: List<String>, hasMembers: Boolean): FileLocation { val filename = qualifiedName.map { identifierToFilename(it) }.joinToString("-") - return FileLocation(File(root, filename).appendExtension(extension)) + return FileLocation(File(rootFile, filename).appendExtension(extension)) } + + override val root: Location + get() = FileLocation(rootFile) }
\ No newline at end of file |