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.
|
// 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
|
// 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,
|
type,
|
||||||
Nullability.NOT_NULL)
|
Nullability.NOT_NULL)
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ object DataFlowValueFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val result = getIdForStableIdentifier(expression, bindingContext, containingDeclarationOrModule)
|
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
|
@JvmStatic
|
||||||
@@ -138,7 +138,7 @@ object DataFlowValueFactory {
|
|||||||
private fun createDataFlowValueForComplexExpression(
|
private fun createDataFlowValueForComplexExpression(
|
||||||
expression: KtExpression,
|
expression: KtExpression,
|
||||||
type: KotlinType
|
type: KotlinType
|
||||||
) = DataFlowValue(ExpressionIdentifierInfo(expression, true), type)
|
) = DataFlowValue(ExpressionIdentifierInfo(expression, stableComplex = true), type)
|
||||||
|
|
||||||
private data class PostfixIdentifierInfo(val argumentInfo: IdentifierInfo) : IdentifierInfo {
|
private data class PostfixIdentifierInfo(val argumentInfo: IdentifierInfo) : IdentifierInfo {
|
||||||
override val kind: DataFlowValue.Kind get() = argumentInfo.kind
|
override val kind: DataFlowValue.Kind get() = argumentInfo.kind
|
||||||
@@ -146,9 +146,9 @@ object DataFlowValueFactory {
|
|||||||
override fun toString() = "$argumentInfo (postfix)"
|
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
|
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 toString() = "$kind $identifierInfo $immanentNullability"
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode() = type.hashCode() + 31 * identifierInfo.hashCode()
|
||||||
var result = identifierInfo.hashCode()
|
|
||||||
result = 31 * result + type.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
|||||||
+11
-15
@@ -49,11 +49,7 @@ interface IdentifierInfo {
|
|||||||
override fun equals(other: Any?) =
|
override fun equals(other: Any?) =
|
||||||
other is Variable && variable == other.variable && kind.isStable() == other.kind.isStable()
|
other is Variable && variable == other.variable && kind.isStable() == other.kind.isStable()
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode() = variable.hashCode() + 31 * (if (kind.isStable()) 1 else 0)
|
||||||
var result = if (kind.isStable()) 1 else 0
|
|
||||||
result = 31 * result + variable.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString() = variable.toString()
|
override fun toString() = variable.toString()
|
||||||
}
|
}
|
||||||
@@ -73,27 +69,27 @@ interface IdentifierInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Qualified(
|
class Qualified(
|
||||||
val receiverInfo: IdentifierInfo, val selectorInfo: IdentifierInfo,
|
val receiverInfo: IdentifierInfo,
|
||||||
val safe: Boolean, val receiverType: KotlinType?
|
val selectorInfo: IdentifierInfo,
|
||||||
|
val safe: Boolean,
|
||||||
|
val receiverType: KotlinType?
|
||||||
) : IdentifierInfo {
|
) : IdentifierInfo {
|
||||||
override val kind: DataFlowValue.Kind get() = if (receiverInfo.kind.isStable()) selectorInfo.kind else OTHER
|
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 equals(other: Any?) = other is Qualified && receiverInfo == other.receiverInfo && selectorInfo == other.selectorInfo
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode() = 31 * receiverInfo.hashCode() + selectorInfo.hashCode()
|
||||||
var result = receiverInfo.hashCode()
|
|
||||||
result = 31 * result + selectorInfo.hashCode()
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString() = "$receiverInfo(?).$selectorInfo"
|
override fun toString() = "$receiverInfo${if (safe) "?." else "."}$selectorInfo"
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun qualified(
|
fun qualified(
|
||||||
receiverInfo: IdentifierInfo, receiverType: KotlinType?,
|
receiverInfo: IdentifierInfo,
|
||||||
selectorInfo: IdentifierInfo, safe: Boolean
|
receiverType: KotlinType?,
|
||||||
|
selectorInfo: IdentifierInfo,
|
||||||
|
safe: Boolean
|
||||||
) = when (receiverInfo) {
|
) = when (receiverInfo) {
|
||||||
NO -> NO
|
NO -> NO
|
||||||
is PackageOrClass -> selectorInfo
|
is PackageOrClass -> selectorInfo
|
||||||
|
|||||||
Reference in New Issue
Block a user