Cleanup in libraries and tools: use property access syntax.
This commit is contained in:
@@ -42,7 +42,7 @@ public inline fun <T> ReentrantReadWriteLock.read(action: () -> T): T {
|
||||
public inline fun <T> ReentrantReadWriteLock.write(action: () -> T): T {
|
||||
val rl = readLock()
|
||||
|
||||
val readCount = if (getWriteHoldCount() == 0) getReadHoldCount() else 0
|
||||
val readCount = if (writeHoldCount == 0) readHoldCount else 0
|
||||
repeat(readCount) { rl.unlock() }
|
||||
|
||||
val wl = writeLock()
|
||||
|
||||
@@ -50,7 +50,7 @@ public fun createTempFile(prefix: String = "tmp", suffix: String? = null, direct
|
||||
*/
|
||||
@Deprecated("This property has unclear semantics and will be removed soon.")
|
||||
public val File.directory: File
|
||||
get() = if (isDirectory()) this else parentFile!!
|
||||
get() = if (isDirectory) this else parentFile!!
|
||||
|
||||
/**
|
||||
* Returns parent of this abstract path name, or `null` if it has no parent.
|
||||
@@ -265,20 +265,20 @@ public fun File.relativePath(descendant: File): String {
|
||||
public fun File.copyTo(dst: File, overwrite: Boolean = false, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long {
|
||||
if (!exists()) {
|
||||
throw NoSuchFileException(file = this, reason = "The source file doesn't exist")
|
||||
} else if (isDirectory()) {
|
||||
} else if (isDirectory) {
|
||||
throw IllegalArgumentException("Use copyRecursively to copy a directory $this")
|
||||
} else if (dst.exists()) {
|
||||
if (!overwrite) {
|
||||
throw FileAlreadyExistsException(file = this,
|
||||
other = dst,
|
||||
reason = "The destination file already exists")
|
||||
} else if (dst.isDirectory() && dst.listFiles().any()) {
|
||||
} else if (dst.isDirectory && dst.listFiles().any()) {
|
||||
// In this case file should be copied *into* this directory,
|
||||
// no matter whether it is empty or not
|
||||
return copyTo(dst.resolve(name), overwrite, bufferSize)
|
||||
}
|
||||
}
|
||||
dst.getParentFile()?.mkdirs()
|
||||
dst.parentFile?.mkdirs()
|
||||
dst.delete()
|
||||
val input = FileInputStream(this)
|
||||
return input.use<FileInputStream, Long> {
|
||||
@@ -340,12 +340,12 @@ public fun File.copyRecursively(dst: File,
|
||||
} else {
|
||||
val relPath = src.relativeTo(this)
|
||||
val dstFile = File(dst, relPath)
|
||||
if (dstFile.exists() && !(src.isDirectory() && dstFile.isDirectory())) {
|
||||
if (dstFile.exists() && !(src.isDirectory && dstFile.isDirectory)) {
|
||||
if (onError(dstFile, FileAlreadyExistsException(file = src,
|
||||
other = dstFile,
|
||||
reason = "The destination file already exists")) == OnErrorAction.TERMINATE)
|
||||
return false
|
||||
} else if (src.isDirectory()) {
|
||||
} else if (src.isDirectory) {
|
||||
dstFile.mkdirs()
|
||||
} else {
|
||||
if (src.copyTo(dstFile, true) != src.length()) {
|
||||
|
||||
@@ -8,8 +8,8 @@ class C()
|
||||
|
||||
class JavaClassTest() : TestCase() {
|
||||
fun testMe () {
|
||||
assertEquals("java.util.ArrayList", java.util.ArrayList<Any>().javaClass.getName())
|
||||
assertEquals("java.util.ArrayList", ArrayList::class.java.getName())
|
||||
assertEquals("testjc.C", C::class.java.getName())
|
||||
assertEquals("java.util.ArrayList", java.util.ArrayList<Any>().javaClass.name)
|
||||
assertEquals("java.util.ArrayList", ArrayList::class.java.name)
|
||||
assertEquals("testjc.C", C::class.java.name)
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ class FileTreeWalkTest {
|
||||
val basedir = createTestFiles()
|
||||
try {
|
||||
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
|
||||
assertEquals(referenceNames, basedir.walkTopDown().filter { it.isDirectory() }.map {
|
||||
assertEquals(referenceNames, basedir.walkTopDown().filter { it.isDirectory }.map {
|
||||
it.relativeToOrSelf(basedir).invariantSeparatorsPath
|
||||
}.toHashSet())
|
||||
} finally {
|
||||
@@ -145,7 +145,7 @@ class FileTreeWalkTest {
|
||||
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
|
||||
val namesTopDown = HashSet<String>()
|
||||
fun enter(file: File) {
|
||||
assertTrue(file.isDirectory())
|
||||
assertTrue(file.isDirectory)
|
||||
for (child in file.listFiles()) {
|
||||
if (child.name.endsWith("txt"))
|
||||
child.delete()
|
||||
@@ -168,7 +168,7 @@ class FileTreeWalkTest {
|
||||
val referenceNames = setOf("", "1", "1/2", "1/3", "6", "8")
|
||||
val namesTopDown = HashSet<String>()
|
||||
fun enter(file: File) {
|
||||
assertTrue(file.isDirectory())
|
||||
assertTrue(file.isDirectory)
|
||||
for (child in file.listFiles()) {
|
||||
if (child.name.endsWith("txt"))
|
||||
child.delete()
|
||||
@@ -287,7 +287,7 @@ class FileTreeWalkTest {
|
||||
failed.add(dir.name)
|
||||
}
|
||||
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
|
||||
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory()) visitFile(it) }
|
||||
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory) visitFile(it) }
|
||||
assertTrue(stack.isEmpty())
|
||||
for (fileName in arrayOf("", "1", "1/2", "1/3", "6", "8")) {
|
||||
assertTrue(dirs.contains(File(fileName)), fileName)
|
||||
@@ -313,7 +313,7 @@ class FileTreeWalkTest {
|
||||
files.clear()
|
||||
dirs.clear()
|
||||
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
|
||||
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory()) visitFile(it) }
|
||||
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory) visitFile(it) }
|
||||
assertTrue(stack.isEmpty())
|
||||
assertEquals(setOf("1"), failed)
|
||||
assertEquals(listOf("", "1", "6", "8").map { File(it) }.toSet(), dirs)
|
||||
@@ -335,7 +335,7 @@ class FileTreeWalkTest {
|
||||
val visited = HashSet<File>()
|
||||
val block: (File) -> Unit = {
|
||||
assertTrue(!visited.contains(it), it.toString())
|
||||
assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile()), it.toString())
|
||||
assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.parentFile), it.toString())
|
||||
visited.add(it)
|
||||
}
|
||||
basedir.walkTopDown().forEach(block)
|
||||
@@ -353,7 +353,7 @@ class FileTreeWalkTest {
|
||||
val visited = HashSet<File>()
|
||||
val block: (File) -> Unit = {
|
||||
assertTrue(!visited.contains(it), it.toString())
|
||||
assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile()), it.toString())
|
||||
assertTrue(it == basedir && visited.isEmpty() || visited.contains(it.parentFile), it.toString())
|
||||
visited.add(it)
|
||||
}
|
||||
basedir.walkTopDown().forEach(block)
|
||||
@@ -376,7 +376,7 @@ class FileTreeWalkTest {
|
||||
val basedir1 = createTestFiles()
|
||||
try {
|
||||
basedir1.walkTopDown().forEach {
|
||||
if (it.isFile()) {
|
||||
if (it.isFile) {
|
||||
makeBackup(it)
|
||||
}
|
||||
}
|
||||
@@ -389,7 +389,7 @@ class FileTreeWalkTest {
|
||||
val basedir2 = createTestFiles()
|
||||
try {
|
||||
basedir2.walkTopDown().forEach {
|
||||
if (it.isFile()) {
|
||||
if (it.isFile) {
|
||||
makeBackup(it)
|
||||
}
|
||||
}
|
||||
@@ -424,7 +424,7 @@ class FileTreeWalkTest {
|
||||
val found = HashSet<File>()
|
||||
for (file in basedir.walkTopDown()) {
|
||||
if (file.name == ".git") {
|
||||
found.add(file.getParentFile())
|
||||
found.add(file.parentFile)
|
||||
}
|
||||
}
|
||||
assertEquals(3, found.size)
|
||||
|
||||
@@ -20,16 +20,16 @@ class FilesTest {
|
||||
@test fun testCreateTempDir() {
|
||||
val dirSuf = System.currentTimeMillis().toString()
|
||||
val dir1 = createTempDir("temp", dirSuf)
|
||||
assertTrue(dir1.exists() && dir1.isDirectory() && dir1.name.startsWith("temp") && dir1.name.endsWith(dirSuf))
|
||||
assertTrue(dir1.exists() && dir1.isDirectory && dir1.name.startsWith("temp") && dir1.name.endsWith(dirSuf))
|
||||
assertFailsWith(IllegalArgumentException::class) {
|
||||
createTempDir("a")
|
||||
}
|
||||
|
||||
val dir2 = createTempDir("temp")
|
||||
assertTrue(dir2.exists() && dir2.isDirectory() && dir2.name.endsWith(".tmp"))
|
||||
assertTrue(dir2.exists() && dir2.isDirectory && dir2.name.endsWith(".tmp"))
|
||||
|
||||
val dir3 = createTempDir()
|
||||
assertTrue(dir3.exists() && dir3.isDirectory())
|
||||
assertTrue(dir3.exists() && dir3.isDirectory)
|
||||
|
||||
dir1.delete()
|
||||
dir2.delete()
|
||||
@@ -63,10 +63,10 @@ class FilesTest {
|
||||
createTempFile("temp3", ".kt", dir)
|
||||
|
||||
// This line works only with Kotlin File.listFiles(filter)
|
||||
val result = dir.listFiles { it -> it.getName().endsWith(".kt") } // todo ambiguity on SAM
|
||||
val result = dir.listFiles { it -> it.name.endsWith(".kt") } // todo ambiguity on SAM
|
||||
assertEquals(2, result!!.size)
|
||||
// This line works both with Kotlin File.listFiles(filter) and the same Java function because of SAM
|
||||
val result2 = dir.listFiles { it -> it.getName().endsWith(".kt") }
|
||||
val result2 = dir.listFiles { it -> it.name.endsWith(".kt") }
|
||||
assertEquals(2, result2!!.size)
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ class FilesTest {
|
||||
}
|
||||
|
||||
@test fun copyToNameWithoutParent() {
|
||||
val currentDir = File("").getAbsoluteFile()!!
|
||||
val currentDir = File("").absoluteFile!!
|
||||
val srcFile = createTempFile()
|
||||
val dstFile = createTempFile(directory = currentDir)
|
||||
try {
|
||||
@@ -474,7 +474,7 @@ class FilesTest {
|
||||
for (file in src.walkTopDown()) {
|
||||
val dstFile = File(dst, file.relativeTo(src))
|
||||
assertTrue(dstFile.exists())
|
||||
if (dstFile.isFile()) {
|
||||
if (dstFile.isFile) {
|
||||
assertEquals(file.readText(), dstFile.readText())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user