mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
Java: Fixed "Unwrap else branch" - create consistent PSI (IDEA-192543)
This commit is contained in:
@@ -44,9 +44,10 @@ public class UnwrapElseBranchAction extends PsiElementBaseIntentionAction {
|
||||
if (elseBranch != null && grandParent != null) {
|
||||
if (!(grandParent instanceof PsiCodeBlock)) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
|
||||
PsiCodeBlock codeBlock = factory.createCodeBlockFromText("{" + ifStatement.getText() + "}", ifStatement);
|
||||
codeBlock = (PsiCodeBlock)ifStatement.replace(codeBlock);
|
||||
ifStatement = (PsiIfStatement)codeBlock.getStatements()[0];
|
||||
PsiBlockStatement blockStatement =
|
||||
(PsiBlockStatement)factory.createStatementFromText("{" + ifStatement.getText() + "}", ifStatement);
|
||||
blockStatement = (PsiBlockStatement)ifStatement.replace(blockStatement);
|
||||
ifStatement = (PsiIfStatement)blockStatement.getCodeBlock().getStatements()[0];
|
||||
elseBranch = ifStatement.getElseBranch();
|
||||
LOG.assertTrue(elseBranch != null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Unwrap 'else' branch" "true"
|
||||
|
||||
class T {
|
||||
String f(boolean a, boolean b) {
|
||||
if (b) {
|
||||
return "When true";
|
||||
} else {
|
||||
if (a) {
|
||||
return "a";
|
||||
}
|
||||
return "Otherwise";
|
||||
}
|
||||
return "Default";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Unwrap 'else' branch" "true"
|
||||
|
||||
class T {
|
||||
String f(boolean a, boolean b) {
|
||||
if (b) {
|
||||
return "When true";
|
||||
} else if (a) {
|
||||
return "a";
|
||||
} <caret>else {
|
||||
return "Otherwise";
|
||||
}
|
||||
return "Default";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user