Minor: improve message from future for use and useLines

Annotate RequireKotlin and apiVersionIsAtLeast with SinceKotlin
This commit is contained in:
Ilya Gorbunov
2017-10-15 19:36:15 +03:00
parent 88bb14d0b4
commit 18d4b91b2d
5 changed files with 6 additions and 4 deletions
@@ -95,6 +95,7 @@ internal annotation class AccessibleLateinitPropertyLiteral
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.TYPEALIAS)
@Retention(AnnotationRetention.SOURCE)
@SinceKotlin("1.2")
internal annotation class RequireKotlin(
val version: String,
val message: String = "",
@@ -106,6 +107,7 @@ internal annotation class RequireKotlin(
/**
* The kind of the version that is required by [RequireKotlin].
*/
@SinceKotlin("1.2")
internal enum class RequireKotlinVersionKind {
LANGUAGE_VERSION,
COMPILER_VERSION,
@@ -72,6 +72,6 @@ private fun getJavaVersion(): Int {
* The function usages are validated to have literal argument values.
*/
@PublishedApi
@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION)
@SinceKotlin("1.2")
internal fun apiVersionIsAtLeast(major: Int, minor: Int, patch: Int) =
KotlinVersion.CURRENT.isAtLeast(major, minor, patch)
+1 -1
View File
@@ -29,7 +29,7 @@ import kotlin.internal.*
* @return the result of [block] function invoked on this resource.
*/
@InlineOnly
@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION)
@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION, message = "Requires newer compiler version to be inlined correctly.")
public inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {
var exception: Throwable? = null
try {
@@ -196,6 +196,6 @@ public fun File.readLines(charset: Charset = Charsets.UTF_8): List<String> {
* @param charset character set to use. By default uses UTF-8 charset.
* @return the value returned by [block].
*/
@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION)
@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION, message = "Requires newer compiler version to be inlined correctly.")
public inline fun <T> File.useLines(charset: Charset = Charsets.UTF_8, block: (Sequence<String>) -> T): T =
bufferedReader(charset).use { block(it.lineSequence()) }
+1 -1
View File
@@ -43,7 +43,7 @@ public fun Reader.readLines(): List<String> {
* the processing is complete.
* @return the value returned by [block].
*/
@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION)
@RequireKotlin("1.2", versionKind = RequireKotlinVersionKind.COMPILER_VERSION, message = "Requires newer compiler version to be inlined correctly.")
public inline fun <T> Reader.useLines(block: (Sequence<String>) -> T): T =
buffered().use { block(it.lineSequence()) }