mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
IDEA-231280 Quick fix for compare() method can be used to compare numbers generates broken code
Also declaration is joined automatically GitOrigin-RevId: f94ddf5ae3e94edffdb44cd56ad6bf8b3a9054b4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e512fa3c6a
commit
619bfa9963
@@ -13,6 +13,7 @@ import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import com.siyeh.ig.psiutils.ControlFlowUtils;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ig.style.SimplifiableIfStatementInspection;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -102,7 +103,7 @@ public class UseCompareMethodInspection extends AbstractBaseJavaLocalInspectionT
|
||||
if (!storeCondition(result, firstCondition, firstExpression)) return null;
|
||||
if (!storeCondition(result, secondCondition, ExpressionUtils.getAssignmentTo(secondStatement, variable))) return null;
|
||||
if (!storeCondition(result, null, ExpressionUtils.getAssignmentTo(thirdStatement, variable))) return null;
|
||||
return fromMap(result, firstExpression, assignment);
|
||||
return fromMap(result, firstExpression, firstStatement);
|
||||
}
|
||||
|
||||
private static PsiStatement getElse(PsiIfStatement ifStatement) {
|
||||
@@ -299,7 +300,7 @@ public class UseCompareMethodInspection extends AbstractBaseJavaLocalInspectionT
|
||||
myClass = aClass;
|
||||
}
|
||||
|
||||
private void replace(PsiElement toReplace, CommentTracker ct) {
|
||||
private @NotNull PsiElement replace(PsiElement toReplace, CommentTracker ct) {
|
||||
String replacement;
|
||||
if (this.myLeft.getType() instanceof PsiClassType) {
|
||||
replacement = ct.text(this.myLeft, ParenthesesUtils.METHOD_CALL_PRECEDENCE) + ".compareTo(" + ct.text(this.myRight) + ")";
|
||||
@@ -307,10 +308,10 @@ public class UseCompareMethodInspection extends AbstractBaseJavaLocalInspectionT
|
||||
replacement = this.myClass.getCanonicalText() + ".compare(" + ct.text(this.myLeft) + "," + ct.text(this.myRight) + ")";
|
||||
}
|
||||
if(toReplace == myTemplate) {
|
||||
ct.replaceAndRestoreComments(myToReplace, replacement);
|
||||
return ct.replaceAndRestoreComments(myToReplace, replacement);
|
||||
} else {
|
||||
ct.replace(myToReplace, replacement);
|
||||
ct.replaceAndRestoreComments(toReplace, myTemplate);
|
||||
return ct.replaceAndRestoreComments(toReplace, myTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,8 +370,9 @@ public class UseCompareMethodInspection extends AbstractBaseJavaLocalInspectionT
|
||||
}
|
||||
if (info == null) return;
|
||||
CommentTracker ct = new CommentTracker();
|
||||
info.replace(toReplace, ct);
|
||||
PsiElement result = info.replace(toReplace, ct);
|
||||
StreamEx.of(toDelete).nonNull().filter(PsiElement::isValid).forEach(e -> new CommentTracker().deleteAndRestoreComments(e));
|
||||
SimplifiableIfStatementInspection.tryJoinDeclaration(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user