From f39c6f3b7a32a575372e29afc924872d8a1e45b7 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Tue, 3 Jul 2018 16:14:07 +0200 Subject: [PATCH] Drop half-backed support of "dynamic" annotations on scripts... leaving it in the history so it could be restored and finished, if needed --- .../jetbrains/kotlin/diagnostics/Errors.java | 1 - .../rendering/DefaultErrorMessages.java | 1 - .../lazy/descriptors/LazyScriptDescriptor.kt | 28 +------------------ .../kotlin/codegen/CustomScriptCodegenTest.kt | 11 -------- 4 files changed, 1 insertion(+), 40 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index bec7aeefd4d..908084707e2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -101,7 +101,6 @@ public interface Errors { DiagnosticFactory1 MISSING_SCRIPT_BASE_CLASS = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 MISSING_SCRIPT_RECEIVER_CLASS = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 MISSING_SCRIPT_ENVIRONMENT_PROPERTY_CLASS = DiagnosticFactory1.create(ERROR); - DiagnosticFactory2 INVALID_SCRIPT_TARGET_ANNOTATION_CLASS = DiagnosticFactory2.create(ERROR); DiagnosticFactory1 PRE_RELEASE_CLASS = DiagnosticFactory1.create(ERROR); DiagnosticFactory2> INCOMPATIBLE_CLASS = DiagnosticFactory2.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index ce541425af5..58e02b173a6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -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}", diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptDescriptor.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptDescriptor.kt index 58e2adf47e6..01aebe33a6d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptDescriptor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptDescriptor.kt @@ -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>() - 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 diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt b/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt index 886ce605ccc..151361d0ff7 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CustomScriptCodegenTest.kt @@ -96,14 +96,3 @@ annotation class MyScriptConstructorAnnotation @MyScriptClassAnnotation() abstract class TestScriptWithAnnotatedBaseClass @MyScriptConstructorAnnotation constructor() -object TestScriptWithMethodAnnotationsConfiguration : ArrayList, Any?>>( - listOf( - ScriptCompileConfigurationProperties.generatedClassAnnotations to listOf() - ) -) - -@Suppress("unused") -@KotlinScript -@KotlinScriptDefaultCompilationConfiguration(TestScriptWithMethodAnnotationsConfiguration::class) -abstract class TestScriptWithMethodAnnotations -