Fix equality and serializability of scripting data, fix relevant caching behaviour

This commit is contained in:
Ilya Chernikov
2019-03-14 12:00:04 +01:00
parent 7a4d369c9f
commit 931b1c66d8
6 changed files with 52 additions and 5 deletions
@@ -32,4 +32,13 @@ class KotlinType private constructor(
* Constructs KotlinType from reflected [ktype]
*/
constructor(type: KType) : this(type.classifier as KClass<*>)
override fun equals(other: Any?): Boolean =
(other as? KotlinType)?.let { typeName == it.typeName } == true
override fun hashCode(): Int = typeName.hashCode()
companion object {
private const val serialVersionUID: Long = 1L
}
}
@@ -190,14 +190,18 @@ class RefineConfigurationBuilder : PropertiesCollection.Builder() {
typealias RefineScriptCompilationConfigurationHandler =
(ScriptConfigurationRefinementContext) -> ResultWithDiagnostics<ScriptCompilationConfiguration>
class RefineConfigurationUnconditionallyData(
data class RefineConfigurationUnconditionallyData(
val handler: RefineScriptCompilationConfigurationHandler
) : Serializable
) : Serializable {
companion object { private const val serialVersionUID: Long = 1L }
}
class RefineConfigurationOnAnnotationsData(
data class RefineConfigurationOnAnnotationsData(
val annotations: List<KotlinType>,
val handler: RefineScriptCompilationConfigurationHandler
) : Serializable
) : Serializable {
companion object { private const val serialVersionUID: Long = 1L }
}
/**
@@ -66,7 +66,9 @@ interface ExternalSourceCode : SourceCode {
/**
* The source code [range] with the the optional [name]
*/
data class ScriptSourceNamedFragment(val name: String?, val range: SourceCode.Range)
data class ScriptSourceNamedFragment(val name: String?, val range: SourceCode.Range) : Serializable {
companion object { private const val serialVersionUID: Long = 1L }
}
/**
* The general interface to the Script dependency (see platform-specific implementations)
@@ -6,6 +6,8 @@
package kotlin.script.experimental.host
import java.io.File
import java.io.IOError
import java.io.IOException
import java.net.URL
import kotlin.script.experimental.api.*
@@ -47,6 +49,11 @@ open class FileScriptSource(val file: File, private val preloadedText: String? =
override val text: String by lazy { preloadedText ?: file.readText() }
override val name: String? get() = file.name
override val locationId: String? get() = file.path
override fun equals(other: Any?): Boolean =
this === other || (other as? FileScriptSource)?.let { file.absolutePath == it.file.absolutePath && textSafe == it.textSafe } == true
override fun hashCode(): Int = file.absolutePath.hashCode() + textSafe.hashCode() * 23
}
/**
@@ -56,6 +63,11 @@ open class UrlScriptSource(override val externalLocation: URL) : ExternalSourceC
override val text: String by lazy { externalLocation.readText() }
override val name: String? get() = externalLocation.file
override val locationId: String? get() = externalLocation.toString()
override fun equals(other: Any?): Boolean =
this === other || (other as? UrlScriptSource)?.let { externalLocation == it.externalLocation && textSafe == it.textSafe } == true
override fun hashCode(): Int = externalLocation.hashCode() + textSafe.hashCode() * 17
}
/**
@@ -71,9 +83,22 @@ open class StringScriptSource(val source: String, override val name: String? = n
override val text: String get() = source
override val locationId: String? = null
override fun equals(other: Any?): Boolean =
this === other || (other as? StringScriptSource)?.let { text == it.text && name == it.name && locationId == it.locationId } == true
override fun hashCode(): Int = text.hashCode() + name.hashCode() * 17 + locationId.hashCode() * 23
}
/**
* Converts the String into the SourceCode
*/
fun String.toScriptSource(name: String? = null): SourceCode = StringScriptSource(this, name)
private val ExternalSourceCode.textSafe: String?
get() =
try {
text
} catch (e: Throwable) {
null
}
@@ -48,6 +48,11 @@ open class PropertiesCollection(private val properties: Map<Key<*>, Any?> = empt
fun entries(): Set<Map.Entry<Key<*>, Any?>> = properties.entries
override fun equals(other: Any?): Boolean =
(other as? PropertiesCollection)?.let { it.properties == properties } == true
override fun hashCode(): Int = properties.hashCode()
companion object {
fun <T> key(defaultValue: T? = null) = PropertyKeyDelegate(defaultValue)
fun <T> keyCopy(source: Key<T>) = PropertyKeyCopyDelegate(source)
@@ -15,6 +15,8 @@ import kotlin.script.experimental.util.PropertiesCollection
data class JvmDependency(val classpath: List<File>) : ScriptDependency {
@Suppress("unused")
constructor(vararg classpathEntries: File) : this(classpathEntries.asList())
companion object { private const val serialVersionUID: Long = 1L }
}
interface JvmScriptCompilationConfigurationKeys