[minor] Drop some usages of kotlin reflection in scripting compiler plugin

This commit is contained in:
Ilya Chernikov
2019-09-11 14:13:37 +02:00
parent 689a5cbdf5
commit f8db150a2b
7 changed files with 10 additions and 10 deletions
@@ -8,9 +8,7 @@ jvmTarget = "1.6"
dependencies {
compile(kotlinStdlib())
compileOnly(project(":kotlin-reflect-api"))
compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false }
runtime(project(":kotlin-reflect"))
testCompile(commonDep("junit"))
}
@@ -25,7 +25,7 @@ class KotlinType private constructor(
/**
* Constructs KotlinType from reflected [kclass]
*/
constructor(kclass: KClass<*>) : this(kclass.qualifiedName!!, kclass)
constructor(kclass: KClass<*>) : this(kclass.java.name, kclass)
// TODO: implement other approach for non-class types
/**
@@ -22,6 +22,8 @@ dependencies {
// FIXME: drop after removing references to LocalFileSystem they don't exist in intellij-core
compileOnly(intellijDep()) { includeJars("platform-api") }
runtime(project(":kotlin-reflect"))
testCompile(project(":compiler:frontend"))
testCompile(project(":compiler:plugin-api"))
testCompile(project(":compiler:util"))
@@ -71,7 +71,7 @@ class LazyScriptDefinitionFromDiscoveredClass internal constructor(
override val evaluationConfiguration: ScriptEvaluationConfiguration get() = configurations.second
override val fileExtension: String by lazy(LazyThreadSafetyMode.PUBLICATION) {
annotationsFromAsm.find { it.name == KotlinScript::class.simpleName }?.args
annotationsFromAsm.find { it.name == KotlinScript::class.java.simpleName }?.args
?.find { it.name == "fileExtension" }?.value
?: compilationConfiguration.let {
it[ScriptCompilationConfiguration.fileExtension] ?: super.fileExtension
@@ -79,7 +79,7 @@ class LazyScriptDefinitionFromDiscoveredClass internal constructor(
}
override val name: String by lazy(LazyThreadSafetyMode.PUBLICATION) {
annotationsFromAsm.find { it.name == KotlinScript::class.simpleName!! }?.args?.find { it.name == "name" }?.value
annotationsFromAsm.find { it.name == KotlinScript::class.java.simpleName!! }?.args?.find { it.name == "name" }?.value
?: super.name
}
}
@@ -289,7 +289,7 @@ private fun loadScriptDefinition(
val anns = loadAnnotationsFromClass(templateClassBytes)
for (ann in anns) {
var def: ScriptDefinition? = null
if (ann.name == KotlinScript::class.simpleName) {
if (ann.name == KotlinScript::class.java.simpleName) {
def = LazyScriptDefinitionFromDiscoveredClass(
hostConfiguration,
anns,
@@ -297,7 +297,7 @@ private fun loadScriptDefinition(
classpathWithLoader.classpath,
messageReporter
)
} else if (ann.name == ScriptTemplateDefinition::class.simpleName) {
} else if (ann.name == ScriptTemplateDefinition::class.java.simpleName) {
val templateClass = classpathWithLoader.classLoader.loadClass(templateClassName).kotlin
def = ScriptDefinition.FromLegacy(
hostConfiguration,
@@ -16,7 +16,6 @@ dependencies {
compile(project(":kotlin-scripting-jvm"))
compile(project(":kotlin-scripting-compiler-impl"))
compile(kotlinStdlib())
compileOnly(project(":kotlin-reflect-api"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
testCompile(project(":compiler:frontend"))
@@ -6,13 +6,14 @@
package org.jetbrains.kotlin.scripting.compiler.plugin.impl
import org.jetbrains.kotlin.cli.common.arguments.Argument
import org.jetbrains.kotlin.cli.common.arguments.ArgumentParseErrors
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.scripting.definitions.MessageReporter
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.full.findAnnotation
import kotlin.script.experimental.api.ResultWithDiagnostics
import kotlin.script.experimental.api.ScriptDiagnostic
import kotlin.script.experimental.api.SourceCode
@@ -136,7 +137,7 @@ private fun reportIgnoredArguments(
) {
val ignoredArgKeys = toIgnore.mapNotNull { argProperty ->
if (argProperty.get(arguments) != argProperty.get(reportingState.currentArguments)) {
argProperty.findAnnotation<Argument>()?.value
argProperty.annotations.firstIsInstanceOrNull<Argument>()?.value
?: throw IllegalStateException("unknown compiler argument property: $argProperty: no Argument annotation found")
} else null
}