Drop deprecations and tighten up left ones.

This commit is contained in:
Ilya Gorbunov
2015-11-07 15:26:54 +03:00
parent 5b484f1e05
commit be9b14545f
11 changed files with 29 additions and 77 deletions
@@ -20,7 +20,7 @@ public operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): V? = put(key,
* getOrPut is not supported on [ConcurrentMap] since it cannot be implemented correctly in terms of concurrency.
* Use [concurrentGetOrPut] instead, or cast this to a [MutableMap] if you want to sacrifice the concurrent-safety.
*/
@Deprecated("Use concurrentGetOrPut instead or cast this map to MutableMap.")
@Deprecated("Use concurrentGetOrPut instead or cast this map to MutableMap.", level = DeprecationLevel.ERROR)
public inline fun <K, V> ConcurrentMap<K, V>.getOrPut(key: K, defaultValue: () -> V): Nothing =
throw UnsupportedOperationException("getOrPut is not supported on ConcurrentMap.")
+1 -4
View File
@@ -61,10 +61,7 @@ public fun ByteArray.inputStream(offset: Int, length: Int) : ByteArrayInputStrea
* @param bufferSize the buffer size to use.
*/
public fun InputStream.buffered(bufferSize: Int = defaultBufferSize): InputStream
= if (this is BufferedInputStream)
this
else
BufferedInputStream(this, bufferSize)
= if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize)
/** Creates a reader on this input stream using UTF-8 or the specified [charset]. */
public fun InputStream.reader(charset: Charset = Charsets.UTF_8): InputStreamReader = InputStreamReader(this, charset)
@@ -48,12 +48,6 @@ public fun String.reader(): StringReader = StringReader(this)
*/
public fun BufferedReader.lineSequence(): Sequence<String> = LinesSequence(this).constrainOnce()
@Deprecated("Use lineSequence() instead to avoid conflict with JDK8 lines() method.", ReplaceWith("lineSequence()"))
public fun BufferedReader.lines(): Sequence<String> = lineSequence()
@Deprecated("Use lineSequence() function which returns Sequence<String>")
public fun BufferedReader.lineIterator(): Iterator<String> = lineSequence().iterator()
private class LinesSequence(private val reader: BufferedReader) : Sequence<String> {
override public fun iterator(): Iterator<String> {
return object : Iterator<String> {
@@ -211,16 +211,6 @@ public class FileTreeWalk(private val start: File,
return FileTreeWalk(start, direction, enter, leave, function, filter, maxDepth)
}
/**
* Sets tree filter [predicate].
* Tree filter [predicate] function is called before visiting files and entering directories.
* If it returns `false`, file is not visited, directory is not entered and all its content is also not visited.
* If it returns `true`, everything goes in the regular way.
*/
@Deprecated("Use treeFilter instead", ReplaceWith("treeFilter(predicate)"))
public fun filter(predicate: (File) -> Boolean): FileTreeWalk {
return FileTreeWalk(start, direction, enter, leave, fail, predicate, maxDepth)
}
/**
* Sets tree filter [predicate].
@@ -295,7 +285,7 @@ public fun File.walkBottomUp(): FileTreeWalk = walk(FileWalkDirection.BOTTOM_UP)
*
* @param function the function to call on each file.
*/
@Deprecated("It's recommended to use walkTopDown() / walkBottomUp()", ReplaceWith("walkTopDown().forEach(function)"))
@Deprecated("It's recommended to use walkTopDown() / walkBottomUp()", ReplaceWith("walkTopDown().forEach(function)"), DeprecationLevel.ERROR)
public fun File.recurse(function: (File) -> Unit): Unit {
walkTopDown().forEach(function)
}
+1 -22
View File
@@ -54,31 +54,10 @@ public val File.directory: File
/**
* Returns parent of this abstract path name, or `null` if it has no parent.
*/
@Deprecated("Use parentFile", ReplaceWith("parentFile"))
@Deprecated("Use parentFile", ReplaceWith("parentFile"), DeprecationLevel.ERROR)
public val File.parent: File?
get() = parentFile
/**
* Returns the canonical path of this file.
*/
@Deprecated("Is replaced with automatic synthetic extension", ReplaceWith("canonicalPath"), level = DeprecationLevel.HIDDEN)
public val File.canonicalPath: String
get() = getCanonicalPath()
/**
* Returns the file name.
*/
@Deprecated("Is replaced with automatic synthetic extension", ReplaceWith("name"), level = DeprecationLevel.HIDDEN)
public val File.name: String
get() = getName()
/**
* Returns the file path.
*/
@Deprecated("Is replaced with automatic synthetic extension", ReplaceWith("path"), level = DeprecationLevel.HIDDEN)
public val File.path: String
get() = getPath()
/**
* Returns the extension of this file (not including the dot), or an empty string if it doesn't have one.
*/
@@ -117,7 +117,7 @@ public class Regex internal constructor(private val nativePattern: Pattern) {
/** Indicates whether the regular expression can find at least one match in the specified [input]. */
public fun containsMatchIn(input: CharSequence): Boolean = nativePattern.matcher(input).find()
@Deprecated("Use containsMatchIn() or 'in' operator instead.", ReplaceWith("this in input"))
@Deprecated("Use containsMatchIn() or 'in' operator instead.", ReplaceWith("this in input"), DeprecationLevel.ERROR)
public fun hasMatch(input: CharSequence): Boolean = containsMatchIn(input)
/**
@@ -128,7 +128,7 @@ public class Regex internal constructor(private val nativePattern: Pattern) {
*/
public fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = nativePattern.matcher(input).findNext(startIndex, input)
@Deprecated("Use find() instead.", ReplaceWith("find(input, startIndex)"))
@Deprecated("Use find() instead.", ReplaceWith("find(input, startIndex)"), DeprecationLevel.ERROR)
public fun match(input: CharSequence, startIndex: Int = 0): MatchResult? = find(input, startIndex)
/**
@@ -136,7 +136,7 @@ public class Regex internal constructor(private val nativePattern: Pattern) {
*/
public fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = sequence({ find(input, startIndex) }, { match -> match.next() })
@Deprecated("Use findAll() instead.", ReplaceWith("findAll(input, startIndex)"))
@Deprecated("Use findAll() instead.", ReplaceWith("findAll(input, startIndex)"), DeprecationLevel.ERROR)
public fun matchAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = findAll(input, startIndex)
/**
@@ -5,7 +5,7 @@ package kotlin
private object _Assertions
@Deprecated("Must be public to make assert() inlinable")
@Deprecated("Not supposed to be used directly, exposed to make assert() inlinable.")
public val ASSERTIONS_ENABLED: Boolean = _Assertions.javaClass.desiredAssertionStatus()
/**
@@ -22,6 +22,7 @@ public fun assert(value: Boolean) {
*/
@Deprecated("Use assert with lazy message instead.", ReplaceWith("assert(value) { message }"))
public fun assert(value: Boolean, message: Any = "Assertion failed") {
@Suppress("DEPRECATION")
if (ASSERTIONS_ENABLED) {
if (!value) {
throw AssertionError(message)
@@ -34,6 +35,7 @@ public fun assert(value: Boolean, message: Any = "Assertion failed") {
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
*/
public inline fun assert(value: Boolean, lazyMessage: () -> Any) {
@Suppress("DEPRECATION")
if (ASSERTIONS_ENABLED) {
if (!value) {
val message = lazyMessage()
+1 -1
View File
@@ -25,7 +25,7 @@ import kotlin.reflect.KClass
* @property exceptionClasses the list of checked exception classes that may be thrown by the function.
*/
@Retention(AnnotationRetention.SOURCE)
@Deprecated("Use 'kotlin.jvm.Throws' instead", ReplaceWith("kotlin.jvm.Throws"))
@Deprecated("Use 'kotlin.jvm.Throws' instead", ReplaceWith("kotlin.jvm.Throws"), DeprecationLevel.ERROR)
public annotation class throws(public vararg val exceptionClasses: KClass<out Throwable>)
/**
@@ -19,9 +19,6 @@ package kotlin
import java.util.Comparator
@Deprecated("Use compareValuesBy", ReplaceWith("compareValuesBy(a, b, *selectors)"), level = DeprecationLevel.HIDDEN)
public fun <T> compareValuesByNullable(a: T, b: T, vararg selectors: (T) -> Comparable<*>?): Int = compareValuesBy(a, b, *selectors)
/**
* Compares two values using the specified functions [selectors] to calculate the result of the comparison.
* The functions are called sequentially, receive the given values [a] and [b] and return [Comparable]
@@ -44,9 +44,8 @@ class MapJVMTest {
@test fun getOrPutFailsOnConcurrentMap() {
val map = ConcurrentHashMap<String, Int>()
assertFails {
map.getOrPut("x") { 1 }
}
// now this is an error
// map.getOrPut("x") { 1 }
expect(1) {
map.concurrentGetOrPut("x") { 1 }
}
+16 -22
View File
@@ -333,7 +333,7 @@ class FilesTest {
}
fun visitFile(file: File) {
assert(stack.last().listFiles().contains(file), file)
assert(stack.last().listFiles().contains(file)) { file }
files.add(file.relativeTo(basedir))
}
@@ -347,10 +347,10 @@ class FilesTest {
assert(stack.isEmpty())
val sep = File.separator
for (fileName in arrayOf("", "1", "1${sep}2", "1${sep}3", "6", "8")) {
assert(dirs.contains(fileName), fileName)
assert(dirs.contains(fileName)) { fileName }
}
for (fileName in arrayOf("1${sep}3${sep}4.txt", "1${sep}3${sep}4.txt", "7.txt", "8${sep}9.txt")) {
assert(files.contains(fileName), fileName)
assert(files.contains(fileName)) { fileName }
}
//limit maxDepth
@@ -359,9 +359,9 @@ class FilesTest {
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).maxDepth(1).
forEach { it -> if (it != basedir) visitFile(it) }
assert(stack.isEmpty())
assert(dirs.size() == 1 && dirs.contains(""), dirs.size())
assert(dirs.size() == 1 && dirs.contains("")) { dirs.size() }
for (file in arrayOf("1", "6", "7.txt", "8")) {
assert(files.contains(file), file)
assert(files.contains(file)) { file }
}
//restrict access
@@ -372,14 +372,14 @@ class FilesTest {
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory()) visitFile(it) }
assert(stack.isEmpty())
assert(failed.size() == 1 && failed.contains("1"), failed.size())
assert(dirs.size() == 4, dirs.size())
assert(failed.size() == 1 && failed.contains("1")) { failed.size() }
assert(dirs.size() == 4) { dirs.size() }
for (dir in arrayOf("", "1", "6", "8")) {
assert(dirs.contains(dir), dir)
assert(dirs.contains(dir)) { dir }
}
assert(files.size() == 2, files.size())
assert(files.size() == 2) { files.size() }
for (file in arrayOf("7.txt", "8${sep}9.txt")) {
assert(files.contains(file), file)
assert(files.contains(file)) { file }
}
} finally {
File(basedir, "1").setReadable(true)
@@ -397,12 +397,12 @@ class FilesTest {
try {
val visited = HashSet<File>()
val block: (File) -> Unit = {
assert(!visited.contains(it), it)
assert(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile()), it)
assert(!visited.contains(it)) { it }
assert(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile())) { it }
visited.add(it)
}
basedir.walkTopDown().forEach(block)
assert(visited.size() == 10, visited.size())
assert(visited.size() == 10) { visited.size() }
} finally {
basedir.deleteRecursively()
@@ -416,12 +416,12 @@ class FilesTest {
if (restricted.setReadable(false)) {
val visited = HashSet<File>()
val block: (File) -> Unit = {
assert(!visited.contains(it), it)
assert(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile()), it)
assert(!visited.contains(it)) { it }
assert(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile())) { it }
visited.add(it)
}
basedir.walkTopDown().forEach(block)
assert(visited.size() == 6, visited.size())
assert(visited.size() == 6) { visited.size() }
}
} finally {
restricted.setReadable(true)
@@ -521,12 +521,6 @@ class FilesTest {
}
}
@test fun recurse() {
val set: MutableSet<String> = HashSet()
val dir = createTestFiles()
dir.recurse { set.add(it.path) }
assertEquals(10, set.size())
}
}
@test fun listFilesWithFilter() {