Refine type arguments resolution and rendering

In case of type constructors captured parameters from outer classes

 #KT-5510 Fixed
 #KT-3112 Fixed
 #KT-6325 Fixed
 #KT-408  Fixed
 #KT-6337 Fixed
This commit is contained in:
Denis Zharkov
2015-11-03 14:28:34 +03:00
parent 990bd7e71d
commit deea0643ad
72 changed files with 1450 additions and 94 deletions
@@ -40,6 +40,7 @@ public enum class NoLookupLocation : LookupLocation {
FROM_REFLECTION,
WHEN_RESOLVE_DECLARATION,
WHEN_GET_DECLARATION_SCOPE,
WHEN_RESOLVING_DEFAULT_TYPE_ARGUMENTS,
FOR_ALREADY_TRACKED,
// TODO replace with real location (e.g. FROM_IDE) where it possible
WHEN_GET_ALL_DESCRIPTORS,
@@ -246,6 +246,15 @@ internal class DescriptorRendererImpl(
}.toString()
}
private fun renderTypeArgumentsForTypeConstructor(
type: KotlinType,
typeConstructor: TypeConstructor
): String {
return type.arguments.zip(type.constructor.parameters).filter {
(it.second.original.containingDeclaration as? ClassifierDescriptor)?.typeConstructor == typeConstructor
}.map { it.first }.let { renderTypeArguments(it) }
}
private fun renderDefaultType(type: KotlinType): String {
val sb = StringBuilder()
@@ -253,17 +262,43 @@ internal class DescriptorRendererImpl(
if (type.isError()) {
sb.append(type.getConstructor().toString()) // Debug name of an error type is more informative
sb.append(renderTypeArguments(type.getArguments()))
}
else {
sb.append(renderTypeConstructor(type.getConstructor()))
sb.append(renderTypeConstructorAndArguments(type))
}
sb.append(renderTypeArguments(type.getArguments()))
if (type.isMarkedNullable()) {
sb.append("?")
}
return sb.toString()
}
private fun renderTypeConstructorAndArguments(
type: KotlinType,
typeConstructor: TypeConstructor = type.constructor
): String =
StringBuilder().apply {
val classDescriptor = typeConstructor.declarationDescriptor as? ClassDescriptor
if (classDescriptor is MissingDependencyErrorClass) {
append(renderTypeConstructor(typeConstructor))
append(renderTypeArguments(type.arguments))
return@apply
}
if (classDescriptor != null && classDescriptor.isInner) {
append(renderTypeConstructorAndArguments(type, (classDescriptor.containingDeclaration as ClassDescriptor).typeConstructor))
append('.')
append(renderName(classDescriptor.name))
}
else {
append(renderTypeConstructor(typeConstructor))
}
append(renderTypeArgumentsForTypeConstructor(type, typeConstructor))
}.toString()
override fun renderTypeConstructor(typeConstructor: TypeConstructor): String {
val cd = typeConstructor.getDeclarationDescriptor()
return when (cd) {