Minor improvements in DataFlowValue / IdentifierInfo
This commit is contained in:
+5
-5
@@ -89,7 +89,7 @@ object DataFlowValueFactory {
|
||||
//
|
||||
// But there are some problem with types built on type parameters, e.g.
|
||||
// fun <T : Any?> foo(x: T) = x!!.hashCode() // there no way in type system to denote that `x!!` is not nullable
|
||||
return DataFlowValue(ExpressionIdentifierInfo(expression, false),
|
||||
return DataFlowValue(ExpressionIdentifierInfo(expression),
|
||||
type,
|
||||
Nullability.NOT_NULL)
|
||||
}
|
||||
@@ -99,7 +99,7 @@ object DataFlowValueFactory {
|
||||
}
|
||||
|
||||
val result = getIdForStableIdentifier(expression, bindingContext, containingDeclarationOrModule)
|
||||
return DataFlowValue(if (result === IdentifierInfo.NO) ExpressionIdentifierInfo(expression, false) else result, type)
|
||||
return DataFlowValue(if (result === IdentifierInfo.NO) ExpressionIdentifierInfo(expression) else result, type)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -138,7 +138,7 @@ object DataFlowValueFactory {
|
||||
private fun createDataFlowValueForComplexExpression(
|
||||
expression: KtExpression,
|
||||
type: KotlinType
|
||||
) = DataFlowValue(ExpressionIdentifierInfo(expression, true), type)
|
||||
) = DataFlowValue(ExpressionIdentifierInfo(expression, stableComplex = true), type)
|
||||
|
||||
private data class PostfixIdentifierInfo(val argumentInfo: IdentifierInfo) : IdentifierInfo {
|
||||
override val kind: DataFlowValue.Kind get() = argumentInfo.kind
|
||||
@@ -146,9 +146,9 @@ object DataFlowValueFactory {
|
||||
override fun toString() = "$argumentInfo (postfix)"
|
||||
}
|
||||
|
||||
class ExpressionIdentifierInfo(val expression: KtExpression, isComplex: Boolean) : IdentifierInfo {
|
||||
class ExpressionIdentifierInfo(val expression: KtExpression, stableComplex: Boolean = false) : IdentifierInfo {
|
||||
|
||||
override val kind = if (isComplex) STABLE_COMPLEX_EXPRESSION else OTHER
|
||||
override val kind = if (stableComplex) STABLE_COMPLEX_EXPRESSION else OTHER
|
||||
|
||||
override fun equals(other: Any?) = other is ExpressionIdentifierInfo && expression == other.expression
|
||||
|
||||
|
||||
+1
-5
@@ -85,11 +85,7 @@ class DataFlowValue(val identifierInfo: IdentifierInfo,
|
||||
|
||||
override fun toString() = "$kind $identifierInfo $immanentNullability"
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = identifierInfo.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
override fun hashCode() = type.hashCode() + 31 * identifierInfo.hashCode()
|
||||
|
||||
companion object {
|
||||
|
||||
|
||||
+11
-15
@@ -49,11 +49,7 @@ interface IdentifierInfo {
|
||||
override fun equals(other: Any?) =
|
||||
other is Variable && variable == other.variable && kind.isStable() == other.kind.isStable()
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = if (kind.isStable()) 1 else 0
|
||||
result = 31 * result + variable.hashCode()
|
||||
return result
|
||||
}
|
||||
override fun hashCode() = variable.hashCode() + 31 * (if (kind.isStable()) 1 else 0)
|
||||
|
||||
override fun toString() = variable.toString()
|
||||
}
|
||||
@@ -73,27 +69,27 @@ interface IdentifierInfo {
|
||||
}
|
||||
|
||||
class Qualified(
|
||||
val receiverInfo: IdentifierInfo, val selectorInfo: IdentifierInfo,
|
||||
val safe: Boolean, val receiverType: KotlinType?
|
||||
val receiverInfo: IdentifierInfo,
|
||||
val selectorInfo: IdentifierInfo,
|
||||
val safe: Boolean,
|
||||
val receiverType: KotlinType?
|
||||
) : IdentifierInfo {
|
||||
override val kind: DataFlowValue.Kind get() = if (receiverInfo.kind.isStable()) selectorInfo.kind else OTHER
|
||||
|
||||
override fun equals(other: Any?) = other is Qualified && receiverInfo == other.receiverInfo && selectorInfo == other.selectorInfo
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = receiverInfo.hashCode()
|
||||
result = 31 * result + selectorInfo.hashCode()
|
||||
return result
|
||||
}
|
||||
override fun hashCode() = 31 * receiverInfo.hashCode() + selectorInfo.hashCode()
|
||||
|
||||
override fun toString() = "$receiverInfo(?).$selectorInfo"
|
||||
override fun toString() = "$receiverInfo${if (safe) "?." else "."}$selectorInfo"
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun qualified(
|
||||
receiverInfo: IdentifierInfo, receiverType: KotlinType?,
|
||||
selectorInfo: IdentifierInfo, safe: Boolean
|
||||
receiverInfo: IdentifierInfo,
|
||||
receiverType: KotlinType?,
|
||||
selectorInfo: IdentifierInfo,
|
||||
safe: Boolean
|
||||
) = when (receiverInfo) {
|
||||
NO -> NO
|
||||
is PackageOrClass -> selectorInfo
|
||||
|
||||
Reference in New Issue
Block a user