mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: compute constant value shouldn't be available on parentheses (IDEA-367924)
GitOrigin-RevId: bc1540b49e395db9385ba3e87bb3930014907dd1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
10011c9b79
commit
abf7dd20c2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.siyeh.ig.style;
|
||||
|
||||
import com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool;
|
||||
@@ -59,7 +59,7 @@ public final class ConstantExpressionInspection extends AbstractBaseJavaLocalIns
|
||||
}
|
||||
|
||||
private void handle(@NotNull PsiExpression expression) {
|
||||
if (expression instanceof PsiLiteralExpression) return;
|
||||
if (expression instanceof PsiLiteralExpression || expression instanceof PsiParenthesizedExpression) return;
|
||||
// inspection disabled for long expressions because of performance issues on
|
||||
// relatively common large string expressions.
|
||||
Object value = computeConstant(expression);
|
||||
@@ -84,13 +84,11 @@ public final class ConstantExpressionInspection extends AbstractBaseJavaLocalIns
|
||||
}
|
||||
|
||||
private @Nullable Object computeConstant(PsiExpression expression) {
|
||||
if (expression.getTextLength() > MAX_EXPRESSION_LENGTH) return null;
|
||||
if (expression.getType() == null) return null;
|
||||
if (expression.getTextLength() > MAX_EXPRESSION_LENGTH || expression.getType() == null) return null;
|
||||
Object value = computeValue(expression);
|
||||
if (value == null) return null;
|
||||
final PsiExpression parent = getParentExpression(expression);
|
||||
if (parent != null && computeValue(parent) != null) return null;
|
||||
return value;
|
||||
return (parent != null && computeValue(parent) != null) ? null : value;
|
||||
}
|
||||
|
||||
private Object computeValue(PsiExpression expression) {
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Fix all 'Constant expression can be evaluated' problems in file" "false"
|
||||
class Test {
|
||||
double d = ((((<caret>0.1))));
|
||||
String s = ((((("asdf")))));
|
||||
}
|
||||
Reference in New Issue
Block a user