Data flow values: STABLE_COMPLEX_EXPRESSION kind is removed, no use cases exist for them

This commit is contained in:
Mikhail Glukhikh
2016-07-25 11:24:02 +03:00
parent c7af3f7865
commit 1c9f08e986
2 changed files with 3 additions and 29 deletions
@@ -57,16 +57,6 @@ object DataFlowValueFactory {
resolutionContext: ResolutionContext<*>
) = createDataFlowValue(expression, type, resolutionContext.trace.bindingContext, resolutionContext.scope.ownerDescriptor)
private fun isComplexExpression(expression: KtExpression): Boolean = when(expression) {
is KtBlockExpression, is KtIfExpression, is KtWhenExpression -> true
is KtBinaryExpression -> expression.operationToken === KtTokens.ELVIS
is KtParenthesizedExpression -> {
val deparenthesized = KtPsiUtil.deparenthesize(expression)
deparenthesized != null && isComplexExpression(deparenthesized)
}
else -> false
}
@JvmStatic
fun createDataFlowValue(
expression: KtExpression,
@@ -95,10 +85,6 @@ object DataFlowValueFactory {
Nullability.NOT_NULL)
}
if (isComplexExpression(expression)) {
return createDataFlowValueForComplexExpression(expression, type)
}
val result = getIdForStableIdentifier(expression, bindingContext, containingDeclarationOrModule)
return DataFlowValue(if (result === IdentifierInfo.NO) ExpressionIdentifierInfo(expression) else result, type)
}
@@ -136,11 +122,6 @@ object DataFlowValueFactory {
variableKind(variableDescriptor, usageContainingModule, bindingContext, property)),
variableDescriptor.type)
private fun createDataFlowValueForComplexExpression(
expression: KtExpression,
type: KotlinType
) = DataFlowValue(ExpressionIdentifierInfo(expression, stableComplex = true), type)
// For only ++ and -- postfix operations
private data class PostfixIdentifierInfo(val argumentInfo: IdentifierInfo, val op: KtToken) : IdentifierInfo {
override val kind: DataFlowValue.Kind get() = argumentInfo.kind
@@ -148,13 +129,8 @@ object DataFlowValueFactory {
override fun toString() = "$argumentInfo($op)"
}
class ExpressionIdentifierInfo(val expression: KtExpression, stableComplex: Boolean = false) : IdentifierInfo {
override val kind = if (stableComplex) STABLE_COMPLEX_EXPRESSION else OTHER
override fun equals(other: Any?) = other is ExpressionIdentifierInfo && expression == other.expression
override fun hashCode() = expression.hashCode()
data class ExpressionIdentifierInfo(val expression: KtExpression) : IdentifierInfo {
override val kind = OTHER
override fun toString() = expression.text ?: "(empty expression)"
}
@@ -39,8 +39,6 @@ class DataFlowValue(val identifierInfo: IdentifierInfo,
// or protected / public member value from the same module without open / custom getter
// Smart casts are completely safe
STABLE_VALUE("stable"),
// Block, or if / else, or when, or (in future) some other complex expression
STABLE_COMPLEX_EXPRESSION("complex expression", ""),
// Member value with open / custom getter
// Smart casts are not safe
PROPERTY_WITH_GETTER("custom getter", "property that has open or custom getter"),
@@ -70,7 +68,7 @@ class DataFlowValue(val identifierInfo: IdentifierInfo,
* Predictable means here we do not expect some sudden change of their values,
* like accessing mutable properties in another thread, so smart casts can be used safely.
*/
val isPredictable = (kind == Kind.STABLE_VALUE || kind == Kind.STABLE_COMPLEX_EXPRESSION || kind == Kind.PREDICTABLE_VARIABLE)
val isPredictable = (kind == Kind.STABLE_VALUE || kind == Kind.PREDICTABLE_VARIABLE)
@JvmName("isPredictable") get
override fun equals(other: Any?): Boolean {