Renames + parameter to receiver

This commit is contained in:
Valentin Kipyatkov
2016-03-29 21:29:26 +03:00
parent 1f39511950
commit 40e69318b8
7 changed files with 23 additions and 25 deletions
@@ -16,18 +16,18 @@
package org.jetbrains.kotlin.idea.util
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.isDynamic
import org.jetbrains.kotlin.types.typeUtil.builtIns
object IdeDescriptorRenderers {
@JvmField val APPROXIMATE_FLEXIBLE_TYPES: (KotlinType) -> KotlinType = { approximateFlexibleTypes(it, true) }
@JvmField val APPROXIMATE_FLEXIBLE_TYPES: (KotlinType) -> KotlinType = { it.approximateFlexibleTypes(preferNotNull = false) }
@JvmField val APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS: (KotlinType) -> KotlinType = { approximateFlexibleTypes(it, false) }
@JvmField val APPROXIMATE_FLEXIBLE_TYPES_NOT_NULL: (KotlinType) -> KotlinType = { it.approximateFlexibleTypes(preferNotNull = true) }
private fun unwrapAnonymousType(type: KotlinType): KotlinType {
if (type.isDynamic()) return type
@@ -58,9 +58,9 @@ object IdeDescriptorRenderers {
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
}
@JvmField val SOURCE_CODE_FOR_TYPE_ARGUMENTS: DescriptorRenderer = BASE.withOptions {
@JvmField val SOURCE_CODE_NOT_NULL_TYPE_APPROXIMATION: DescriptorRenderer = BASE.withOptions {
classifierNamePolicy = ClassifierNamePolicy.SOURCE_CODE_QUALIFIED
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS(unwrapAnonymousType(it)) }
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES_NOT_NULL(unwrapAnonymousType(it)) }
}
@JvmField val SOURCE_CODE_SHORT_NAMES_IN_TYPES: DescriptorRenderer = BASE.withOptions {
@@ -22,9 +22,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_NULLABLE_ANNOTATION
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -34,10 +32,10 @@ import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.*
fun approximateFlexibleTypes(jetType: KotlinType, outermost: Boolean = true): KotlinType {
if (jetType.isDynamic()) return jetType
if (jetType.isFlexible()) {
val flexible = jetType.flexibility()
fun KotlinType.approximateFlexibleTypes(preferNotNull: Boolean = false): KotlinType {
if (isDynamic()) return this
if (isFlexible()) {
val flexible = flexibility()
val lowerClass = flexible.lowerBound.constructor.declarationDescriptor as? ClassDescriptor?
val isCollection = lowerClass != null && JavaToKotlinClassMap.INSTANCE.isMutable(lowerClass)
// (Mutable)Collection<T>! -> MutableCollection<T>?
@@ -46,13 +44,13 @@ fun approximateFlexibleTypes(jetType: KotlinType, outermost: Boolean = true): Ko
// Foo<Bar!>! -> Foo<Bar>?
var approximation =
if (isCollection)
TypeUtils.makeNullableAsSpecified(if (jetType.isAnnotatedReadOnly()) flexible.upperBound else flexible.lowerBound, outermost)
TypeUtils.makeNullableAsSpecified(if (isAnnotatedReadOnly()) flexible.upperBound else flexible.lowerBound, !preferNotNull)
else
if (outermost) flexible.upperBound else flexible.lowerBound
if (preferNotNull) flexible.lowerBound else flexible.upperBound
approximation = approximateFlexibleTypes(approximation)
approximation = approximation.approximateFlexibleTypes()
approximation = if (jetType.isAnnotatedNotNull()) approximation.makeNotNullable() else approximation
approximation = if (isAnnotatedNotNull()) approximation.makeNotNullable() else approximation
if (approximation.isMarkedNullable && !flexible.lowerBound.isMarkedNullable && TypeUtils.isTypeParameter(approximation) && TypeUtils.hasNullableSuperType(approximation)) {
approximation = approximation.makeNotNullable()
@@ -61,10 +59,10 @@ fun approximateFlexibleTypes(jetType: KotlinType, outermost: Boolean = true): Ko
return approximation
}
return KotlinTypeImpl.create(
jetType.annotations,
jetType.constructor,
jetType.isMarkedNullable,
jetType.arguments.map { it.substitute { type -> approximateFlexibleTypes(type, false)} },
annotations,
constructor,
isMarkedNullable,
arguments.map { it.substitute { type -> type.approximateFlexibleTypes(preferNotNull = true) } },
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
)
}