mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
Java: don't report casts of constants (IDEA-373869)
in "Constant expression can be evaluated" inspection GitOrigin-RevId: aa1bac4aef1e306c5c9671b9cdf3aca638feb95b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7a4ff0ad80
commit
0a60753921
@@ -59,9 +59,14 @@ public final class ConstantExpressionInspection extends AbstractBaseJavaLocalIns
|
||||
}
|
||||
|
||||
private void handle(@NotNull PsiExpression expression) {
|
||||
if (expression instanceof PsiLiteralExpression || expression instanceof PsiParenthesizedExpression) return;
|
||||
// inspection disabled for long expressions because of performance issues on
|
||||
// relatively common large string expressions.
|
||||
if (expression instanceof PsiLiteralExpression
|
||||
|| expression instanceof PsiParenthesizedExpression
|
||||
|| expression instanceof PsiTypeCastExpression) {
|
||||
// inspection disabled for long expressions because of performance issues on
|
||||
// relatively common large string expressions.
|
||||
// casts and parentheses are handled by other inspections
|
||||
return;
|
||||
}
|
||||
Object value = computeConstant(expression);
|
||||
if (value == null) return;
|
||||
if (value instanceof PsiField && !(value instanceof PsiEnumConstant)) return;
|
||||
@@ -162,8 +167,8 @@ public final class ConstantExpressionInspection extends AbstractBaseJavaLocalIns
|
||||
else if (value instanceof Long) {
|
||||
newExpression = value.toString() + 'L';
|
||||
}
|
||||
else if (value instanceof Double) {
|
||||
final double v = ((Double)value).doubleValue();
|
||||
else if (value instanceof Double d) {
|
||||
final double v = d.doubleValue();
|
||||
if (Double.isNaN(v)) {
|
||||
newExpression = "java.lang.Double.NaN";
|
||||
}
|
||||
@@ -179,8 +184,8 @@ public final class ConstantExpressionInspection extends AbstractBaseJavaLocalIns
|
||||
newExpression = Double.toString(v);
|
||||
}
|
||||
}
|
||||
else if (value instanceof Float) {
|
||||
final float v = ((Float)value).floatValue();
|
||||
else if (value instanceof Float f) {
|
||||
final float v = f.floatValue();
|
||||
if (Float.isNaN(v)) {
|
||||
newExpression = "java.lang.Float.NaN";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Fix all 'Constant expression can be evaluated' problems in file" "false"
|
||||
|
||||
class ConstantCast {
|
||||
static void doSomething(String param1, byte param2) {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
doSomething(args[0], (byte)<caret> 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user