diff --git a/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt b/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt index 4c1e951998f..518567200ee 100644 --- a/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt +++ b/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt @@ -122,8 +122,8 @@ class PartialBodyResolveFilter( map.getOrPut(name, { ArrayList(places.size) }).addAll(places) } - fun addIfCanBeSmartCasted(expression: JetExpression) { - val name = expression.smartCastedExpressionName() ?: return + fun addIfCanBeSmartCast(expression: JetExpression) { + val name = expression.smartCastExpressionName() ?: return if (filter(name)) { addPlace(name, expression) } @@ -134,7 +134,7 @@ class PartialBodyResolveFilter( expression.acceptChildren(this) if (expression.getOperationToken() == JetTokens.EXCLEXCL) { - addIfCanBeSmartCasted(expression.getBaseExpression()) + addIfCanBeSmartCast(expression.getBaseExpression()) } } @@ -142,7 +142,7 @@ class PartialBodyResolveFilter( expression.acceptChildren(this) if (expression.getOperationReference()?.getReferencedNameElementType() == JetTokens.AS_KEYWORD) { - addIfCanBeSmartCasted(expression.getLeft()) + addIfCanBeSmartCast(expression.getLeft()) } } @@ -151,11 +151,11 @@ class PartialBodyResolveFilter( val thenBranch = expression.getThen() val elseBranch = expression.getElse() - val smartCastedNames = collectPossiblySmartCastedInCondition(condition).filter(filter) - if (smartCastedNames.isNotEmpty()) { + val smartCastNames = collectPossiblySmartCastInCondition(condition).filter(filter) + if (smartCastNames.isNotEmpty()) { val exits = collectAlwaysExitPoints(thenBranch) + collectAlwaysExitPoints(elseBranch) if (exits.isNotEmpty()) { - for (name in smartCastedNames) { + for (name in smartCastNames) { addPlaces(name, exits) } } @@ -204,7 +204,7 @@ class PartialBodyResolveFilter( return map } - private fun collectPossiblySmartCastedInCondition(condition: JetExpression?): Set { + private fun collectPossiblySmartCastInCondition(condition: JetExpression?): Set { val result = HashSet() condition?.accept(object : ControlFlowVisitor() { override fun visitBinaryExpression(expression: JetBinaryExpression) { @@ -212,15 +212,15 @@ class PartialBodyResolveFilter( val operation = expression.getOperationToken() if (operation == JetTokens.EQEQ || operation == JetTokens.EXCLEQ) { - result.addIfNotNull(expression.getLeft()?.smartCastedExpressionName()) - result.addIfNotNull(expression.getRight()?.smartCastedExpressionName()) + result.addIfNotNull(expression.getLeft()?.smartCastExpressionName()) + result.addIfNotNull(expression.getRight()?.smartCastExpressionName()) } } override fun visitIsExpression(expression: JetIsExpression) { expression.acceptChildren(this) - result.addIfNotNull(expression.getLeftHandSide()?.smartCastedExpressionName()) + result.addIfNotNull(expression.getLeftHandSide()?.smartCastExpressionName()) } }) return result @@ -342,15 +342,15 @@ class PartialBodyResolveFilter( private fun PsiElement.isStatement() = this is JetExpression && getParent() is JetBlockExpression - private fun JetExpression.smartCastedExpressionName(): String? { + private fun JetExpression.smartCastExpressionName(): String? { return when (this) { is JetSimpleNameExpression -> this.getReferencedName() is JetQualifiedExpression -> { - val selectorName = getSelectorExpression().smartCastedExpressionName() ?: return null + val selectorName = getSelectorExpression().smartCastExpressionName() ?: return null val receiver = getReceiverExpression() if (receiver is JetThisExpression) return selectorName - val receiverName = receiver.smartCastedExpressionName() ?: return null + val receiverName = receiver.smartCastExpressionName() ?: return null return selectorName + "." + receiverName } diff --git a/idea/testData/resolve/partialBodyResolve/As.dump b/idea/testData/resolve/partialBodyResolve/As.dump index 73ef7de224b..fdd812621c6 100644 --- a/idea/testData/resolve/partialBodyResolve/As.dump +++ b/idea/testData/resolve/partialBodyResolve/As.dump @@ -1,4 +1,4 @@ -Resolve target: value-parameter val p: kotlin.Any smart-casted to kotlin.String +Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String Skipped statements: y(p as? Int) z(f() as String) diff --git a/idea/testData/resolve/partialBodyResolve/BangBang.dump b/idea/testData/resolve/partialBodyResolve/BangBang.dump index 162a996d387..b2c613dec24 100644 --- a/idea/testData/resolve/partialBodyResolve/BangBang.dump +++ b/idea/testData/resolve/partialBodyResolve/BangBang.dump @@ -1,4 +1,4 @@ -Resolve target: value-parameter val p: kotlin.String? smart-casted to kotlin.String +Resolve target: value-parameter val p: kotlin.String? smart-cast to kotlin.String Skipped statements: y(f()!!) p1!! diff --git a/idea/testData/resolve/partialBodyResolve/BangBangInIfCondition.dump b/idea/testData/resolve/partialBodyResolve/BangBangInIfCondition.dump index 514abfa40ed..6c209b341c8 100644 --- a/idea/testData/resolve/partialBodyResolve/BangBangInIfCondition.dump +++ b/idea/testData/resolve/partialBodyResolve/BangBangInIfCondition.dump @@ -1,3 +1,3 @@ -Resolve target: value-parameter val p: kotlin.Boolean? smart-casted to kotlin.Boolean +Resolve target: value-parameter val p: kotlin.Boolean? smart-cast to kotlin.Boolean Skipped statements: print(p1!!.hashCode()) diff --git a/idea/testData/resolve/partialBodyResolve/For.dump b/idea/testData/resolve/partialBodyResolve/For.dump index 00e04717322..99904c51d02 100644 --- a/idea/testData/resolve/partialBodyResolve/For.dump +++ b/idea/testData/resolve/partialBodyResolve/For.dump @@ -1,3 +1,3 @@ -Resolve target: value-parameter val p: kotlin.Any? smart-casted to kotlin.String +Resolve target: value-parameter val p: kotlin.Any? smart-cast to kotlin.String Skipped statements: print(p1!!) diff --git a/idea/testData/resolve/partialBodyResolve/IfBranchesAutoCasts2.dump b/idea/testData/resolve/partialBodyResolve/IfBranchesAutoCasts2.dump index 9e22be03604..186e30a76f2 100644 --- a/idea/testData/resolve/partialBodyResolve/IfBranchesAutoCasts2.dump +++ b/idea/testData/resolve/partialBodyResolve/IfBranchesAutoCasts2.dump @@ -1,4 +1,4 @@ -Resolve target: value-parameter val p1: kotlin.Any? smart-casted to kotlin.Any +Resolve target: value-parameter val p1: kotlin.Any? smart-cast to kotlin.Any Skipped statements: print(p!!) print(p2!!) diff --git a/idea/testData/resolve/partialBodyResolve/IfBranchesSmartCast.dump b/idea/testData/resolve/partialBodyResolve/IfBranchesSmartCast.dump index 1c569ab1dab..c4977876c04 100644 --- a/idea/testData/resolve/partialBodyResolve/IfBranchesSmartCast.dump +++ b/idea/testData/resolve/partialBodyResolve/IfBranchesSmartCast.dump @@ -1,2 +1,2 @@ -Resolve target: value-parameter val o: kotlin.Any? smart-casted to kotlin.Any +Resolve target: value-parameter val o: kotlin.Any? smart-cast to kotlin.Any Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfEqAutoCast.dump b/idea/testData/resolve/partialBodyResolve/IfEqAutoCast.dump index 55d4dd145f7..a37c92224ef 100644 --- a/idea/testData/resolve/partialBodyResolve/IfEqAutoCast.dump +++ b/idea/testData/resolve/partialBodyResolve/IfEqAutoCast.dump @@ -1,2 +1,2 @@ -Resolve target: value-parameter val o: kotlin.String? smart-casted to kotlin.String +Resolve target: value-parameter val o: kotlin.String? smart-cast to kotlin.String Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsError.dump b/idea/testData/resolve/partialBodyResolve/IfNotIsError.dump index 7578f928cce..7d7ee5e312e 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNotIsError.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNotIsError.dump @@ -1,2 +1,2 @@ -Resolve target: value-parameter val p: kotlin.Any smart-casted to kotlin.String +Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.dump b/idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.dump index 7578f928cce..7d7ee5e312e 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNotIsErrorQualifier.dump @@ -1,2 +1,2 @@ -Resolve target: value-parameter val p: kotlin.Any smart-casted to kotlin.String +Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsMyError.dump b/idea/testData/resolve/partialBodyResolve/IfNotIsMyError.dump index 7578f928cce..7d7ee5e312e 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNotIsMyError.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNotIsMyError.dump @@ -1,2 +1,2 @@ -Resolve target: value-parameter val p: kotlin.Any smart-casted to kotlin.String +Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsNothingProp.dump b/idea/testData/resolve/partialBodyResolve/IfNotIsNothingProp.dump index 7578f928cce..7d7ee5e312e 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNotIsNothingProp.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNotIsNothingProp.dump @@ -1,2 +1,2 @@ -Resolve target: value-parameter val p: kotlin.Any smart-casted to kotlin.String +Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsReturn.dump b/idea/testData/resolve/partialBodyResolve/IfNotIsReturn.dump index 6b805adef18..acb6ca6aaec 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNotIsReturn.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNotIsReturn.dump @@ -1,3 +1,3 @@ -Resolve target: value-parameter val p: kotlin.Any? smart-casted to kotlin.String +Resolve target: value-parameter val p: kotlin.Any? smart-cast to kotlin.String Skipped statements: print("null") diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsReturn2.dump b/idea/testData/resolve/partialBodyResolve/IfNotIsReturn2.dump index cb36d9b5d79..8abf86f91c1 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNotIsReturn2.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNotIsReturn2.dump @@ -1,2 +1,2 @@ -Resolve target: val v: kotlin.Any smart-casted to kotlin.String +Resolve target: val v: kotlin.Any smart-cast to kotlin.String Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNotIsThrow.dump b/idea/testData/resolve/partialBodyResolve/IfNotIsThrow.dump index 7578f928cce..7d7ee5e312e 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNotIsThrow.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNotIsThrow.dump @@ -1,2 +1,2 @@ -Resolve target: value-parameter val p: kotlin.Any smart-casted to kotlin.String +Resolve target: value-parameter val p: kotlin.Any smart-cast to kotlin.String Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNotNullElseReturn.dump b/idea/testData/resolve/partialBodyResolve/IfNotNullElseReturn.dump index 7034d64f6e5..c551bd13abb 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNotNullElseReturn.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNotNullElseReturn.dump @@ -1,3 +1,3 @@ -Resolve target: value-parameter val p: kotlin.Any? smart-casted to kotlin.Any +Resolve target: value-parameter val p: kotlin.Any? smart-cast to kotlin.Any Skipped statements: print("not null") diff --git a/idea/testData/resolve/partialBodyResolve/IfNullBreak.dump b/idea/testData/resolve/partialBodyResolve/IfNullBreak.dump index a7ff535776f..19278dac234 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNullBreak.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNullBreak.dump @@ -1,2 +1,2 @@ -Resolve target: val x: kotlin.Any? smart-casted to kotlin.Any +Resolve target: val x: kotlin.Any? smart-cast to kotlin.Any Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNullContinue.dump b/idea/testData/resolve/partialBodyResolve/IfNullContinue.dump index a7ff535776f..19278dac234 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNullContinue.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNullContinue.dump @@ -1,2 +1,2 @@ -Resolve target: val x: kotlin.Any? smart-casted to kotlin.Any +Resolve target: val x: kotlin.Any? smart-cast to kotlin.Any Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/IfNullReturn.dump b/idea/testData/resolve/partialBodyResolve/IfNullReturn.dump index 730615033a5..e0a888b2395 100644 --- a/idea/testData/resolve/partialBodyResolve/IfNullReturn.dump +++ b/idea/testData/resolve/partialBodyResolve/IfNullReturn.dump @@ -1,3 +1,3 @@ -Resolve target: value-parameter val p: kotlin.Any? smart-casted to kotlin.Any +Resolve target: value-parameter val p: kotlin.Any? smart-cast to kotlin.Any Skipped statements: print("null") diff --git a/idea/testData/resolve/partialBodyResolve/LocalNothingFun.dump b/idea/testData/resolve/partialBodyResolve/LocalNothingFun.dump index 2edd08e7601..01a452af78c 100644 --- a/idea/testData/resolve/partialBodyResolve/LocalNothingFun.dump +++ b/idea/testData/resolve/partialBodyResolve/LocalNothingFun.dump @@ -1,2 +1,2 @@ -Resolve target: value-parameter val p: kotlin.String? smart-casted to kotlin.String +Resolve target: value-parameter val p: kotlin.String? smart-cast to kotlin.String Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/ThisQualifiedAutoCast.dump b/idea/testData/resolve/partialBodyResolve/ThisQualifiedAutoCast.dump index 00e26f8caa3..d26b0ecf3ab 100644 --- a/idea/testData/resolve/partialBodyResolve/ThisQualifiedAutoCast.dump +++ b/idea/testData/resolve/partialBodyResolve/ThisQualifiedAutoCast.dump @@ -1,2 +1,2 @@ -Resolve target: val s: kotlin.String? smart-casted to kotlin.String +Resolve target: val s: kotlin.String? smart-cast to kotlin.String Skipped statements: diff --git a/idea/testData/resolve/partialBodyResolve/While.dump b/idea/testData/resolve/partialBodyResolve/While.dump index d19623a1327..b0cb7570bfb 100644 --- a/idea/testData/resolve/partialBodyResolve/While.dump +++ b/idea/testData/resolve/partialBodyResolve/While.dump @@ -1,3 +1,3 @@ -Resolve target: value-parameter val p: kotlin.Any? smart-casted to kotlin.Any +Resolve target: value-parameter val p: kotlin.Any? smart-cast to kotlin.Any Skipped statements: print(p1!!) diff --git a/idea/tests/org/jetbrains/jet/resolve/AbstractPartialBodyResolveTest.kt b/idea/tests/org/jetbrains/jet/resolve/AbstractPartialBodyResolveTest.kt index 29a5eb2565f..7d7b5c985d5 100644 --- a/idea/tests/org/jetbrains/jet/resolve/AbstractPartialBodyResolveTest.kt +++ b/idea/tests/org/jetbrains/jet/resolve/AbstractPartialBodyResolveTest.kt @@ -109,7 +109,7 @@ public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtur val renderType = this is VariableDescriptor && type != this.getReturnType() if (!renderType) return s - return s + " smart-casted to " + if (type != null) DescriptorRenderer.COMPACT.renderType(type) else "unknown type" + return s + " smart-cast to " + if (type != null) DescriptorRenderer.COMPACT.renderType(type) else "unknown type" } private fun JetExpression.presentation(): String {