From 0d23cefe7009c27c42df97adf12e0e5dffca60d6 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Fri, 26 Jan 2018 12:36:52 +0700 Subject: [PATCH] ConstantExpressionInspection: display computed value in inspection message, cosmetics Review ID: IDEA-CR-28753 --- .../com/siyeh/InspectionGadgetsBundle.properties | 1 + .../ig/style/ConstantExpressionInspection.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties index 567a27878581..772bb038de76 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties @@ -2264,6 +2264,7 @@ fix.add.argument.family.name=Add argument fix.add.argument.name=Add ''{0}'' argument inspection.constant.expression.display.name=Constant expression can be evaluated +inspection.constant.expression.message=Constant expression can be evaluated to ''{0}'' inspection.constant.expression.fix.name=Compute constant value of ''{0}'' inspection.constant.expression.fix.name.with.value=Replace ''{0}'' with constant value ''{1}'' inspection.constant.expression.fix.family.name=Compute constant value 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 cfb216173340..314c4d640eef 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantExpressionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantExpressionInspection.java @@ -20,6 +20,9 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; public class ConstantExpressionInspection extends AbstractBaseJavaLocalInspectionTool { + private static final int MAX_RESULT_LENGTH_TO_DISPLAY = 50; + private static final int MAX_EXPRESSION_LENGTH = 200; + @NotNull @Override public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { @@ -35,9 +38,9 @@ public class ConstantExpressionInspection extends AbstractBaseJavaLocalInspectio } void handle(PsiExpression expression) { - // intention disabled for long expressions because of performance issues on + // inspection disabled for long expressions because of performance issues on // relatively common large string expressions. - if (expression.getTextLength() > 200) return; + if (expression.getTextLength() > MAX_EXPRESSION_LENGTH) return; if (expression.getType() == null) return; if (!PsiUtil.isConstantExpression(expression)) return; final PsiElement parent = expression.getParent(); @@ -47,7 +50,10 @@ public class ConstantExpressionInspection extends AbstractBaseJavaLocalInspectio if (value != null) { String valueText = getValueText(value); if (!expression.textMatches(valueText)) { - holder.registerProblem(expression, InspectionGadgetsBundle.message("inspection.constant.expression.display.name"), + String message = valueText.length() > MAX_RESULT_LENGTH_TO_DISPLAY ? + InspectionGadgetsBundle.message("inspection.constant.expression.display.name") : + InspectionGadgetsBundle.message("inspection.constant.expression.message", valueText); + holder.registerProblem(expression, message, new ComputeConstantValueFix(expression, valueText)); } } @@ -71,7 +77,7 @@ public class ConstantExpressionInspection extends AbstractBaseJavaLocalInspectio @NotNull @Override public String getName() { - if (myValueText.length() > 50) { + if (myValueText.length() > MAX_RESULT_LENGTH_TO_DISPLAY) { return InspectionGadgetsBundle.message("inspection.constant.expression.fix.name", myText); } return InspectionGadgetsBundle.message("inspection.constant.expression.fix.name.with.value", myText, myValueText);