diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/constantExpression/afterParens.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/constantExpression/afterParens.java new file mode 100644 index 000000000000..04c227e9eff7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/constantExpression/afterParens.java @@ -0,0 +1,4 @@ +// "Replace '"a" + "b"' with constant value '"ab"'" "true" +class Test { + String x = ("ab"); +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/constantExpression/beforeParens.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/constantExpression/beforeParens.java new file mode 100644 index 000000000000..a38d9078f581 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/constantExpression/beforeParens.java @@ -0,0 +1,4 @@ +// "Replace '"a" + "b"' with constant value '"ab"'" "true" +class Test { + String x = ("a" + "b"); +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantExpressionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantExpressionInspection.java index 9abc08662d30..8df880c11578 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantExpressionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantExpressionInspection.java @@ -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);