Implement basic support of the new scripting in the frontend and plugin

This commit is contained in:
Ilya Chernikov
2018-02-14 16:58:19 +01:00
parent 3732422e6a
commit 3f22e28a51
4 changed files with 86 additions and 9 deletions
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.gradle.dsl.Coroutines
plugins {
kotlin("jvm")
@@ -9,6 +10,8 @@ jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
compile(project(":kotlin-scripting-common"))
compile(project(":kotlin-scripting-jvm"))
compile(projectDist(":kotlin-stdlib"))
compileOnly(project(":kotlin-reflect-api"))
compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false }
@@ -21,3 +24,6 @@ sourceSets {
"test" {}
}
kotlin {
experimental.coroutines = Coroutines.ENABLE
}
@@ -0,0 +1,53 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.script.experimental
import com.intellij.openapi.fileTypes.LanguageFileType
import kotlinx.coroutines.experimental.runBlocking
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.NameUtils
import org.jetbrains.kotlin.psi.KtScript
import org.jetbrains.kotlin.script.KotlinScriptDefinition
import kotlin.reflect.KClass
import kotlin.script.experimental.api.ScriptCompileConfigurationParams
import kotlin.script.experimental.api.ScriptDefinition
import kotlin.script.experimental.api.getOrNull
import kotlin.script.experimental.api.resultOrNull
import kotlin.script.experimental.dependencies.DependenciesResolver
import kotlin.script.experimental.jvm.impl.BridgeDependenciesResolver
class KotlinScriptDefinitionAdapterFromNewAPI(val scriptDefinition: ScriptDefinition) : KotlinScriptDefinition(scriptDefinition.baseClass) {
override val name: String get() = scriptDefinition.selector.name
// TODO: consider creating separate type (subtype? for kotlin scripts)
override val fileType: LanguageFileType = KotlinFileType.INSTANCE
override val annotationsForSamWithReceivers: List<String>
get() = emptyList()
override fun isScript(fileName: String): Boolean =
fileName.endsWith("." + scriptDefinition.selector.fileExtension)
override fun getScriptName(script: KtScript): Name {
val fileBasedName = NameUtils.getScriptNameForFile(script.containingKtFile.name)
return Name.identifier(scriptDefinition.selector.makeScriptName(fileBasedName.identifier))
}
override val dependencyResolver: DependenciesResolver by lazy {
BridgeDependenciesResolver(scriptDefinition.configurator)
}
override val acceptedAnnotations: List<KClass<out Annotation>> by lazy {
runBlocking {
scriptDefinition.configurator.baseConfiguration(null)
}.resultOrNull()?.getOrNull(ScriptCompileConfigurationParams.updateConfigurationOnAnnotations)?.toList()
?: emptyList()
}
}