ManualMinMaxCalculationInspection: remove implicit else branch during replacement (IDEA-221837)

GitOrigin-RevId: 68d542bcaa2ccaffa7b8b82a2f5a909ae08d2fd6
This commit is contained in:
Artemiy Sartakov
2019-09-16 17:33:53 +00:00
committed by intellij-monorepo-bot
parent 5c617cde0e
commit ed0eda2fbb
3 changed files with 22 additions and 0 deletions
@@ -140,6 +140,10 @@ public class ManualMinMaxCalculationInspection extends AbstractBaseJavaLocalInsp
CommentTracker tracker = new CommentTracker();
PsiStatement thenBranch = model.getThenBranch();
tracker.text(thenBranch);
PsiStatement elseBranch = model.getElseBranch();
if (!PsiTreeUtil.isAncestor(ifStatement, elseBranch, true)) {
new CommentTracker().deleteAndRestoreComments(elseBranch);
}
PsiElement result = PsiReplacementUtil.replaceStatement(ifStatement, thenBranch.getText(), tracker);
SimplifiableIfStatementInspection.tryJoinDeclaration(result);
}
@@ -0,0 +1,8 @@
// "Replace with 'Math.min'" "true"
class Test {
public int mymin(int a, int b) {
return Math.min(a, b);
/*comment*/
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Math.min'" "true"
class Test {
public int mymin(int a, int b) {
if<caret>(a < b) {
return a;
}
return (/*comment*/(b));
}
}