"Introduce 'when' subject" intention: suggest for "this" expression
#KT-12567 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
aaf533df16
commit
fef0cc5d2b
+3
-4
@@ -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 -> {}
|
||||
}
|
||||
}
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user