mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Unwrap break-with-value when the value is a switch expression (IDEA-204393)
This commit is contained in:
+7
-1
@@ -93,8 +93,14 @@ public class RedundantLabeledSwitchRuleCodeBlockInspection extends LocalInspecti
|
||||
private static void unwrapBreakValue(PsiStatement body, PsiBreakStatement breakStatement) {
|
||||
PsiExpression valueExpression = breakStatement.getValueExpression();
|
||||
if (valueExpression != null) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(body.getProject());
|
||||
PsiExpressionStatement statement = (PsiExpressionStatement)factory.createStatementFromText("x=1;", body);
|
||||
statement.getExpression().replace(valueExpression);
|
||||
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
tracker.replaceAndRestoreComments(body, tracker.text(valueExpression) + ';');
|
||||
// replaceAndRestoreComments() will work with a copy of the expression so it won't see the original comments
|
||||
tracker.markUnchanged(valueExpression);
|
||||
tracker.replaceAndRestoreComments(body, statement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Unwrap code block of labeled rule" "LIKE_UNUSED_SYMBOL"
|
||||
class C {
|
||||
int foo(final int x, int n) {
|
||||
return switch (x) {
|
||||
case 0 -> /*1*/ /*3*/ //4
|
||||
switch (n) { // 2
|
||||
case 0 -> 0;
|
||||
default -> 1;
|
||||
};
|
||||
default -> 2;
|
||||
};
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Unwrap code block of labeled rule" "LIKE_UNUSED_SYMBOL"
|
||||
class C {
|
||||
int foo(final int x, int n) {
|
||||
return switch (x) {
|
||||
case 0 -> {
|
||||
<caret>break /*1*/ switch (n) { // 2
|
||||
case 0 -> 0;
|
||||
default -> 1;
|
||||
}/*3*/; //4
|
||||
}
|
||||
default -> 2;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user