mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: replace unnecessary boxing with Boolean constant (IDEA-152361)
This commit is contained in:
+11
@@ -99,6 +99,17 @@ public class UnnecessaryBoxingInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiExpression unboxedExpression = arguments[0];
|
||||
final Object value = ExpressionUtils.computeConstantExpression(unboxedExpression);
|
||||
if (value != null) {
|
||||
if (value == Boolean.TRUE) {
|
||||
PsiReplacementUtil.replaceExpression(expression, "java.lang.Boolean.TRUE");
|
||||
return;
|
||||
}
|
||||
else if (value == Boolean.FALSE) {
|
||||
PsiReplacementUtil.replaceExpression(expression, "java.lang.Boolean.FALSE");
|
||||
return;
|
||||
}
|
||||
}
|
||||
final String replacementText = getUnboxedExpressionText(unboxedExpression, boxedType);
|
||||
if (replacementText == null) {
|
||||
return;
|
||||
|
||||
+6
@@ -56,6 +56,12 @@ public class UnnecessaryBoxingFixTest extends IGQuickFixesTestCase {
|
||||
"Double l = 1d;");
|
||||
}
|
||||
|
||||
public void testBooleanLiteral() {
|
||||
doMemberTest(InspectionGadgetsBundle.message("unnecessary.boxing.remove.quickfix"),
|
||||
"final Boolean aBoolean = Boolean.valueOf(/**/true);",
|
||||
"final Boolean aBoolean = Boolean.TRUE;");
|
||||
}
|
||||
|
||||
public void testCast() {
|
||||
doFixTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user