Primitive support for LocalVariables for function parameters

This commit is contained in:
Denis Vnukov
2018-08-07 08:25:57 -07:00
committed by Mikhael Bogdanov
parent 1a56af9bb0
commit 65c79ecfe9
21 changed files with 293 additions and 26 deletions
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.utils.join
open class ValueParameterDescriptorImpl(
containingDeclaration: CallableDescriptor,
@@ -60,6 +61,16 @@ open class ValueParameterDescriptorImpl(
WithDestructuringDeclaration(containingDeclaration, original, index, annotations, name, outType,
declaresDefaultValue, isCrossinline, isNoinline, varargElementType, source,
destructuringVariables)
@JvmStatic
fun getNameForDestructuredParameterOrNull(valueParameterDescriptor: ValueParameterDescriptor): String? {
val variablesOrNull = ValueParameterDescriptorImpl.getDestructuringVariablesOrNull(valueParameterDescriptor)
return if (variablesOrNull == null) null else
"$" + join(
variablesOrNull.map { descriptor -> if (descriptor.name.isSpecial) "\$_\$" else descriptor.name.asString() },
"_"
)
}
}
class WithDestructuringDeclaration internal constructor(
@@ -81,6 +92,13 @@ open class ValueParameterDescriptorImpl(
// as value parameters.
// Must be forced via ForceResolveUtil.forceResolveAllContents()
val destructuringVariables by lazy(destructuringVariables)
override fun copy(newOwner: CallableDescriptor, newName: Name, newIndex: Int): ValueParameterDescriptor {
return WithDestructuringDeclaration(
newOwner, null, newIndex, annotations, newName, type, declaresDefaultValue(),
isCrossinline, isNoinline, varargElementType, SourceElement.NO_SOURCE
) { destructuringVariables }
}
}
private val original: ValueParameterDescriptor = original ?: this