Callable Builder: Allow to forbid substitution for any TypeInfo
This commit is contained in:
+1
-1
@@ -158,7 +158,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
typeInfo: TypeInfo,
|
||||
substitutions: List<JetTypeSubstitution>,
|
||||
scope: JetScope): List<TypeCandidate> {
|
||||
if (typeInfo is TypeInfo.ByType && typeInfo.keepUnsubstituted) return computeTypeCandidates(typeInfo)
|
||||
if (!typeInfo.substitutionsAllowed) return computeTypeCandidates(typeInfo)
|
||||
return typeCandidates.getOrPut(typeInfo) {
|
||||
val types = typeInfo.getPossibleTypes(this).reverse()
|
||||
|
||||
|
||||
+14
-2
@@ -10,7 +10,6 @@ import org.jetbrains.jet.plugin.refactoring.JetNameSuggester
|
||||
import org.jetbrains.jet.plugin.refactoring.EmptyValidator
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.plugin.util.supertypes
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
@@ -38,7 +37,7 @@ abstract class TypeInfo(val variance: Variance) {
|
||||
builder.currentFileContext[BindingContext.TYPE, typeReference].getPossibleSupertypes(variance)
|
||||
}
|
||||
|
||||
class ByType(val theType: JetType, variance: Variance, val keepUnsubstituted: Boolean = false): TypeInfo(variance) {
|
||||
class ByType(val theType: JetType, variance: Variance): TypeInfo(variance) {
|
||||
override fun getPossibleTypes(builder: CallableBuilder): List<JetType> =
|
||||
theType.getPossibleSupertypes(variance)
|
||||
}
|
||||
@@ -48,6 +47,17 @@ abstract class TypeInfo(val variance: Variance) {
|
||||
(builder.placement as CallablePlacement.WithReceiver).receiverTypeCandidate.theType.getPossibleSupertypes(variance)
|
||||
}
|
||||
|
||||
abstract class DelegatingTypeInfo(val delegate: TypeInfo): TypeInfo(delegate.variance) {
|
||||
override val substitutionsAllowed: Boolean = delegate.substitutionsAllowed
|
||||
override val possibleNamesFromExpression: Array<String> get() = delegate.possibleNamesFromExpression
|
||||
override fun getPossibleTypes(builder: CallableBuilder): List<JetType> = delegate.getPossibleTypes(builder)
|
||||
}
|
||||
|
||||
class NoSubstitutions(delegate: TypeInfo): DelegatingTypeInfo(delegate) {
|
||||
override val substitutionsAllowed: Boolean = false
|
||||
}
|
||||
|
||||
open val substitutionsAllowed: Boolean = true
|
||||
open val possibleNamesFromExpression: Array<String> get() = ArrayUtil.EMPTY_STRING_ARRAY
|
||||
abstract fun getPossibleTypes(builder: CallableBuilder): List<JetType>
|
||||
|
||||
@@ -65,6 +75,8 @@ fun TypeInfo(expressionOfType: JetExpression, variance: Variance): TypeInfo = Ty
|
||||
fun TypeInfo(typeReference: JetTypeReference, variance: Variance): TypeInfo = TypeInfo.ByTypeReference(typeReference, variance)
|
||||
fun TypeInfo(theType: JetType, variance: Variance): TypeInfo = TypeInfo.ByType(theType, variance)
|
||||
|
||||
fun TypeInfo.noSubstitutions(): TypeInfo = (this as? TypeInfo.NoSubstitutions) ?: TypeInfo.NoSubstitutions(this)
|
||||
|
||||
/**
|
||||
* Encapsulates information about a function parameter that is going to be created.
|
||||
*/
|
||||
|
||||
+2
-2
@@ -33,8 +33,8 @@ public object CreateBinaryOperationActionFactory: JetSingleIntentionActionFactor
|
||||
|
||||
val receiverType = TypeInfo(receiverExpr, Variance.IN_VARIANCE)
|
||||
val returnType = when {
|
||||
inOperation -> TypeInfo.ByType(builtIns.getBooleanType(), Variance.INVARIANT, true)
|
||||
comparisonOperation -> TypeInfo.ByType(builtIns.getIntType(), Variance.INVARIANT, true)
|
||||
inOperation -> TypeInfo.ByType(builtIns.getBooleanType(), Variance.INVARIANT).noSubstitutions()
|
||||
comparisonOperation -> TypeInfo.ByType(builtIns.getIntType(), Variance.INVARIANT).noSubstitutions()
|
||||
else -> TypeInfo(callExpr, Variance.OUT_VARIANCE)
|
||||
}
|
||||
val parameters = Collections.singletonList(ParameterInfo(TypeInfo(argumentExpr, Variance.IN_VARIANCE)))
|
||||
|
||||
Reference in New Issue
Block a user