Drop half-backed support of "dynamic" annotations on scripts...

leaving it in the history so it could be restored and finished, if needed
This commit is contained in:
Ilya Chernikov
2018-07-03 16:14:07 +02:00
parent dee141b26b
commit f39c6f3b7a
4 changed files with 1 additions and 40 deletions
@@ -101,7 +101,6 @@ public interface Errors {
DiagnosticFactory1<PsiElement, String> MISSING_SCRIPT_BASE_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, String> MISSING_SCRIPT_RECEIVER_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, String> MISSING_SCRIPT_ENVIRONMENT_PROPERTY_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory2<PsiElement, String, String> INVALID_SCRIPT_TARGET_ANNOTATION_CLASS = DiagnosticFactory2.create(ERROR);
DiagnosticFactory1<PsiElement, String> PRE_RELEASE_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory2<PsiElement, String, IncompatibleVersionErrorData<?>> INCOMPATIBLE_CLASS = DiagnosticFactory2.create(ERROR);
@@ -360,7 +360,6 @@ public class DefaultErrorMessages {
MAP.put(MISSING_SCRIPT_BASE_CLASS, "Cannot access script base class ''{0}''. Check your module classpath for missing or conflicting dependencies", TO_STRING);
MAP.put(MISSING_SCRIPT_RECEIVER_CLASS, "Cannot access implicit script receiver class ''{0}''. Check your module classpath for missing or conflicting dependencies", TO_STRING);
MAP.put(MISSING_SCRIPT_ENVIRONMENT_PROPERTY_CLASS, "Cannot access script environment property class ''{0}''. Check your module classpath for missing or conflicting dependencies", TO_STRING);
MAP.put(INVALID_SCRIPT_TARGET_ANNOTATION_CLASS, "Cannot access script generated target annotation class ''{0}'': {1}. Check your module classpath for missing or conflicting dependencies", TO_STRING, TO_STRING);
MAP.put(PRE_RELEASE_CLASS, "{0} is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler", TO_STRING);
MAP.put(INCOMPATIBLE_CLASS,
"{0} was compiled with an incompatible version of Kotlin. {1}",
@@ -24,8 +24,6 @@ import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.constants.ConstantValueFactory
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.lazy.LazyClassContext
@@ -157,37 +155,13 @@ class LazyScriptDescriptor(
override fun getOuterScope(): LexicalScope = scriptOuterScope()
private val scriptClassAnnotations: () -> Annotations = resolveSession.storageManager.createLazyValue {
val baseAnnotations = baseClassDescriptor()?.annotations?.let { ann ->
baseClassDescriptor()?.annotations?.let { ann ->
FilteredAnnotations(ann) { fqname ->
val shortName = fqname.shortName().identifier
// TODO: consider more precise annotation filtering
!shortName.startsWith("KotlinScript") && !shortName.startsWith("ScriptTemplate")
}
} ?: super.annotations
val syntheticAnnotations =
scriptDefinition().targetClassAnnotations.mapNotNull { annInstance ->
try {
val annDescriptor = findTypeDescriptor(annInstance.annotationClass, null) ?: throw Exception("class not found")
val annArguments = HashMap<Name, ConstantValue<*>>()
for (arg in annInstance.annotationClass.java.declaredMethods) {
val argVal = ConstantValueFactory.createConstantValue(arg.invoke(annInstance))
?: throw Exception("Unsupported annotation argument: ${arg.name}")
annArguments[Name.identifier(arg.name)] = argVal
}
AnnotationDescriptorImpl(annDescriptor.defaultType, annArguments, source)
} catch (e: Throwable) {
resolveSession.trace.report(
Errors.INVALID_SCRIPT_TARGET_ANNOTATION_CLASS.on(
scriptInfo.script,
annInstance.toString(),
e.message ?: ""
)
)
null
}
}
if (syntheticAnnotations.isEmpty()) baseAnnotations
else CompositeAnnotations(baseAnnotations, AnnotationsImpl(syntheticAnnotations))
}
override val annotations: Annotations
@@ -96,14 +96,3 @@ annotation class MyScriptConstructorAnnotation
@MyScriptClassAnnotation()
abstract class TestScriptWithAnnotatedBaseClass @MyScriptConstructorAnnotation constructor()
object TestScriptWithMethodAnnotationsConfiguration : ArrayList<Pair<TypedKey<*>, Any?>>(
listOf(
ScriptCompileConfigurationProperties.generatedClassAnnotations to listOf()
)
)
@Suppress("unused")
@KotlinScript
@KotlinScriptDefaultCompilationConfiguration(TestScriptWithMethodAnnotationsConfiguration::class)
abstract class TestScriptWithMethodAnnotations