diff --git a/js/js.libraries/src/core/annotationsJVM.kt b/js/js.libraries/src/core/annotationsJVM.kt index 4033d2f3ad5..e9fc929142f 100644 --- a/js/js.libraries/src/core/annotationsJVM.kt +++ b/js/js.libraries/src/core/annotationsJVM.kt @@ -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 \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/util/KotlinVersion.kt b/libraries/stdlib/src/kotlin/util/KotlinVersion.kt new file mode 100644 index 00000000000..daf3330964f --- /dev/null +++ b/libraries/stdlib/src/kotlin/util/KotlinVersion.kt @@ -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 { + 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'? + + } +} \ No newline at end of file diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt index 45c1c7fcf6c..317c2bee790 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt @@ -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 (II)V + public fun (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