[java-inspections] ConstantExpressionInspection: minor fixes

1. Disable for literals
2. Checkbox description moved to the form

GitOrigin-RevId: 48303e0c704ef9db5e09f64f34d3ee32d2743194
This commit is contained in:
Tagir Valeev
2023-08-04 15:20:12 +00:00
committed by intellij-monorepo-bot
parent 70dc1b43b7
commit 13cf92eb7f
4 changed files with 16 additions and 7 deletions
@@ -2259,6 +2259,8 @@ inspection.constant.expression.fix.name.short=Replace with constant value
inspection.constant.expression.fix.name.with.value=Replace ''{0}'' with constant value ''{1}''
inspection.constant.expression.fix.family.name=Compute constant value
inspection.constant.expression.skip.non.literal=Don't report when the expression contains references to defined constants
inspection.constant.expression.skip.non.literal.description=Ignore the expressions which contain references to non-literal operands, \
such as fields, and variables.
inspection.constant.expression.report.compile.time=Report only compile time constants
inspection.constant.expression.report.compile.time.description=By default, the inspection can evaluate some constants that involve \
library method calls, or even deduce the constant value based on the surrounding code. \
@@ -38,7 +38,8 @@ public class ConstantExpressionInspection extends AbstractBaseJavaLocalInspectio
public @NotNull OptPane getOptionsPane() {
return OptPane.pane(
OptPane.checkbox("skipIfContainsReferenceExpression",
InspectionGadgetsBundle.message("inspection.constant.expression.skip.non.literal")),
InspectionGadgetsBundle.message("inspection.constant.expression.skip.non.literal"))
.description(InspectionGadgetsBundle.message("inspection.constant.expression.skip.non.literal.description")),
OptPane.checkbox("reportOnlyCompileTimeConstants",
InspectionGadgetsBundle.message("inspection.constant.expression.report.compile.time"))
.description(InspectionGadgetsBundle.message("inspection.constant.expression.report.compile.time.description")));
@@ -59,6 +60,7 @@ public class ConstantExpressionInspection extends AbstractBaseJavaLocalInspectio
}
private void handle(@NotNull PsiExpression expression) {
if (expression instanceof PsiLiteralExpression) return;
// inspection disabled for long expressions because of performance issues on
// relatively common large string expressions.
Object value = computeConstant(expression);
@@ -1,12 +1,10 @@
<html>
<body>
Reports compile-time constant expressions and suggests replacing them with their
actual values. For example, you will be prompted to replace "2 + 2" with "4".
Reports constant expressions, whose value can be evaluated statically,
and suggests replacing them with their actual values.
For example, you will be prompted to replace <code>2 + 2</code> with <code>4</code>,
or <code>Math.sqrt(9.0)</code> with <code>3.0</code>.
<!-- tooltip end -->
<p>
Use the <b>Don't report when the expression contains references to defined constants</b> option to ignore the expressions which contain references to non-literal operands,
such as fields, and variables.
<p><small>New in 2018.1</small></p>
</body>
</html>
@@ -0,0 +1,7 @@
// "Compute constant value of '""" ...'" "false"
class Literal {
void test() {
System.out.println("""
<caret>Hello""");
}
}