Introduce KotlinVersion API
#KT-14789
This commit is contained in:
@@ -31,3 +31,8 @@ internal annotation class JvmName(public val name: String)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
@MustBeDocumented
|
||||
internal annotation class JvmMultifileClass
|
||||
|
||||
@Target(AnnotationTarget.FIELD)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
@MustBeDocumented
|
||||
internal annotation class JvmField
|
||||
@@ -0,0 +1,65 @@
|
||||
package kotlin
|
||||
|
||||
/**
|
||||
* Represents a version of the Kotlin standard library
|
||||
*/
|
||||
public class KotlinVersion(val major: Int, val minor: Int, val patch: Int) : Comparable<KotlinVersion> {
|
||||
public constructor(major: Int, minor: Int) : this(major, minor, 0)
|
||||
|
||||
private val version = versionOf(major, minor, patch)
|
||||
|
||||
private fun versionOf(major: Int, minor: Int, patch: Int): Int {
|
||||
require(major in 0..99 && minor in 0..99 && patch in 0..99) { "Version components are out of range: $major.$minor.$patch" }
|
||||
return major * 100 * 100 + minor * 100 + patch
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integer representation of this version.
|
||||
*
|
||||
* Integer representations of two [KotlinVersion] instances can be compared,
|
||||
* so that if `v1.toInt() > v2.toInt()` then `v1 > v2`.
|
||||
*
|
||||
* This value should not be persisted, as it can change between program runs.
|
||||
*/
|
||||
public fun toInt(): Int = version
|
||||
|
||||
/**
|
||||
* Returns the string representation of this version
|
||||
*/
|
||||
override fun toString(): String = "$major.$minor.$patch"
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
val otherVersion = (other as? KotlinVersion) ?: return false
|
||||
return this.version == otherVersion.version
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = version
|
||||
|
||||
override fun compareTo(other: KotlinVersion): Int = version - other.version
|
||||
|
||||
public fun isAtLeast(major: Int, minor: Int): Boolean =
|
||||
// or this.version >= versionOf(major, minor, 0)
|
||||
this.major > major || (this.major == major &&
|
||||
this.minor >= minor)
|
||||
|
||||
public fun isAtLeast(major: Int, minor: Int, patch: Int): Boolean =
|
||||
// or this.version >= versionOf(major, minor, patch)
|
||||
this.major > major || (this.major == major &&
|
||||
(this.minor > minor || this.minor == minor &&
|
||||
this.patch >= patch))
|
||||
|
||||
public fun isAtLeast(version: KotlinVersion): Boolean = this >= version
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Returns the current version of the Kotlin standard library
|
||||
*/
|
||||
// TODO: get from metadata or hardcode automatically during build
|
||||
@kotlin.jvm.JvmField
|
||||
public val CURRENT: KotlinVersion = KotlinVersion(1, 1, 0)
|
||||
|
||||
// should we have 'parse'?
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,28 @@ public final class kotlin/ExceptionsKt {
|
||||
public static final fun getStackTrace (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;
|
||||
}
|
||||
|
||||
public final class kotlin/KotlinVersion : java/lang/Comparable {
|
||||
public static final field CURRENT Lkotlin/KotlinVersion;
|
||||
public static final field Companion Lkotlin/KotlinVersion$Companion;
|
||||
public fun <init> (II)V
|
||||
public fun <init> (III)V
|
||||
public synthetic fun compareTo (Ljava/lang/Object;)I
|
||||
public fun compareTo (Lkotlin/KotlinVersion;)I
|
||||
public fun equals (Ljava/lang/Object;)Z
|
||||
public final fun getMajor ()I
|
||||
public final fun getMinor ()I
|
||||
public final fun getPatch ()I
|
||||
public fun hashCode ()I
|
||||
public final fun isAtLeast (II)Z
|
||||
public final fun isAtLeast (III)Z
|
||||
public final fun isAtLeast (Lkotlin/KotlinVersion;)Z
|
||||
public final fun toInt ()I
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class kotlin/KotlinVersion$Companion {
|
||||
}
|
||||
|
||||
public abstract interface class kotlin/Lazy {
|
||||
public abstract fun getValue ()Ljava/lang/Object;
|
||||
public abstract fun isInitialized ()Z
|
||||
|
||||
Reference in New Issue
Block a user