"Introduce 'when' subject" intention: suggest for "this" expression

#KT-12567 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-05-14 22:54:22 +09:00
committed by Mikhail Glukhikh
parent aaf533df16
commit fef0cc5d2b
4 changed files with 22 additions and 4 deletions
@@ -59,15 +59,14 @@ fun KtWhenExpression.getSubjectToIntroduce(): KtExpression? {
for (condition in conditions) {
if (condition !is KtWhenConditionWithExpression) return null
val candidate = condition.expression?.getWhenConditionSubjectCandidate() as? KtNameReferenceExpression ?: return null
val candidate = condition.expression?.getWhenConditionSubjectCandidate() ?: return null
if (candidate !is KtNameReferenceExpression && candidate !is KtThisExpression) return null
if (lastCandidate == null) {
lastCandidate = candidate
}
else if (!lastCandidate.matches(candidate)) {
} else if (!lastCandidate.matches(candidate)) {
return null
}
}
}
@@ -0,0 +1,7 @@
fun Number.test() {
<caret>when {
this is Int -> {}
this is Long -> {}
this is Short -> {}
}
}
@@ -0,0 +1,7 @@
fun Number.test() {
<caret>when (this) {
is Int -> {}
is Long -> {}
is Short -> {}
}
}
@@ -460,6 +460,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/branched/introduceWhenSubject/lineBreaksAndComments.kt");
}
@TestMetadata("this.kt")
public void testThis() throws Exception {
runTest("idea/testData/inspectionsLocal/branched/introduceWhenSubject/this.kt");
}
@TestMetadata("whenWithEqualityTests.kt")
public void testWhenWithEqualityTests() throws Exception {
runTest("idea/testData/inspectionsLocal/branched/introduceWhenSubject/whenWithEqualityTests.kt");