Pass KotlinBuiltIns into getExpectedTypePredicate utility
This commit is contained in:
@@ -69,10 +69,12 @@ fun getReceiverTypePredicate(resolvedCall: ResolvedCall<*>, receiverValue: Recei
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getExpectedTypePredicate(value: PseudoValue, bindingContext: BindingContext): TypePredicate {
|
public fun getExpectedTypePredicate(
|
||||||
|
value: PseudoValue,
|
||||||
|
bindingContext: BindingContext,
|
||||||
|
builtIns: KotlinBuiltIns
|
||||||
|
): TypePredicate {
|
||||||
val pseudocode = value.createdAt?.owner ?: return AllTypes
|
val pseudocode = value.createdAt?.owner ?: return AllTypes
|
||||||
val builtIns = KotlinBuiltIns.getInstance()
|
|
||||||
|
|
||||||
val typePredicates = LinkedHashSet<TypePredicate?>()
|
val typePredicates = LinkedHashSet<TypePredicate?>()
|
||||||
|
|
||||||
fun addSubtypesOf(jetType: JetType?) = typePredicates.add(jetType?.getSubtypesPredicate())
|
fun addSubtypesOf(jetType: JetType?) = typePredicates.add(jetType?.getSubtypesPredicate())
|
||||||
|
|||||||
@@ -16,15 +16,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.cfg
|
package org.jetbrains.kotlin.cfg
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue
|
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeImpl
|
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeImpl
|
||||||
|
import org.jetbrains.kotlin.cfg.pseudocode.TypePredicate
|
||||||
|
import org.jetbrains.kotlin.cfg.pseudocode.getExpectedTypePredicate
|
||||||
|
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.InstructionWithValue
|
||||||
import org.jetbrains.kotlin.psi.JetElement
|
import org.jetbrains.kotlin.psi.JetElement
|
||||||
import org.jetbrains.kotlin.psi.JetTreeVisitorVoid
|
import org.jetbrains.kotlin.psi.JetTreeVisitorVoid
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.TypePredicate
|
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.getExpectedTypePredicate
|
|
||||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.InstructionWithValue
|
|
||||||
|
|
||||||
public abstract class AbstractPseudoValueTest : AbstractPseudocodeTest() {
|
public abstract class AbstractPseudoValueTest : AbstractPseudocodeTest() {
|
||||||
override fun dumpInstructions(pseudocode: PseudocodeImpl, out: StringBuilder, bindingContext: BindingContext) {
|
override fun dumpInstructions(pseudocode: PseudocodeImpl, out: StringBuilder, bindingContext: BindingContext) {
|
||||||
@@ -49,7 +50,9 @@ public abstract class AbstractPseudoValueTest : AbstractPseudocodeTest() {
|
|||||||
element?.getText()?.replace("\\s+".toRegex(), " ") ?: ""
|
element?.getText()?.replace("\\s+".toRegex(), " ") ?: ""
|
||||||
|
|
||||||
fun valueDecl(value: PseudoValue): String {
|
fun valueDecl(value: PseudoValue): String {
|
||||||
val typePredicate = expectedTypePredicateMap.getOrPut(value) { getExpectedTypePredicate(value, bindingContext) }
|
val typePredicate = expectedTypePredicateMap.getOrPut(value) {
|
||||||
|
getExpectedTypePredicate(value, bindingContext, KotlinBuiltIns.getInstance())
|
||||||
|
}
|
||||||
return "${value.debugName}: $typePredicate"
|
return "${value.debugName}: $typePredicate"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -198,7 +198,7 @@ fun JetExpression.guessTypes(
|
|||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
pseudocode?.getElementValue(this)?.let {
|
pseudocode?.getElementValue(this)?.let {
|
||||||
getExpectedTypePredicate(it, context).getRepresentativeTypes().toTypedArray()
|
getExpectedTypePredicate(it, context, module.builtIns).getRepresentativeTypes().toTypedArray()
|
||||||
} ?: arrayOf() // can't infer anything
|
} ?: arrayOf() // can't infer anything
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -600,7 +600,7 @@ private fun ExtractionData.inferParametersInfo(
|
|||||||
commonParent: PsiElement,
|
commonParent: PsiElement,
|
||||||
pseudocode: Pseudocode,
|
pseudocode: Pseudocode,
|
||||||
bindingContext: BindingContext,
|
bindingContext: BindingContext,
|
||||||
targetScope: LexicalScope?,
|
targetScope: LexicalScope,
|
||||||
modifiedVarDescriptors: Set<VariableDescriptor>
|
modifiedVarDescriptors: Set<VariableDescriptor>
|
||||||
): ParametersInfo {
|
): ParametersInfo {
|
||||||
val info = ParametersInfo()
|
val info = ParametersInfo()
|
||||||
@@ -769,7 +769,7 @@ private fun ExtractionData.inferParametersInfo(
|
|||||||
val instruction = pseudocode.getElementValue(callElement)?.createdAt as? InstructionWithReceivers
|
val instruction = pseudocode.getElementValue(callElement)?.createdAt as? InstructionWithReceivers
|
||||||
val receiverValue = instruction?.receiverValues?.entrySet()?.singleOrNull { it.getValue() == receiverToExtract }?.getKey()
|
val receiverValue = instruction?.receiverValues?.entrySet()?.singleOrNull { it.getValue() == receiverToExtract }?.getKey()
|
||||||
if (receiverValue != null) {
|
if (receiverValue != null) {
|
||||||
parameter.addTypePredicate(getExpectedTypePredicate(receiverValue, bindingContext))
|
parameter.addTypePredicate(getExpectedTypePredicate(receiverValue, bindingContext, targetScope.ownerDescriptor.builtIns))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (extractFunctionRef) {
|
else if (extractFunctionRef) {
|
||||||
@@ -777,7 +777,7 @@ private fun ExtractionData.inferParametersInfo(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pseudocode.getElementValuesRecursively(originalRef).forEach {
|
pseudocode.getElementValuesRecursively(originalRef).forEach {
|
||||||
parameter.addTypePredicate(getExpectedTypePredicate(it, bindingContext))
|
parameter.addTypePredicate(getExpectedTypePredicate(it, bindingContext, targetScope.ownerDescriptor.builtIns))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user