Skip to content

Commit

Permalink
revert 18dc298, use Path and not T: Path as extension point
Browse files Browse the repository at this point in the history
There is no benefit in doing so as we don't return T anywhere. It was
misconception on my part that it would be required for invariant places
  • Loading branch information
robstoll committed Sep 8, 2019
1 parent 47a1a42 commit 1afd89b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 71 deletions.
80 changes: 40 additions & 40 deletions src/main/kotlin/ch/tutteli/niok/PathDelegateToFiles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,115 +11,115 @@ import java.nio.file.attribute.*
/**
* Delegates to [Files.copy] with overload for [OutputStream].
*/
inline fun <T: Path> T.copyTo(outputStream: OutputStream): Long = Files.copy(this, outputStream)
inline fun Path.copyTo(outputStream: OutputStream): Long = Files.copy(this, outputStream)

/**
* Delegates to [Files.createDirectory].
*/
inline fun <T: Path> T.createDirectory(vararg fileAttributes: FileAttribute<*>): Path =
inline fun Path.createDirectory(vararg fileAttributes: FileAttribute<*>): Path =
Files.createDirectory(this, *fileAttributes)

/**
* Delegates to [Files.createDirectories].
*/
inline fun <T: Path> T.createDirectories(vararg fileAttributes: FileAttribute<*>): Path =
inline fun Path.createDirectories(vararg fileAttributes: FileAttribute<*>): Path =
Files.createDirectories(this, *fileAttributes)

/**
* Delegates to [Files.createFile].
*/
inline fun <T: Path> T.createFile(vararg fileAttributes: FileAttribute<*>): Path =
inline fun Path.createFile(vararg fileAttributes: FileAttribute<*>): Path =
Files.createFile(this, *fileAttributes)

/**
* Creates a new link (directory entry) for this [Path].
* Delegates to [Files.createLink].
*/
inline fun <T: Path> T.createLink(link: Path): Path = Files.createLink(link, this)
inline fun Path.createLink(link: Path): Path = Files.createLink(link, this)

/**
* Creates a symbolic link for this [Path].
* Delegates to [Files.createDirectory].
*/
inline fun <T: Path> T.createSymbolicLink(link: Path, vararg fileAttributes: FileAttribute<*>): Path =
inline fun Path.createSymbolicLink(link: Path, vararg fileAttributes: FileAttribute<*>): Path =
Files.createSymbolicLink(link, this, *fileAttributes)

/**
* Delegates to [Files.delete].
*/
inline fun <T: Path> T.delete(): Unit = Files.delete(this)
inline fun Path.delete(): Unit = Files.delete(this)

/**
* Delegates to [Files.deleteIfExists].
*/
inline fun <T: Path> T.deleteIfExists(): Boolean = Files.deleteIfExists(this)
inline fun Path.deleteIfExists(): Boolean = Files.deleteIfExists(this)

/**
* Delegates to [Files.exists].
*/
inline val <T: Path> T.exists get(): Boolean = Files.exists(this)
inline val Path.exists get(): Boolean = Files.exists(this)

/**
* Delegates to [Files.isDirectory] without [LinkOption]s.
*/
inline val <T: Path> T.isDirectory get(): Boolean = Files.isDirectory(this)
inline val Path.isDirectory get(): Boolean = Files.isDirectory(this)

/**
* Delegates to [Files.isDirectory].
*/
inline fun <T: Path> T.isDirectory(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption): Boolean =
inline fun Path.isDirectory(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption): Boolean =
Files.isDirectory(this, linkOption, *furtherLinkOptions)

/**
* Delegates to [Files.isExecutable].
*/
inline val <T: Path> T.isExecutable get(): Boolean = Files.isExecutable(this)
inline val Path.isExecutable get(): Boolean = Files.isExecutable(this)

/**
* Delegates to [Files.isHidden].
*/
inline val <T: Path> T.isHidden get(): Boolean = Files.isHidden(this)
inline val Path.isHidden get(): Boolean = Files.isHidden(this)

/**
* Delegates to [Files.isReadable].
*/
inline val <T: Path> T.isReadable get(): Boolean = Files.isReadable(this)
inline val Path.isReadable get(): Boolean = Files.isReadable(this)

/**
* Delegates to [Files.isRegularFile] without [LinkOption]s.
*/
inline val <T: Path> T.isRegularFile get(): Boolean = Files.isRegularFile(this)
inline val Path.isRegularFile get(): Boolean = Files.isRegularFile(this)

/**
* Delegates to [Files.isRegularFile].
*/
inline fun <T: Path> T.isRegularFile(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption): Boolean =
inline fun Path.isRegularFile(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption): Boolean =
Files.isRegularFile(this, linkOption, *furtherLinkOptions)

/**
* Delegates to [Files.isSameFile].
*/
inline fun <T: Path> T.isSameFile(other: Path): Boolean = Files.isSameFile(this, other)
inline fun Path.isSameFile(other: Path): Boolean = Files.isSameFile(this, other)

