ConstantExpressionInspection: make it working inside parentheses

This commit is contained in:
Tagir Valeev
2018-07-05 13:25:29 +07:00
parent ee8d7915e8
commit 5fc5a86cdf
3 changed files with 9 additions and 1 deletions
@@ -0,0 +1,4 @@
// "Replace '"a" + "b"' with constant value '"ab"'" "true"
class Test {
String x = ("ab");
}
@@ -0,0 +1,4 @@
// "Replace '"a" + "b"' with constant value '"ab"'" "true"
class Test {
String x = ("a" + <caret>"b");
}
@@ -43,7 +43,7 @@ public class ConstantExpressionInspection extends AbstractBaseJavaLocalInspectio
if (expression.getTextLength() > MAX_EXPRESSION_LENGTH) return;
if (expression.getType() == null) return;
if (!PsiUtil.isConstantExpression(expression)) return;
final PsiElement parent = expression.getParent();
final PsiElement parent = PsiUtil.skipParenthesizedExprUp(expression.getParent());
if (parent instanceof PsiExpression && PsiUtil.isConstantExpression((PsiExpression)parent)) return;
try {
final Object value = ExpressionUtils.computeConstantExpression(expression, true);