Implement SamWithReceiverAnnotations annotation and it's handling (KT-15848)

TODO: tests
This commit is contained in:
Ilya Chernikov
2017-01-24 18:45:04 +01:00
parent f1c4230a68
commit 4bb5e978a7
7 changed files with 159 additions and 3 deletions
@@ -63,6 +63,10 @@ open class KotlinScriptDefinitionFromAnnotatedTemplate(
}
}
val samWithReceiverAnnotations: List<String>? by lazy {
template.annotations.firstIsInstanceOrNull<SamWithReceiverAnnotations>()?.annotations?.toList()
}
private val acceptedAnnotations: List<KClass<out Annotation>> by lazy {
val resolveMethod = ScriptDependenciesResolver::resolve
val resolverMethodAnnotations =
@@ -146,9 +150,10 @@ open class KotlinScriptDefinitionFromAnnotatedTemplate(
override val text: CharSequence? by lazy { getFileContents(myFile) }
}
override fun toString(): String {
return "KotlinScriptDefinitionFromAnnotatedTemplate - ${template.simpleName}"
}
override fun toString(): String = "KotlinScriptDefinitionFromAnnotatedTemplate - ${template.simpleName}"
override val annotationsForSamWithReceivers: List<String>
get() = samWithReceiverAnnotations ?: super.annotationsForSamWithReceivers
companion object {
internal val log = Logger.getInstance(KotlinScriptDefinitionFromAnnotatedTemplate::class.java)
@@ -30,6 +30,10 @@ const val DEFAULT_SCRIPT_FILE_PATTERN = ".*\\.kts"
annotation class ScriptTemplateDefinition(val resolver: KClass<out ScriptDependenciesResolver> = BasicScriptDependenciesResolver::class,
val scriptFilePattern: String = DEFAULT_SCRIPT_FILE_PATTERN)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class SamWithReceiverAnnotations(vararg val annotations: String)
interface ScriptContents {
data class Position(val line: Int, val col: Int)