mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ConvertSwitchToIfIntention: preserve comments from expression when only default branch is present
This commit is contained in:
+5
-3
@@ -91,7 +91,6 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
return;
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
commentTracker.markUnchanged(switchExpression);
|
||||
final boolean isSwitchOnString = switchExpressionType.equalsToText(CommonClassNames.JAVA_LANG_STRING);
|
||||
boolean useEquals = isSwitchOnString;
|
||||
if (!useEquals) {
|
||||
@@ -114,8 +113,11 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
final boolean hadSideEffects;
|
||||
final String expressionText;
|
||||
final Project project = switchStatement.getProject();
|
||||
if (allBranches.stream().mapToInt(br -> br.getCaseValues().size()).sum() > 1 &&
|
||||
RemoveUnusedVariableUtil.checkSideEffects(switchExpression, null, new ArrayList<>())) {
|
||||
int totalCases = allBranches.stream().mapToInt(br -> br.getCaseValues().size()).sum();
|
||||
if (totalCases > 0) {
|
||||
commentTracker.markUnchanged(switchExpression);
|
||||
}
|
||||
if (totalCases > 1 && RemoveUnusedVariableUtil.checkSideEffects(switchExpression, null, new ArrayList<>())) {
|
||||
hadSideEffects = true;
|
||||
|
||||
final String variableName = new VariableNameGenerator(switchExpression, VariableKind.LOCAL_VARIABLE)
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
// "Unwrap 'switch'" "true"
|
||||
class X {
|
||||
String test(char c) {
|
||||
/*comment*/
|
||||
if (c == 'a') {
|
||||
System.out.println("foo");
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// "Unwrap 'switch'" "true"
|
||||
class X {
|
||||
String test(char c) {
|
||||
s<caret>witch (c) {
|
||||
s<caret>witch (c/*comment*/) {
|
||||
default:
|
||||
if(c == 'a') {
|
||||
System.out.println("foo");
|
||||
|
||||
Reference in New Issue
Block a user