Adjust exposed visibility of platform specific implementations.

This commit is contained in:
Ilya Gorbunov
2016-06-16 00:44:58 +03:00
parent a45da393b9
commit dd0ecb5ece
4 changed files with 49 additions and 43 deletions
@@ -20,44 +20,42 @@ internal open class PlatformImplementations {
public open fun getMatchResultNamedGroup(matchResult: MatchResult, name: String): MatchGroup? {
throw UnsupportedOperationException("Retrieving groups by name is not supported on this platform.")
}
companion object {
@JvmField
@InlineExposed
val INSTANCE: PlatformImplementations = run {
val version = getJavaVersion()
try {
if (version >= 0x10008)
return@run Class.forName("kotlin.internal.JDK8PlatformImplementations").newInstance() as PlatformImplementations
} catch (e: ClassNotFoundException) {}
try {
if (version >= 0x10007)
return@run Class.forName("kotlin.internal.JDK7PlatformImplementations").newInstance() as PlatformImplementations
} catch (e: ClassNotFoundException) {}
PlatformImplementations()
}
private fun getJavaVersion(): Int {
val default = 0x10006
val version = System.getProperty("java.version") ?: return default
val firstDot = version.indexOf('.')
if (firstDot < 0) return default
var secondDot = version.indexOf('.', firstDot + 1)
if (secondDot < 0) secondDot = version.length
val firstPart = version.substring(0, firstDot)
val secondPart = version.substring(firstDot + 1, secondDot)
return try {
firstPart.toInt() * 0x10000 + secondPart.toInt()
} catch (e: NumberFormatException) {
default
}
}
}
}
@kotlin.internal.InlineExposed
internal fun platformCloseSuppressed(instance: Closeable, cause: Throwable) = IMPLEMENTATIONS.closeSuppressed(instance, cause)
@JvmField
internal val IMPLEMENTATIONS: PlatformImplementations = run {
val version = getJavaVersion()
try {
if (version >= 0x10008)
return@run Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance() as PlatformImplementations
} catch (e: ClassNotFoundException) {}
try {
if (version >= 0x10007)
return@run Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance() as PlatformImplementations
} catch (e: ClassNotFoundException) {}
PlatformImplementations()
}
private fun getJavaVersion(): Int {
val default = 0x10006
val version = System.getProperty("java.version") ?: return default
val firstDot = version.indexOf('.')
if (firstDot < 0) return default
var secondDot = version.indexOf('.', firstDot + 1)
if (secondDot < 0) secondDot = version.length
val firstPart = version.substring(0, firstDot)
val secondPart = version.substring(firstDot + 1, secondDot)
return try {
firstPart.toInt() * 0x10000 + secondPart.toInt()
} catch (e: NumberFormatException) {
default
}
}