Refactor script definition and related parts:

- simplify script definition interface, convert it to class
 - create simple definitions right from base
 - refactor (rename and simplify) script definition with annotated template
 - simplify usages of script definition in many places
This commit is contained in:
Ilya Chernikov
2016-09-20 23:34:14 +02:00
parent 6bc488d95d
commit fe69185cd4
24 changed files with 290 additions and 358 deletions
@@ -16,12 +16,7 @@
package org.jetbrains.kotlin.descriptors;
import kotlin.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.types.KotlinType;
import java.util.List;
public interface ScriptDescriptor extends ClassDescriptor {
int getPriority();
@@ -29,6 +24,4 @@ public interface ScriptDescriptor extends ClassDescriptor {
@NotNull
@Override
ClassConstructorDescriptor getUnsubstitutedPrimaryConstructor();
List<Pair<Name, KotlinType>> getScriptParametersToPassToSuperclass();
}
@@ -255,20 +255,6 @@ fun <D : CallableDescriptor> D.overriddenTreeUniqueAsSequence(useOriginal: Boole
return doBuildOverriddenTreeAsSequence()
}
fun ClassDescriptor.getConstructorByParams(params: List<KotlinType>): ConstructorDescriptor? =
getConstructors().firstOrNull {
when {
it.valueParameters.isEmpty() && params.isEmpty() -> true
it.valueParameters.size != params.size -> false
else -> it.valueParameters.zip(params) { ctorP, p -> ctorP.type == p }.all { it }
}
}
// TODO: inline and remove as soon as all usage sies are converted to kotlin
fun getConstructorByParamsMap(classDescriptor: ClassDescriptor, params: List<Pair<Name, KotlinType>>): ConstructorDescriptor? =
classDescriptor.getConstructorByParams(params.map { it.second })
fun CallableDescriptor.varargParameterPosition() =
valueParameters.indexOfFirst { it.varargElementType != null }