IG: don't try to convert hex and octal to float literal (IDEA-186852)

This commit is contained in:
Bas Leijdekkers
2018-02-18 15:41:37 +01:00
parent e9f93ef9e8
commit d6f4db2b1b
2 changed files with 20 additions and 6 deletions
@@ -138,12 +138,14 @@ public class UnnecessaryBoxingInspection extends BaseInspection {
if (unboxedType.equals(PsiType.LONG) && expressionType.equals(PsiType.INT)) {
return text + 'L';
}
else if (unboxedType.equals(PsiType.FLOAT) && (expressionType.equals(PsiType.INT) || (expressionType.equals(PsiType.DOUBLE)) &&
!StringUtil.endsWithIgnoreCase(text, "d"))) {
return text + 'f';
}
else if (unboxedType.equals(PsiType.DOUBLE) && expressionType.equals(PsiType.INT)) {
return text + 'd';
else if (!text.startsWith("0")) { // no octal & hex
if (unboxedType.equals(PsiType.FLOAT) && (expressionType.equals(PsiType.INT) || (expressionType.equals(PsiType.DOUBLE)) &&
!StringUtil.endsWithIgnoreCase(text, "d"))) {
return text + 'f';
}
else if (unboxedType.equals(PsiType.DOUBLE) && expressionType.equals(PsiType.INT)) {
return text + 'd';
}
}
}
if (ParenthesesUtils.getPrecedence(unboxedExpression) > ParenthesesUtils.TYPE_CAST_PRECEDENCE) {
@@ -74,6 +74,18 @@ public class UnnecessaryBoxingFixTest extends IGQuickFixesTestCase {
"\"a\" + (1L - 2L) + \"b\"");
}
public void testHex() {
doMemberTest(InspectionGadgetsBundle.message("unnecessary.boxing.remove.quickfix"),
"float f = Float./**/valueOf(0x123);",
"float f = (float) 0x123;");
}
public void testOctal() {
doMemberTest(InspectionGadgetsBundle.message("unnecessary.boxing.remove.quickfix"),
"float f = Float.valueOf/**/(0123);",
"float f = (float) 0123;");
}
public void testCast() {
doFixTest();
}