/**
* Delegates to [Files.isSymbolicLink].
*/
inline val <T: Path> T.isSymbolicLink get(): Boolean = Files.isSymbolicLink(this)
inline val Path.isSymbolicLink get(): Boolean = Files.isSymbolicLink(this)

/**
* Delegates to [Files.isWritable].
*/
inline val <T: Path> T.isWritable get(): Boolean = Files.isWritable(this)
inline val Path.isWritable get(): Boolean = Files.isWritable(this)

/**
* Delegates to [Files.getFileStore].
*/
inline val <T: Path> T.fileStore get(): FileStore = Files.getFileStore(this)
inline val Path.fileStore get(): FileStore = Files.getFileStore(this)

/**
* Delegates to [Files.getAttribute].
*/
inline fun <T: Path> T.getAttribute(attribute: String, vararg linkOptions: LinkOption): Any =
inline fun Path.getAttribute(attribute: String, vararg linkOptions: LinkOption): Any =
Files.getAttribute(this, attribute, *linkOptions)

/**
Expand All @@ -131,70 +131,70 @@ inline fun <reified V : FileAttributeView> Path.getFileAttributeView(vararg link
/**
* Delegates to [Files.getLastModifiedTime] without [LinkOption]s.
*/
inline val <T: Path> T.lastModifiedTime get(): FileTime = Files.getLastModifiedTime(this)
inline val Path.lastModifiedTime get(): FileTime = Files.getLastModifiedTime(this)

/**
* Delegates to [Files.getLastModifiedTime].
*/
inline fun <T: Path> T.lastModifiedTime(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption): FileTime =
inline fun Path.lastModifiedTime(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption): FileTime =
Files.getLastModifiedTime(this, linkOption, *furtherLinkOptions)

/**
* Delegates to [Files.move].
*/
inline fun <T: Path> T.move(target: Path, vararg copyOptions: CopyOption): Path =
inline fun Path.move(target: Path, vararg copyOptions: CopyOption): Path =
Files.move(this, target, *copyOptions)

/**
* Delegates to [Files.newByteChannel].
*/
inline fun <T: Path> T.newByteChannel(vararg openOptions: OpenOption): SeekableByteChannel =
inline fun Path.newByteChannel(vararg openOptions: OpenOption): SeekableByteChannel =
Files.newByteChannel(this, *openOptions)

