Rename ScriptSource to SourceCode, extract location to another i-face...

other related refactorings. The goal - make interface terminologically
more suitable for usage in REPL.
This commit is contained in:
Ilya Chernikov
2018-09-03 13:37:27 +02:00
parent 1e85a26b62
commit 67ba8b5361
10 changed files with 37 additions and 42 deletions
@@ -10,7 +10,7 @@ package kotlin.script.experimental.api
data class ScriptDiagnostic(
val message: String,
val severity: Severity = Severity.ERROR,
val location: ScriptSource.Location? = null,
val location: SourceCode.Location? = null,
val exception: Throwable? = null
) {
enum class Severity { FATAL, ERROR, WARNING, INFO, DEBUG }
@@ -56,10 +56,10 @@ operator fun <R> List<ScriptDiagnostic>.plus(res: ResultWithDiagnostics<R>): Res
fun <R> R.asSuccess(reports: List<ScriptDiagnostic> = listOf()): ResultWithDiagnostics.Success<R> =
ResultWithDiagnostics.Success(this, reports)
fun Throwable.asDiagnostics(customMessage: String? = null, location: ScriptSource.Location? = null): ScriptDiagnostic =
fun Throwable.asDiagnostics(customMessage: String? = null, location: SourceCode.Location? = null): ScriptDiagnostic =
ScriptDiagnostic(customMessage ?: message ?: "$this", ScriptDiagnostic.Severity.ERROR, location, this)
fun String.asErrorDiagnostics(location: ScriptSource.Location? = null): ScriptDiagnostic =
fun String.asErrorDiagnostics(location: SourceCode.Location? = null): ScriptDiagnostic =
ScriptDiagnostic(this, ScriptDiagnostic.Severity.ERROR, location)
fun<R> ResultWithDiagnostics<R>.resultOrNull(): R? = when (this) {
@@ -120,7 +120,7 @@ class RefineConfigurationOnSectionsData(
interface ScriptCompiler {
suspend operator fun invoke(
script: ScriptSource,
script: SourceCode,
scriptCompilationConfiguration: ScriptCompilationConfiguration
): ResultWithDiagnostics<CompiledScript<*>>
}
@@ -10,16 +10,19 @@ package kotlin.script.experimental.api
import java.net.URL
import kotlin.script.experimental.util.PropertiesCollection
interface ScriptSource {
val location: URL?
val text: String?
interface SourceCode {
val text: String
data class Position(val line: Int, val col: Int, val absolutePos: Int? = null)
data class Range(val start: Position, val end: Position)
data class Location(val start: Position, val end: Position? = null)
}
data class ScriptSourceNamedFragment(val name: String?, val range: ScriptSource.Range)
interface ExternalSourceCode : SourceCode {
val externalLocation: URL
}
data class ScriptSourceNamedFragment(val name: String?, val range: SourceCode.Range)
enum class ScriptBodyTarget {
Constructor,
@@ -53,7 +56,7 @@ val ScriptCollectedDataKeys.foundAnnotations by PropertiesCollection.key<List<An
val ScriptCollectedDataKeys.foundFragments by PropertiesCollection.key<List<ScriptSourceNamedFragment>>()
class ScriptConfigurationRefinementContext(
val source: ScriptSource,
val script: SourceCode,
val compilationConfiguration: ScriptCompilationConfiguration,
val collectedData: ScriptCollectedData? = null
)