Refactoring. Remove type capability Flexibility.
This commit is contained in:
@@ -39,7 +39,7 @@ fun KotlinType.approximateFlexibleTypes(preferNotNull: Boolean = false): KotlinT
|
||||
|
||||
private fun KotlinType.approximateNonDynamicFlexibleTypes(preferNotNull: Boolean = false): SimpleType {
|
||||
if (isFlexible()) {
|
||||
val flexible = flexibility()
|
||||
val flexible = asFlexibleType()
|
||||
val lowerClass = flexible.lowerBound.constructor.declarationDescriptor as? ClassDescriptor?
|
||||
val isCollection = lowerClass != null && JavaToKotlinClassMap.INSTANCE.isMutable(lowerClass)
|
||||
// (Mutable)Collection<T>! -> MutableCollection<T>?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,9 +23,10 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.Flexibility
|
||||
import org.jetbrains.kotlin.types.FlexibleType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.unwrap
|
||||
|
||||
fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?> {
|
||||
val literalParent = (this.parent as KtLambdaExpression).parent
|
||||
@@ -77,11 +78,11 @@ private fun chooseMoreSpecific(type1: KotlinType, type2: KotlinType): KotlinType
|
||||
!type1IsSubtype && !type2IsSubtype -> return null
|
||||
|
||||
else -> { // type1IsSubtype && type2IsSubtype
|
||||
val flexibility1 = type1.getCapability(Flexibility::class.java)
|
||||
val flexibility2 = type2.getCapability(Flexibility::class.java)
|
||||
val flexible1 = type1.unwrap() as? FlexibleType
|
||||
val flexible2 = type2.unwrap() as? FlexibleType
|
||||
when {
|
||||
flexibility1 != null && flexibility2 == null -> return type2
|
||||
flexibility2 != null && flexibility1 == null -> return type1
|
||||
flexible1 != null && flexible2 == null -> return type2
|
||||
flexible2 != null && flexible1 == null -> return type1
|
||||
else -> return null //TODO?
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.idea.decompiler.textBuilder.defaultDecompilerRendere
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.types.flexibility
|
||||
import org.jetbrains.kotlin.types.asFlexibleType
|
||||
import org.jetbrains.kotlin.types.isFlexible
|
||||
|
||||
class KotlinClassFileDecompiler : ClassFileDecompilers.Full() {
|
||||
@@ -63,7 +63,7 @@ class KtClsFile(provider: KotlinDecompiledFileViewProvider) : KtDecompiledFile(p
|
||||
|
||||
private val decompilerRendererForClassFiles = DescriptorRenderer.withOptions {
|
||||
defaultDecompilerRendererOptions()
|
||||
typeNormalizer = { type -> if (type.isFlexible()) type.flexibility().lowerBound else type }
|
||||
typeNormalizer = { type -> if (type.isFlexible()) type.asFlexibleType().lowerBound else type }
|
||||
}
|
||||
|
||||
fun buildDecompiledTextForClassFile(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.flexibility
|
||||
import org.jetbrains.kotlin.types.asFlexibleType
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
|
||||
class CastExpressionFix(element: KtExpression, type: KotlinType) : KotlinQuickFixAction<KtExpression>(element) {
|
||||
@@ -65,7 +65,7 @@ class CastExpressionFix(element: KtExpression, type: KotlinType) : KotlinQuickFi
|
||||
|
||||
object GenericVarianceConversion : Factory() {
|
||||
override fun extractFixData(element: KtExpression, diagnostic: Diagnostic): KotlinType? {
|
||||
return ErrorsJvm.JAVA_TYPE_MISMATCH.cast(diagnostic).b.flexibility().upperBound
|
||||
return ErrorsJvm.JAVA_TYPE_MISMATCH.cast(diagnostic).b.asFlexibleType().upperBound
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -334,7 +334,7 @@ val ControlFlow.possibleReturnTypes: List<KotlinType>
|
||||
returnType.isAnnotatedNotNull() || returnType.isAnnotatedNullable() ->
|
||||
listOf(returnType.approximateFlexibleTypes())
|
||||
else ->
|
||||
returnType.getCapability(Flexibility::class.java).let { listOf(it!!.upperBound, it.lowerBound) }
|
||||
(returnType.unwrap() as FlexibleType).let { listOf(it.upperBound, it.lowerBound) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -518,7 +518,7 @@ internal class MutableParameter(
|
||||
val typePredicate = and(typePredicates)
|
||||
|
||||
val typeSet = if (defaultType.isFlexible()) {
|
||||
val bounds = defaultType.getCapability(Flexibility::class.java)!!
|
||||
val bounds = defaultType.asFlexibleType()
|
||||
LinkedHashSet<KotlinType>().apply {
|
||||
if (typePredicate(bounds.upperBound)) add(bounds.upperBound)
|
||||
if (typePredicate(bounds.lowerBound)) add(bounds.lowerBound)
|
||||
|
||||
Reference in New Issue
Block a user