/**
* Delegates to [Files.newByteChannel].
*/
inline fun <T: Path> T.newByteChannel(
inline fun Path.newByteChannel(
openOptions: Set<OpenOption>,
vararg fileAttributes: FileAttribute<*>
): SeekableByteChannel = Files.newByteChannel(this, openOptions, *fileAttributes)

/**
* Delegates to [Files.notExists] without [LinkOption]s.
*/
inline val <T: Path> T.notExists get(): Boolean = Files.notExists(this)
inline val Path.notExists get(): Boolean = Files.notExists(this)

/**
* Delegates to [Files.notExists].
*/
inline fun <T: Path> T.notExists(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption): Boolean =
inline fun Path.notExists(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption): Boolean =
Files.notExists(this, linkOption, *furtherLinkOptions)

/**
* Delegates to [Files.getPosixFilePermissions] without [LinkOption]s.
*/
inline val <T: Path> T.posixFilePersmissions get(): Set<PosixFilePermission> = Files.getPosixFilePermissions(this)
inline val Path.posixFilePersmissions get(): Set<PosixFilePermission> = Files.getPosixFilePermissions(this)

/**
* Delegates to [Files.getPosixFilePermissions].
*/
inline fun <T: Path> T.posixFilePersmissions(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption) =
inline fun Path.posixFilePersmissions(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption) =
Files.getPosixFilePermissions(this, linkOption, *furtherLinkOptions)

/**
* Delegates to [Files.probeContentType].
*/
inline fun <T: Path> T.probeContentType(): String = Files.probeContentType(this)
inline fun Path.probeContentType(): String = Files.probeContentType(this)

/**
* Delegates to [Files.getLastModifiedTime] without [LinkOption]s.
*/
inline val <T: Path> T.owner get(): UserPrincipal = Files.getOwner(this)
inline val Path.owner get(): UserPrincipal = Files.getOwner(this)

/**
* Delegates to [Files.getLastModifiedTime].
*/
inline fun <T: Path> T.owner(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption): UserPrincipal =
inline fun Path.owner(linkOption: LinkOption, vararg furtherLinkOptions: LinkOption): UserPrincipal =
Files.getOwner(this, linkOption, *furtherLinkOptions)


Expand All @@ -207,39 +207,39 @@ inline fun <reified A : BasicFileAttributes> Path.readAttributes(vararg linkOpti
/**
* Delegates to [Files.readAttributes].
*/
inline fun <T: Path> T.readAttributes(attributes: String, vararg linkOptions: LinkOption): Map<String, Any> =
inline fun Path.readAttributes(attributes: String, vararg linkOptions: LinkOption): Map<String, Any> =
Files.readAttributes(this, attributes, *linkOptions)

/**
* Delegates to [Files.readSymbolicLink].
*/
inline fun <T: Path> T.readSymbolicLink() = Files.readSymbolicLink(this)
inline fun Path.readSymbolicLink() = Files.readSymbolicLink(this)

/**
* Delegates to [Files.setAttribute].
*/
inline fun <T: Path> T.setAttribute(attribute: String, value: Any, vararg linkOptions: LinkOption) =
inline fun Path.setAttribute(attribute: String, value: Any, vararg linkOptions: LinkOption) =
Files.setAttribute(this, attribute, value, *linkOptions)

/**
* Delegates to [Files.setLastModifiedTime].
*/
inline fun <T: Path> T.setLastModifiedTime(fileTime: FileTime) = Files.setLastModifiedTime(this, fileTime)
inline fun Path.setLastModifiedTime(fileTime: FileTime) = Files.setLastModifiedTime(this, fileTime)

/**
* Delegates to [Files.setPosixFilePermissions].
*/
inline fun <T: Path> T.setPosixFilePermissions(perms: Set<PosixFilePermission>) = Files.setPosixFilePermissions(this, perms)
inline fun Path.setPosixFilePermissions(perms: Set<PosixFilePermission>) = Files.setPosixFilePermissions(this, perms)

/**
* Delegates to [Files.size].
*/
inline val <T: Path> T.size get(): Long = Files.size(this)
inline val Path.size get(): Long = Files.size(this)

/**
* Delegates to [Files.write].
*/
inline fun <T: Path> T.writeLines(
inline fun Path.writeLines(
lines: Iterable<CharSequence>,
charset: Charset = Charsets.UTF_8,
vararg openOptions: OpenOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,51 @@ import java.nio.file.Path
/**
* Delegates to [Files.newBufferedReader].
*/
inline fun <T: Path> T.newBufferedReader(charset: Charset = Charsets.UTF_8): BufferedReader =
inline fun Path.newBufferedReader(charset: Charset = Charsets.UTF_8): BufferedReader =
Files.newBufferedReader(this, charset)

/**
* Delegates to [Files.newBufferedWriter].
*/
inline fun <T: Path> T.newBufferedWriter(charset: Charset = Charsets.UTF_8, vararg openOptions: OpenOption): BufferedWriter =
inline fun Path.newBufferedWriter(charset: Charset = Charsets.UTF_8, vararg openOptions: OpenOption): BufferedWriter =
Files.newBufferedWriter(this, charset, *openOptions)

/**
* Delegates to [Files.copy].
*/
inline fun <T: Path> T.copyTo(target: Path, vararg copyOptions: CopyOption): Path =
inline fun Path.copyTo(target: Path, vararg copyOptions: CopyOption): Path =
Files.copy(this, target, *copyOptions)

/**
* Delegates to [Files.newInputStream].
*/
inline fun <T: Path> T.newInputStream(vararg openOptions: OpenOption): InputStream =
inline fun Path.newInputStream(vararg openOptions: OpenOption): InputStream =
Files.newInputStream(this, *openOptions)

/**
* Delegates to [Files.newOutputStream].
*/
inline fun <T: Path> T.newOutputStream(vararg openOptions: OpenOption): OutputStream =
inline fun Path.newOutputStream(vararg openOptions: OpenOption): OutputStream =
Files.newOutputStream(this, *openOptions)

/**
* Delegates to [Files.readAllBytes].
*/
inline fun <T: Path> T.readAllBytes(): ByteArray = Files.readAllBytes(this)
inline fun Path.readAllBytes(): ByteArray = Files.readAllBytes(this)

/**
* Delegates to [Files.readAllLines].
*/
inline fun <T: Path> T.readAllLines(charset: Charset = Charsets.UTF_8): List<String> = Files.readAllLines(this, charset)
inline fun Path.readAllLines(charset: Charset = Charsets.UTF_8): List<String> = Files.readAllLines(this, charset)

/**
* Converts [Path.readAllBytes] to a string using the given [charset].
*/
inline fun <T: Path> T.readText(charset: Charset = Charsets.UTF_8): String =
inline fun Path.readText(charset: Charset = Charsets.UTF_8): String =
readAllBytes().toString(charset)

/**
* Delegates to [Files.write].
*/
inline fun <T: Path> T.writeBytes(array: ByteArray, vararg openOptions: OpenOption): Path =
inline fun Path.writeBytes(array: ByteArray, vararg openOptions: OpenOption): Path =
Files.write(this, array, *openOptions)
Loading

0 comments on commit 1afd89b

Please sign in to comment.