IDEA-270441 IJ-CR-12027 convert switch to if: fix "null" class name for local Enums

GitOrigin-RevId: bd6d592522e497f7897c92799333630d611dc6e1
This commit is contained in:
Alexandr Suhinin
2021-07-20 10:46:10 +03:00
committed by intellij-monorepo-bot
parent 0bf2802f19
commit 8496dd3b7f
3 changed files with 27 additions and 1 deletions

View File

@@ -375,7 +375,9 @@ public class ConvertSwitchToIfIntention implements IntentionActionWithFixAllOpti
if (aClass == null) {
return commentTracker.text(value);
}
return aClass.getQualifiedName() + '.' + commentTracker.text(referenceExpression);
String qualifiedName = aClass.getQualifiedName();
String className = qualifiedName != null ? qualifiedName : aClass.getName();
return className + '.' + commentTracker.text(referenceExpression);
}
private static void dumpBody(SwitchStatementBranch branch, @NonNls StringBuilder out, CommentTracker commentTracker) {

View File

@@ -0,0 +1,11 @@
// "Replace 'switch' with 'if'" "true"
class Test {
void test() {
enum P {
s;
}
P p = null;
if (p == P.s) {
}
}
}

View File

@@ -0,0 +1,13 @@
// "Replace 'switch' with 'if'" "true"
class Test {
void test() {
enum P {
s;
}
P p = null;
<caret>switch (p) {
case s -> {}
default -> {}
}
}
}